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