Mercurial > projects > dwt-addons
annotate dwtx/jface/viewers/AbstractListViewer.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 | 46a6e0e6ccd4 |
children |
rev | line source |
---|---|
10 | 1 /******************************************************************************* |
2 * Copyright (c) 2004, 2007 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 * Chris Longfield <clongfield@internap.com> - Fix for Bug 70856 | |
11 * Tom Schindl - fix for bug 157309 | |
12 * Brad Reynolds - bug 141435 | |
13 * Port to the D programming language: | |
14 * Frank Benoit <benoit@tionex.de> | |
15 *******************************************************************************/ | |
16 | |
17 module dwtx.jface.viewers.AbstractListViewer; | |
18 | |
19 import dwtx.jface.viewers.StructuredViewer; | |
20 import dwtx.jface.viewers.ILabelProvider; | |
21 import dwtx.jface.viewers.IBaseLabelProvider; | |
22 import dwtx.jface.viewers.ViewerComparator; | |
23 import dwtx.jface.viewers.IElementComparer; | |
24 | |
25 | |
26 import dwt.widgets.Control; | |
27 import dwt.widgets.Widget; | |
28 import dwtx.core.runtime.Assert; | |
29 | |
30 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:
70
diff
changeset
|
31 import dwtx.dwtxhelper.Collection; |
10 | 32 import dwt.dwthelper.Runnable; |
33 | |
34 /** | |
35 * Abstract base class for viewers that contain lists of items (such as a combo or list). | |
36 * Most of the viewer implementation is in this base class, except for the minimal code that | |
37 * actually communicates with the underlying widget. | |
38 * | |
39 * @see dwtx.jface.viewers.ListViewer | |
40 * @see dwtx.jface.viewers.ComboViewer | |
41 * | |
42 * @since 3.0 | |
43 */ | |
44 public abstract class AbstractListViewer : StructuredViewer { | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
42
diff
changeset
|
45 alias StructuredViewer.internalRefresh internalRefresh; |
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
42
diff
changeset
|
46 alias StructuredViewer.setSelectionToWidget setSelectionToWidget; |
10 | 47 |
48 /** | |
49 * A list of viewer elements (element type: <code>Object</code>). | |
50 */ | |
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:
70
diff
changeset
|
51 private dwtx.dwtxhelper.Collection.List listMap; |
10 | 52 |
53 /** | |
54 * Adds the given string to the underlying widget at the given index | |
55 * | |
56 * @param string the string to add | |
57 * @param index position to insert the string into | |
58 */ | |
59 protected abstract void listAdd(String string, int index); | |
60 | |
61 /** | |
62 * Sets the text of the item at the given index in the underlying widget. | |
63 * | |
64 * @param index index to modify | |
65 * @param string new text | |
66 */ | |
67 protected abstract void listSetItem(int index, String string); | |
68 | |
69 /** | |
70 * Returns the zero-relative indices of the items which are currently | |
71 * selected in the underlying widget. The array is empty if no items are selected. | |
72 * <p> | |
73 * Note: This is not the actual structure used by the receiver | |
74 * to maintain its selection, so modifying the array will | |
75 * not affect the receiver. | |
76 * </p> | |
77 * @return the array of indices of the selected items | |
78 */ | |
79 protected abstract int[] listGetSelectionIndices(); | |
80 | |
81 /** | |
82 * Returns the number of items contained in the underlying widget. | |
83 * | |
84 * @return the number of items | |
85 */ | |
86 protected abstract int listGetItemCount(); | |
87 | |
88 /** | |
89 * Sets the underlying widget's items to be the given array of items. | |
90 * | |
91 * @param labels the array of label text | |
92 */ | |
93 protected abstract void listSetItems(String[] labels); | |
94 | |
95 /** | |
96 * Removes all of the items from the underlying widget. | |
97 */ | |
98 protected abstract void listRemoveAll(); | |
99 | |
100 /** | |
101 * Removes the item from the underlying widget at the given | |
102 * zero-relative index. | |
103 * | |
104 * @param index the index for the item | |
105 */ | |
106 protected abstract void listRemove(int index); | |
107 | |
108 /** | |
109 * Selects the items at the given zero-relative indices in the underlying widget. | |
110 * The current selection is cleared before the new items are selected. | |
111 * <p> | |
112 * Indices that are out of range and duplicate indices are ignored. | |
113 * If the receiver is single-select and multiple indices are specified, | |
114 * then all indices are ignored. | |
115 * | |
116 * @param ixs the indices of the items to select | |
117 */ | |
118 protected abstract void listSetSelection(int[] ixs); | |
119 | |
120 /** | |
121 * Shows the selection. If the selection is already showing in the receiver, | |
122 * this method simply returns. Otherwise, the items are scrolled until | |
123 * the selection is visible. | |
124 */ | |
125 protected abstract void listShowSelection(); | |
126 | |
127 /** | |
128 * Deselects all selected items in the underlying widget. | |
129 */ | |
130 protected abstract void listDeselectAll(); | |
131 | |
132 public this(){ | |
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:
70
diff
changeset
|
133 listMap = new ArrayList(); |
10 | 134 } |
135 | |
136 /** | |
137 * Adds the given elements to this list viewer. | |
138 * If this viewer does not have a sorter, the elements are added at the end | |
139 * in the order given; otherwise the elements are inserted at appropriate positions. | |
140 * <p> | |
141 * This method should be called (by the content provider) when elements | |
142 * have been added to the model, in order to cause the viewer to accurately | |
143 * reflect the model. This method only affects the viewer, not the model. | |
144 * </p> | |
145 * | |
146 * @param elements the elements to add | |
147 */ | |
148 public void add(Object[] elements) { | |
149 assertElementsNotNull(elements); | |
150 Object[] filtered = filter(elements); | |
151 ILabelProvider labelProvider = cast(ILabelProvider) getLabelProvider(); | |
152 for (int i = 0; i < filtered.length; i++) { | |
153 Object element = filtered[i]; | |
154 int ix = indexForElement(element); | |
155 insertItem(labelProvider, element, ix); | |
156 } | |
157 } | |
158 | |
159 private void insertItem(ILabelProvider labelProvider, Object element, int index) { | |
160 listAdd(getLabelProviderText(labelProvider, element), index); | |
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:
70
diff
changeset
|
161 listMap.add(index, element); |
10 | 162 mapElement(element, getControl()); // must map it, since findItem only looks in map, if enabled |
163 } | |
164 | |
165 /** | |
166 * Inserts the given element into this list viewer at the given position. | |
167 * If this viewer has a sorter, the position is ignored and the element is | |
168 * inserted at the correct position in the sort order. | |
169 * <p> | |
170 * This method should be called (by the content provider) when elements have | |
171 * been added to the model, in order to cause the viewer to accurately | |
172 * reflect the model. This method only affects the viewer, not the model. | |
173 * </p> | |
174 * | |
175 * @param element | |
176 * the element | |
177 * @param position | |
178 * a 0-based position relative to the model, or -1 to indicate | |
179 * the last position | |
180 * @since 3.3 | |
181 */ | |
182 public void insert(Object element, int position) { | |
183 if (getComparator() !is null || hasFilters()) { | |
184 add(element); | |
185 return; | |
186 } | |
187 | |
188 insertItem(cast(ILabelProvider) getLabelProvider(), element, position); | |
189 } | |
190 | |
191 | |
192 /** | |
193 * Return the text for the element from the labelProvider. | |
194 * If it is null then return the empty String. | |
195 * @param labelProvider ILabelProvider | |
196 * @param element | |
197 * @return String. Return the emptyString if the labelProvider | |
198 * returns null for the text. | |
199 * | |
200 * @since 3.1 | |
201 */ | |
202 private String getLabelProviderText(ILabelProvider labelProvider, Object element){ | |
203 String text = labelProvider.getText(element); | |
204 if(text is null) { | |
205 return "";//$NON-NLS-1$ | |
206 } | |
207 return text; | |
208 } | |
209 | |
210 /** | |
211 * Adds the given element to this list viewer. | |
212 * If this viewer does not have a sorter, the element is added at the end; | |
213 * otherwise the element is inserted at the appropriate position. | |
214 * <p> | |
215 * This method should be called (by the content provider) when a single element | |
216 * has been added to the model, in order to cause the viewer to accurately | |
217 * reflect the model. This method only affects the viewer, not the model. | |
218 * Note that there is another method for efficiently processing the simultaneous | |
219 * addition of multiple elements. | |
220 * </p> | |
221 * | |
222 * @param element the element | |
223 */ | |
224 public void add(Object element) { | |
225 add([ element ]); | |
226 } | |
227 | |
228 /* (non-Javadoc) | |
229 * Method declared on StructuredViewer. | |
230 * Since DWT.List doesn't use items we always return the List itself. | |
231 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
42
diff
changeset
|
232 protected override Widget doFindInputItem(Object element) { |
10 | 233 if (element !is null && opEquals(element, getRoot())) { |
234 return getControl(); | |
235 } | |
236 return null; | |
237 } | |
238 | |
239 /* (non-Javadoc) | |
240 * Method declared on StructuredViewer. | |
241 * Since DWT.List doesn't use items we always return the List itself. | |
242 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
42
diff
changeset
|
243 protected override Widget doFindItem(Object element) { |
10 | 244 if (element !is null) { |
245 if (listMapContains(element)) { | |
246 return getControl(); | |
247 } | |
248 } | |
249 return null; | |
250 } | |
251 | |
252 /* (non-Javadoc) | |
253 * Method declared on StructuredViewer. | |
254 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
42
diff
changeset
|
255 protected override void doUpdateItem(Widget data, Object element, bool fullMap) { |
10 | 256 if (element !is null) { |
257 int ix = getElementIndex(element); | |
258 if (ix >= 0) { | |
259 ILabelProvider labelProvider = cast(ILabelProvider) getLabelProvider(); | |
260 listSetItem(ix, getLabelProviderText(labelProvider,element)); | |
261 } | |
262 } | |
263 } | |
264 | |
265 /** | |
266 * Returns the element with the given index from this list viewer. | |
267 * Returns <code>null</code> if the index is out of range. | |
268 * | |
269 * @param index the zero-based index | |
270 * @return the element at the given index, or <code>null</code> if the | |
271 * index is out of range | |
272 */ | |
273 public Object getElementAt(int index) { | |
274 if (index >= 0 && index < listMap.size()) { | |
275 return listMap.get(index); | |
276 } | |
277 return null; | |
278 } | |
279 | |
280 /** | |
281 * The list viewer implementation of this <code>Viewer</code> framework | |
282 * method returns the label provider, which in the case of list | |
283 * viewers will be an instance of <code>ILabelProvider</code>. | |
284 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
42
diff
changeset
|
285 public override IBaseLabelProvider getLabelProvider() { |
10 | 286 return super.getLabelProvider(); |
287 } | |
288 | |
289 /* (non-Javadoc) | |
290 * Method declared on Viewer. | |
291 */ | |
292 /* (non-Javadoc) | |
293 * Method declared on StructuredViewer. | |
294 */ | |
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:
70
diff
changeset
|
295 protected override List getSelectionFromWidget() { |
10 | 296 int[] ixs = listGetSelectionIndices(); |
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:
70
diff
changeset
|
297 ArrayList list = new ArrayList(ixs.length); |
10 | 298 for (int i = 0; i < ixs.length; i++) { |
299 Object e = getElementAt(ixs[i]); | |
300 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:
70
diff
changeset
|
301 list.add(e); |
10 | 302 } |
303 } | |
304 return list; | |
305 } | |
306 | |
307 /** | |
308 * @param element the element to insert | |
309 * @return the index where the item should be inserted. | |
310 */ | |
311 protected int indexForElement(Object element) { | |
312 ViewerComparator comparator = getComparator(); | |
313 if (comparator is null) { | |
314 return listGetItemCount(); | |
315 } | |
316 int count = listGetItemCount(); | |
317 int min = 0, max = count - 1; | |
318 while (min <= max) { | |
319 int mid = (min + max) / 2; | |
320 Object data = listMap.get(mid); | |
321 int compare = comparator.compare(this, data, element); | |
322 if (compare is 0) { | |
323 // find first item > element | |
324 while (compare is 0) { | |
325 ++mid; | |
326 if (mid >= count) { | |
327 break; | |
328 } | |
329 data = listMap.get(mid); | |
330 compare = comparator.compare(this, data, element); | |
331 } | |
332 return mid; | |
333 } | |
334 if (compare < 0) { | |
335 min = mid + 1; | |
336 } else { | |
337 max = mid - 1; | |
338 } | |
339 } | |
340 return min; | |
341 } | |
342 | |
343 /* (non-Javadoc) | |
344 * Method declared on Viewer. | |
345 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
42
diff
changeset
|
346 protected override void inputChanged(Object input, Object oldInput) { |
10 | 347 listMap.clear(); |
348 Object[] children = getSortedChildren(getRoot()); | |
349 int size = children.length; | |
350 | |
351 listRemoveAll(); | |
352 String[] labels = new String[size]; | |
353 for (int i = 0; i < size; i++) { | |
354 Object el = children[i]; | |
355 labels[i] = getLabelProviderText(cast(ILabelProvider) getLabelProvider(),el); | |
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:
70
diff
changeset
|
356 listMap.add(el); |
10 | 357 mapElement(el, getControl()); // must map it, since findItem only looks in map, if enabled |
358 } | |
359 listSetItems(labels); | |
360 } | |
361 | |
362 /* (non-Javadoc) | |
363 * Method declared on StructuredViewer. | |
364 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
42
diff
changeset
|
365 protected override void internalRefresh(Object element) { |
10 | 366 Control list = getControl(); |
367 if (element is null || opEquals(element, getRoot())) { | |
368 // the parent | |
369 if (listMap !is null) { | |
370 listMap.clear(); | |
371 } | |
372 unmapAllElements(); | |
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:
70
diff
changeset
|
373 List selection = getSelectionFromWidget(); |
10 | 374 |
375 int topIndex = -1; | |
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:
70
diff
changeset
|
376 if (selection is null || selection.isEmpty()) { |
10 | 377 topIndex = listGetTopIndex(); |
378 } | |
379 | |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
380 Object[] children = null; |
10 | 381 list.setRedraw(false); |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
382 try { |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
383 listRemoveAll(); |
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:
70
diff
changeset
|
384 |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
385 children = getSortedChildren(getRoot()); |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
386 String[] items = new String[children.length]; |
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:
70
diff
changeset
|
387 |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
388 ILabelProvider labelProvider = cast(ILabelProvider) getLabelProvider(); |
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:
70
diff
changeset
|
389 |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
390 for (int i = 0; i < items.length; i++) { |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
391 Object el = children[i]; |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
392 items[i] = getLabelProviderText(labelProvider, el); |
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:
70
diff
changeset
|
393 listMap.add(el); |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
394 mapElement(el, list); // must map it, since findItem only looks in map, if enabled |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
395 } |
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:
70
diff
changeset
|
396 |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
397 listSetItems(items); |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
398 } finally { |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
399 list.setRedraw(true); |
10 | 400 } |
401 | |
402 if (topIndex is -1) { | |
403 setSelectionToWidget(selection, false); | |
404 } else { | |
405 listSetTopIndex(Math.min(topIndex, children.length)); | |
406 } | |
407 } else { | |
408 doUpdateItem(list, element, true); | |
409 } | |
410 } | |
411 | |
412 /** | |
413 * Returns the index of the item currently at the top of the viewable area. | |
414 * <p> | |
415 * Default implementation returns -1. | |
416 * </p> | |
417 * @return index, -1 for none | |
418 * @since 3.3 | |
419 */ | |
420 protected int listGetTopIndex(){ | |
421 return -1; | |
422 } | |
423 | |
424 /** | |
425 * Sets the index of the item to be at the top of the viewable area. | |
426 * <p> | |
427 * Default implementation does nothing. | |
428 * </p> | |
429 * @param index the given index. -1 for none. index will always refer to a valid index. | |
430 * @since 3.3 | |
431 */ | |
432 protected void listSetTopIndex(int index) { | |
433 } | |
434 | |
435 /** | |
436 * Removes the given elements from this list viewer. | |
437 * | |
438 * @param elements the elements to remove | |
439 */ | |
440 private void internalRemove(Object[] elements) { | |
441 Object input = getInput(); | |
442 for (int i = 0; i < elements.length; ++i) { | |
443 if ( opEquals(elements[i], input)) { | |
444 setInput(null); | |
445 return; | |
446 } | |
447 int ix = getElementIndex(elements[i]); | |
448 if (ix >= 0) { | |
449 listRemove(ix); | |
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:
70
diff
changeset
|
450 listMap.remove(ix); |
10 | 451 unmapElement(elements[i], getControl()); |
452 } | |
453 } | |
454 } | |
455 | |
456 /** | |
457 * Removes the given elements from this list viewer. | |
458 * The selection is updated if required. | |
459 * <p> | |
460 * This method should be called (by the content provider) when elements | |
461 * have been removed from the model, in order to cause the viewer to accurately | |
462 * reflect the model. This method only affects the viewer, not the model. | |
463 * </p> | |
464 * | |
465 * @param elements the elements to remove | |
466 */ | |
467 public void remove(Object[] elements) { | |
468 assertElementsNotNull(elements); | |
469 if (elements.length is 0) { | |
470 return; | |
471 } | |
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:
70
diff
changeset
|
472 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:
70
diff
changeset
|
473 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:
70
diff
changeset
|
474 }, elements)); |
10 | 475 } |
476 | |
477 /** | |
478 * Removes the given element from this list viewer. | |
479 * The selection is updated if necessary. | |
480 * <p> | |
481 * This method should be called (by the content provider) when a single element | |
482 * has been removed from the model, in order to cause the viewer to accurately | |
483 * reflect the model. This method only affects the viewer, not the model. | |
484 * Note that there is another method for efficiently processing the simultaneous | |
485 * removal of multiple elements. | |
486 * </p> | |
487 * | |
488 * @param element the element | |
489 */ | |
490 public void remove(Object element) { | |
491 remove([ element ]); | |
492 } | |
493 | |
494 /** | |
495 * The list viewer implementation of this <code>Viewer</code> framework | |
496 * method ensures that the given label provider is an instance of | |
497 * <code>ILabelProvider</code>. | |
498 * | |
499 * <b>The optional interfaces {@link IColorProvider} and | |
500 * {@link IFontProvider} have no effect for this type of viewer</b> | |
501 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
42
diff
changeset
|
502 public override void setLabelProvider(IBaseLabelProvider labelProvider) { |
10 | 503 Assert.isTrue( null !is cast(ILabelProvider)labelProvider ); |
504 super.setLabelProvider(labelProvider); | |
505 } | |
506 | |
507 /* (non-Javadoc) | |
508 * Method declared on StructuredViewer. | |
509 */ | |
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:
70
diff
changeset
|
510 protected override void setSelectionToWidget(List in_, bool reveal) { |
10 | 511 if (in_ is null || in_.size() is 0) { // clear selection |
512 listDeselectAll(); | |
513 } else { | |
514 int n = in_.size(); | |
515 int[] ixs = new int[n]; | |
516 int count = 0; | |
517 for (int i = 0; i < n; ++i) { | |
518 Object el = in_.get(i); | |
519 int ix = getElementIndex(el); | |
520 if (ix >= 0) { | |
521 ixs[count++] = ix; | |
522 } | |
523 } | |
524 if (count < n) { | |
525 System.arraycopy(ixs, 0, ixs = new int[count], 0, count); | |
526 } | |
527 listSetSelection(ixs); | |
528 if (reveal) { | |
529 listShowSelection(); | |
530 } | |
531 } | |
532 } | |
533 | |
534 /** | |
535 * Returns the index of the given element in listMap, or -1 if the element cannot be found. | |
536 * As of 3.3, uses the element comparer if available. | |
537 * | |
538 * @param element | |
539 * @return the index | |
540 */ | |
541 int getElementIndex(Object element) { | |
542 IElementComparer comparer = getComparer(); | |
543 if (comparer 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:
70
diff
changeset
|
544 return listMap.indexOf(element); |
10 | 545 } |
546 int size = listMap.size(); | |
547 for (int i = 0; i < size; i++) { | |
548 if (comparer.opEquals(element, listMap.get(i))) | |
549 return i; | |
550 } | |
551 return -1; | |
552 } | |
553 | |
554 /** | |
555 * @param element | |
556 * @return true if listMap contains the given element | |
557 * | |
558 * @since 3.3 | |
559 */ | |
560 private bool listMapContains(Object element) { | |
561 return getElementIndex(element) !is -1; | |
562 } | |
563 | |
564 } |