comparison jface/snippets/viewers/Snippet016TableLayout.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/Snippet016TableLayout.d@79ace43ff0a4
children
comparison
equal deleted inserted replaced
144:7248e4c09c4f 145:161f7698cfb8
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 * yidabu at gmail dot com ( D China http://www.d-programming-language-china.org/ )
12 *******************************************************************************/
13
14 module snippets.viewers.Snippet016TableLayout;
15
16
17 import dwtx.jface.layout.TableColumnLayout;
18 import dwtx.jface.viewers.ColumnWeightData;
19 import dwtx.jface.viewers.IStructuredContentProvider;
20 import dwtx.jface.viewers.ITableLabelProvider;
21 import dwtx.jface.viewers.LabelProvider;
22 import dwtx.jface.viewers.TableViewer;
23 import dwtx.jface.viewers.Viewer;
24 import dwt.DWT;
25 import dwt.graphics.Image;
26 import dwt.layout.FillLayout;
27 import dwt.widgets.Composite;
28 import dwt.widgets.Display;
29 import dwt.widgets.Shell;
30 import dwt.widgets.Table;
31 import dwt.widgets.TableColumn;
32
33 import dwt.dwthelper.utils;
34
35 import tango.util.Convert;
36 /**
37 * @param args
38 */
39 void main(String[] args) {
40 Display display = new Display();
41 Shell shell = new Shell(display);
42 //shell.setSize(400, 150);
43 shell.setLayout(new FillLayout());
44
45 new Snippet016TableLayout(shell);
46 shell.open();
47
48 while (!shell.isDisposed()) {
49 if (!display.readAndDispatch())
50 display.sleep();
51 }
52
53 display.dispose();
54
55 }
56
57 /**
58 * A simple TableViewer to demonstrate usage
59 *
60 * @author Tom Schindl <tom.schindl@bestsolution.at>
61 * @since 3.3M3
62 */
63 public class Snippet016TableLayout {
64 private class MyContentProvider : IStructuredContentProvider {
65
66 /*
67 * (non-Javadoc)
68 *
69 * @see dwtx.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
70 */
71 public Object[] getElements(Object inputElement) {
72 return (cast(ArrayWrapperObject) inputElement).array;
73 }
74
75 /*
76 * (non-Javadoc)
77 *
78 * @see dwtx.jface.viewers.IContentProvider#dispose()
79 */
80 public void dispose() {
81
82 }
83
84 /*
85 * (non-Javadoc)
86 *
87 * @see dwtx.jface.viewers.IContentProvider#inputChanged(dwtx.jface.viewers.Viewer,
88 * java.lang.Object, java.lang.Object)
89 */
90 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
91
92 }
93
94 }
95
96 private class MyLabelProvider : LabelProvider, ITableLabelProvider {
97
98 public Image getColumnImage(Object element, int columnIndex) {
99 return null;
100 }
101
102 public String getColumnText(Object element, int columnIndex) {
103 return to!(char[])(columnIndex) ~ " - " ~ element.toString();
104 }
105
106 }
107
108 public class MyModel {
109 public int counter;
110
111 public this(int counter) {
112 this.counter = counter;
113 }
114
115 public String toString() {
116 return "Item " ~ to!(char[])(this.counter);
117 }
118 }
119
120 public this(Composite comp) {
121 final TableViewer v = new TableViewer(new Table(comp, DWT.BORDER));
122 v.setLabelProvider(new MyLabelProvider());
123 v.setContentProvider(new MyContentProvider());
124 v.getTable().setHeaderVisible(true);
125
126 TableColumnLayout ad = new TableColumnLayout();
127 comp.setLayout(ad);
128
129 TableColumn column = new TableColumn(v.getTable(), DWT.NONE);
130 column.setText("Column 1");
131 column.setMoveable(true);
132 ad.setColumnData(column, new ColumnWeightData(90, 290));
133
134 column = new TableColumn(v.getTable(), DWT.NONE);
135 column.setText("Column 2");
136 column.setMoveable(true);
137 ad.setColumnData(column, new ColumnWeightData(10, 200));
138
139 MyModel[] model = createModel();
140 v.setInput(new ArrayWrapperObject(model));
141 v.getTable().setLinesVisible(true);
142 }
143
144 private MyModel[] createModel() {
145 MyModel[] elements = new MyModel[10];
146
147 for (int i = 0; i < 10; i++) {
148 elements[i] = new MyModel(i);
149 }
150
151 return elements;
152 }
153
154
155
156 }