comparison jface/snippets/Snippet007FullSelection.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 *******************************************************************************/
11
12 module jface.snippets.Snippet007FullSelection;
13
14 import dwtx.jface.viewers.CellEditor;
15 import dwtx.jface.viewers.ICellModifier;
16 import dwtx.jface.viewers.IStructuredContentProvider;
17 import dwtx.jface.viewers.LabelProvider;
18 import dwtx.jface.viewers.TableViewer;
19 import dwtx.jface.viewers.TextCellEditor;
20 import dwtx.jface.viewers.Viewer;
21 import dwt.DWT;
22 import dwt.graphics.Color;
23 import dwt.graphics.GC;
24 import dwt.graphics.Point;
25 import dwt.graphics.Rectangle;
26 import dwt.layout.FillLayout;
27 import dwt.widgets.Display;
28 import dwt.widgets.Event;
29 import dwt.widgets.Listener;
30 import dwt.widgets.Shell;
31 import dwt.widgets.TableColumn;
32 import dwt.widgets.TableItem;
33
34 import dwt.dwthelper.utils;
35
36 import tango.util.Convert;
37 import tango.util.collection.ArraySeq;
38
39 /**
40 * TableViewer: Hide full selection
41 *
42 * @author Tom Schindl <tom.schindl@bestsolution.at>
43 *
44 */
45 public class Snippet007FullSelection {
46 alias ArraySeq!(MyModel) MyModelArray;
47
48 private class MyContentProvider : IStructuredContentProvider {
49
50 /* (non-Javadoc)
51 * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
52 */
53 public Object[] getElements(Object inputElement) {
54 return (cast(MyModelArray)inputElement).toArray;
55 }
56
57 /* (non-Javadoc)
58 * @see org.eclipse.jface.viewers.IContentProvider#dispose()
59 */
60 public void dispose() {
61
62 }
63
64 /* (non-Javadoc)
65 * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
66 */
67 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
68
69 }
70
71 }
72
73 public class MyModel {
74 public int counter;
75
76 public this(int counter) {
77 this.counter = counter;
78 }
79
80 public String toString() {
81 return "Item " ~ to!(char[])(this.counter);
82 }
83 }
84
85 public this(Shell shell) {
86 final TableViewer v = new TableViewer(shell,DWT.BORDER|DWT.FULL_SELECTION);
87 v.setLabelProvider(new LabelProvider());
88 v.setContentProvider(new MyContentProvider());
89 v.setCellModifier(new class(v) ICellModifier {
90 TableViewer v;
91 this(TableViewer v_) { this.v=v_; }
92
93 public bool canModify(Object element, String property) {
94 return true;
95 }
96
97 public Object getValue(Object element, String property) {
98 return new ArrayWrapperString( to!(char[])((cast(MyModel)element).counter) );
99 }
100
101 public void modify(Object element, String property, Object value) {
102 auto item = cast(TableItem)element;
103 auto valuestr = cast(ArrayWrapperString)value;
104 (cast(MyModel)item.getData()).counter = to!(int)(valuestr.array);
105 v.update(item.getData(), null);
106 }
107
108 });
109 v.setColumnProperties(["column1", "column2" ]);
110 v.setCellEditors([ new TextCellEditor(v.getTable()),new TextCellEditor(v.getTable()) ]);
111
112 TableColumn column = new TableColumn(v.getTable(),DWT.NONE);
113 column.setWidth(100);
114 column.setText("Column 1");
115
116 column = new TableColumn(v.getTable(),DWT.NONE);
117 column.setWidth(100);
118 column.setText("Column 2");
119
120 MyModelArray model = createModel();
121 v.setInput(model);
122 v.getTable().setLinesVisible(true);
123 v.getTable().setHeaderVisible(true);
124
125 v.getTable().addListener(DWT.EraseItem, new class Listener {
126
127 /* (non-Javadoc)
128 * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
129 */
130 public void handleEvent(Event event) {
131 event.detail &= ~DWT.SELECTED;
132 }
133 });
134
135 }
136
137 private MyModelArray createModel() {
138 auto elements = new MyModelArray;
139 elements.capacity = 10;
140
141 for( int i = 0; i < 10; i++ ) {
142 elements ~= new MyModel(i);
143 }
144
145 return elements;
146 }
147
148 }
149
150
151 void main() {
152 Display display = new Display ();
153 Shell shell = new Shell(display);
154 shell.setLayout(new FillLayout());
155 new Snippet007FullSelection(shell);
156 shell.open ();
157
158 while (!shell.isDisposed ()) {
159 if (!display.readAndDispatch ()) display.sleep ();
160 }
161
162 display.dispose ();
163
164 }
165