Mercurial > projects > dwt-addons
annotate dwtx/jface/viewers/AbstractTableViewer.d @ 104:04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
These new wrappers now use the tango.util.containers instead of the tango.util.collections.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Thu, 07 Aug 2008 15:01:33 +0200 |
parents | 7ffeace6c47f |
children |
rev | line source |
---|---|
10 | 1 /******************************************************************************* |
90 | 2 * Copyright (c) 2000, 2008 IBM Corporation and others. |
10 | 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 * IBM Corporation - initial API and implementation | |
10 * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation bug 154329 | |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
11 * - fixes in bug 170381, 198665, 200731 |
10 | 12 * Port to the D programming language: |
13 * Frank Benoit <benoit@tionex.de> | |
14 *******************************************************************************/ | |
15 | |
16 module dwtx.jface.viewers.AbstractTableViewer; | |
17 | |
18 import dwtx.jface.viewers.ColumnViewer; | |
19 import dwtx.jface.viewers.ViewerRow; | |
20 import dwtx.jface.viewers.IBaseLabelProvider; | |
21 import dwtx.jface.viewers.IContentProvider; | |
22 import dwtx.jface.viewers.ILazyContentProvider; | |
23 import dwtx.jface.viewers.ViewerColumn; | |
24 import dwtx.jface.viewers.ViewerCell; | |
25 import dwtx.jface.viewers.ViewerComparator; | |
26 import dwtx.jface.viewers.IStructuredContentProvider; | |
27 | |
28 | |
29 import dwt.DWT; | |
30 import dwt.widgets.Control; | |
31 import dwt.widgets.Event; | |
32 import dwt.widgets.Item; | |
33 import dwt.widgets.Listener; | |
34 import dwt.widgets.Widget; | |
35 import dwtx.core.runtime.Assert; | |
36 | |
37 import dwt.dwthelper.utils; | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
38 import dwtx.dwtxhelper.Collection; |
10 | 39 import dwt.dwthelper.Runnable; |
40 import tango.core.Array; | |
41 | |
42 /** | |
43 * This is a widget independent class implementors of | |
44 * {@link dwt.widgets.Table} like widgets can use to provide a | |
45 * viewer on top of their widget implementations. | |
46 * | |
47 * @since 3.3 | |
48 */ | |
49 public abstract class AbstractTableViewer : ColumnViewer { | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
39
diff
changeset
|
50 alias ColumnViewer.getLabelProvider getLabelProvider; |
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
39
diff
changeset
|
51 alias ColumnViewer.setSelectionToWidget setSelectionToWidget; |
10 | 52 |
53 private class VirtualManager { | |
54 | |
55 /** | |
56 * The currently invisible elements as provided by the content provider | |
57 * or by addition. This will not be populated by an | |
58 * ILazyStructuredContentProvider as an ILazyStructuredContentProvider | |
59 * is only queried on the virtual callback. | |
60 */ | |
61 private Object[] cachedElements = null; | |
62 | |
63 /** | |
64 * Create a new instance of the receiver. | |
65 * | |
66 */ | |
67 public this() { | |
68 addTableListener(); | |
69 } | |
70 | |
71 /** | |
72 * Add the listener for SetData on the table | |
73 */ | |
74 private void addTableListener() { | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
75 getControl().addListener(DWT.SetData, dgListener( (Event event){ |
10 | 76 /* |
77 * (non-Javadoc) | |
78 * | |
79 * @see dwt.widgets.Listener#handleEvent(dwt.widgets.Event) | |
80 */ | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
81 Item item = cast(Item) event.item; |
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
82 final int index = doIndexOf(item); |
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
83 Object element = resolveElement(index); |
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
84 if (element is null) { |
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
85 // Didn't find it so make a request |
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
86 // Keep looking if it is not in the cache. |
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
87 IContentProvider contentProvider = getContentProvider(); |
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
88 // If we are building lazily then request lookup now |
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
89 if (auto lcp = cast(ILazyContentProvider)contentProvider ) { |
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
90 lcp.updateElement(index); |
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
91 return; |
10 | 92 } |
93 } | |
94 | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
95 associate(element, item); |
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
96 updateItem(item, element); |
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
97 })); |
10 | 98 } |
99 | |
100 /** | |
101 * Get the element at index.Resolve it lazily if this is available. | |
102 * | |
103 * @param index | |
104 * @return Object or <code>null</code> if it could not be found | |
105 */ | |
106 protected Object resolveElement(int index) { | |
107 | |
108 Object element = null; | |
109 if (index < cachedElements.length) { | |
110 element = cachedElements[index]; | |
111 } | |
112 | |
113 return element; | |
114 } | |
115 | |
116 /** | |
117 * A non visible item has been added. | |
118 * | |
119 * @param element | |
120 * @param index | |
121 */ | |
122 public void notVisibleAdded(Object element, int index) { | |
123 | |
124 int requiredCount = doGetItemCount() + 1; | |
125 | |
126 Object[] newCache = new Object[requiredCount]; | |
127 System.arraycopy(cachedElements, 0, newCache, 0, index); | |
128 if (index < cachedElements.length) { | |
129 System.arraycopy(cachedElements, index, newCache, index + 1, | |
130 cachedElements.length - index); | |
131 } | |
132 newCache[index] = element; | |
133 cachedElements = newCache; | |
134 | |
135 doSetItemCount(requiredCount); | |
136 } | |
137 | |
138 /** | |
139 * The elements with the given indices need to be removed from the | |
140 * cache. | |
141 * | |
142 * @param indices | |
143 */ | |
144 public void removeIndices(int[] indices) { | |
145 if (indices.length is 1) { | |
146 removeIndicesFromTo(indices[0], indices[0]); | |
147 } | |
148 int requiredCount = doGetItemCount() - indices.length; | |
149 | |
150 tango.core.Array.sort( indices ); | |
151 Object[] newCache = new Object[requiredCount]; | |
152 int indexInNewCache = 0; | |
153 int nextToSkip = 0; | |
154 for (int i = 0; i < cachedElements.length; i++) { | |
155 if (nextToSkip < indices.length && i is indices[nextToSkip]) { | |
156 nextToSkip++; | |
157 } else { | |
158 newCache[indexInNewCache++] = cachedElements[i]; | |
159 } | |
160 } | |
161 cachedElements = newCache; | |
162 } | |
163 | |
164 /** | |
165 * The elements between the given indices (inclusive) need to be removed | |
166 * from the cache. | |
167 * | |
168 * @param from | |
169 * @param to | |
170 */ | |
171 public void removeIndicesFromTo(int from, int to) { | |
172 int indexAfterTo = to + 1; | |
173 Object[] newCache = new Object[cachedElements.length | |
174 - (indexAfterTo - from)]; | |
175 System.arraycopy(cachedElements, 0, newCache, 0, from); | |
176 if (indexAfterTo < cachedElements.length) { | |
177 System.arraycopy(cachedElements, indexAfterTo, newCache, from, | |
178 cachedElements.length - indexAfterTo); | |
179 } | |
180 } | |
181 | |
182 /** | |
183 * @param element | |
184 * @return the index of the element in the cache, or null | |
185 */ | |
186 public int find(Object element) { | |
187 int res = tango.core.Array.find( cachedElements, element ); | |
188 if( res is cachedElements.length ) res = -1; | |
189 return res; | |
190 } | |
191 | |
192 /** | |
193 * @param count | |
194 */ | |
195 public void adjustCacheSize(int count) { | |
196 if (count is cachedElements.length) { | |
197 return; | |
198 } else if (count < cachedElements.length) { | |
199 Object[] newCache = new Object[count]; | |
200 System.arraycopy(cachedElements, 0, newCache, 0, count); | |
201 cachedElements = newCache; | |
202 } else { | |
203 Object[] newCache = new Object[count]; | |
204 System.arraycopy(cachedElements, 0, newCache, 0, | |
205 cachedElements.length); | |
206 cachedElements = newCache; | |
207 } | |
208 } | |
209 | |
210 } | |
211 | |
212 private VirtualManager virtualManager; | |
213 | |
214 /** | |
215 * Create the new viewer for table like widgets | |
216 */ | |
217 public this() { | |
218 super(); | |
219 } | |
220 | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
39
diff
changeset
|
221 protected override void hookControl(Control control) { |
10 | 222 super.hookControl(control); |
223 initializeVirtualManager(getControl().getStyle()); | |
224 } | |
225 | |
226 /** | |
227 * Initialize the virtual manager to manage the virtual state if the table | |
228 * is VIRTUAL. If not use the default no-op version. | |
229 * | |
230 * @param style | |
231 */ | |
232 private void initializeVirtualManager(int style) { | |
233 if ((style & DWT.VIRTUAL) is 0) { | |
234 return; | |
235 } | |
236 | |
237 virtualManager = new VirtualManager(); | |
238 } | |
239 | |
240 /** | |
241 * Adds the given elements to this table viewer. If this viewer does not | |
242 * have a sorter, the elements are added at the end in the order given; | |
243 * otherwise the elements are inserted at appropriate positions. | |
244 * <p> | |
245 * This method should be called (by the content provider) when elements have | |
246 * been added to the model, in order to cause the viewer to accurately | |
247 * reflect the model. This method only affects the viewer, not the model. | |
248 * </p> | |
249 * | |
250 * @param elements | |
251 * the elements to add | |
252 */ | |
253 public void add(Object[] elements) { | |
254 assertElementsNotNull(elements); | |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
255 if (checkBusy()) |
10 | 256 return; |
257 Object[] filtered = filter(elements); | |
258 | |
259 for (int i = 0; i < filtered.length; i++) { | |
260 Object element = filtered[i]; | |
261 int index = indexForElement(element); | |
262 createItem(element, index); | |
263 } | |
264 } | |
265 | |
266 /** | |
267 * Create a new TableItem at index if required. | |
268 * | |
269 * @param element | |
270 * @param index | |
271 * | |
272 * @since 3.1 | |
273 */ | |
274 private void createItem(Object element, int index) { | |
275 if (virtualManager is null) { | |
276 updateItem(internalCreateNewRowPart(DWT.NONE, index).getItem(), | |
277 element); | |
278 } else { | |
279 virtualManager.notVisibleAdded(element, index); | |
280 | |
281 } | |
282 } | |
283 | |
284 /** | |
285 * Create a new row. Callers can only use the returned object locally and before | |
286 * making the next call on the viewer since it may be re-used for subsequent method | |
287 * calls. | |
288 * | |
289 * @param style | |
290 * the style for the new row | |
291 * @param rowIndex | |
292 * the index of the row or -1 if the row is appended at the end | |
293 * @return the newly created row | |
294 */ | |
295 protected abstract ViewerRow internalCreateNewRowPart(int style, | |
296 int rowIndex); | |
297 | |
298 /** | |
299 * Adds the given element to this table viewer. If this viewer does not have | |
300 * a sorter, the element is added at the end; otherwise the element is | |
301 * inserted at the appropriate position. | |
302 * <p> | |
303 * This method should be called (by the content provider) when a single | |
304 * element has been added to the model, in order to cause the viewer to | |
305 * accurately reflect the model. This method only affects the viewer, not | |
306 * the model. Note that there is another method for efficiently processing | |
307 * the simultaneous addition of multiple elements. | |
308 * </p> | |
309 * | |
310 * @param element | |
311 * the element to add | |
312 */ | |
313 public void add(Object element) { | |
314 add([ element ]); | |
315 } | |
316 | |
317 /* | |
318 * (non-Javadoc) | |
319 * | |
320 * @see dwtx.jface.viewers.StructuredViewer#doFindInputItem(java.lang.Object) | |
321 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
39
diff
changeset
|
322 protected override Widget doFindInputItem(Object element) { |
10 | 323 if (opEquals(element, getRoot())) { |
324 return getControl(); | |
325 } | |
326 return null; | |
327 } | |
328 | |
329 /* | |
330 * (non-Javadoc) | |
331 * | |
332 * @see dwtx.jface.viewers.StructuredViewer#doFindItem(java.lang.Object) | |
333 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
39
diff
changeset
|
334 protected override Widget doFindItem(Object element) { |
10 | 335 |
336 Item[] children = doGetItems(); | |
337 for (int i = 0; i < children.length; i++) { | |
338 Item item = children[i]; | |
339 Object data = item.getData(); | |
340 if (data !is null && opEquals(data, element)) { | |
341 return item; | |
342 } | |
343 } | |
344 | |
345 return null; | |
346 } | |
347 | |
348 /* | |
349 * (non-Javadoc) | |
350 * | |
351 * @see dwtx.jface.viewers.StructuredViewer#doUpdateItem(dwt.widgets.Widget, | |
352 * java.lang.Object, bool) | |
353 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
39
diff
changeset
|
354 protected override void doUpdateItem(Widget widget, Object element, bool fullMap) { |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
355 bool oldBusy = isBusy(); |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
356 setBusy(true); |
10 | 357 try { |
358 if ( auto item = cast(Item)widget ) { | |
359 | |
360 // remember element we are showing | |
361 if (fullMap) { | |
362 associate(element, item); | |
363 } else { | |
364 Object data = item.getData(); | |
365 if (data !is null) { | |
366 unmapElement(data, item); | |
367 } | |
368 item.setData(element); | |
369 mapElement(element, item); | |
370 } | |
371 | |
372 int columnCount = doGetColumnCount(); | |
373 if (columnCount is 0) | |
374 columnCount = 1;// If there are no columns do the first one | |
375 | |
376 ViewerRow viewerRowFromItem = getViewerRowFromItem(item); | |
377 | |
378 bool isVirtual = (getControl().getStyle() & DWT.VIRTUAL) !is 0; | |
379 | |
380 // If the control is virtual, we cannot use the cached viewer row object. See bug 188663. | |
381 if (isVirtual) { | |
382 viewerRowFromItem = cast(ViewerRow) viewerRowFromItem.clone(); | |
383 } | |
384 | |
385 // Also enter loop if no columns added. See 1G9WWGZ: JFUIF:WINNT - | |
386 // TableViewer with 0 columns does not work | |
387 for (int column = 0; column < columnCount || column is 0; column++) { | |
388 ViewerColumn columnViewer = getViewerColumn(column); | |
389 ViewerCell cellToUpdate = updateCell(viewerRowFromItem, | |
390 column, element); | |
391 | |
392 // If the control is virtual, we cannot use the cached cell object. See bug 188663. | |
393 if (isVirtual) { | |
394 cellToUpdate = new ViewerCell(cellToUpdate.getViewerRow(), cellToUpdate.getColumnIndex(), element); | |
395 } | |
396 | |
397 columnViewer.refresh(cellToUpdate); | |
398 | |
399 // clear cell (see bug 201280) | |
400 updateCell(null, 0, null); | |
401 | |
402 // As it is possible for user code to run the event | |
403 // loop check here. | |
404 if (item.isDisposed()) { | |
405 unmapElement(element, item); | |
406 return; | |
407 } | |
408 | |
409 } | |
410 | |
411 } | |
412 } finally { | |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
413 setBusy(oldBusy); |
10 | 414 } |
415 } | |
416 | |
417 /* | |
418 * (non-Javadoc) | |
419 * | |
420 * @see dwtx.jface.viewers.ColumnViewer#getColumnViewerOwner(int) | |
421 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
39
diff
changeset
|
422 protected override Widget getColumnViewerOwner(int columnIndex) { |
10 | 423 int columnCount = doGetColumnCount(); |
424 | |
425 if (columnIndex < 0 | |
426 || (columnIndex > 0 && columnIndex >= columnCount)) { | |
427 return null; | |
428 } | |
429 | |
430 if (columnCount is 0)// Hang it off the table if it | |
431 return getControl(); | |
432 | |
433 return doGetColumn(columnIndex); | |
434 } | |
435 | |
436 /** | |
437 * Returns the element with the given index from this table viewer. Returns | |
438 * <code>null</code> if the index is out of range. | |
439 * <p> | |
440 * This method is internal to the framework. | |
441 * </p> | |
442 * | |
443 * @param index | |
444 * the zero-based index | |
445 * @return the element at the given index, or <code>null</code> if the | |
446 * index is out of range | |
447 */ | |
448 public Object getElementAt(int index) { | |
449 if (index >= 0 && index < doGetItemCount()) { | |
450 Item i = doGetItem(index); | |
451 if (i !is null) { | |
452 return i.getData(); | |
453 } | |
454 } | |
455 return null; | |
456 } | |
457 | |
458 /** | |
459 * The table viewer implementation of this <code>Viewer</code> framework | |
460 * method returns the label provider, which in the case of table viewers | |
461 * will be an instance of either <code>ITableLabelProvider</code> or | |
462 * <code>ILabelProvider</code>. If it is an | |
463 * <code>ITableLabelProvider</code>, then it provides a separate label | |
464 * text and image for each column. If it is an <code>ILabelProvider</code>, | |
465 * then it provides only the label text and image for the first column, and | |
466 * any remaining columns are blank. | |
467 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
39
diff
changeset
|
468 public override IBaseLabelProvider getLabelProvider() { |
10 | 469 return super.getLabelProvider(); |
470 } | |
471 | |
472 /* | |
473 * (non-Javadoc) | |
474 * | |
475 * @see dwtx.jface.viewers.StructuredViewer#getSelectionFromWidget() | |
476 */ | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
477 protected override List getSelectionFromWidget() { |
10 | 478 if (virtualManager !is null) { |
479 return getVirtualSelection(); | |
480 } | |
481 Widget[] items = doGetSelection(); | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
482 ArrayList list = new ArrayList(items.length); |
10 | 483 for (int i = 0; i < items.length; i++) { |
484 Widget item = items[i]; | |
485 Object e = item.getData(); | |
486 if (e !is null) { | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
487 list.add(e); |
10 | 488 } |
489 } | |
490 return list; | |
491 } | |
492 | |
493 /** | |
494 * Get the virtual selection. Avoid calling DWT whenever possible to prevent | |
495 * extra widget creation. | |
496 * | |
497 * @return List of Object | |
498 */ | |
499 | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
500 private List getVirtualSelection() { |
10 | 501 |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
502 List result = new ArrayList(); |
10 | 503 int[] selectionIndices = doGetSelectionIndices(); |
504 if (auto lazy_ = cast(ILazyContentProvider) getContentProvider() ) { | |
505 for (int i = 0; i < selectionIndices.length; i++) { | |
506 int selectionIndex = selectionIndices[i]; | |
507 lazy_.updateElement(selectionIndex);// Start the update | |
508 Object element = doGetItem(selectionIndex).getData(); | |
509 // Only add the element if it got updated. | |
510 // If this is done deferred the selection will | |
511 // be incomplete until selection is finished. | |
512 if (element !is null) { | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
513 result.add(element); |
10 | 514 } |
515 } | |
516 } else { | |
517 for (int i = 0; i < selectionIndices.length; i++) { | |
518 Object element = null; | |
519 // See if it is cached | |
520 int selectionIndex = selectionIndices[i]; | |
521 if (selectionIndex < virtualManager.cachedElements.length) { | |
522 element = virtualManager.cachedElements[selectionIndex]; | |
523 } | |
524 if (element is null) { | |
525 // Not cached so try the item's data | |
526 Item item = doGetItem(selectionIndex); | |
527 element = item.getData(); | |
528 } | |
529 if (element !is null) { | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
530 result.add(element); |
10 | 531 } |
532 } | |
533 | |
534 } | |
535 return result; | |
536 } | |
537 | |
538 /** | |
539 * @param element | |
540 * the element to insert | |
541 * @return the index where the item should be inserted. | |
542 */ | |
543 protected int indexForElement(Object element) { | |
544 ViewerComparator comparator = getComparator(); | |
545 if (comparator is null) { | |
546 return doGetItemCount(); | |
547 } | |
548 int count = doGetItemCount(); | |
549 int min = 0, max = count - 1; | |
550 while (min <= max) { | |
551 int mid = (min + max) / 2; | |
552 Object data = doGetItem(mid).getData(); | |
553 int compare = comparator.compare(this, data, element); | |
554 if (compare is 0) { | |
555 // find first item > element | |
556 while (compare is 0) { | |
557 ++mid; | |
558 if (mid >= count) { | |
559 break; | |
560 } | |
561 data = doGetItem(mid).getData(); | |
562 compare = comparator.compare(this, data, element); | |
563 } | |
564 return mid; | |
565 } | |
566 if (compare < 0) { | |
567 min = mid + 1; | |
568 } else { | |
569 max = mid - 1; | |
570 } | |
571 } | |
572 return min; | |
573 } | |
574 | |
575 /* | |
576 * (non-Javadoc) | |
577 * | |
578 * @see dwtx.jface.viewers.Viewer#inputChanged(java.lang.Object, | |
579 * java.lang.Object) | |
580 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
39
diff
changeset
|
581 protected override void inputChanged(Object input, Object oldInput) { |
10 | 582 getControl().setRedraw(false); |
583 try { | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
584 preservingSelection(dgRunnable( { |
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
585 internalRefresh(getRoot()); |
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
586 })); |
10 | 587 } finally { |
588 getControl().setRedraw(true); | |
589 } | |
590 } | |
591 | |
592 /** | |
593 * Inserts the given element into this table viewer at the given position. | |
594 * If this viewer has a sorter, the position is ignored and the element is | |
595 * inserted at the correct position in the sort order. | |
596 * <p> | |
597 * This method should be called (by the content provider) when elements have | |
598 * been added to the model, in order to cause the viewer to accurately | |
599 * reflect the model. This method only affects the viewer, not the model. | |
600 * </p> | |
601 * | |
602 * @param element | |
603 * the element | |
604 * @param position | |
605 * a 0-based position relative to the model, or -1 to indicate | |
606 * the last position | |
607 */ | |
608 public void insert(Object element, int position) { | |
609 applyEditorValue(); | |
610 if (getComparator() !is null || hasFilters()) { | |
611 add(element); | |
612 return; | |
613 } | |
614 if (position is -1) { | |
615 position = doGetItemCount(); | |
616 } | |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
617 if (checkBusy()) |
10 | 618 return; |
619 createItem(element, position); | |
620 } | |
621 | |
622 /* | |
623 * (non-Javadoc) | |
624 * | |
625 * @see dwtx.jface.viewers.StructuredViewer#internalRefresh(java.lang.Object) | |
626 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
39
diff
changeset
|
627 protected override void internalRefresh(Object element) { |
10 | 628 internalRefresh(element, true); |
629 } | |
630 | |
631 /* | |
632 * (non-Javadoc) | |
633 * | |
634 * @see dwtx.jface.viewers.StructuredViewer#internalRefresh(java.lang.Object, | |
635 * bool) | |
636 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
39
diff
changeset
|
637 protected override void internalRefresh(Object element, bool updateLabels) { |
10 | 638 applyEditorValue(); |
639 if (element is null || opEquals(element, getRoot())) { | |
640 if (virtualManager is null) { | |
641 internalRefreshAll(updateLabels); | |
642 } else { | |
643 internalVirtualRefreshAll(); | |
644 } | |
645 } else { | |
646 Widget w = findItem(element); | |
647 if (w !is null) { | |
648 updateItem(w, element); | |
649 } | |
650 } | |
651 } | |
652 | |
653 /** | |
654 * Refresh all with virtual elements. | |
655 * | |
656 * @since 3.1 | |
657 */ | |
658 private void internalVirtualRefreshAll() { | |
659 | |
660 Object root = getRoot(); | |
661 IContentProvider contentProvider = getContentProvider(); | |
662 | |
663 // Invalidate for lazy | |
664 if (!(cast(ILazyContentProvider)contentProvider ) | |
665 && cast(IStructuredContentProvider)contentProvider ) { | |
666 // Don't cache if the root is null but cache if it is not lazy. | |
667 if (root !is null) { | |
668 virtualManager.cachedElements = getSortedChildren(root); | |
669 doSetItemCount(virtualManager.cachedElements.length); | |
670 } | |
671 } | |
672 doClearAll(); | |
673 } | |
674 | |
675 /** | |
676 * Refresh all of the elements of the table. update the labels if | |
677 * updatLabels is true; | |
678 * | |
679 * @param updateLabels | |
680 * | |
681 * @since 3.1 | |
682 */ | |
683 private void internalRefreshAll(bool updateLabels) { | |
684 // the parent | |
685 | |
686 // in the code below, it is important to do all disassociates | |
687 // before any associates, since a later disassociate can undo an | |
688 // earlier associate | |
689 // e.g. if (a, b) is replaced by (b, a), the disassociate of b to | |
690 // item 1 could undo | |
691 // the associate of b to item 0. | |
692 | |
693 Object[] children = getSortedChildren(getRoot()); | |
694 Item[] items = doGetItems(); | |
695 int min = Math.min(children.length, items.length); | |
696 for (int i = 0; i < min; ++i) { | |
697 | |
698 Item item = items[i]; | |
699 | |
700 // if the element is unchanged, update its label if appropriate | |
701 if (opEquals(children[i], item.getData())) { | |
702 if (updateLabels) { | |
703 updateItem(item, children[i]); | |
704 } else { | |
705 // associate the new element, even if equal to the old | |
706 // one, | |
707 // to remove stale references (see bug 31314) | |
708 associate(children[i], item); | |
709 } | |
710 } else { | |
711 // updateItem does an associate(...), which can mess up | |
712 // the associations if the order of elements has changed. | |
713 // E.g. (a, b) -> (b, a) first replaces a->0 with b->0, then | |
714 // replaces b->1 with a->1, but this actually removes b->0. | |
715 // So, if the object associated with this item has changed, | |
716 // just disassociate it for now, and update it below. | |
717 // we also need to reset the item (set its text,images etc. to | |
718 // default values) because the label decorators rely on this | |
719 disassociate(item); | |
720 doClear(i); | |
721 } | |
722 } | |
723 // dispose of all items beyond the end of the current elements | |
724 if (min < items.length) { | |
725 for (int i = items.length; --i >= min;) { | |
726 | |
727 disassociate(items[i]); | |
728 } | |
729 if (virtualManager !is null) { | |
730 virtualManager.removeIndicesFromTo(min, items.length - 1); | |
731 } | |
732 doRemove(min, items.length - 1); | |
733 } | |
734 // Workaround for 1GDGN4Q: ITPUI:WIN2000 - TableViewer icons get | |
735 // scrunched | |
736 if (doGetItemCount() is 0) { | |
737 doRemoveAll(); | |
738 } | |
739 // Update items which were disassociated above | |
740 for (int i = 0; i < min; ++i) { | |
741 | |
742 Item item = items[i]; | |
743 if (item.getData() is null) { | |
744 updateItem(item, children[i]); | |
745 } | |
746 } | |
747 // add any remaining elements | |
748 for (int i = min; i < children.length; ++i) { | |
749 createItem(children[i], i); | |
750 } | |
751 } | |
752 | |
753 /** | |
754 * Removes the given elements from this table viewer. | |
755 * | |
756 * @param elements | |
757 * the elements to remove | |
758 */ | |
759 private void internalRemove(Object[] elements) { | |
760 Object input = getInput(); | |
761 for (int i = 0; i < elements.length; ++i) { | |
762 if (opEquals(elements[i], input)) { | |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
763 bool oldBusy = isBusy(); |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
764 setBusy(false); |
10 | 765 try { |
766 setInput(null); | |
767 } finally { | |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
768 setBusy(oldBusy); |
10 | 769 } |
770 return; | |
771 } | |
772 } | |
773 // use remove(int[]) rather than repeated TableItem.dispose() calls | |
774 // to allow DWT to optimize multiple removals | |
775 int[] indices = new int[elements.length]; | |
776 int count = 0; | |
777 for (int i = 0; i < elements.length; ++i) { | |
778 Widget w = findItem(elements[i]); | |
779 if (w is null && virtualManager !is null) { | |
780 int index = virtualManager.find(elements[i]); | |
781 if (index !is -1) { | |
782 indices[count++] = index; | |
783 } | |
784 } else if (auto item = cast(Item) w ) { | |
785 disassociate(item); | |
786 indices[count++] = doIndexOf(item); | |
787 } | |
788 } | |
789 if (count < indices.length) { | |
790 System.arraycopy(indices, 0, indices = new int[count], 0, count); | |
791 } | |
792 if (virtualManager !is null) { | |
793 virtualManager.removeIndices(indices); | |
794 } | |
795 doRemove(indices); | |
796 | |
797 // Workaround for 1GDGN4Q: ITPUI:WIN2000 - TableViewer icons get | |
798 // scrunched | |
799 if (doGetItemCount() is 0) { | |
800 doRemoveAll(); | |
801 } | |
802 } | |
803 | |
804 /** | |
805 * Removes the given elements from this table viewer. The selection is | |
806 * updated if required. | |
807 * <p> | |
808 * This method should be called (by the content provider) when elements have | |
809 * been removed from the model, in order to cause the viewer to accurately | |
810 * reflect the model. This method only affects the viewer, not the model. | |
811 * </p> | |
812 * | |
813 * @param elements | |
814 * the elements to remove | |
815 */ | |
816 public void remove( Object[] elements) { | |
817 assertElementsNotNull(elements); | |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
818 if (checkBusy()) |
10 | 819 return; |
820 if (elements.length is 0) { | |
821 return; | |
822 } | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
823 preservingSelection(dgRunnable( (Object[] elements_){ |
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
824 internalRemove(elements_); |
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
825 }, elements)); |
10 | 826 } |
827 | |
828 /** | |
829 * Removes the given element from this table viewer. The selection is | |
830 * updated if necessary. | |
831 * <p> | |
832 * This method should be called (by the content provider) when a single | |
833 * element has been removed from the model, in order to cause the viewer to | |
834 * accurately reflect the model. This method only affects the viewer, not | |
835 * the model. Note that there is another method for efficiently processing | |
836 * the simultaneous removal of multiple elements. | |
837 * </p> | |
838 * <strong>NOTE:</strong> removing an object from a virtual table will | |
839 * decrement the itemCount. | |
840 * | |
841 * @param element | |
842 * the element | |
843 */ | |
844 public void remove(Object element) { | |
845 remove([ element ]); | |
846 } | |
847 | |
848 /* | |
849 * (non-Javadoc) | |
850 * | |
851 * @see dwtx.jface.viewers.StructuredViewer#reveal(java.lang.Object) | |
852 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
39
diff
changeset
|
853 public override void reveal(Object element) { |
10 | 854 Assert.isNotNull(element); |
855 Widget w = findItem(element); | |
856 if (auto i = cast(Item)w ) { | |
857 doShowItem(i); | |
858 } | |
859 } | |
860 | |
861 /* | |
862 * (non-Javadoc) | |
863 * | |
864 * @see dwtx.jface.viewers.StructuredViewer#setSelectionToWidget(java.util.List, | |
865 * bool) | |
866 */ | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
867 protected override void setSelectionToWidget(List list, bool reveal) { |
10 | 868 if (list is null) { |
869 doDeselectAll(); | |
870 return; | |
871 } | |
872 | |
873 if (virtualManager !is null) { | |
874 virtualSetSelectionToWidget(list, reveal); | |
875 return; | |
876 } | |
877 | |
878 // This is vital to use doSetSelection because on DWT-Table on Win32 this will also | |
879 // move the focus to this row (See bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=198665) | |
880 if (reveal) { | |
881 int size = list.size(); | |
882 Item[] items = new Item[size]; | |
883 int count = 0; | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
884 for (int i = 0; i < size; ++i) { |
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
885 Object o = list.get(i); |
10 | 886 Widget w = findItem(o); |
887 if (auto item = cast(Item)w ) { | |
888 items[count++] = item; | |
889 } | |
890 } | |
891 if (count < size) { | |
892 System.arraycopy(items, 0, items = new Item[count], 0, count); | |
893 } | |
894 doSetSelection(items); | |
895 } else { | |
896 doDeselectAll(); // Clear the selection | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
897 if( ! list.isEmpty() ) { |
10 | 898 int[] indices = new int[list.size()]; |
899 | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
900 Iterator it = list.iterator(); |
10 | 901 Item[] items = doGetItems(); |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
902 Object modelElement; |
10 | 903 |
904 int count = 0; | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
905 while( it.hasNext() ) { |
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
906 modelElement = it.next(); |
10 | 907 bool found = false; |
908 for (int i = 0; i < items.length && !found; i++) { | |
909 if (opEquals(modelElement, items[i].getData())) { | |
910 indices[count++] = i; | |
911 found = true; | |
912 } | |
913 } | |
914 } | |
915 | |
916 if (count < indices.length) { | |
917 System.arraycopy(indices, 0, indices = new int[count], 0, count); | |
918 } | |
919 | |
920 doSelect(indices); | |
921 } | |
922 } | |
923 } | |
924 | |
925 /** | |
926 * Set the selection on a virtual table | |
927 * | |
928 * @param list | |
929 * The elements to set | |
930 * @param reveal | |
931 * Whether or not reveal the first item. | |
932 */ | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
933 private void virtualSetSelectionToWidget(List list, bool reveal) { |
10 | 934 int size = list.size(); |
935 int[] indices = new int[list.size()]; | |
936 | |
937 Item firstItem = null; | |
938 int count = 0; | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
939 HashSet virtualElements = new HashSet(); |
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
940 for (int i = 0; i < size; ++i) { |
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
941 Object o = list.get(i); |
10 | 942 Widget w = findItem(o); |
943 if (auto item = cast(Item)w ) { | |
944 indices[count++] = doIndexOf(item); | |
945 if (firstItem is null) { | |
946 firstItem = item; | |
947 } | |
948 } else { | |
949 virtualElements.add(o); | |
950 } | |
951 } | |
952 | |
953 if ( auto provider = cast(ILazyContentProvider) getContentProvider() ) { | |
954 | |
955 // Now go through it again until all is done or we are no longer | |
956 // virtual | |
957 // This may create all items so it is not a good | |
958 // idea in general. | |
959 // Use #setSelection (int [] indices,bool reveal) instead | |
960 for (int i = 0; virtualElements.size() > 0 && i < doGetItemCount(); i++) { | |
961 provider.updateElement(i); | |
962 Item item = doGetItem(i); | |
963 if (virtualElements.contains(item.getData())) { | |
964 indices[count++] = i; | |
965 virtualElements.remove(item.getData()); | |
966 if (firstItem is null) { | |
967 firstItem = item; | |
968 } | |
969 } | |
970 } | |
971 } else { | |
972 | |
973 if (count !is list.size()) {// As this is expensive skip it if all | |
974 // have been found | |
975 // If it is not lazy we can use the cache | |
976 for (int i = 0; i < virtualManager.cachedElements.length; i++) { | |
977 Object element = virtualManager.cachedElements[i]; | |
978 if (virtualElements.contains(element)) { | |
979 Item item = doGetItem(i); | |
980 item.getText();// Be sure to fire the update | |
981 indices[count++] = i; | |
982 virtualElements.remove(element); | |
983 if (firstItem is null) { | |
984 firstItem = item; | |
985 } | |
986 } | |
987 } | |
988 } | |
989 } | |
990 | |
991 if (count < size) { | |
992 System.arraycopy(indices, 0, indices = new int[count], 0, count); | |
993 } | |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
994 doDeselectAll(); |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
995 doSelect(indices); |
10 | 996 |
997 if (reveal && firstItem !is null) { | |
998 doShowItem(firstItem); | |
999 } | |
1000 } | |
1001 | |
1002 /** | |
1003 * Set the item count of the receiver. | |
1004 * | |
1005 * @param count | |
1006 * the new table size. | |
1007 * | |
1008 * @since 3.1 | |
1009 */ | |
1010 public void setItemCount(int count) { | |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
1011 if (checkBusy()) |
10 | 1012 return; |
1013 int oldCount = doGetItemCount(); | |
1014 if (count < oldCount) { | |
1015 // need to disassociate elements that are being disposed | |
1016 for (int i = count; i < oldCount; i++) { | |
1017 Item item = doGetItem(i); | |
1018 if (item.getData() !is null) { | |
1019 disassociate(item); | |
1020 } | |
1021 } | |
1022 } | |
1023 doSetItemCount(count); | |
1024 if (virtualManager !is null) { | |
1025 virtualManager.adjustCacheSize(count); | |
1026 } | |
1027 getControl().redraw(); | |
1028 } | |
1029 | |
1030 /** | |
90 | 1031 * Replace the element at the given index with the given element. This |
1032 * method will not call the content provider to verify. <strong>Note that | |
1033 * this method will materialize a TableItem the given index.</strong>. | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
1034 * |
10 | 1035 * @param element |
1036 * @param index | |
1037 * @see ILazyContentProvider | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
1038 * |
10 | 1039 * @since 3.1 |
1040 */ | |
1041 public void replace(Object element, int index) { | |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
1042 if (checkBusy()) |
10 | 1043 return; |
1044 Item item = doGetItem(index); | |
1045 refreshItem(item, element); | |
1046 } | |
1047 | |
1048 /** | |
1049 * Clear the table item at the specified index | |
1050 * | |
1051 * @param index | |
1052 * the index of the table item to be cleared | |
1053 * | |
1054 * @since 3.1 | |
1055 */ | |
1056 public void clear(int index) { | |
1057 Item item = doGetItem(index); | |
1058 if (item.getData() !is null) { | |
1059 disassociate(item); | |
1060 } | |
1061 doClear(index); | |
1062 } | |
1063 | |
1064 /* | |
1065 * (non-Javadoc) | |
1066 * | |
1067 * @see dwtx.jface.viewers.StructuredViewer#getRawChildren(java.lang.Object) | |
1068 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
39
diff
changeset
|
1069 protected override Object[] getRawChildren(Object parent) { |
10 | 1070 |
1071 Assert.isTrue(!( null !is cast(ILazyContentProvider) getContentProvider() ), | |
1072 "Cannot get raw children with an ILazyContentProvider");//$NON-NLS-1$ | |
1073 return super.getRawChildren(parent); | |
1074 | |
1075 } | |
1076 | |
1077 /* | |
1078 * (non-Javadoc) | |
1079 * | |
1080 * @see dwtx.jface.viewers.StructuredViewer#assertContentProviderType(dwtx.jface.viewers.IContentProvider) | |
1081 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
39
diff
changeset
|
1082 protected override void assertContentProviderType(IContentProvider provider) { |
10 | 1083 Assert.isTrue(null !is cast(IStructuredContentProvider)provider |
1084 || null !is cast(ILazyContentProvider)provider ); | |
1085 } | |
1086 | |
1087 /** | |
1088 * Searches the receiver's list starting at the first item (index 0) until | |
1089 * an item is found that is equal to the argument, and returns the index of | |
1090 * that item. If no item is found, returns -1. | |
1091 * | |
1092 * @param item | |
1093 * the search item | |
1094 * @return the index of the item | |
1095 * | |
1096 * @since 3.3 | |
1097 */ | |
1098 protected abstract int doIndexOf(Item item); | |
1099 | |
1100 /** | |
1101 * Returns the number of items contained in the receiver. | |
1102 * | |
1103 * @return the number of items | |
1104 * | |
1105 * @since 3.3 | |
1106 */ | |
1107 protected abstract int doGetItemCount(); | |
1108 | |
1109 /** | |
1110 * Sets the number of items contained in the receiver. | |
1111 * | |
1112 * @param count | |
1113 * the number of items | |
1114 * | |
1115 * @since 3.3 | |
1116 */ | |
1117 protected abstract void doSetItemCount(int count); | |
1118 | |
1119 /** | |
1120 * Returns a (possibly empty) array of TableItems which are the items in the | |
1121 * receiver. | |
1122 * | |
1123 * @return the items in the receiver | |
1124 * | |
1125 * @since 3.3 | |
1126 */ | |
1127 protected abstract Item[] doGetItems(); | |
1128 | |
1129 /** | |
1130 * Returns the column at the given, zero-relative index in the receiver. | |
1131 * Throws an exception if the index is out of range. Columns are returned in | |
1132 * the order that they were created. If no TableColumns were created by the | |
1133 * programmer, this method will throw ERROR_INVALID_RANGE despite the fact | |
1134 * that a single column of data may be visible in the table. This occurs | |
1135 * when the programmer uses the table like a list, adding items but never | |
1136 * creating a column. | |
1137 * | |
1138 * @param index | |
1139 * the index of the column to return | |
1140 * @return the column at the given index | |
1141 * @exception IllegalArgumentException - | |
1142 * if the index is not between 0 and the number of elements | |
1143 * in the list minus 1 (inclusive) | |
1144 * | |
1145 * @since 3.3 | |
1146 */ | |
1147 protected abstract Widget doGetColumn(int index); | |
1148 | |
1149 /** | |
1150 * Returns the item at the given, zero-relative index in the receiver. | |
1151 * Throws an exception if the index is out of range. | |
1152 * | |
1153 * @param index | |
1154 * the index of the item to return | |
1155 * @return the item at the given index | |
1156 * @exception IllegalArgumentException - | |
1157 * if the index is not between 0 and the number of elements | |
1158 * in the list minus 1 (inclusive) | |
1159 * | |
1160 * @since 3.3 | |
1161 */ | |
1162 protected abstract Item doGetItem(int index); | |
1163 | |
1164 /** | |
1165 * Returns an array of {@link Item} that are currently selected in the | |
1166 * receiver. The order of the items is unspecified. An empty array indicates | |
1167 * that no items are selected. | |
1168 * | |
1169 * @return an array representing the selection | |
1170 * | |
1171 * @since 3.3 | |
1172 */ | |
1173 protected abstract Item[] doGetSelection(); | |
1174 | |
1175 /** | |
1176 * Returns the zero-relative indices of the items which are currently | |
1177 * selected in the receiver. The order of the indices is unspecified. The | |
1178 * array is empty if no items are selected. | |
1179 * | |
1180 * @return an array representing the selection | |
1181 * | |
1182 * @since 3.3 | |
1183 */ | |
1184 protected abstract int[] doGetSelectionIndices(); | |
1185 | |
1186 /** | |
1187 * Clears all the items in the receiver. The text, icon and other attributes | |
1188 * of the items are set to their default values. If the table was created | |
1189 * with the <code>DWT.VIRTUAL</code> style, these attributes are requested | |
1190 * again as needed. | |
1191 * | |
1192 * @since 3.3 | |
1193 */ | |
1194 protected abstract void doClearAll(); | |
1195 | |
1196 /** | |
1197 * Resets the given item in the receiver. The text, icon and other attributes | |
1198 * of the item are set to their default values. | |
1199 * | |
1200 * @param item the item to reset | |
1201 * | |
1202 * @since 3.3 | |
1203 */ | |
1204 protected abstract void doResetItem(Item item); | |
1205 | |
1206 /** | |
1207 * Removes the items from the receiver which are between the given | |
1208 * zero-relative start and end indices (inclusive). | |
1209 * | |
1210 * @param start | |
1211 * the start of the range | |
1212 * @param end | |
1213 * the end of the range | |
1214 * | |
1215 * @exception IllegalArgumentException - | |
1216 * if either the start or end are not between 0 and the | |
1217 * number of elements in the list minus 1 (inclusive) | |
1218 * | |
1219 * @since 3.3 | |
1220 */ | |
1221 protected abstract void doRemove(int start, int end); | |
1222 | |
1223 /** | |
1224 * Removes all of the items from the receiver. | |
1225 * | |
1226 * @since 3.3 | |
1227 */ | |
1228 protected abstract void doRemoveAll(); | |
1229 | |
1230 /** | |
1231 * Removes the items from the receiver's list at the given zero-relative | |
1232 * indices. | |
1233 * | |
1234 * @param indices | |
1235 * the array of indices of the items | |
1236 * | |
1237 * @exception IllegalArgumentException - | |
1238 * if the array is null, or if any of the indices is not | |
1239 * between 0 and the number of elements in the list minus 1 | |
1240 * (inclusive) | |
1241 * | |
1242 * @since 3.3 | |
1243 */ | |
1244 protected abstract void doRemove(int[] indices); | |
1245 | |
1246 /** | |
1247 * Shows the item. If the item is already showing in the receiver, this | |
1248 * method simply returns. Otherwise, the items are scrolled until the item | |
1249 * is visible. | |
1250 * | |
1251 * @param item | |
1252 * the item to be shown | |
1253 * | |
1254 * @exception IllegalArgumentException - | |
1255 * if the item is null | |
1256 * | |
1257 * @since 3.3 | |
1258 */ | |
1259 protected abstract void doShowItem(Item item); | |
1260 | |
1261 /** | |
1262 * Deselects all selected items in the receiver. | |
1263 * | |
1264 * @since 3.3 | |
1265 */ | |
1266 protected abstract void doDeselectAll(); | |
1267 | |
1268 /** | |
1269 * Sets the receiver's selection to be the given array of items. The current | |
1270 * selection is cleared before the new items are selected. | |
1271 * <p> | |
1272 * Items that are not in the receiver are ignored. If the receiver is | |
1273 * single-select and multiple items are specified, then all items are | |
1274 * ignored. | |
1275 * </p> | |
1276 * | |
1277 * @param items | |
1278 * the array of items | |
1279 * | |
1280 * @exception IllegalArgumentException - | |
1281 * if the array of items is null | |
1282 * | |
1283 * @since 3.3 | |
1284 */ | |
1285 protected abstract void doSetSelection(Item[] items); | |
1286 | |
1287 /** | |
1288 * Shows the selection. If the selection is already showing in the receiver, | |
1289 * this method simply returns. Otherwise, the items are scrolled until the | |
1290 * selection is visible. | |
1291 * | |
1292 * @since 3.3 | |
1293 */ | |
1294 protected abstract void doShowSelection(); | |
1295 | |
1296 /** | |
1297 * Selects the items at the given zero-relative indices in the receiver. The | |
1298 * current selection is cleared before the new items are selected. | |
1299 * <p> | |
1300 * Indices that are out of range and duplicate indices are ignored. If the | |
1301 * receiver is single-select and multiple indices are specified, then all | |
1302 * indices are ignored. | |
1303 * </p> | |
1304 * | |
1305 * @param indices | |
1306 * the indices of the items to select | |
1307 * | |
1308 * @exception IllegalArgumentException - | |
1309 * if the array of indices is null | |
1310 * | |
1311 * @since 3.3 | |
1312 */ | |
1313 protected abstract void doSetSelection(int[] indices); | |
1314 | |
1315 /** | |
1316 * Clears the item at the given zero-relative index in the receiver. The | |
1317 * text, icon and other attributes of the item are set to the default value. | |
1318 * If the table was created with the <code>DWT.VIRTUAL</code> style, these | |
1319 * attributes are requested again as needed. | |
1320 * | |
1321 * @param index | |
1322 * the index of the item to clear | |
1323 * | |
1324 * @exception IllegalArgumentException - | |
1325 * if the index is not between 0 and the number of elements | |
1326 * in the list minus 1 (inclusive) | |
1327 * | |
1328 * @see DWT#VIRTUAL | |
1329 * @see DWT#SetData | |
1330 * | |
1331 * @since 3.3 | |
1332 */ | |
1333 protected abstract void doClear(int index); | |
1334 | |
1335 | |
1336 | |
1337 /** | |
1338 * Selects the items at the given zero-relative indices in the receiver. | |
1339 * The current selection is not cleared before the new items are selected. | |
1340 * <p> | |
1341 * If the item at a given index is not selected, it is selected. | |
1342 * If the item at a given index was already selected, it remains selected. | |
1343 * Indices that are out of range and duplicate indices are ignored. | |
1344 * If the receiver is single-select and multiple indices are specified, | |
1345 * then all indices are ignored. | |
1346 * </p> | |
1347 * | |
1348 * @param indices the array of indices for the items to select | |
1349 * | |
1350 * @exception IllegalArgumentException - if the array of indices is null | |
1351 * | |
1352 */ | |
1353 protected abstract void doSelect(int[] indices); | |
1354 | |
1355 } |