|
Lines 7-12
Link Here
|
| 7 |
* |
7 |
* |
| 8 |
* Contributors: |
8 |
* Contributors: |
| 9 |
* IBM Corporation - initial API and implementation |
9 |
* IBM Corporation - initial API and implementation |
|
|
10 |
* Tom Schindl <tom.schindl@bestsolution.at> (bug 83200) |
| 10 |
*******************************************************************************/ |
11 |
*******************************************************************************/ |
| 11 |
|
12 |
|
| 12 |
package org.eclipse.jface.viewers; |
13 |
package org.eclipse.jface.viewers; |
|
Lines 28-33
Link Here
|
| 28 |
import org.eclipse.swt.widgets.Item; |
29 |
import org.eclipse.swt.widgets.Item; |
| 29 |
import org.eclipse.swt.widgets.Listener; |
30 |
import org.eclipse.swt.widgets.Listener; |
| 30 |
import org.eclipse.swt.widgets.Table; |
31 |
import org.eclipse.swt.widgets.Table; |
|
|
32 |
import org.eclipse.swt.widgets.TableColumn; |
| 31 |
import org.eclipse.swt.widgets.TableItem; |
33 |
import org.eclipse.swt.widgets.TableItem; |
| 32 |
import org.eclipse.swt.widgets.Widget; |
34 |
import org.eclipse.swt.widgets.Widget; |
| 33 |
|
35 |
|
|
Lines 64-241
Link Here
|
| 64 |
* @see #internalRefresh(Object, boolean) |
66 |
* @see #internalRefresh(Object, boolean) |
| 65 |
*/ |
67 |
*/ |
| 66 |
public class TableViewer extends StructuredViewer { |
68 |
public class TableViewer extends StructuredViewer { |
| 67 |
|
69 |
|
| 68 |
private class VirtualManager{ |
70 |
private class VirtualManager { |
| 69 |
|
71 |
|
| 70 |
/** |
72 |
/** |
| 71 |
* The currently invisible elements as provided |
73 |
* The currently invisible elements as provided by the content provider |
| 72 |
* by the content provider or by addition. |
74 |
* or by addition. This will not be populated by an |
| 73 |
* This will not be populated by an ILazyStructuredContentProvider |
75 |
* ILazyStructuredContentProvider as an ILazyStructuredContentProvider |
| 74 |
* as an ILazyStructuredContentProvider is only queried |
76 |
* is only queried on the virtual callback. |
| 75 |
* on the virtual callback. |
|
|
| 76 |
*/ |
77 |
*/ |
| 77 |
private Object[] cachedElements = new Object[0]; |
78 |
private Object[] cachedElements = new Object[0]; |
|
|
79 |
|
| 78 |
/** |
80 |
/** |
| 79 |
* Create a new instance of the receiver. |
81 |
* Create a new instance of the receiver. |
| 80 |
* |
82 |
* |
| 81 |
*/ |
83 |
*/ |
| 82 |
public VirtualManager(){ |
84 |
public VirtualManager() { |
| 83 |
addTableListener(); |
85 |
addTableListener(); |
| 84 |
} |
86 |
} |
| 85 |
|
87 |
|
| 86 |
|
|
|
| 87 |
/** |
88 |
/** |
| 88 |
* Add the listener for SetData on the table |
89 |
* Add the listener for SetData on the table |
| 89 |
*/ |
90 |
*/ |
| 90 |
private void addTableListener() { |
91 |
private void addTableListener() { |
| 91 |
table.addListener(SWT.SetData,new Listener(){ |
92 |
table.addListener(SWT.SetData, new Listener() { |
| 92 |
/* (non-Javadoc) |
93 |
/* |
|
|
94 |
* (non-Javadoc) |
| 95 |
* |
| 93 |
* @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event) |
96 |
* @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event) |
| 94 |
*/ |
97 |
*/ |
| 95 |
public void handleEvent(Event event) { |
98 |
public void handleEvent(Event event) { |
| 96 |
TableItem item = (TableItem) event.item; |
99 |
TableItem item = (TableItem) event.item; |
| 97 |
final int index = table.indexOf(item); |
100 |
final int index = table.indexOf(item); |
| 98 |
Object element = resolveElement(index); |
101 |
Object element = resolveElement(index); |
| 99 |
if(element == null){ |
102 |
if (element == null) { |
| 100 |
//Didn't find it so make a request |
103 |
// Didn't find it so make a request |
| 101 |
//Keep looking if it is not in the cache. |
104 |
// Keep looking if it is not in the cache. |
| 102 |
IContentProvider contentProvider = getContentProvider(); |
105 |
IContentProvider contentProvider = getContentProvider(); |
| 103 |
//If we are building lazily then request lookup now |
106 |
// If we are building lazily then request lookup now |
| 104 |
if(contentProvider instanceof ILazyContentProvider){ |
107 |
if (contentProvider instanceof ILazyContentProvider) { |
| 105 |
((ILazyContentProvider) contentProvider). |
108 |
((ILazyContentProvider) contentProvider) |
| 106 |
updateElement(index); |
109 |
.updateElement(index); |
| 107 |
return; |
110 |
return; |
| 108 |
} |
111 |
} |
| 109 |
} |
112 |
} |
| 110 |
|
113 |
|
| 111 |
|
114 |
associate(element, item); |
| 112 |
associate(element,item); |
115 |
updateItem(item, element); |
| 113 |
updateItem(item,element); |
|
|
| 114 |
} |
116 |
} |
| 115 |
|
117 |
|
| 116 |
}); |
118 |
}); |
| 117 |
} |
119 |
} |
| 118 |
|
120 |
|
| 119 |
/** |
121 |
/** |
| 120 |
* Get the element at index.Resolve it lazily if this |
122 |
* Get the element at index.Resolve it lazily if this is available. |
| 121 |
* is available. |
123 |
* |
| 122 |
* @param index |
124 |
* @param index |
| 123 |
* @return Object or <code>null</code> if it could |
125 |
* @return Object or <code>null</code> if it could not be found |
| 124 |
* not be found |
|
|
| 125 |
*/ |
126 |
*/ |
| 126 |
protected Object resolveElement(int index) { |
127 |
protected Object resolveElement(int index) { |
| 127 |
|
128 |
|
| 128 |
Object element = null; |
129 |
Object element = null; |
| 129 |
if(index < cachedElements.length) { |
130 |
if (index < cachedElements.length) { |
| 130 |
element = cachedElements[index]; |
131 |
element = cachedElements[index]; |
| 131 |
} |
132 |
} |
| 132 |
|
133 |
|
| 133 |
return element; |
134 |
return element; |
| 134 |
} |
135 |
} |
| 135 |
|
136 |
|
| 136 |
/** |
137 |
/** |
| 137 |
* A non visible item has been added. |
138 |
* A non visible item has been added. |
|
|
139 |
* |
| 138 |
* @param element |
140 |
* @param element |
| 139 |
* @param index |
141 |
* @param index |
| 140 |
*/ |
142 |
*/ |
| 141 |
public void notVisibleAdded(Object element, int index) { |
143 |
public void notVisibleAdded(Object element, int index) { |
| 142 |
|
144 |
|
| 143 |
int requiredCount = index + 1; |
145 |
int requiredCount = index + 1; |
| 144 |
|
146 |
|
| 145 |
if(requiredCount > getTable().getItemCount()){ |
147 |
if (requiredCount > getTable().getItemCount()) { |
| 146 |
getTable().setItemCount(requiredCount); |
148 |
getTable().setItemCount(requiredCount); |
| 147 |
Object[] newCache = new Object[requiredCount]; |
149 |
Object[] newCache = new Object[requiredCount]; |
| 148 |
System.arraycopy(cachedElements, 0, newCache, 0, cachedElements.length); |
150 |
System.arraycopy(cachedElements, 0, newCache, 0, |
|
|
151 |
cachedElements.length); |
| 149 |
cachedElements = newCache; |
152 |
cachedElements = newCache; |
| 150 |
} |
153 |
} |
| 151 |
|
154 |
|
| 152 |
|
|
|
| 153 |
cachedElements[index] = element; |
155 |
cachedElements[index] = element; |
| 154 |
|
156 |
|
| 155 |
} |
157 |
} |
| 156 |
|
158 |
|
| 157 |
} |
159 |
} |
| 158 |
|
160 |
|
| 159 |
private VirtualManager virtualManager; |
161 |
private VirtualManager virtualManager; |
| 160 |
|
|
|
| 161 |
/** |
| 162 |
* TableColorAndFontNoOp is an optimization for tables without |
| 163 |
* color and font support. |
| 164 |
* @see ITableColorProvider |
| 165 |
* @see ITableFontProvider |
| 166 |
*/ |
| 167 |
private class TableColorAndFontNoOp{ |
| 168 |
|
| 169 |
/** |
| 170 |
* Create a new instance of the receiver. |
| 171 |
* |
| 172 |
*/ |
| 173 |
TableColorAndFontNoOp(){ |
| 174 |
|
| 175 |
} |
| 176 |
|
| 177 |
/** |
| 178 |
* Set the fonts and colors for the tableItem if there is a color |
| 179 |
* and font provider available. |
| 180 |
* @param tableItem The item to update. |
| 181 |
* @param element The element being represented |
| 182 |
* @param column The column index |
| 183 |
*/ |
| 184 |
public void setFontsAndColors(TableItem tableItem, Object element, int column){ |
| 185 |
} |
| 186 |
|
| 187 |
} |
| 188 |
|
162 |
|
| 189 |
/** |
163 |
/** |
| 190 |
* TableColorAndFontCollector is an helper class for color and font |
|
|
| 191 |
* support for tables that support the ITableFontProvider and |
| 192 |
* the ITableColorProvider. |
| 193 |
* @see ITableColorProvider |
| 194 |
* @see ITableFontProvider |
| 195 |
*/ |
| 196 |
|
| 197 |
private class TableColorAndFontCollector extends TableColorAndFontNoOp{ |
| 198 |
|
| 199 |
ITableFontProvider fontProvider = null; |
| 200 |
ITableColorProvider colorProvider = null; |
| 201 |
|
| 202 |
/** |
| 203 |
* Create an instance of the receiver. Set the color and font |
| 204 |
* providers if provider can be cast to the correct type. |
| 205 |
* @param provider IBaseLabelProvider |
| 206 |
*/ |
| 207 |
public TableColorAndFontCollector(IBaseLabelProvider provider){ |
| 208 |
if(provider instanceof ITableFontProvider) { |
| 209 |
fontProvider = (ITableFontProvider) provider; |
| 210 |
} |
| 211 |
if(provider instanceof ITableColorProvider) { |
| 212 |
colorProvider = (ITableColorProvider) provider; |
| 213 |
} |
| 214 |
} |
| 215 |
|
| 216 |
|
| 217 |
/** |
| 218 |
* Set the fonts and colors for the tableItem if there is a color |
| 219 |
* and font provider available. |
| 220 |
* @param tableItem The item to update. |
| 221 |
* @param element The element being represented |
| 222 |
* @param column The column index |
| 223 |
*/ |
| 224 |
public void setFontsAndColors(TableItem tableItem, Object element, int column){ |
| 225 |
if (colorProvider != null) { |
| 226 |
tableItem.setBackground(column, colorProvider.getBackground(element, |
| 227 |
column)); |
| 228 |
tableItem.setForeground(column, colorProvider.getForeground(element, |
| 229 |
column)); |
| 230 |
} |
| 231 |
if(fontProvider != null) { |
| 232 |
tableItem.setFont(column,fontProvider.getFont(element,column)); |
| 233 |
} |
| 234 |
} |
| 235 |
|
| 236 |
} |
| 237 |
|
| 238 |
/** |
| 239 |
* Internal table viewer implementation. |
164 |
* Internal table viewer implementation. |
| 240 |
*/ |
165 |
*/ |
| 241 |
private TableEditorImpl tableViewerImpl; |
166 |
private TableEditorImpl tableViewerImpl; |
|
Lines 249-260
Link Here
|
| 249 |
* This viewer's table editor. |
174 |
* This viewer's table editor. |
| 250 |
*/ |
175 |
*/ |
| 251 |
private TableEditor tableEditor; |
176 |
private TableEditor tableEditor; |
| 252 |
|
177 |
|
| 253 |
/** |
178 |
|
| 254 |
* The color and font collector for the cells. |
|
|
| 255 |
*/ |
| 256 |
private TableColorAndFontNoOp tableColorAndFont = new TableColorAndFontNoOp(); |
| 257 |
|
| 258 |
/** |
179 |
/** |
| 259 |
* Creates a table viewer on a newly-created table control under the given |
180 |
* Creates a table viewer on a newly-created table control under the given |
| 260 |
* parent. The table control is created using the SWT style bits |
181 |
* parent. The table control is created using the SWT style bits |
|
Lines 281-287
Link Here
|
| 281 |
* SWT style bits |
202 |
* SWT style bits |
| 282 |
*/ |
203 |
*/ |
| 283 |
public TableViewer(Composite parent, int style) { |
204 |
public TableViewer(Composite parent, int style) { |
| 284 |
this(new Table(parent, style)); |
205 |
this(new Table(parent, style)); |
| 285 |
} |
206 |
} |
| 286 |
|
207 |
|
| 287 |
/** |
208 |
/** |
|
Lines 299-317
Link Here
|
| 299 |
initTableViewerImpl(); |
220 |
initTableViewerImpl(); |
| 300 |
initializeVirtualManager(table.getStyle()); |
221 |
initializeVirtualManager(table.getStyle()); |
| 301 |
} |
222 |
} |
| 302 |
|
223 |
|
| 303 |
/** |
224 |
/** |
| 304 |
* Initialize the virtual manager to manage the virtual state |
225 |
* Initialize the virtual manager to manage the virtual state if the table |
| 305 |
* if the table is VIRTUAL. If not use the default no-op |
226 |
* is VIRTUAL. If not use the default no-op version. |
| 306 |
* version. |
227 |
* |
| 307 |
* @param style |
228 |
* @param style |
| 308 |
*/ |
229 |
*/ |
| 309 |
private void initializeVirtualManager(int style) { |
230 |
private void initializeVirtualManager(int style) { |
| 310 |
if((style & SWT.VIRTUAL) == 0) { |
231 |
if ((style & SWT.VIRTUAL) == 0) { |
| 311 |
return; |
232 |
return; |
| 312 |
} |
233 |
} |
| 313 |
|
234 |
|
| 314 |
virtualManager = new VirtualManager(); |
235 |
virtualManager = new VirtualManager(); |
| 315 |
} |
236 |
} |
| 316 |
|
237 |
|
| 317 |
/** |
238 |
/** |
|
Lines 330-336
Link Here
|
| 330 |
public void add(Object[] elements) { |
251 |
public void add(Object[] elements) { |
| 331 |
assertElementsNotNull(elements); |
252 |
assertElementsNotNull(elements); |
| 332 |
Object[] filtered = filter(elements); |
253 |
Object[] filtered = filter(elements); |
| 333 |
|
254 |
|
| 334 |
for (int i = 0; i < filtered.length; i++) { |
255 |
for (int i = 0; i < filtered.length; i++) { |
| 335 |
Object element = filtered[i]; |
256 |
Object element = filtered[i]; |
| 336 |
int index = indexForElement(element); |
257 |
int index = indexForElement(element); |
|
Lines 340-356
Link Here
|
| 340 |
|
261 |
|
| 341 |
/** |
262 |
/** |
| 342 |
* Create a new TableItem at index if required. |
263 |
* Create a new TableItem at index if required. |
|
|
264 |
* |
| 343 |
* @param element |
265 |
* @param element |
| 344 |
* @param index |
266 |
* @param index |
| 345 |
* |
267 |
* |
| 346 |
* @since 3.1 |
268 |
* @since 3.1 |
| 347 |
*/ |
269 |
*/ |
| 348 |
private void createItem(Object element, int index) { |
270 |
private void createItem(Object element, int index) { |
| 349 |
if(virtualManager == null) { |
271 |
if (virtualManager == null) { |
| 350 |
updateItem(new TableItem(getTable(), SWT.NONE, index), element); |
272 |
updateItem(new TableItem(getTable(), SWT.NONE, index), element); |
| 351 |
} else{ |
273 |
} else { |
| 352 |
virtualManager.notVisibleAdded(element,index); |
274 |
virtualManager.notVisibleAdded(element, index); |
| 353 |
|
275 |
|
| 354 |
} |
276 |
} |
| 355 |
} |
277 |
} |
| 356 |
|
278 |
|
|
Lines 382-388
Link Here
|
| 382 |
} |
304 |
} |
| 383 |
|
305 |
|
| 384 |
/* |
306 |
/* |
| 385 |
* (non-Javadoc) |
307 |
* (non-Javadoc) |
|
|
308 |
* |
| 386 |
* @see org.eclipse.jface.viewers.StructuredViewer#doFindInputItem(java.lang.Object) |
309 |
* @see org.eclipse.jface.viewers.StructuredViewer#doFindInputItem(java.lang.Object) |
| 387 |
*/ |
310 |
*/ |
| 388 |
protected Widget doFindInputItem(Object element) { |
311 |
protected Widget doFindInputItem(Object element) { |
|
Lines 393-403
Link Here
|
| 393 |
} |
316 |
} |
| 394 |
|
317 |
|
| 395 |
/* |
318 |
/* |
| 396 |
* (non-Javadoc) |
319 |
* (non-Javadoc) |
|
|
320 |
* |
| 397 |
* @see org.eclipse.jface.viewers.StructuredViewer#doFindItem(java.lang.Object) |
321 |
* @see org.eclipse.jface.viewers.StructuredViewer#doFindItem(java.lang.Object) |
| 398 |
*/ |
322 |
*/ |
| 399 |
protected Widget doFindItem(Object element) { |
323 |
protected Widget doFindItem(Object element) { |
| 400 |
|
324 |
|
| 401 |
TableItem[] children = table.getItems(); |
325 |
TableItem[] children = table.getItems(); |
| 402 |
for (int i = 0; i < children.length; i++) { |
326 |
for (int i = 0; i < children.length; i++) { |
| 403 |
TableItem item = children[i]; |
327 |
TableItem item = children[i]; |
|
Lines 411-418
Link Here
|
| 411 |
} |
335 |
} |
| 412 |
|
336 |
|
| 413 |
/* |
337 |
/* |
| 414 |
* (non-Javadoc) |
338 |
* (non-Javadoc) |
| 415 |
* @see org.eclipse.jface.viewers.StructuredViewer#doUpdateItem(org.eclipse.swt.widgets.Widget, java.lang.Object, boolean) |
339 |
* |
|
|
340 |
* @see org.eclipse.jface.viewers.StructuredViewer#doUpdateItem(org.eclipse.swt.widgets.Widget, |
| 341 |
* java.lang.Object, boolean) |
| 416 |
*/ |
342 |
*/ |
| 417 |
protected void doUpdateItem(Widget widget, Object element, boolean fullMap) { |
343 |
protected void doUpdateItem(Widget widget, Object element, boolean fullMap) { |
| 418 |
if (widget instanceof TableItem) { |
344 |
if (widget instanceof TableItem) { |
|
Lines 422-508
Link Here
|
| 422 |
if (fullMap) { |
348 |
if (fullMap) { |
| 423 |
associate(element, item); |
349 |
associate(element, item); |
| 424 |
} else { |
350 |
} else { |
| 425 |
Object data = item.getData(); |
351 |
Object data = item.getData(); |
| 426 |
if (data != null) { |
352 |
if (data != null) { |
| 427 |
unmapElement(data, item); |
353 |
unmapElement(data, item); |
| 428 |
} |
354 |
} |
| 429 |
item.setData(element); |
355 |
item.setData(element); |
| 430 |
mapElement(element, item); |
356 |
mapElement(element, item); |
| 431 |
} |
357 |
} |
| 432 |
|
358 |
|
| 433 |
IBaseLabelProvider prov = getLabelProvider(); |
|
|
| 434 |
ITableLabelProvider tprov = null; |
| 435 |
ILabelProvider lprov = null; |
| 436 |
IViewerLabelProvider vprov = null; |
| 437 |
|
| 438 |
if(prov instanceof ILabelProvider) { |
| 439 |
lprov = (ILabelProvider) prov; |
| 440 |
} |
| 441 |
|
| 442 |
if (prov instanceof IViewerLabelProvider) { |
| 443 |
vprov = (IViewerLabelProvider) prov; |
| 444 |
} |
| 445 |
|
| 446 |
if (prov instanceof ITableLabelProvider) { |
| 447 |
tprov = (ITableLabelProvider) prov; |
| 448 |
} |
| 449 |
|
| 450 |
int columnCount = table.getColumnCount(); |
359 |
int columnCount = table.getColumnCount(); |
| 451 |
TableItem ti = item; |
360 |
if(columnCount == 0) |
| 452 |
getColorAndFontCollector().setFontsAndColors(element); |
361 |
columnCount = 1;//If there are no columns do the first one |
| 453 |
|
362 |
|
| 454 |
// Also enter loop if no columns added. See 1G9WWGZ: JFUIF:WINNT - |
363 |
// Also enter loop if no columns added. See 1G9WWGZ: JFUIF:WINNT - |
| 455 |
// TableViewer with 0 columns does not work |
364 |
// TableViewer with 0 columns does not work |
| 456 |
for (int column = 0; column < columnCount || column == 0; column++) { |
365 |
for (int column = 0; column < columnCount || column == 0; column++) { |
| 457 |
// Similar code in TreeViewer.doUpdateItem() |
366 |
ColumnViewerPart columnViewer = getColumnViewer(column); |
| 458 |
String text = "";//$NON-NLS-1$ |
367 |
columnViewer.refresh(item, element,column); |
| 459 |
Image image = null; |
|
|
| 460 |
tableColorAndFont.setFontsAndColors(ti,element,column); |
| 461 |
|
| 462 |
if (tprov == null) { |
| 463 |
if (column == 0) { |
| 464 |
ViewerLabel updateLabel = new ViewerLabel(item |
| 465 |
.getText(), item.getImage()); |
| 466 |
|
| 467 |
if(vprov != null) { |
| 468 |
buildLabel(updateLabel,element,vprov); |
| 469 |
} else{ |
| 470 |
if(lprov != null) { |
| 471 |
buildLabel(updateLabel,element,lprov); |
| 472 |
} |
| 473 |
} |
| 474 |
|
| 475 |
// As it is possible for user code to run the event |
| 476 |
//loop check here. |
| 477 |
if (item.isDisposed()) { |
| 478 |
unmapElement(element, item); |
| 479 |
return; |
| 480 |
} |
| 481 |
|
| 482 |
text = updateLabel.getText(); |
| 483 |
image = updateLabel.getImage(); |
| 484 |
} |
| 485 |
} else { |
| 486 |
text = tprov.getColumnText(element, column); |
| 487 |
image = tprov.getColumnImage(element, column); |
| 488 |
} |
| 489 |
|
368 |
|
| 490 |
//Avoid setting text to null |
369 |
// As it is possible for user code to run the event |
| 491 |
if (text == null) { |
370 |
// loop check here. |
| 492 |
text = ""; //$NON-NLS-1$ |
371 |
if (item.isDisposed()) { |
| 493 |
} |
372 |
unmapElement(element, item); |
| 494 |
ti.setText(column, text); |
373 |
return; |
| 495 |
if (ti.getImage(column) != image) { |
|
|
| 496 |
ti.setImage(column, image); |
| 497 |
} |
374 |
} |
|
|
375 |
|
| 498 |
} |
376 |
} |
| 499 |
|
377 |
|
| 500 |
|
|
|
| 501 |
getColorAndFontCollector().applyFontsAndColors(ti); |
| 502 |
} |
378 |
} |
| 503 |
} |
379 |
} |
| 504 |
|
380 |
|
| 505 |
/** |
381 |
/** |
|
|
382 |
* Return the TableColumnViewer at columnIndex |
| 383 |
* |
| 384 |
* @param columnIndex |
| 385 |
* @return TableColumnViewer |
| 386 |
*/ |
| 387 |
public ColumnViewerPart getColumnViewer(int columnIndex) { |
| 388 |
|
| 389 |
Object viewer; |
| 390 |
Widget columnOwner; |
| 391 |
if (getTable().getColumnCount() == 0)// Hang it off the table if it |
| 392 |
// has no columns |
| 393 |
columnOwner = getTable(); |
| 394 |
else |
| 395 |
columnOwner = getTable().getColumn(columnIndex); |
| 396 |
viewer = columnOwner.getData(ColumnViewerPart.COLUMN_VIEWER_KEY); |
| 397 |
|
| 398 |
if (viewer == null) { |
| 399 |
viewer = new ColumnViewerPart( |
| 400 |
ViewerLabelProvider.createViewerLabelProvider(getLabelProvider())); |
| 401 |
columnOwner.setData(ColumnViewerPart.COLUMN_VIEWER_KEY, viewer); |
| 402 |
} |
| 403 |
return (ColumnViewerPart) viewer; |
| 404 |
} |
| 405 |
|
| 406 |
/** |
| 407 |
* Set the TableColumnViewerPart at columnIndex to be viewerPart. |
| 408 |
* |
| 409 |
* @param viewerPart |
| 410 |
* @param columnIndex |
| 411 |
*/ |
| 412 |
public void setColumnPart(ColumnViewerPart viewerPart, int columnIndex) { |
| 413 |
TableColumn column = getTable().getColumn(columnIndex); |
| 414 |
column.setData(ColumnViewerPart.COLUMN_VIEWER_KEY, viewerPart); |
| 415 |
} |
| 416 |
|
| 417 |
|
| 418 |
/** |
| 506 |
* Starts editing the given element. |
419 |
* Starts editing the given element. |
| 507 |
* |
420 |
* |
| 508 |
* @param element |
421 |
* @param element |
|
Lines 544-550
Link Here
|
| 544 |
} |
457 |
} |
| 545 |
|
458 |
|
| 546 |
/* |
459 |
/* |
| 547 |
* (non-Javadoc) |
460 |
* (non-Javadoc) |
|
|
461 |
* |
| 548 |
* @see org.eclipse.jface.viewers.Viewer#getControl() |
462 |
* @see org.eclipse.jface.viewers.Viewer#getControl() |
| 549 |
*/ |
463 |
*/ |
| 550 |
public Control getControl() { |
464 |
public Control getControl() { |
|
Lines 588-598
Link Here
|
| 588 |
} |
502 |
} |
| 589 |
|
503 |
|
| 590 |
/* |
504 |
/* |
| 591 |
* (non-Javadoc) |
505 |
* (non-Javadoc) |
|
|
506 |
* |
| 592 |
* @see org.eclipse.jface.viewers.StructuredViewer#getSelectionFromWidget() |
507 |
* @see org.eclipse.jface.viewers.StructuredViewer#getSelectionFromWidget() |
| 593 |
*/ |
508 |
*/ |
| 594 |
protected List getSelectionFromWidget() { |
509 |
protected List getSelectionFromWidget() { |
| 595 |
if(virtualManager != null) { |
510 |
if (virtualManager != null) { |
| 596 |
return getVirtualSelection(); |
511 |
return getVirtualSelection(); |
| 597 |
} |
512 |
} |
| 598 |
Widget[] items = table.getSelection(); |
513 |
Widget[] items = table.getSelection(); |
|
Lines 606-655
Link Here
|
| 606 |
} |
521 |
} |
| 607 |
return list; |
522 |
return list; |
| 608 |
} |
523 |
} |
| 609 |
|
524 |
|
| 610 |
/** |
525 |
/** |
| 611 |
* Get the virtual selection. Avoid calling SWT whenever possible |
526 |
* Get the virtual selection. Avoid calling SWT whenever possible to prevent |
| 612 |
* to prevent extra widget creation. |
527 |
* extra widget creation. |
|
|
528 |
* |
| 613 |
* @return List of Object |
529 |
* @return List of Object |
| 614 |
*/ |
530 |
*/ |
| 615 |
|
531 |
|
| 616 |
private List getVirtualSelection() { |
532 |
private List getVirtualSelection() { |
| 617 |
|
533 |
|
| 618 |
List result = new ArrayList(); |
534 |
List result = new ArrayList(); |
| 619 |
int[] selectionIndices = getTable().getSelectionIndices(); |
535 |
int[] selectionIndices = getTable().getSelectionIndices(); |
| 620 |
if(getContentProvider() instanceof ILazyContentProvider){ |
536 |
if (getContentProvider() instanceof ILazyContentProvider) { |
| 621 |
ILazyContentProvider lazy = (ILazyContentProvider) getContentProvider(); |
537 |
ILazyContentProvider lazy = (ILazyContentProvider) getContentProvider(); |
| 622 |
for (int i = 0; i < selectionIndices.length; i++) { |
538 |
for (int i = 0; i < selectionIndices.length; i++) { |
| 623 |
int selectionIndex = selectionIndices[i]; |
539 |
int selectionIndex = selectionIndices[i]; |
| 624 |
lazy.updateElement(selectionIndex);//Start the update |
540 |
lazy.updateElement(selectionIndex);// Start the update |
| 625 |
Object element = getTable().getItem(selectionIndex).getData(); |
541 |
Object element = getTable().getItem(selectionIndex).getData(); |
| 626 |
//Only add the element if it got updated. |
542 |
// Only add the element if it got updated. |
| 627 |
//If this is done deferred the selection will |
543 |
// If this is done deferred the selection will |
| 628 |
//be incomplete until selection is finished. |
544 |
// be incomplete until selection is finished. |
| 629 |
if (element != null) { |
545 |
if (element != null) { |
| 630 |
result.add(element); |
546 |
result.add(element); |
| 631 |
} |
547 |
} |
| 632 |
} |
548 |
} |
| 633 |
} |
549 |
} else { |
| 634 |
else{ |
|
|
| 635 |
for (int i = 0; i < selectionIndices.length; i++) { |
550 |
for (int i = 0; i < selectionIndices.length; i++) { |
| 636 |
Object element = null; |
551 |
Object element = null; |
| 637 |
//See if it is cached |
552 |
// See if it is cached |
| 638 |
int selectionIndex = selectionIndices[i]; |
553 |
int selectionIndex = selectionIndices[i]; |
| 639 |
if (selectionIndex < virtualManager.cachedElements.length){ |
554 |
if (selectionIndex < virtualManager.cachedElements.length) { |
| 640 |
element = virtualManager.cachedElements[selectionIndex]; |
555 |
element = virtualManager.cachedElements[selectionIndex]; |
| 641 |
} |
556 |
} |
| 642 |
if (element == null){ |
557 |
if (element == null) { |
| 643 |
// Not cached so try the item's data |
558 |
// Not cached so try the item's data |
| 644 |
TableItem item = getTable().getItem(selectionIndex); |
559 |
TableItem item = getTable().getItem(selectionIndex); |
| 645 |
element = item.getData(); |
560 |
element = item.getData(); |
| 646 |
} |
561 |
} |
| 647 |
if (element != null) { |
562 |
if (element != null) { |
| 648 |
result.add(element); |
563 |
result.add(element); |
| 649 |
} |
564 |
} |
| 650 |
} |
565 |
} |
| 651 |
|
566 |
|
| 652 |
|
|
|
| 653 |
} |
567 |
} |
| 654 |
return result; |
568 |
return result; |
| 655 |
} |
569 |
} |
|
Lines 664-670
Link Here
|
| 664 |
} |
578 |
} |
| 665 |
|
579 |
|
| 666 |
/* |
580 |
/* |
| 667 |
* (non-Javadoc) |
581 |
* (non-Javadoc) |
|
|
582 |
* |
| 668 |
* @see org.eclipse.jface.viewers.ContentViewer#hookControl(org.eclipse.swt.widgets.Control) |
583 |
* @see org.eclipse.jface.viewers.ContentViewer#hookControl(org.eclipse.swt.widgets.Control) |
| 669 |
*/ |
584 |
*/ |
| 670 |
protected void hookControl(Control control) { |
585 |
protected void hookControl(Control control) { |
|
Lines 757-764
Link Here
|
| 757 |
} |
672 |
} |
| 758 |
|
673 |
|
| 759 |
/* |
674 |
/* |
| 760 |
* (non-Javadoc) |
675 |
* (non-Javadoc) |
| 761 |
* @see org.eclipse.jface.viewers.Viewer#inputChanged(java.lang.Object, java.lang.Object) |
676 |
* |
|
|
677 |
* @see org.eclipse.jface.viewers.Viewer#inputChanged(java.lang.Object, |
| 678 |
* java.lang.Object) |
| 762 |
*/ |
679 |
*/ |
| 763 |
protected void inputChanged(Object input, Object oldInput) { |
680 |
protected void inputChanged(Object input, Object oldInput) { |
| 764 |
getControl().setRedraw(false); |
681 |
getControl().setRedraw(false); |
|
Lines 795-806
Link Here
|
| 795 |
if (position == -1) { |
712 |
if (position == -1) { |
| 796 |
position = table.getItemCount(); |
713 |
position = table.getItemCount(); |
| 797 |
} |
714 |
} |
| 798 |
|
715 |
|
| 799 |
createItem(element,position); |
716 |
createItem(element, position); |
| 800 |
} |
717 |
} |
| 801 |
|
718 |
|
| 802 |
/* |
719 |
/* |
| 803 |
* (non-Javadoc) |
720 |
* (non-Javadoc) |
|
|
721 |
* |
| 804 |
* @see org.eclipse.jface.viewers.StructuredViewer#internalRefresh(java.lang.Object) |
722 |
* @see org.eclipse.jface.viewers.StructuredViewer#internalRefresh(java.lang.Object) |
| 805 |
*/ |
723 |
*/ |
| 806 |
protected void internalRefresh(Object element) { |
724 |
protected void internalRefresh(Object element) { |
|
Lines 808-822
Link Here
|
| 808 |
} |
726 |
} |
| 809 |
|
727 |
|
| 810 |
/* |
728 |
/* |
| 811 |
* (non-Javadoc) |
729 |
* (non-Javadoc) |
| 812 |
* @see org.eclipse.jface.viewers.StructuredViewer#internalRefresh(java.lang.Object, boolean) |
730 |
* |
|
|
731 |
* @see org.eclipse.jface.viewers.StructuredViewer#internalRefresh(java.lang.Object, |
| 732 |
* boolean) |
| 813 |
*/ |
733 |
*/ |
| 814 |
protected void internalRefresh(Object element, boolean updateLabels) { |
734 |
protected void internalRefresh(Object element, boolean updateLabels) { |
| 815 |
tableViewerImpl.applyEditorValue(); |
735 |
tableViewerImpl.applyEditorValue(); |
| 816 |
if (element == null || equals(element, getRoot())) { |
736 |
if (element == null || equals(element, getRoot())) { |
| 817 |
if(virtualManager == null) { |
737 |
if (virtualManager == null) { |
| 818 |
internalRefreshAll(updateLabels); |
738 |
internalRefreshAll(updateLabels); |
| 819 |
} else{ |
739 |
} else { |
| 820 |
internalVirtualRefreshAll(); |
740 |
internalVirtualRefreshAll(); |
| 821 |
} |
741 |
} |
| 822 |
} else { |
742 |
} else { |
|
Lines 833-849
Link Here
|
| 833 |
* @since 3.1 |
753 |
* @since 3.1 |
| 834 |
*/ |
754 |
*/ |
| 835 |
private void internalVirtualRefreshAll() { |
755 |
private void internalVirtualRefreshAll() { |
| 836 |
|
756 |
|
| 837 |
Object root = getRoot(); |
757 |
Object root = getRoot(); |
| 838 |
IContentProvider contentProvider = getContentProvider(); |
758 |
IContentProvider contentProvider = getContentProvider(); |
| 839 |
|
759 |
|
| 840 |
//Invalidate for lazy |
760 |
// Invalidate for lazy |
| 841 |
if(!(contentProvider instanceof ILazyContentProvider) |
761 |
if (!(contentProvider instanceof ILazyContentProvider) |
| 842 |
&& (contentProvider instanceof IStructuredContentProvider)) { |
762 |
&& (contentProvider instanceof IStructuredContentProvider)) { |
| 843 |
//Don't cache if the root is null but cache if it is not lazy. |
763 |
// Don't cache if the root is null but cache if it is not lazy. |
| 844 |
if(root != null){ |
764 |
if (root != null) { |
| 845 |
virtualManager.cachedElements = |
765 |
virtualManager.cachedElements = ((IStructuredContentProvider) getContentProvider()) |
| 846 |
((IStructuredContentProvider) getContentProvider()).getElements(root); |
766 |
.getElements(root); |
| 847 |
getTable().setItemCount(virtualManager.cachedElements.length); |
767 |
getTable().setItemCount(virtualManager.cachedElements.length); |
| 848 |
} |
768 |
} |
| 849 |
} |
769 |
} |
|
Lines 851-858
Link Here
|
| 851 |
} |
771 |
} |
| 852 |
|
772 |
|
| 853 |
/** |
773 |
/** |
| 854 |
* Refresh all of the elements of the table. update the |
774 |
* Refresh all of the elements of the table. update the labels if |
| 855 |
* labels if updatLabels is true; |
775 |
* updatLabels is true; |
|
|
776 |
* |
| 856 |
* @param updateLabels |
777 |
* @param updateLabels |
| 857 |
* |
778 |
* |
| 858 |
* @since 3.1 |
779 |
* @since 3.1 |
|
Lines 871-880
Link Here
|
| 871 |
TableItem[] items = getTable().getItems(); |
792 |
TableItem[] items = getTable().getItems(); |
| 872 |
int min = Math.min(children.length, items.length); |
793 |
int min = Math.min(children.length, items.length); |
| 873 |
for (int i = 0; i < min; ++i) { |
794 |
for (int i = 0; i < min; ++i) { |
| 874 |
|
795 |
|
| 875 |
|
|
|
| 876 |
TableItem item = items[i]; |
796 |
TableItem item = items[i]; |
| 877 |
|
797 |
|
| 878 |
// if the element is unchanged, update its label if appropriate |
798 |
// if the element is unchanged, update its label if appropriate |
| 879 |
if (equals(children[i], item.getData())) { |
799 |
if (equals(children[i], item.getData())) { |
| 880 |
if (updateLabels) { |
800 |
if (updateLabels) { |
|
Lines 893-906
Link Here
|
| 893 |
// So, if the object associated with this item has changed, |
813 |
// So, if the object associated with this item has changed, |
| 894 |
// just disassociate it for now, and update it below. |
814 |
// just disassociate it for now, and update it below. |
| 895 |
item.setText(""); //$NON-NLS-1$ |
815 |
item.setText(""); //$NON-NLS-1$ |
| 896 |
item.setImage(new Image[Math.max(1,table.getColumnCount())]);//Clear all images |
816 |
item.setImage(new Image[Math.max(1, table.getColumnCount())]);// Clear |
|
|
817 |
// all |
| 818 |
// images |
| 897 |
disassociate(item); |
819 |
disassociate(item); |
| 898 |
} |
820 |
} |
| 899 |
} |
821 |
} |
| 900 |
// dispose of all items beyond the end of the current elements |
822 |
// dispose of all items beyond the end of the current elements |
| 901 |
if (min < items.length) { |
823 |
if (min < items.length) { |
| 902 |
for (int i = items.length; --i >= min;) { |
824 |
for (int i = items.length; --i >= min;) { |
| 903 |
|
825 |
|
| 904 |
disassociate(items[i]); |
826 |
disassociate(items[i]); |
| 905 |
} |
827 |
} |
| 906 |
table.remove(min, items.length - 1); |
828 |
table.remove(min, items.length - 1); |
|
Lines 912-918
Link Here
|
| 912 |
} |
834 |
} |
| 913 |
// Update items which were removed above |
835 |
// Update items which were removed above |
| 914 |
for (int i = 0; i < min; ++i) { |
836 |
for (int i = 0; i < min; ++i) { |
| 915 |
|
837 |
|
| 916 |
TableItem item = items[i]; |
838 |
TableItem item = items[i]; |
| 917 |
if (item.getData() == null) { |
839 |
if (item.getData() == null) { |
| 918 |
updateItem(item, children[i]); |
840 |
updateItem(item, children[i]); |
|
Lines 920-930
Link Here
|
| 920 |
} |
842 |
} |
| 921 |
// add any remaining elements |
843 |
// add any remaining elements |
| 922 |
for (int i = min; i < children.length; ++i) { |
844 |
for (int i = min; i < children.length; ++i) { |
| 923 |
createItem(children[i],i); |
845 |
createItem(children[i], i); |
| 924 |
} |
846 |
} |
| 925 |
} |
847 |
} |
| 926 |
|
848 |
|
| 927 |
|
|
|
| 928 |
/** |
849 |
/** |
| 929 |
* Removes the given elements from this table viewer. |
850 |
* Removes the given elements from this table viewer. |
| 930 |
* |
851 |
* |
|
Lines 987-995
Link Here
|
| 987 |
*/ |
908 |
*/ |
| 988 |
public void remove(final Object[] elements) { |
909 |
public void remove(final Object[] elements) { |
| 989 |
assertElementsNotNull(elements); |
910 |
assertElementsNotNull(elements); |
| 990 |
if (elements.length == 0) { |
911 |
if (elements.length == 0) { |
| 991 |
return; |
912 |
return; |
| 992 |
} |
913 |
} |
| 993 |
preservingSelection(new Runnable() { |
914 |
preservingSelection(new Runnable() { |
| 994 |
public void run() { |
915 |
public void run() { |
| 995 |
internalRemove(elements); |
916 |
internalRemove(elements); |
|
Lines 1007-1014
Link Here
|
| 1007 |
* the model. Note that there is another method for efficiently processing |
928 |
* the model. Note that there is another method for efficiently processing |
| 1008 |
* the simultaneous removal of multiple elements. |
929 |
* the simultaneous removal of multiple elements. |
| 1009 |
* </p> |
930 |
* </p> |
| 1010 |
* <strong>NOTE:</strong> removing an object from a virtual |
931 |
* <strong>NOTE:</strong> removing an object from a virtual table will |
| 1011 |
* table will decrement the itemCount. |
932 |
* decrement the itemCount. |
| 1012 |
* |
933 |
* |
| 1013 |
* @param element |
934 |
* @param element |
| 1014 |
* the element |
935 |
* the element |
|
Lines 1018-1024
Link Here
|
| 1018 |
} |
939 |
} |
| 1019 |
|
940 |
|
| 1020 |
/* |
941 |
/* |
| 1021 |
* (non-Javadoc) |
942 |
* (non-Javadoc) |
|
|
943 |
* |
| 1022 |
* @see org.eclipse.jface.viewers.StructuredViewer#reveal(java.lang.Object) |
944 |
* @see org.eclipse.jface.viewers.StructuredViewer#reveal(java.lang.Object) |
| 1023 |
*/ |
945 |
*/ |
| 1024 |
public void reveal(Object element) { |
946 |
public void reveal(Object element) { |
|
Lines 1079-1112
Link Here
|
| 1079 |
* may also implement {@link IColorProvider} and/or {@link IFontProvider} to |
1001 |
* may also implement {@link IColorProvider} and/or {@link IFontProvider} to |
| 1080 |
* provide colors and/or fonts. |
1002 |
* provide colors and/or fonts. |
| 1081 |
* </p> |
1003 |
* </p> |
|
|
1004 |
* <p> |
| 1005 |
* If the label provider implements the mixin interface ITooltipProvider, it |
| 1006 |
* can provide custom tooltips. |
| 1007 |
* </p> |
| 1082 |
*/ |
1008 |
*/ |
| 1083 |
public void setLabelProvider(IBaseLabelProvider labelProvider) { |
1009 |
public void setLabelProvider(IBaseLabelProvider labelProvider) { |
| 1084 |
Assert.isTrue(labelProvider instanceof ITableLabelProvider |
1010 |
Assert.isTrue(labelProvider instanceof ITableLabelProvider |
| 1085 |
|| labelProvider instanceof ILabelProvider); |
1011 |
|| labelProvider instanceof ILabelProvider); |
|
|
1012 |
clearColumnParts();//Clear before refresh |
| 1086 |
super.setLabelProvider(labelProvider); |
1013 |
super.setLabelProvider(labelProvider); |
| 1087 |
if(labelProvider instanceof ITableFontProvider || labelProvider instanceof ITableColorProvider) { |
|
|
| 1088 |
tableColorAndFont = new TableColorAndFontCollector(labelProvider); |
| 1089 |
} else { |
| 1090 |
tableColorAndFont = new TableColorAndFontNoOp(); |
| 1091 |
} |
| 1092 |
|
| 1093 |
} |
1014 |
} |
| 1094 |
|
1015 |
|
| 1095 |
/** |
1016 |
/** |
|
|
1017 |
* Clear the viewer parts for the columns |
| 1018 |
*/ |
| 1019 |
private void clearColumnParts() { |
| 1020 |
TableColumn[] columns = getTable().getColumns(); |
| 1021 |
if(columns.length == 0) |
| 1022 |
getTable().setData(ColumnViewerPart.COLUMN_VIEWER_KEY,null); |
| 1023 |
else{ |
| 1024 |
for (int i = 0; i < columns.length; i++) { |
| 1025 |
columns[i].setData(ColumnViewerPart.COLUMN_VIEWER_KEY,null); |
| 1026 |
|
| 1027 |
} |
| 1028 |
} |
| 1029 |
|
| 1030 |
} |
| 1031 |
|
| 1032 |
/** |
| 1096 |
* <p> |
1033 |
* <p> |
| 1097 |
* Sets a new selection for this viewer and optionally makes it visible. |
1034 |
* Sets a new selection for this viewer and optionally makes it visible. The |
| 1098 |
* The TableViewer implmentation of this method is ineffecient for the |
1035 |
* TableViewer implmentation of this method is ineffecient for the |
| 1099 |
* ILazyContentProvider as lookup is done by indices rather than elements |
1036 |
* ILazyContentProvider as lookup is done by indices rather than elements |
| 1100 |
* and may require population of the entire table in worse case. |
1037 |
* and may require population of the entire table in worse case. |
| 1101 |
* </p> |
1038 |
* </p> |
| 1102 |
* <p> |
1039 |
* <p> |
| 1103 |
* Use Table#setSelection(int[] indices) and Table#showSelection() if |
1040 |
* Use Table#setSelection(int[] indices) and Table#showSelection() if you |
| 1104 |
* you wish to set selection more effeciently when using a ILazyContentProvider. |
1041 |
* wish to set selection more effeciently when using a ILazyContentProvider. |
| 1105 |
* </p> |
1042 |
* </p> |
| 1106 |
* |
1043 |
* |
| 1107 |
* @param selection the new selection |
1044 |
* @param selection |
| 1108 |
* @param reveal <code>true</code> if the selection is to be made |
1045 |
* the new selection |
| 1109 |
* visible, and <code>false</code> otherwise |
1046 |
* @param reveal |
|
|
1047 |
* <code>true</code> if the selection is to be made visible, |
| 1048 |
* and <code>false</code> otherwise |
| 1110 |
* @see Table#setSelection(int[]) |
1049 |
* @see Table#setSelection(int[]) |
| 1111 |
* @see Table#showSelection() |
1050 |
* @see Table#showSelection() |
| 1112 |
*/ |
1051 |
*/ |
|
Lines 1115-1135
Link Here
|
| 1115 |
} |
1054 |
} |
| 1116 |
|
1055 |
|
| 1117 |
/* |
1056 |
/* |
| 1118 |
* (non-Javadoc) |
1057 |
* (non-Javadoc) |
| 1119 |
* @see org.eclipse.jface.viewers.StructuredViewer#setSelectionToWidget(java.util.List, boolean) |
1058 |
* |
|
|
1059 |
* @see org.eclipse.jface.viewers.StructuredViewer#setSelectionToWidget(java.util.List, |
| 1060 |
* boolean) |
| 1120 |
*/ |
1061 |
*/ |
| 1121 |
protected void setSelectionToWidget(List list, boolean reveal) { |
1062 |
protected void setSelectionToWidget(List list, boolean reveal) { |
| 1122 |
|
1063 |
|
| 1123 |
if (list == null) { |
1064 |
if (list == null) { |
| 1124 |
table.deselectAll(); |
1065 |
table.deselectAll(); |
| 1125 |
return; |
1066 |
return; |
| 1126 |
} |
1067 |
} |
| 1127 |
|
1068 |
|
| 1128 |
if(virtualManager != null){ |
1069 |
if (virtualManager != null) { |
| 1129 |
virtualSetSelectionToWidget(list, reveal); |
1070 |
virtualSetSelectionToWidget(list, reveal); |
| 1130 |
return; |
1071 |
return; |
| 1131 |
} |
1072 |
} |
| 1132 |
|
1073 |
|
| 1133 |
int size = list.size(); |
1074 |
int size = list.size(); |
| 1134 |
TableItem[] items = new TableItem[size]; |
1075 |
TableItem[] items = new TableItem[size]; |
| 1135 |
int count = 0; |
1076 |
int count = 0; |
|
Lines 1149-1170
Link Here
|
| 1149 |
if (reveal) { |
1090 |
if (reveal) { |
| 1150 |
table.showSelection(); |
1091 |
table.showSelection(); |
| 1151 |
} |
1092 |
} |
| 1152 |
|
1093 |
|
| 1153 |
} |
1094 |
} |
| 1154 |
|
1095 |
|
| 1155 |
|
|
|
| 1156 |
/** |
1096 |
/** |
| 1157 |
* Set the selection on a virtual table |
1097 |
* Set the selection on a virtual table |
| 1158 |
* @param list The elements to set |
1098 |
* |
| 1159 |
* @param reveal Whether or not reveal the first item. |
1099 |
* @param list |
|
|
1100 |
* The elements to set |
| 1101 |
* @param reveal |
| 1102 |
* Whether or not reveal the first item. |
| 1160 |
*/ |
1103 |
*/ |
| 1161 |
private void virtualSetSelectionToWidget(List list, boolean reveal) { |
1104 |
private void virtualSetSelectionToWidget(List list, boolean reveal) { |
| 1162 |
int size = list.size(); |
1105 |
int size = list.size(); |
| 1163 |
int[] indices = new int[list.size()]; |
1106 |
int[] indices = new int[list.size()]; |
| 1164 |
|
1107 |
|
| 1165 |
TableItem firstItem = null; |
1108 |
TableItem firstItem = null; |
| 1166 |
int count = 0; |
1109 |
int count = 0; |
| 1167 |
HashSet virtualElements = new HashSet(); |
1110 |
HashSet virtualElements = new HashSet(); |
| 1168 |
for (int i = 0; i < size; ++i) { |
1111 |
for (int i = 0; i < size; ++i) { |
| 1169 |
Object o = list.get(i); |
1112 |
Object o = list.get(i); |
| 1170 |
Widget w = findItem(o); |
1113 |
Widget w = findItem(o); |
|
Lines 1178-1214
Link Here
|
| 1178 |
virtualElements.add(o); |
1121 |
virtualElements.add(o); |
| 1179 |
} |
1122 |
} |
| 1180 |
} |
1123 |
} |
| 1181 |
|
1124 |
|
| 1182 |
if(getContentProvider() instanceof ILazyContentProvider){ |
1125 |
if (getContentProvider() instanceof ILazyContentProvider) { |
| 1183 |
ILazyContentProvider provider = |
1126 |
ILazyContentProvider provider = (ILazyContentProvider) getContentProvider(); |
| 1184 |
(ILazyContentProvider) getContentProvider(); |
1127 |
|
| 1185 |
|
1128 |
// Now go through it again until all is done or we are no longer |
| 1186 |
//Now go through it again until all is done or we are no longer virtual |
1129 |
// virtual |
| 1187 |
//This may create all items so it is not a good |
1130 |
// This may create all items so it is not a good |
| 1188 |
//idea in general. |
1131 |
// idea in general. |
| 1189 |
//Use #setSelection (int [] indices,boolean reveal) instead |
1132 |
// Use #setSelection (int [] indices,boolean reveal) instead |
| 1190 |
for (int i = 0; virtualElements.size() > 0 && i < getTable().getItemCount(); i++) { |
1133 |
for (int i = 0; virtualElements.size() > 0 |
|
|
1134 |
&& i < getTable().getItemCount(); i++) { |
| 1191 |
provider.updateElement(i); |
1135 |
provider.updateElement(i); |
| 1192 |
TableItem item = getTable().getItem(i); |
1136 |
TableItem item = getTable().getItem(i); |
| 1193 |
if(virtualElements.contains(item.getData())){ |
1137 |
if (virtualElements.contains(item.getData())) { |
| 1194 |
indices[count++] = i; |
1138 |
indices[count++] = i; |
| 1195 |
virtualElements.remove(item.getData()); |
1139 |
virtualElements.remove(item.getData()); |
| 1196 |
if (firstItem == null) { |
1140 |
if (firstItem == null) { |
| 1197 |
firstItem = item; |
1141 |
firstItem = item; |
| 1198 |
} |
1142 |
} |
| 1199 |
} |
1143 |
} |
| 1200 |
} |
1144 |
} |
| 1201 |
} |
1145 |
} else { |
| 1202 |
else{ |
1146 |
|
| 1203 |
|
1147 |
if (count != list.size()) {// As this is expensive skip it if all |
| 1204 |
if(count != list.size()){//As this is expensive skip it if all have been found |
1148 |
// have been found |
| 1205 |
//If it is not lazy we can use the cache |
1149 |
// If it is not lazy we can use the cache |
| 1206 |
for (int i = 0; i < virtualManager.cachedElements.length; i++) { |
1150 |
for (int i = 0; i < virtualManager.cachedElements.length; i++) { |
| 1207 |
Object element = virtualManager.cachedElements[i]; |
1151 |
Object element = virtualManager.cachedElements[i]; |
| 1208 |
if(virtualElements.contains(element)){ |
1152 |
if (virtualElements.contains(element)) { |
| 1209 |
TableItem item = getTable().getItem(i); |
1153 |
TableItem item = getTable().getItem(i); |
| 1210 |
item.getText();//Be sure to fire the update |
1154 |
item.getText();// Be sure to fire the update |
| 1211 |
indices[count++] = i; |
1155 |
indices[count++] = i; |
| 1212 |
virtualElements.remove(element); |
1156 |
virtualElements.remove(element); |
| 1213 |
if (firstItem == null) { |
1157 |
if (firstItem == null) { |
| 1214 |
firstItem = item; |
1158 |
firstItem = item; |
|
Lines 1217-1223
Link Here
|
| 1217 |
} |
1161 |
} |
| 1218 |
} |
1162 |
} |
| 1219 |
} |
1163 |
} |
| 1220 |
|
1164 |
|
| 1221 |
if (count < size) { |
1165 |
if (count < size) { |
| 1222 |
System.arraycopy(indices, 0, indices = new int[count], 0, count); |
1166 |
System.arraycopy(indices, 0, indices = new int[count], 0, count); |
| 1223 |
} |
1167 |
} |
|
Lines 1230-1264
Link Here
|
| 1230 |
|
1174 |
|
| 1231 |
/** |
1175 |
/** |
| 1232 |
* Set the item count of the receiver. |
1176 |
* Set the item count of the receiver. |
| 1233 |
* @param count the new table size. |
1177 |
* |
|
|
1178 |
* @param count |
| 1179 |
* the new table size. |
| 1234 |
* |
1180 |
* |
| 1235 |
* @since 3.1 |
1181 |
* @since 3.1 |
| 1236 |
*/ |
1182 |
*/ |
| 1237 |
public void setItemCount(int count){ |
1183 |
public void setItemCount(int count) { |
| 1238 |
getTable().setItemCount(count); |
1184 |
getTable().setItemCount(count); |
| 1239 |
getTable().redraw(); |
1185 |
getTable().redraw(); |
| 1240 |
} |
1186 |
} |
| 1241 |
|
1187 |
|
| 1242 |
/** |
1188 |
/** |
| 1243 |
* Replace the entries starting at index with elements. |
1189 |
* Replace the entries starting at index with elements. This method assumes |
| 1244 |
* This method assumes all of these values are correct |
1190 |
* all of these values are correct and will not call the content provider to |
| 1245 |
* and will not call the content provider to verify. |
1191 |
* verify. <strong>Note that this method will create a TableItem for all of |
| 1246 |
* <strong>Note that this method will create a TableItem |
1192 |
* the elements provided</strong>. |
| 1247 |
* for all of the elements provided</strong>. |
1193 |
* |
| 1248 |
* @param element |
1194 |
* @param element |
| 1249 |
* @param index |
1195 |
* @param index |
| 1250 |
* @see ILazyContentProvider |
1196 |
* @see ILazyContentProvider |
| 1251 |
* |
1197 |
* |
| 1252 |
* @since 3.1 |
1198 |
* @since 3.1 |
| 1253 |
*/ |
1199 |
*/ |
| 1254 |
public void replace(Object element, int index){ |
1200 |
public void replace(Object element, int index) { |
| 1255 |
TableItem item = getTable().getItem(index); |
1201 |
TableItem item = getTable().getItem(index); |
| 1256 |
refreshItem(item, element); |
1202 |
refreshItem(item, element); |
| 1257 |
} |
1203 |
} |
| 1258 |
|
1204 |
|
| 1259 |
/** |
1205 |
/** |
| 1260 |
* Clear the table item at the specified index |
1206 |
* Clear the table item at the specified index |
| 1261 |
* @param index the index of the table item to be cleared |
1207 |
* |
|
|
1208 |
* @param index |
| 1209 |
* the index of the table item to be cleared |
| 1262 |
* |
1210 |
* |
| 1263 |
* @since 3.1 |
1211 |
* @since 3.1 |
| 1264 |
*/ |
1212 |
*/ |
|
Lines 1269-1294
Link Here
|
| 1269 |
} |
1217 |
} |
| 1270 |
table.clear(index); |
1218 |
table.clear(index); |
| 1271 |
} |
1219 |
} |
| 1272 |
|
1220 |
|
| 1273 |
/* (non-Javadoc) |
1221 |
/* |
|
|
1222 |
* (non-Javadoc) |
| 1223 |
* |
| 1274 |
* @see org.eclipse.jface.viewers.StructuredViewer#getRawChildren(java.lang.Object) |
1224 |
* @see org.eclipse.jface.viewers.StructuredViewer#getRawChildren(java.lang.Object) |
| 1275 |
*/ |
1225 |
*/ |
| 1276 |
protected Object[] getRawChildren(Object parent) { |
1226 |
protected Object[] getRawChildren(Object parent) { |
| 1277 |
|
1227 |
|
| 1278 |
Assert.isTrue(!(getContentProvider() instanceof ILazyContentProvider),"Cannot get raw children with an ILazyContentProvider");//$NON-NLS-1$ |
1228 |
Assert.isTrue(!(getContentProvider() instanceof ILazyContentProvider), |
|
|
1229 |
"Cannot get raw children with an ILazyContentProvider");//$NON-NLS-1$ |
| 1279 |
return super.getRawChildren(parent); |
1230 |
return super.getRawChildren(parent); |
| 1280 |
|
1231 |
|
| 1281 |
} |
1232 |
} |
| 1282 |
|
1233 |
|
| 1283 |
/* (non-Javadoc) |
1234 |
/* |
|
|
1235 |
* (non-Javadoc) |
| 1236 |
* |
| 1284 |
* @see org.eclipse.jface.viewers.StructuredViewer#assertContentProviderType(org.eclipse.jface.viewers.IContentProvider) |
1237 |
* @see org.eclipse.jface.viewers.StructuredViewer#assertContentProviderType(org.eclipse.jface.viewers.IContentProvider) |
| 1285 |
*/ |
1238 |
*/ |
| 1286 |
protected void assertContentProviderType(IContentProvider provider) { |
1239 |
protected void assertContentProviderType(IContentProvider provider) { |
| 1287 |
Assert.isTrue(provider instanceof IStructuredContentProvider || |
1240 |
Assert.isTrue(provider instanceof IStructuredContentProvider |
| 1288 |
provider instanceof ILazyContentProvider); |
1241 |
|| provider instanceof ILazyContentProvider); |
| 1289 |
} |
1242 |
} |
| 1290 |
|
|
|
| 1291 |
|
| 1292 |
|
| 1293 |
} |
| 1294 |
|
1243 |
|
|
|
1244 |
} |