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