comparison dwtx/jface/viewers/TableViewer.d @ 70:46a6e0e6ccd4

Merge with d-fied sources of 3.4M7
author Frank Benoit <benoit@tionex.de>
date Thu, 22 May 2008 01:36:46 +0200
parents ea8ff534f622
children 7ffeace6c47f
comparison
equal deleted inserted replaced
69:07b9d96fd764 70:46a6e0e6ccd4
21 import dwtx.jface.viewers.ColumnViewerEditor; 21 import dwtx.jface.viewers.ColumnViewerEditor;
22 import dwtx.jface.viewers.ISelection; 22 import dwtx.jface.viewers.ISelection;
23 import dwtx.jface.viewers.ViewerRow; 23 import dwtx.jface.viewers.ViewerRow;
24 import dwtx.jface.viewers.TableViewerEditor; 24 import dwtx.jface.viewers.TableViewerEditor;
25 import dwtx.jface.viewers.ColumnViewerEditorActivationStrategy; 25 import dwtx.jface.viewers.ColumnViewerEditorActivationStrategy;
26
27 import dwt.DWT; 26 import dwt.DWT;
28 import dwt.graphics.Point; 27 import dwt.graphics.Point;
29 import dwt.widgets.Composite; 28 import dwt.widgets.Composite;
30 import dwt.widgets.Control; 29 import dwt.widgets.Control;
31 import dwt.widgets.Item; 30 import dwt.widgets.Item;
45 * configured with a domain-specific content provider, table label provider, 44 * configured with a domain-specific content provider, table label provider,
46 * element filter (optional), and element sorter (optional). 45 * element filter (optional), and element sorter (optional).
47 * </p> 46 * </p>
48 * <p> 47 * <p>
49 * Label providers for table viewers must implement either the 48 * Label providers for table viewers must implement either the
50 * <code>ITableLabelProvider</code> or the <code>ILabelProvider</code> 49 * <code>ITableLabelProvider</code> or the <code>ILabelProvider</code> interface
51 * interface (see <code>TableViewer.setLabelProvider</code> for more details). 50 * (see <code>TableViewer.setLabelProvider</code> for more details).
52 * </p> 51 * </p>
53 * <p> 52 * <p>
54 * As of 3.1 the TableViewer now supports the DWT.VIRTUAL flag. If the 53 * As of 3.1 the TableViewer now supports the DWT.VIRTUAL flag. If the
55 * underlying table is DWT.VIRTUAL, the content provider may implement 54 * underlying table is DWT.VIRTUAL, the content provider may implement {@link
56 * {@link ILazyContentProvider} instead of {@link IStructuredContentProvider}. 55 * ILazyContentProvider} instead of {@link IStructuredContentProvider} . Note
57 * Note that in this case, the viewer does not support sorting or filtering. 56 * that in this case, the viewer does not support sorting or filtering. Also
58 * Also note that in this case, the Widget based APIs may return null if the 57 * note that in this case, the Widget based APIs may return null if the element
59 * element is not specified or not created yet. 58 * is not specified or not created yet.
60 * </p> 59 * </p>
61 * <p> 60 * <p>
62 * Users of DWT.VIRTUAL should also avoid using getItems() from the Table within 61 * Users of DWT.VIRTUAL should also avoid using getItems() from the Table within
63 * the TreeViewer as this does not necessarily generate a callback for the 62 * the TreeViewer as this does not necessarily generate a callback for the
64 * TreeViewer to populate the items. It also has the side effect of creating all 63 * TreeViewer to populate the items. It also has the side effect of creating all
65 * of the items thereby eliminating the performance improvements of DWT.VIRTUAL. 64 * of the items thereby eliminating the performance improvements of DWT.VIRTUAL.
66 * </p> 65 * </p>
67 * 66 * <p>
67 * Users setting up an editable table with more than 1 column <b>have</b> to pass the
68 * DWT.FULL_SELECTION style bit
69 * </p>
70 *
68 * @see DWT#VIRTUAL 71 * @see DWT#VIRTUAL
69 * @see #doFindItem(Object) 72 * @see #doFindItem(Object)
70 * @see #internalRefresh(Object, bool) 73 * @see #internalRefresh(Object, bool)
71 */ 74 */
72 public class TableViewer : AbstractTableViewer { 75 public class TableViewer : AbstractTableViewer {
87 * Creates a table viewer on a newly-created table control under the given 90 * Creates a table viewer on a newly-created table control under the given
88 * parent. The table control is created using the DWT style bits 91 * parent. The table control is created using the DWT style bits
89 * <code>MULTI, H_SCROLL, V_SCROLL,</code> and <code>BORDER</code>. The 92 * <code>MULTI, H_SCROLL, V_SCROLL,</code> and <code>BORDER</code>. The
90 * viewer has no input, no content provider, a default label provider, no 93 * viewer has no input, no content provider, a default label provider, no
91 * sorter, and no filters. The table has no columns. 94 * sorter, and no filters. The table has no columns.
92 * 95 *
93 * @param parent 96 * @param parent
94 * the parent control 97 * the parent control
95 */ 98 */
96 public this(Composite parent) { 99 public this(Composite parent) {
97 this(parent, DWT.MULTI | DWT.H_SCROLL | DWT.V_SCROLL | DWT.BORDER); 100 this(parent, DWT.MULTI | DWT.H_SCROLL | DWT.V_SCROLL | DWT.BORDER);
98 } 101 }
99 102
100 /** 103 /**
101 * Creates a table viewer on a newly-created table control under the given 104 * Creates a table viewer on a newly-created table control under the given
102 * parent. The table control is created using the given style bits. The 105 * parent. The table control is created using the given style bits. The
103 * viewer has no input, no content provider, a default label provider, no 106 * viewer has no input, no content provider, a default label provider, no
104 * sorter, and no filters. The table has no columns. 107 * sorter, and no filters. The table has no columns.
105 * 108 *
106 * @param parent 109 * @param parent
107 * the parent control 110 * the parent control
108 * @param style 111 * @param style
109 * DWT style bits 112 * DWT style bits
110 */ 113 */
111 public this(Composite parent, int style) { 114 public this(Composite parent, int style) {
112 this(new Table(parent, style)); 115 this(new Table(parent, style));
113 } 116 }
114 117
115 /** 118 /**
116 * Creates a table viewer on the given table control. The viewer has no 119 * Creates a table viewer on the given table control. The viewer has no
117 * input, no content provider, a default label provider, no sorter, and no 120 * input, no content provider, a default label provider, no sorter, and no
118 * filters. 121 * filters.
119 * 122 *
120 * @param table 123 * @param table
121 * the table control 124 * the table control
122 */ 125 */
123 public this(Table table) { 126 public this(Table table) {
124 this.table = table; 127 this.table = table;
125 hookControl(table); 128 hookControl(table);
126 } 129 }
129 return table; 132 return table;
130 } 133 }
131 134
132 /** 135 /**
133 * Returns this table viewer's table control. 136 * Returns this table viewer's table control.
134 * 137 *
135 * @return the table control 138 * @return the table control
136 */ 139 */
137 public Table getTable() { 140 public Table getTable() {
138 return table; 141 return table;
139 } 142 }
140 143
141 protected override ColumnViewerEditor createViewerEditor() { 144 protected override ColumnViewerEditor createViewerEditor() {
142 return new TableViewerEditor(this,null,new ColumnViewerEditorActivationStrategy(this),ColumnViewerEditor.DEFAULT); 145 return new TableViewerEditor(this, null,
146 new ColumnViewerEditorActivationStrategy(this),
147 ColumnViewerEditor.DEFAULT);
143 } 148 }
144 149
145 /** 150 /**
146 * <p> 151 * <p>
147 * Sets a new selection for this viewer and optionally makes it visible. The 152 * Sets a new selection for this viewer and optionally makes it visible. The
151 * </p> 156 * </p>
152 * <p> 157 * <p>
153 * Use Table#setSelection(int[] indices) and Table#showSelection() if you 158 * Use Table#setSelection(int[] indices) and Table#showSelection() if you
154 * wish to set selection more efficiently when using a ILazyContentProvider. 159 * wish to set selection more efficiently when using a ILazyContentProvider.
155 * </p> 160 * </p>
156 * 161 *
157 * @param selection 162 * @param selection
158 * the new selection 163 * the new selection
159 * @param reveal 164 * @param reveal
160 * <code>true</code> if the selection is to be made visible, 165 * <code>true</code> if the selection is to be made visible, and
161 * and <code>false</code> otherwise 166 * <code>false</code> otherwise
162 * @see Table#setSelection(int[]) 167 * @see Table#setSelection(int[])
163 * @see Table#showSelection() 168 * @see Table#showSelection()
164 */ 169 */
165 public override void setSelection(ISelection selection, bool reveal) { 170 public override void setSelection(ISelection selection, bool reveal) {
166 super.setSelection(selection, reveal); 171 super.setSelection(selection, reveal);
167 } 172 }
168 173
169 protected override ViewerRow getViewerRowFromItem(Widget item) { 174 protected override ViewerRow getViewerRowFromItem(Widget item) {
170 if( cachedRow is null ) { 175 if (cachedRow is null) {
171 cachedRow = new TableViewerRow(cast(TableItem) item); 176 cachedRow = new TableViewerRow(cast(TableItem) item);
172 } else { 177 } else {
173 cachedRow.setItem(cast(TableItem) item); 178 cachedRow.setItem(cast(TableItem) item);
174 } 179 }
175 180
176 return cachedRow; 181 return cachedRow;
177 } 182 }
178 183
179 /** 184 /**
180 * Create a new row with style at index 185 * Create a new row with style at index
181 * 186 *
182 * @param style 187 * @param style
183 * @param rowIndex 188 * @param rowIndex
184 * @return ViewerRow 189 * @return ViewerRow
185 * @since 3.3 190 * @since 3.3
186 */ 191 */
197 } 202 }
198 203
199 protected override Item getItemAt(Point p) { 204 protected override Item getItemAt(Point p) {
200 TableItem[] selection = table.getSelection(); 205 TableItem[] selection = table.getSelection();
201 206
202 if( selection.length is 1 ) { 207 if (selection.length is 1) {
203 int columnCount = table.getColumnCount(); 208 int columnCount = table.getColumnCount();
204 209
205 for( int i = 0; i < columnCount; i++ ) { 210 for (int i = 0; i < columnCount; i++) {
206 if( selection[0].getBounds(i).contains(p) ) { 211 if (selection[0].getBounds(i).contains(p)) {
207 return selection[0]; 212 return selection[0];
208 } 213 }
209 } 214 }
210 } 215 }
211 216
217 protected override int doGetItemCount() { 222 protected override int doGetItemCount() {
218 return table.getItemCount(); 223 return table.getItemCount();
219 } 224 }
220 225
221 protected override int doIndexOf(Item item) { 226 protected override int doIndexOf(Item item) {
222 return table.indexOf(cast(TableItem)item); 227 return table.indexOf(cast(TableItem) item);
223 } 228 }
224 229
225 protected override void doSetItemCount(int count) { 230 protected override void doSetItemCount(int count) {
226 table.setItemCount(count); 231 table.setItemCount(count);
227 } 232 }
276 protected override void doRemove(int[] indices) { 281 protected override void doRemove(int[] indices) {
277 table.remove(indices); 282 table.remove(indices);
278 } 283 }
279 284
280 protected override void doShowItem(Item item) { 285 protected override void doShowItem(Item item) {
281 table.showItem(cast(TableItem)item); 286 table.showItem(cast(TableItem) item);
282 } 287 }
283 288
284 protected override void doDeselectAll() { 289 protected override void doDeselectAll() {
285 table.deselectAll(); 290 table.deselectAll();
286 } 291 }
310 table.select(indices); 315 table.select(indices);
311 } 316 }
312 317
313 /** 318 /**
314 * Refreshes this viewer starting with the given element. Labels are updated 319 * Refreshes this viewer starting with the given element. Labels are updated
315 * as described in <code>refresh(bool updateLabels)</code>. The 320 * as described in <code>refresh(bool updateLabels)</code>. The methods
316 * methods attempts to preserve the selection. 321 * attempts to preserve the selection.
317 * <p> 322 * <p>
318 * Unlike the <code>update</code> methods, this handles structural changes 323 * Unlike the <code>update</code> methods, this handles structural changes
319 * to the given element (e.g. addition or removal of children). If only the 324 * to the given element (e.g. addition or removal of children). If only the
320 * given element needs updating, it is more efficient to use the 325 * given element needs updating, it is more efficient to use the
321 * <code>update</code> methods. 326 * <code>update</code> methods.
322 * </p> 327 * </p>
323 * 328 *
324 * <p> 329 * <p>
325 * Subclasses who can provide this feature can open this method for the 330 * Subclasses who can provide this feature can open this method for the
326 * public 331 * public
327 * </p> 332 * </p>
328 * 333 *
329 * @param element 334 * @param element
330 * the element 335 * the element
331 * @param updateLabels 336 * @param updateLabels
332 * <code>true</code> to update labels for existing elements, 337 * <code>true</code> to update labels for existing elements,
333 * <code>false</code> to only update labels as needed, assuming 338 * <code>false</code> to only update labels as needed, assuming that labels
334 * that labels for existing elements are unchanged. 339 * for existing elements are unchanged.
335 * @param reveal 340 * @param reveal
336 * <code>true</code> to make the preserved selection visible 341 * <code>true</code> to make the preserved selection visible afterwards
337 * afterwards 342 *
338 *
339 * @since 3.3 343 * @since 3.3
340 */ 344 */
341 public void refresh(Object element, bool updateLabels, 345 public void refresh(Object element, bool updateLabels,
342 bool reveal) { 346 bool reveal) {
343 if (isBusy()) 347 if (checkBusy())
344 return; 348 return;
345 349
346 if( isCellEditorActive() ) { 350 if (isCellEditorActive()) {
347 cancelEditing(); 351 cancelEditing();
348 } 352 }
349 353
350 preservingSelection(new class(element,updateLabels) Runnable { 354 preservingSelection(new class(element,updateLabels) Runnable {
351 Object element_; 355 Object element_;
360 }, reveal); 364 }, reveal);
361 } 365 }
362 366
363 /** 367 /**
364 * Refreshes this viewer with information freshly obtained from this 368 * Refreshes this viewer with information freshly obtained from this
365 * viewer's model. If <code>updateLabels</code> is <code>true</code> 369 * viewer's model. If <code>updateLabels</code> is <code>true</code> then
366 * then labels for otherwise unaffected elements are updated as well. 370 * labels for otherwise unaffected elements are updated as well. Otherwise,
367 * Otherwise, it assumes labels for existing elements are unchanged, and 371 * it assumes labels for existing elements are unchanged, and labels are
368 * labels are only obtained as needed (for example, for new elements). 372 * only obtained as needed (for example, for new elements).
369 * <p> 373 * <p>
370 * Calling <code>refresh(true)</code> has the same effect as 374 * Calling <code>refresh(true)</code> has the same effect as
371 * <code>refresh()</code>. 375 * <code>refresh()</code>.
372 * <p> 376 * <p>
373 * Note that the implementation may still obtain labels for existing 377 * Note that the implementation may still obtain labels for existing
374 * elements even if <code>updateLabels</code> is false. The intent is 378 * elements even if <code>updateLabels</code> is false. The intent is simply
375 * simply to allow optimization where possible. 379 * to allow optimization where possible.
376 * 380 *
377 * @param updateLabels 381 * @param updateLabels
378 * <code>true</code> to update labels for existing elements, 382 * <code>true</code> to update labels for existing elements,
379 * <code>false</code> to only update labels as needed, assuming 383 * <code>false</code> to only update labels as needed, assuming that labels
380 * that labels for existing elements are unchanged. 384 * for existing elements are unchanged.
381 * @param reveal 385 * @param reveal
382 * <code>true</code> to make the preserved selection visible 386 * <code>true</code> to make the preserved selection visible afterwards
383 * afterwards 387 *
384 *
385 * @since 3.3 388 * @since 3.3
386 */ 389 */
387 public void refresh(bool updateLabels, bool reveal) { 390 public void refresh(bool updateLabels, bool reveal) {
388 refresh(getRoot(), updateLabels, reveal); 391 refresh(getRoot(), updateLabels, reveal);
389 } 392 }