Mercurial > projects > dwt-samples
comparison jface/snippets/Snippet001TableViewer.d @ 89:cbba80cceb7a
Port of jface Snippets 1,2,4,5,7
author | Bill Baxter <bill@billbaxter.com> |
---|---|
date | Mon, 19 May 2008 23:42:48 +0900 |
parents | |
children | 42c3056512ba |
comparison
equal
deleted
inserted
replaced
88:9ed020f0c2a5 | 89:cbba80cceb7a |
---|---|
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 | |
14 module jface.snippets.Snippet001TableViewer; | |
15 | |
16 import dwtx.jface.viewers.IStructuredContentProvider; | |
17 import dwtx.jface.viewers.LabelProvider; | |
18 import dwtx.jface.viewers.TableViewer; | |
19 import dwtx.jface.viewers.Viewer; | |
20 import dwt.layout.FillLayout; | |
21 import dwt.widgets.Display; | |
22 import dwt.widgets.Shell; | |
23 import dwt.DWT; | |
24 | |
25 import dwt.dwthelper.utils; | |
26 | |
27 import tango.util.Convert; | |
28 import tango.util.collection.ArraySeq; | |
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(ArraySeq!(MyModel))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 ArraySeq!(MyModel) model = createModel(); | |
79 v.setInput(model); | |
80 v.getTable().setLinesVisible(true); | |
81 } | |
82 | |
83 private ArraySeq!(MyModel) createModel() { | |
84 ArraySeq!(MyModel) elements = new ArraySeq!(MyModel); | |
85 elements.capacity = 10; | |
86 | |
87 for( int i = 0; i < 10; i++ ) { | |
88 elements ~= new MyModel(i); | |
89 } | |
90 | |
91 return elements; | |
92 } | |
93 | |
94 } | |
95 | |
96 void main() | |
97 { | |
98 Display display = new Display (); | |
99 Shell shell = new Shell(display); | |
100 shell.setLayout(new FillLayout()); | |
101 new Snippet001TableViewer(shell); | |
102 shell.open (); | |
103 | |
104 while (!shell.isDisposed ()) { | |
105 if (!display.readAndDispatch ()) display.sleep (); | |
106 } | |
107 | |
108 display.dispose (); | |
109 | |
110 } | |
111 |