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