Mercurial > projects > dwt-samples
annotate jface/snippets/viewers/Snippet001TableViewer.d @ 145:161f7698cfb8
Moved jface snippets to viewers subpackage, there are more with conflicting numbers for other packages
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Fri, 08 Aug 2008 14:40:21 +0200 |
parents | jface/snippets/Snippet001TableViewer.d@42c3056512ba |
children |
rev | line source |
---|---|
89
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
1 /******************************************************************************* |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
2 * Copyright (c) 2006 Tom Schindl and others. |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
3 * All rights reserved. This program and the accompanying materials |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
4 * are made available under the terms of the Eclipse Public License v1.0 |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
5 * which accompanies this distribution, and is available at |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
6 * http://www.eclipse.org/legal/epl-v10.html |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
7 * |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
8 * Contributors: |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
9 * Tom Schindl - initial API and implementation |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
10 * Port to the D programming language: |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
11 * wbaxter at gmail dot com |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
12 *******************************************************************************/ |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
13 |
145
161f7698cfb8
Moved jface snippets to viewers subpackage, there are more with conflicting numbers for other packages
Frank Benoit <benoit@tionex.de>
parents:
143
diff
changeset
|
14 module snippets.viewers.Snippet001TableViewer; |
89
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
15 |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
16 import dwtx.jface.viewers.IStructuredContentProvider; |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
17 import dwtx.jface.viewers.LabelProvider; |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
18 import dwtx.jface.viewers.TableViewer; |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
19 import dwtx.jface.viewers.Viewer; |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
20 import dwt.layout.FillLayout; |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
21 import dwt.widgets.Display; |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
22 import dwt.widgets.Shell; |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
23 import dwt.DWT; |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
24 |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
25 import dwt.dwthelper.utils; |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
26 |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
27 import tango.util.Convert; |
143
42c3056512ba
redirect the jface examples to the new collection wrappers
Frank Benoit <benoit@tionex.de>
parents:
89
diff
changeset
|
28 import dwtx.dwtxhelper.Collection; |
89
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
29 |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
30 /** |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
31 * A simple TableViewer to demonstrate usage |
143
42c3056512ba
redirect the jface examples to the new collection wrappers
Frank Benoit <benoit@tionex.de>
parents:
89
diff
changeset
|
32 * |
89
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
33 * @author Tom Schindl <tom.schindl@bestsolution.at> |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
34 * |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
35 */ |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
36 public class Snippet001TableViewer { |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
37 private class MyContentProvider : IStructuredContentProvider { |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
38 |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
39 /* (non-Javadoc) |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
40 * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
41 */ |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
42 public Object[] getElements(Object inputElement) { |
143
42c3056512ba
redirect the jface examples to the new collection wrappers
Frank Benoit <benoit@tionex.de>
parents:
89
diff
changeset
|
43 return (cast(ArrayList)inputElement).toArray; |
89
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
44 } |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
45 |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
46 /* (non-Javadoc) |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
47 * @see org.eclipse.jface.viewers.IContentProvider#dispose() |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
48 */ |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
49 public void dispose() { |
143
42c3056512ba
redirect the jface examples to the new collection wrappers
Frank Benoit <benoit@tionex.de>
parents:
89
diff
changeset
|
50 |
89
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
51 } |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
52 |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
53 /* (non-Javadoc) |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
54 * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
55 */ |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
56 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { |
143
42c3056512ba
redirect the jface examples to the new collection wrappers
Frank Benoit <benoit@tionex.de>
parents:
89
diff
changeset
|
57 |
89
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
58 } |
143
42c3056512ba
redirect the jface examples to the new collection wrappers
Frank Benoit <benoit@tionex.de>
parents:
89
diff
changeset
|
59 |
89
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
60 } |
143
42c3056512ba
redirect the jface examples to the new collection wrappers
Frank Benoit <benoit@tionex.de>
parents:
89
diff
changeset
|
61 |
89
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
62 public class MyModel { |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
63 public int counter; |
143
42c3056512ba
redirect the jface examples to the new collection wrappers
Frank Benoit <benoit@tionex.de>
parents:
89
diff
changeset
|
64 |
89
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
65 public this(int counter) { |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
66 this.counter = counter; |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
67 } |
143
42c3056512ba
redirect the jface examples to the new collection wrappers
Frank Benoit <benoit@tionex.de>
parents:
89
diff
changeset
|
68 |
89
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
69 public String toString() { |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
70 return "Item " ~ to!(char[])(this.counter); |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
71 } |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
72 } |
143
42c3056512ba
redirect the jface examples to the new collection wrappers
Frank Benoit <benoit@tionex.de>
parents:
89
diff
changeset
|
73 |
89
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
74 public this(Shell shell) { |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
75 final TableViewer v = new TableViewer(shell); |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
76 v.setLabelProvider(new LabelProvider()); |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
77 v.setContentProvider(new MyContentProvider()); |
143
42c3056512ba
redirect the jface examples to the new collection wrappers
Frank Benoit <benoit@tionex.de>
parents:
89
diff
changeset
|
78 ArrayList model = createModel(); |
89
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
79 v.setInput(model); |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
80 v.getTable().setLinesVisible(true); |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
81 } |
143
42c3056512ba
redirect the jface examples to the new collection wrappers
Frank Benoit <benoit@tionex.de>
parents:
89
diff
changeset
|
82 |
42c3056512ba
redirect the jface examples to the new collection wrappers
Frank Benoit <benoit@tionex.de>
parents:
89
diff
changeset
|
83 private ArrayList createModel() { |
42c3056512ba
redirect the jface examples to the new collection wrappers
Frank Benoit <benoit@tionex.de>
parents:
89
diff
changeset
|
84 ArrayList elements = new ArrayList(10); |
89
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
85 |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
86 for( int i = 0; i < 10; i++ ) { |
143
42c3056512ba
redirect the jface examples to the new collection wrappers
Frank Benoit <benoit@tionex.de>
parents:
89
diff
changeset
|
87 elements.add( new MyModel(i)); |
89
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
88 } |
143
42c3056512ba
redirect the jface examples to the new collection wrappers
Frank Benoit <benoit@tionex.de>
parents:
89
diff
changeset
|
89 |
89
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
90 return elements; |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
91 } |
143
42c3056512ba
redirect the jface examples to the new collection wrappers
Frank Benoit <benoit@tionex.de>
parents:
89
diff
changeset
|
92 |
89
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
93 } |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
94 |
143
42c3056512ba
redirect the jface examples to the new collection wrappers
Frank Benoit <benoit@tionex.de>
parents:
89
diff
changeset
|
95 void main() |
89
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
96 { |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
97 Display display = new Display (); |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
98 Shell shell = new Shell(display); |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
99 shell.setLayout(new FillLayout()); |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
100 new Snippet001TableViewer(shell); |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
101 shell.open (); |
143
42c3056512ba
redirect the jface examples to the new collection wrappers
Frank Benoit <benoit@tionex.de>
parents:
89
diff
changeset
|
102 |
89
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
103 while (!shell.isDisposed ()) { |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
104 if (!display.readAndDispatch ()) display.sleep (); |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
105 } |
143
42c3056512ba
redirect the jface examples to the new collection wrappers
Frank Benoit <benoit@tionex.de>
parents:
89
diff
changeset
|
106 |
89
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
107 display.dispose (); |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
108 |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
109 } |
cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
Bill Baxter <bill@billbaxter.com>
parents:
diff
changeset
|
110 |