|
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 21-26
Link Here
|
| 21 |
import org.eclipse.swt.events.MouseAdapter; |
22 |
import org.eclipse.swt.events.MouseAdapter; |
| 22 |
import org.eclipse.swt.events.MouseEvent; |
23 |
import org.eclipse.swt.events.MouseEvent; |
| 23 |
import org.eclipse.swt.graphics.Image; |
24 |
import org.eclipse.swt.graphics.Image; |
|
|
25 |
import org.eclipse.swt.graphics.Point; |
| 24 |
import org.eclipse.swt.graphics.Rectangle; |
26 |
import org.eclipse.swt.graphics.Rectangle; |
| 25 |
import org.eclipse.swt.widgets.Composite; |
27 |
import org.eclipse.swt.widgets.Composite; |
| 26 |
import org.eclipse.swt.widgets.Control; |
28 |
import org.eclipse.swt.widgets.Control; |
|
Lines 28-36
Link Here
|
| 28 |
import org.eclipse.swt.widgets.Item; |
30 |
import org.eclipse.swt.widgets.Item; |
| 29 |
import org.eclipse.swt.widgets.Listener; |
31 |
import org.eclipse.swt.widgets.Listener; |
| 30 |
import org.eclipse.swt.widgets.Table; |
32 |
import org.eclipse.swt.widgets.Table; |
|
|
33 |
import org.eclipse.swt.widgets.TableColumn; |
| 31 |
import org.eclipse.swt.widgets.TableItem; |
34 |
import org.eclipse.swt.widgets.TableItem; |
| 32 |
import org.eclipse.swt.widgets.Widget; |
35 |
import org.eclipse.swt.widgets.Widget; |
| 33 |
|
36 |
|
|
|
37 |
|
| 34 |
/** |
38 |
/** |
| 35 |
* A concrete viewer based on a SWT <code>Table</code> control. |
39 |
* A concrete viewer based on a SWT <code>Table</code> control. |
| 36 |
* <p> |
40 |
* <p> |
|
Lines 63-241
Link Here
|
| 63 |
* @see #doFindItem(Object) |
67 |
* @see #doFindItem(Object) |
| 64 |
* @see #internalRefresh(Object, boolean) |
68 |
* @see #internalRefresh(Object, boolean) |
| 65 |
*/ |
69 |
*/ |
| 66 |
public class TableViewer extends StructuredViewer { |
70 |
public class TableViewer extends ColumnViewer { |
| 67 |
|
71 |
|
| 68 |
private class VirtualManager{ |
72 |
private class VirtualManager { |
| 69 |
|
73 |
|
| 70 |
/** |
74 |
/** |
| 71 |
* The currently invisible elements as provided |
75 |
* The currently invisible elements as provided by the content provider |
| 72 |
* by the content provider or by addition. |
76 |
* or by addition. This will not be populated by an |
| 73 |
* This will not be populated by an ILazyStructuredContentProvider |
77 |
* ILazyStructuredContentProvider as an ILazyStructuredContentProvider |
| 74 |
* as an ILazyStructuredContentProvider is only queried |
78 |
* is only queried on the virtual callback. |
| 75 |
* on the virtual callback. |
|
|
| 76 |
*/ |
79 |
*/ |
| 77 |
private Object[] cachedElements = new Object[0]; |
80 |
private Object[] cachedElements = new Object[0]; |
|
|
81 |
|
| 78 |
/** |
82 |
/** |
| 79 |
* Create a new instance of the receiver. |
83 |
* Create a new instance of the receiver. |
| 80 |
* |
84 |
* |
| 81 |
*/ |
85 |
*/ |
| 82 |
public VirtualManager(){ |
86 |
public VirtualManager() { |
| 83 |
addTableListener(); |
87 |
addTableListener(); |
| 84 |
} |
88 |
} |
| 85 |
|
89 |
|
| 86 |
|
|
|
| 87 |
/** |
90 |
/** |
| 88 |
* Add the listener for SetData on the table |
91 |
* Add the listener for SetData on the table |
| 89 |
*/ |
92 |
*/ |
| 90 |
private void addTableListener() { |
93 |
private void addTableListener() { |
| 91 |
table.addListener(SWT.SetData,new Listener(){ |
94 |
table.addListener(SWT.SetData, new Listener() { |
| 92 |
/* (non-Javadoc) |
95 |
/* |
|
|
96 |
* (non-Javadoc) |
| 97 |
* |
| 93 |
* @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event) |
98 |
* @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event) |
| 94 |
*/ |
99 |
*/ |
| 95 |
public void handleEvent(Event event) { |
100 |
public void handleEvent(Event event) { |
| 96 |
TableItem item = (TableItem) event.item; |
101 |
TableItem item = (TableItem) event.item; |
| 97 |
final int index = table.indexOf(item); |
102 |
final int index = table.indexOf(item); |
| 98 |
Object element = resolveElement(index); |
103 |
Object element = resolveElement(index); |
| 99 |
if(element == null){ |
104 |
if (element == null) { |
| 100 |
//Didn't find it so make a request |
105 |
// Didn't find it so make a request |
| 101 |
//Keep looking if it is not in the cache. |
106 |
// Keep looking if it is not in the cache. |
| 102 |
IContentProvider contentProvider = getContentProvider(); |
107 |
IContentProvider contentProvider = getContentProvider(); |
| 103 |
//If we are building lazily then request lookup now |
108 |
// If we are building lazily then request lookup now |
| 104 |
if(contentProvider instanceof ILazyContentProvider){ |
109 |
if (contentProvider instanceof ILazyContentProvider) { |
| 105 |
((ILazyContentProvider) contentProvider). |
110 |
((ILazyContentProvider) contentProvider) |
| 106 |
updateElement(index); |
111 |
.updateElement(index); |
| 107 |
return; |
112 |
return; |
| 108 |
} |
113 |
} |
| 109 |
} |
114 |
} |
| 110 |
|
115 |
|
| 111 |
|
116 |
associate(element, item); |
| 112 |
associate(element,item); |
117 |
updateItem(item, element); |
| 113 |
updateItem(item,element); |
|
|
| 114 |
} |
118 |
} |
| 115 |
|
119 |
|
| 116 |
}); |
120 |
}); |
| 117 |
} |
121 |
} |
| 118 |
|
122 |
|
| 119 |
/** |
123 |
/** |
| 120 |
* Get the element at index.Resolve it lazily if this |
124 |
* Get the element at index.Resolve it lazily if this is available. |
| 121 |
* is available. |
125 |
* |
| 122 |
* @param index |
126 |
* @param index |
| 123 |
* @return Object or <code>null</code> if it could |
127 |
* @return Object or <code>null</code> if it could not be found |
| 124 |
* not be found |
|
|
| 125 |
*/ |
128 |
*/ |
| 126 |
protected Object resolveElement(int index) { |
129 |
protected Object resolveElement(int index) { |
| 127 |
|
130 |
|
| 128 |
Object element = null; |
131 |
Object element = null; |
| 129 |
if(index < cachedElements.length) { |
132 |
if (index < cachedElements.length) { |
| 130 |
element = cachedElements[index]; |
133 |
element = cachedElements[index]; |
| 131 |
} |
134 |
} |
| 132 |
|
135 |
|
| 133 |
return element; |
136 |
return element; |
| 134 |
} |
137 |
} |
| 135 |
|
138 |
|
| 136 |
/** |
139 |
/** |
| 137 |
* A non visible item has been added. |
140 |
* A non visible item has been added. |
|
|
141 |
* |
| 138 |
* @param element |
142 |
* @param element |
| 139 |
* @param index |
143 |
* @param index |
| 140 |
*/ |
144 |
*/ |
| 141 |
public void notVisibleAdded(Object element, int index) { |
145 |
public void notVisibleAdded(Object element, int index) { |
| 142 |
|
146 |
|
| 143 |
int requiredCount = index + 1; |
147 |
int requiredCount = index + 1; |
| 144 |
|
148 |
|
| 145 |
if(requiredCount > getTable().getItemCount()){ |
149 |
if (requiredCount > getTable().getItemCount()) { |
| 146 |
getTable().setItemCount(requiredCount); |
150 |
getTable().setItemCount(requiredCount); |
| 147 |
Object[] newCache = new Object[requiredCount]; |
151 |
Object[] newCache = new Object[requiredCount]; |
| 148 |
System.arraycopy(cachedElements, 0, newCache, 0, cachedElements.length); |
152 |
System.arraycopy(cachedElements, 0, newCache, 0, |
|
|
153 |
cachedElements.length); |
| 149 |
cachedElements = newCache; |
154 |
cachedElements = newCache; |
| 150 |
} |
155 |
} |
| 151 |
|
156 |
|
| 152 |
|
|
|
| 153 |
cachedElements[index] = element; |
157 |
cachedElements[index] = element; |
| 154 |
|
158 |
|
| 155 |
} |
159 |
} |
| 156 |
|
160 |
|
| 157 |
} |
161 |
} |
| 158 |
|
162 |
|
| 159 |
private VirtualManager virtualManager; |
163 |
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 |
|
164 |
|
| 189 |
/** |
165 |
/** |
| 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. |
166 |
* Internal table viewer implementation. |
| 240 |
*/ |
167 |
*/ |
| 241 |
private TableEditorImpl tableViewerImpl; |
168 |
private TableEditorImpl tableViewerImpl; |
|
Lines 251-261
Link Here
|
| 251 |
private TableEditor tableEditor; |
178 |
private TableEditor tableEditor; |
| 252 |
|
179 |
|
| 253 |
/** |
180 |
/** |
| 254 |
* The color and font collector for the cells. |
|
|
| 255 |
*/ |
| 256 |
private TableColorAndFontNoOp tableColorAndFont = new TableColorAndFontNoOp(); |
| 257 |
|
| 258 |
/** |
| 259 |
* Creates a table viewer on a newly-created table control under the given |
181 |
* 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 |
182 |
* parent. The table control is created using the SWT style bits |
| 261 |
* <code>MULTI, H_SCROLL, V_SCROLL,</code> and <code>BORDER</code>. The |
183 |
* <code>MULTI, H_SCROLL, V_SCROLL,</code> and <code>BORDER</code>. The |
|
Lines 281-287
Link Here
|
| 281 |
* SWT style bits |
203 |
* SWT style bits |
| 282 |
*/ |
204 |
*/ |
| 283 |
public TableViewer(Composite parent, int style) { |
205 |
public TableViewer(Composite parent, int style) { |
| 284 |
this(new Table(parent, style)); |
206 |
this(new Table(parent, style)); |
| 285 |
} |
207 |
} |
| 286 |
|
208 |
|
| 287 |
/** |
209 |
/** |
|
Lines 299-317
Link Here
|
| 299 |
initTableViewerImpl(); |
221 |
initTableViewerImpl(); |
| 300 |
initializeVirtualManager(table.getStyle()); |
222 |
initializeVirtualManager(table.getStyle()); |
| 301 |
} |
223 |
} |
| 302 |
|
224 |
|
| 303 |
/** |
225 |
/** |
| 304 |
* Initialize the virtual manager to manage the virtual state |
226 |
* 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 |
227 |
* is VIRTUAL. If not use the default no-op version. |
| 306 |
* version. |
228 |
* |
| 307 |
* @param style |
229 |
* @param style |
| 308 |
*/ |
230 |
*/ |
| 309 |
private void initializeVirtualManager(int style) { |
231 |
private void initializeVirtualManager(int style) { |
| 310 |
if((style & SWT.VIRTUAL) == 0) { |
232 |
if ((style & SWT.VIRTUAL) == 0) { |
| 311 |
return; |
233 |
return; |
| 312 |
} |
234 |
} |
| 313 |
|
235 |
|
| 314 |
virtualManager = new VirtualManager(); |
236 |
virtualManager = new VirtualManager(); |
| 315 |
} |
237 |
} |
| 316 |
|
238 |
|
| 317 |
/** |
239 |
/** |
|
Lines 330-336
Link Here
|
| 330 |
public void add(Object[] elements) { |
252 |
public void add(Object[] elements) { |
| 331 |
assertElementsNotNull(elements); |
253 |
assertElementsNotNull(elements); |
| 332 |
Object[] filtered = filter(elements); |
254 |
Object[] filtered = filter(elements); |
| 333 |
|
255 |
|
| 334 |
for (int i = 0; i < filtered.length; i++) { |
256 |
for (int i = 0; i < filtered.length; i++) { |
| 335 |
Object element = filtered[i]; |
257 |
Object element = filtered[i]; |
| 336 |
int index = indexForElement(element); |
258 |
int index = indexForElement(element); |
|
Lines 340-356
Link Here
|
| 340 |
|
262 |
|
| 341 |
/** |
263 |
/** |
| 342 |
* Create a new TableItem at index if required. |
264 |
* Create a new TableItem at index if required. |
|
|
265 |
* |
| 343 |
* @param element |
266 |
* @param element |
| 344 |
* @param index |
267 |
* @param index |
| 345 |
* |
268 |
* |
| 346 |
* @since 3.1 |
269 |
* @since 3.1 |
| 347 |
*/ |
270 |
*/ |
| 348 |
private void createItem(Object element, int index) { |
271 |
private void createItem(Object element, int index) { |
| 349 |
if(virtualManager == null) { |
272 |
if (virtualManager == null) { |
| 350 |
updateItem(new TableItem(getTable(), SWT.NONE, index), element); |
273 |
updateItem(createNewRowPart(null, SWT.NONE, index).getItem(), element); |
| 351 |
} else{ |
274 |
} else { |
| 352 |
virtualManager.notVisibleAdded(element,index); |
275 |
virtualManager.notVisibleAdded(element, index); |
| 353 |
|
276 |
|
| 354 |
} |
277 |
} |
| 355 |
} |
278 |
} |
| 356 |
|
279 |
|
|
Lines 382-388
Link Here
|
| 382 |
} |
305 |
} |
| 383 |
|
306 |
|
| 384 |
/* |
307 |
/* |
| 385 |
* (non-Javadoc) |
308 |
* (non-Javadoc) |
|
|
309 |
* |
| 386 |
* @see org.eclipse.jface.viewers.StructuredViewer#doFindInputItem(java.lang.Object) |
310 |
* @see org.eclipse.jface.viewers.StructuredViewer#doFindInputItem(java.lang.Object) |
| 387 |
*/ |
311 |
*/ |
| 388 |
protected Widget doFindInputItem(Object element) { |
312 |
protected Widget doFindInputItem(Object element) { |
|
Lines 393-403
Link Here
|
| 393 |
} |
317 |
} |
| 394 |
|
318 |
|
| 395 |
/* |
319 |
/* |
| 396 |
* (non-Javadoc) |
320 |
* (non-Javadoc) |
|
|
321 |
* |
| 397 |
* @see org.eclipse.jface.viewers.StructuredViewer#doFindItem(java.lang.Object) |
322 |
* @see org.eclipse.jface.viewers.StructuredViewer#doFindItem(java.lang.Object) |
| 398 |
*/ |
323 |
*/ |
| 399 |
protected Widget doFindItem(Object element) { |
324 |
protected Widget doFindItem(Object element) { |
| 400 |
|
325 |
|
| 401 |
TableItem[] children = table.getItems(); |
326 |
TableItem[] children = table.getItems(); |
| 402 |
for (int i = 0; i < children.length; i++) { |
327 |
for (int i = 0; i < children.length; i++) { |
| 403 |
TableItem item = children[i]; |
328 |
TableItem item = children[i]; |
|
Lines 411-418
Link Here
|
| 411 |
} |
336 |
} |
| 412 |
|
337 |
|
| 413 |
/* |
338 |
/* |
| 414 |
* (non-Javadoc) |
339 |
* (non-Javadoc) |
| 415 |
* @see org.eclipse.jface.viewers.StructuredViewer#doUpdateItem(org.eclipse.swt.widgets.Widget, java.lang.Object, boolean) |
340 |
* |
|
|
341 |
* @see org.eclipse.jface.viewers.StructuredViewer#doUpdateItem(org.eclipse.swt.widgets.Widget, |
| 342 |
* java.lang.Object, boolean) |
| 416 |
*/ |
343 |
*/ |
| 417 |
protected void doUpdateItem(Widget widget, Object element, boolean fullMap) { |
344 |
protected void doUpdateItem(Widget widget, Object element, boolean fullMap) { |
| 418 |
if (widget instanceof TableItem) { |
345 |
if (widget instanceof TableItem) { |
|
Lines 422-507
Link Here
|
| 422 |
if (fullMap) { |
349 |
if (fullMap) { |
| 423 |
associate(element, item); |
350 |
associate(element, item); |
| 424 |
} else { |
351 |
} else { |
| 425 |
Object data = item.getData(); |
352 |
Object data = item.getData(); |
| 426 |
if (data != null) { |
353 |
if (data != null) { |
| 427 |
unmapElement(data, item); |
354 |
unmapElement(data, item); |
| 428 |
} |
355 |
} |
| 429 |
item.setData(element); |
356 |
item.setData(element); |
| 430 |
mapElement(element, item); |
357 |
mapElement(element, item); |
| 431 |
} |
358 |
} |
| 432 |
|
359 |
|
| 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(); |
360 |
int columnCount = table.getColumnCount(); |
| 451 |
TableItem ti = item; |
361 |
if(columnCount == 0) |
| 452 |
getColorAndFontCollector().setFontsAndColors(element); |
362 |
columnCount = 1;//If there are no columns do the first one |
| 453 |
|
363 |
|
| 454 |
// Also enter loop if no columns added. See 1G9WWGZ: JFUIF:WINNT - |
364 |
// Also enter loop if no columns added. See 1G9WWGZ: JFUIF:WINNT - |
| 455 |
// TableViewer with 0 columns does not work |
365 |
// TableViewer with 0 columns does not work |
| 456 |
for (int column = 0; column < columnCount || column == 0; column++) { |
366 |
for (int column = 0; column < columnCount || column == 0; column++) { |
| 457 |
// Similar code in TreeViewer.doUpdateItem() |
367 |
ColumnViewerPart columnViewer = getColumnViewer(column); |
| 458 |
String text = "";//$NON-NLS-1$ |
368 |
columnViewer.refresh( getRowPartFromItem(item),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 |
|
369 |
|
| 490 |
//Avoid setting text to null |
370 |
// As it is possible for user code to run the event |
| 491 |
if (text == null) { |
371 |
// loop check here. |
| 492 |
text = ""; //$NON-NLS-1$ |
372 |
if (item.isDisposed()) { |
| 493 |
} |
373 |
unmapElement(element, item); |
| 494 |
ti.setText(column, text); |
374 |
return; |
| 495 |
if (ti.getImage(column) != image) { |
|
|
| 496 |
ti.setImage(column, image); |
| 497 |
} |
375 |
} |
|
|
376 |
|
| 498 |
} |
377 |
} |
| 499 |
|
378 |
|
| 500 |
|
379 |
} |
| 501 |
getColorAndFontCollector().applyFontsAndColors(ti); |
380 |
} |
|
|
381 |
|
| 382 |
|
| 383 |
/* (non-Javadoc) |
| 384 |
* @see org.eclipse.jface.viewers.ColumnViewer#getColumnViewerOwner(int) |
| 385 |
*/ |
| 386 |
protected Widget getColumnViewerOwner(int columnIndex) { |
| 387 |
if( columnIndex < 0 || columnIndex > getTable().getColumnCount() ) { |
| 388 |
return null; |
| 502 |
} |
389 |
} |
|
|
390 |
|
| 391 |
if (getTable().getColumnCount() == 0)// Hang it off the table if it |
| 392 |
return getTable(); |
| 393 |
|
| 394 |
|
| 395 |
return getTable().getColumn(columnIndex); |
| 396 |
} |
| 397 |
|
| 398 |
/** |
| 399 |
* Set the TableColumnViewerPart at columnIndex to be viewerPart. |
| 400 |
* |
| 401 |
* @param viewerPart |
| 402 |
* @param columnIndex |
| 403 |
*/ |
| 404 |
public void setColumnPart(ColumnViewerPart viewerPart, int columnIndex) { |
| 405 |
TableColumn column = getTable().getColumn(columnIndex); |
| 406 |
column.setData(ColumnViewerPart.COLUMN_VIEWER_KEY, viewerPart); |
| 503 |
} |
407 |
} |
| 504 |
|
408 |
|
|
|
409 |
|
| 505 |
/** |
410 |
/** |
| 506 |
* Starts editing the given element. |
411 |
* Starts editing the given element. |
| 507 |
* |
412 |
* |
|
Lines 514-550
Link Here
|
| 514 |
tableViewerImpl.editElement(element, column); |
419 |
tableViewerImpl.editElement(element, column); |
| 515 |
} |
420 |
} |
| 516 |
|
421 |
|
| 517 |
/** |
422 |
|
| 518 |
* Returns the cell editors of this table viewer. |
423 |
/* (non-Javadoc) |
| 519 |
* |
424 |
* @see org.eclipse.jface.viewers.ColumnViewer#getCellEditors() |
| 520 |
* @return the list of cell editors |
|
|
| 521 |
*/ |
425 |
*/ |
| 522 |
public CellEditor[] getCellEditors() { |
426 |
public CellEditor[] getCellEditors() { |
| 523 |
return tableViewerImpl.getCellEditors(); |
427 |
return tableViewerImpl.getCellEditors(); |
| 524 |
} |
428 |
} |
| 525 |
|
429 |
|
| 526 |
/** |
430 |
|
| 527 |
* Returns the cell modifier of this table viewer. |
431 |
/* (non-Javadoc) |
| 528 |
* |
432 |
* @see org.eclipse.jface.viewers.ColumnViewer#getCellModifier() |
| 529 |
* @return the cell modifier |
|
|
| 530 |
*/ |
433 |
*/ |
| 531 |
public ICellModifier getCellModifier() { |
434 |
public ICellModifier getCellModifier() { |
| 532 |
return tableViewerImpl.getCellModifier(); |
435 |
return tableViewerImpl.getCellModifier(); |
| 533 |
} |
436 |
} |
| 534 |
|
437 |
|
| 535 |
/** |
438 |
/* (non-Javadoc) |
| 536 |
* Returns the column properties of this table viewer. The properties must |
439 |
* @see org.eclipse.jface.viewers.ColumnViewer#getColumnProperties() |
| 537 |
* correspond with the columns of the table control. They are used to |
|
|
| 538 |
* identify the column in a cell modifier. |
| 539 |
* |
| 540 |
* @return the list of column properties |
| 541 |
*/ |
440 |
*/ |
| 542 |
public Object[] getColumnProperties() { |
441 |
public Object[] getColumnProperties() { |
| 543 |
return tableViewerImpl.getColumnProperties(); |
442 |
return tableViewerImpl.getColumnProperties(); |
| 544 |
} |
443 |
} |
| 545 |
|
444 |
|
| 546 |
/* |
445 |
/* |
| 547 |
* (non-Javadoc) |
446 |
* (non-Javadoc) |
|
|
447 |
* |
| 548 |
* @see org.eclipse.jface.viewers.Viewer#getControl() |
448 |
* @see org.eclipse.jface.viewers.Viewer#getControl() |
| 549 |
*/ |
449 |
*/ |
| 550 |
public Control getControl() { |
450 |
public Control getControl() { |
|
Lines 588-598
Link Here
|
| 588 |
} |
488 |
} |
| 589 |
|
489 |
|
| 590 |
/* |
490 |
/* |
| 591 |
* (non-Javadoc) |
491 |
* (non-Javadoc) |
|
|
492 |
* |
| 592 |
* @see org.eclipse.jface.viewers.StructuredViewer#getSelectionFromWidget() |
493 |
* @see org.eclipse.jface.viewers.StructuredViewer#getSelectionFromWidget() |
| 593 |
*/ |
494 |
*/ |
| 594 |
protected List getSelectionFromWidget() { |
495 |
protected List getSelectionFromWidget() { |
| 595 |
if(virtualManager != null) { |
496 |
if (virtualManager != null) { |
| 596 |
return getVirtualSelection(); |
497 |
return getVirtualSelection(); |
| 597 |
} |
498 |
} |
| 598 |
Widget[] items = table.getSelection(); |
499 |
Widget[] items = table.getSelection(); |
|
Lines 606-655
Link Here
|
| 606 |
} |
507 |
} |
| 607 |
return list; |
508 |
return list; |
| 608 |
} |
509 |
} |
| 609 |
|
510 |
|
| 610 |
/** |
511 |
/** |
| 611 |
* Get the virtual selection. Avoid calling SWT whenever possible |
512 |
* Get the virtual selection. Avoid calling SWT whenever possible to prevent |
| 612 |
* to prevent extra widget creation. |
513 |
* extra widget creation. |
|
|
514 |
* |
| 613 |
* @return List of Object |
515 |
* @return List of Object |
| 614 |
*/ |
516 |
*/ |
| 615 |
|
517 |
|
| 616 |
private List getVirtualSelection() { |
518 |
private List getVirtualSelection() { |
| 617 |
|
519 |
|
| 618 |
List result = new ArrayList(); |
520 |
List result = new ArrayList(); |
| 619 |
int[] selectionIndices = getTable().getSelectionIndices(); |
521 |
int[] selectionIndices = getTable().getSelectionIndices(); |
| 620 |
if(getContentProvider() instanceof ILazyContentProvider){ |
522 |
if (getContentProvider() instanceof ILazyContentProvider) { |
| 621 |
ILazyContentProvider lazy = (ILazyContentProvider) getContentProvider(); |
523 |
ILazyContentProvider lazy = (ILazyContentProvider) getContentProvider(); |
| 622 |
for (int i = 0; i < selectionIndices.length; i++) { |
524 |
for (int i = 0; i < selectionIndices.length; i++) { |
| 623 |
int selectionIndex = selectionIndices[i]; |
525 |
int selectionIndex = selectionIndices[i]; |
| 624 |
lazy.updateElement(selectionIndex);//Start the update |
526 |
lazy.updateElement(selectionIndex);// Start the update |
| 625 |
Object element = getTable().getItem(selectionIndex).getData(); |
527 |
Object element = getTable().getItem(selectionIndex).getData(); |
| 626 |
//Only add the element if it got updated. |
528 |
// Only add the element if it got updated. |
| 627 |
//If this is done deferred the selection will |
529 |
// If this is done deferred the selection will |
| 628 |
//be incomplete until selection is finished. |
530 |
// be incomplete until selection is finished. |
| 629 |
if (element != null) { |
531 |
if (element != null) { |
| 630 |
result.add(element); |
532 |
result.add(element); |
| 631 |
} |
533 |
} |
| 632 |
} |
534 |
} |
| 633 |
} |
535 |
} else { |
| 634 |
else{ |
|
|
| 635 |
for (int i = 0; i < selectionIndices.length; i++) { |
536 |
for (int i = 0; i < selectionIndices.length; i++) { |
| 636 |
Object element = null; |
537 |
Object element = null; |
| 637 |
//See if it is cached |
538 |
// See if it is cached |
| 638 |
int selectionIndex = selectionIndices[i]; |
539 |
int selectionIndex = selectionIndices[i]; |
| 639 |
if (selectionIndex < virtualManager.cachedElements.length){ |
540 |
if (selectionIndex < virtualManager.cachedElements.length) { |
| 640 |
element = virtualManager.cachedElements[selectionIndex]; |
541 |
element = virtualManager.cachedElements[selectionIndex]; |
| 641 |
} |
542 |
} |
| 642 |
if (element == null){ |
543 |
if (element == null) { |
| 643 |
// Not cached so try the item's data |
544 |
// Not cached so try the item's data |
| 644 |
TableItem item = getTable().getItem(selectionIndex); |
545 |
TableItem item = getTable().getItem(selectionIndex); |
| 645 |
element = item.getData(); |
546 |
element = item.getData(); |
| 646 |
} |
547 |
} |
| 647 |
if (element != null) { |
548 |
if (element != null) { |
| 648 |
result.add(element); |
549 |
result.add(element); |
| 649 |
} |
550 |
} |
| 650 |
} |
551 |
} |
| 651 |
|
552 |
|
| 652 |
|
|
|
| 653 |
} |
553 |
} |
| 654 |
return result; |
554 |
return result; |
| 655 |
} |
555 |
} |
|
Lines 664-670
Link Here
|
| 664 |
} |
564 |
} |
| 665 |
|
565 |
|
| 666 |
/* |
566 |
/* |
| 667 |
* (non-Javadoc) |
567 |
* (non-Javadoc) |
|
|
568 |
* |
| 668 |
* @see org.eclipse.jface.viewers.ContentViewer#hookControl(org.eclipse.swt.widgets.Control) |
569 |
* @see org.eclipse.jface.viewers.ContentViewer#hookControl(org.eclipse.swt.widgets.Control) |
| 669 |
*/ |
570 |
*/ |
| 670 |
protected void hookControl(Control control) { |
571 |
protected void hookControl(Control control) { |
|
Lines 757-764
Link Here
|
| 757 |
} |
658 |
} |
| 758 |
|
659 |
|
| 759 |
/* |
660 |
/* |
| 760 |
* (non-Javadoc) |
661 |
* (non-Javadoc) |
| 761 |
* @see org.eclipse.jface.viewers.Viewer#inputChanged(java.lang.Object, java.lang.Object) |
662 |
* |
|
|
663 |
* @see org.eclipse.jface.viewers.Viewer#inputChanged(java.lang.Object, |
| 664 |
* java.lang.Object) |
| 762 |
*/ |
665 |
*/ |
| 763 |
protected void inputChanged(Object input, Object oldInput) { |
666 |
protected void inputChanged(Object input, Object oldInput) { |
| 764 |
getControl().setRedraw(false); |
667 |
getControl().setRedraw(false); |
|
Lines 795-806
Link Here
|
| 795 |
if (position == -1) { |
698 |
if (position == -1) { |
| 796 |
position = table.getItemCount(); |
699 |
position = table.getItemCount(); |
| 797 |
} |
700 |
} |
| 798 |
|
701 |
|
| 799 |
createItem(element,position); |
702 |
createItem(element, position); |
| 800 |
} |
703 |
} |
| 801 |
|
704 |
|
| 802 |
/* |
705 |
/* |
| 803 |
* (non-Javadoc) |
706 |
* (non-Javadoc) |
|
|
707 |
* |
| 804 |
* @see org.eclipse.jface.viewers.StructuredViewer#internalRefresh(java.lang.Object) |
708 |
* @see org.eclipse.jface.viewers.StructuredViewer#internalRefresh(java.lang.Object) |
| 805 |
*/ |
709 |
*/ |
| 806 |
protected void internalRefresh(Object element) { |
710 |
protected void internalRefresh(Object element) { |
|
Lines 808-822
Link Here
|
| 808 |
} |
712 |
} |
| 809 |
|
713 |
|
| 810 |
/* |
714 |
/* |
| 811 |
* (non-Javadoc) |
715 |
* (non-Javadoc) |
| 812 |
* @see org.eclipse.jface.viewers.StructuredViewer#internalRefresh(java.lang.Object, boolean) |
716 |
* |
|
|
717 |
* @see org.eclipse.jface.viewers.StructuredViewer#internalRefresh(java.lang.Object, |
| 718 |
* boolean) |
| 813 |
*/ |
719 |
*/ |
| 814 |
protected void internalRefresh(Object element, boolean updateLabels) { |
720 |
protected void internalRefresh(Object element, boolean updateLabels) { |
| 815 |
tableViewerImpl.applyEditorValue(); |
721 |
tableViewerImpl.applyEditorValue(); |
| 816 |
if (element == null || equals(element, getRoot())) { |
722 |
if (element == null || equals(element, getRoot())) { |
| 817 |
if(virtualManager == null) { |
723 |
if (virtualManager == null) { |
| 818 |
internalRefreshAll(updateLabels); |
724 |
internalRefreshAll(updateLabels); |
| 819 |
} else{ |
725 |
} else { |
| 820 |
internalVirtualRefreshAll(); |
726 |
internalVirtualRefreshAll(); |
| 821 |
} |
727 |
} |
| 822 |
} else { |
728 |
} else { |
|
Lines 833-849
Link Here
|
| 833 |
* @since 3.1 |
739 |
* @since 3.1 |
| 834 |
*/ |
740 |
*/ |
| 835 |
private void internalVirtualRefreshAll() { |
741 |
private void internalVirtualRefreshAll() { |
| 836 |
|
742 |
|
| 837 |
Object root = getRoot(); |
743 |
Object root = getRoot(); |
| 838 |
IContentProvider contentProvider = getContentProvider(); |
744 |
IContentProvider contentProvider = getContentProvider(); |
| 839 |
|
745 |
|
| 840 |
//Invalidate for lazy |
746 |
// Invalidate for lazy |
| 841 |
if(!(contentProvider instanceof ILazyContentProvider) |
747 |
if (!(contentProvider instanceof ILazyContentProvider) |
| 842 |
&& (contentProvider instanceof IStructuredContentProvider)) { |
748 |
&& (contentProvider instanceof IStructuredContentProvider)) { |
| 843 |
//Don't cache if the root is null but cache if it is not lazy. |
749 |
// Don't cache if the root is null but cache if it is not lazy. |
| 844 |
if(root != null){ |
750 |
if (root != null) { |
| 845 |
virtualManager.cachedElements = |
751 |
virtualManager.cachedElements = ((IStructuredContentProvider) getContentProvider()) |
| 846 |
((IStructuredContentProvider) getContentProvider()).getElements(root); |
752 |
.getElements(root); |
| 847 |
getTable().setItemCount(virtualManager.cachedElements.length); |
753 |
getTable().setItemCount(virtualManager.cachedElements.length); |
| 848 |
} |
754 |
} |
| 849 |
} |
755 |
} |
|
Lines 851-858
Link Here
|
| 851 |
} |
757 |
} |
| 852 |
|
758 |
|
| 853 |
/** |
759 |
/** |
| 854 |
* Refresh all of the elements of the table. update the |
760 |
* Refresh all of the elements of the table. update the labels if |
| 855 |
* labels if updatLabels is true; |
761 |
* updatLabels is true; |
|
|
762 |
* |
| 856 |
* @param updateLabels |
763 |
* @param updateLabels |
| 857 |
* |
764 |
* |
| 858 |
* @since 3.1 |
765 |
* @since 3.1 |
|
Lines 871-880
Link Here
|
| 871 |
TableItem[] items = getTable().getItems(); |
778 |
TableItem[] items = getTable().getItems(); |
| 872 |
int min = Math.min(children.length, items.length); |
779 |
int min = Math.min(children.length, items.length); |
| 873 |
for (int i = 0; i < min; ++i) { |
780 |
for (int i = 0; i < min; ++i) { |
| 874 |
|
781 |
|
| 875 |
|
|
|
| 876 |
TableItem item = items[i]; |
782 |
TableItem item = items[i]; |
| 877 |
|
783 |
|
| 878 |
// if the element is unchanged, update its label if appropriate |
784 |
// if the element is unchanged, update its label if appropriate |
| 879 |
if (equals(children[i], item.getData())) { |
785 |
if (equals(children[i], item.getData())) { |
| 880 |
if (updateLabels) { |
786 |
if (updateLabels) { |
|
Lines 893-906
Link Here
|
| 893 |
// So, if the object associated with this item has changed, |
799 |
// So, if the object associated with this item has changed, |
| 894 |
// just disassociate it for now, and update it below. |
800 |
// just disassociate it for now, and update it below. |
| 895 |
item.setText(""); //$NON-NLS-1$ |
801 |
item.setText(""); //$NON-NLS-1$ |
| 896 |
item.setImage(new Image[Math.max(1,table.getColumnCount())]);//Clear all images |
802 |
item.setImage(new Image[Math.max(1, table.getColumnCount())]);// Clear |
|
|
803 |
// all |
| 804 |
// images |
| 897 |
disassociate(item); |
805 |
disassociate(item); |
| 898 |
} |
806 |
} |
| 899 |
} |
807 |
} |
| 900 |
// dispose of all items beyond the end of the current elements |
808 |
// dispose of all items beyond the end of the current elements |
| 901 |
if (min < items.length) { |
809 |
if (min < items.length) { |
| 902 |
for (int i = items.length; --i >= min;) { |
810 |
for (int i = items.length; --i >= min;) { |
| 903 |
|
811 |
|
| 904 |
disassociate(items[i]); |
812 |
disassociate(items[i]); |
| 905 |
} |
813 |
} |
| 906 |
table.remove(min, items.length - 1); |
814 |
table.remove(min, items.length - 1); |
|
Lines 912-918
Link Here
|
| 912 |
} |
820 |
} |
| 913 |
// Update items which were removed above |
821 |
// Update items which were removed above |
| 914 |
for (int i = 0; i < min; ++i) { |
822 |
for (int i = 0; i < min; ++i) { |
| 915 |
|
823 |
|
| 916 |
TableItem item = items[i]; |
824 |
TableItem item = items[i]; |
| 917 |
if (item.getData() == null) { |
825 |
if (item.getData() == null) { |
| 918 |
updateItem(item, children[i]); |
826 |
updateItem(item, children[i]); |
|
Lines 920-930
Link Here
|
| 920 |
} |
828 |
} |
| 921 |
// add any remaining elements |
829 |
// add any remaining elements |
| 922 |
for (int i = min; i < children.length; ++i) { |
830 |
for (int i = min; i < children.length; ++i) { |
| 923 |
createItem(children[i],i); |
831 |
createItem(children[i], i); |
| 924 |
} |
832 |
} |
| 925 |
} |
833 |
} |
| 926 |
|
834 |
|
| 927 |
|
|
|
| 928 |
/** |
835 |
/** |
| 929 |
* Removes the given elements from this table viewer. |
836 |
* Removes the given elements from this table viewer. |
| 930 |
* |
837 |
* |
|
Lines 987-995
Link Here
|
| 987 |
*/ |
894 |
*/ |
| 988 |
public void remove(final Object[] elements) { |
895 |
public void remove(final Object[] elements) { |
| 989 |
assertElementsNotNull(elements); |
896 |
assertElementsNotNull(elements); |
| 990 |
if (elements.length == 0) { |
897 |
if (elements.length == 0) { |
| 991 |
return; |
898 |
return; |
| 992 |
} |
899 |
} |
| 993 |
preservingSelection(new Runnable() { |
900 |
preservingSelection(new Runnable() { |
| 994 |
public void run() { |
901 |
public void run() { |
| 995 |
internalRemove(elements); |
902 |
internalRemove(elements); |
|
Lines 1007-1014
Link Here
|
| 1007 |
* the model. Note that there is another method for efficiently processing |
914 |
* the model. Note that there is another method for efficiently processing |
| 1008 |
* the simultaneous removal of multiple elements. |
915 |
* the simultaneous removal of multiple elements. |
| 1009 |
* </p> |
916 |
* </p> |
| 1010 |
* <strong>NOTE:</strong> removing an object from a virtual |
917 |
* <strong>NOTE:</strong> removing an object from a virtual table will |
| 1011 |
* table will decrement the itemCount. |
918 |
* decrement the itemCount. |
| 1012 |
* |
919 |
* |
| 1013 |
* @param element |
920 |
* @param element |
| 1014 |
* the element |
921 |
* the element |
|
Lines 1018-1024
Link Here
|
| 1018 |
} |
925 |
} |
| 1019 |
|
926 |
|
| 1020 |
/* |
927 |
/* |
| 1021 |
* (non-Javadoc) |
928 |
* (non-Javadoc) |
|
|
929 |
* |
| 1022 |
* @see org.eclipse.jface.viewers.StructuredViewer#reveal(java.lang.Object) |
930 |
* @see org.eclipse.jface.viewers.StructuredViewer#reveal(java.lang.Object) |
| 1023 |
*/ |
931 |
*/ |
| 1024 |
public void reveal(Object element) { |
932 |
public void reveal(Object element) { |
|
Lines 1079-1112
Link Here
|
| 1079 |
* may also implement {@link IColorProvider} and/or {@link IFontProvider} to |
987 |
* may also implement {@link IColorProvider} and/or {@link IFontProvider} to |
| 1080 |
* provide colors and/or fonts. |
988 |
* provide colors and/or fonts. |
| 1081 |
* </p> |
989 |
* </p> |
|
|
990 |
* <p> |
| 991 |
* If the label provider implements the mixin interface ITooltipProvider, it |
| 992 |
* can provide custom tooltips. |
| 993 |
* </p> |
| 1082 |
*/ |
994 |
*/ |
| 1083 |
public void setLabelProvider(IBaseLabelProvider labelProvider) { |
995 |
public void setLabelProvider(IBaseLabelProvider labelProvider) { |
| 1084 |
Assert.isTrue(labelProvider instanceof ITableLabelProvider |
996 |
Assert.isTrue(labelProvider instanceof ITableLabelProvider |
| 1085 |
|| labelProvider instanceof ILabelProvider); |
997 |
|| labelProvider instanceof ILabelProvider); |
|
|
998 |
clearColumnParts();//Clear before refresh |
| 1086 |
super.setLabelProvider(labelProvider); |
999 |
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 |
} |
1000 |
} |
| 1094 |
|
1001 |
|
| 1095 |
/** |
1002 |
/** |
|
|
1003 |
* Clear the viewer parts for the columns |
| 1004 |
*/ |
| 1005 |
private void clearColumnParts() { |
| 1006 |
TableColumn[] columns = getTable().getColumns(); |
| 1007 |
if(columns.length == 0) |
| 1008 |
getTable().setData(ColumnViewerPart.COLUMN_VIEWER_KEY,null); |
| 1009 |
else{ |
| 1010 |
for (int i = 0; i < columns.length; i++) { |
| 1011 |
columns[i].setData(ColumnViewerPart.COLUMN_VIEWER_KEY,null); |
| 1012 |
|
| 1013 |
} |
| 1014 |
} |
| 1015 |
|
| 1016 |
} |
| 1017 |
|
| 1018 |
/** |
| 1096 |
* <p> |
1019 |
* <p> |
| 1097 |
* Sets a new selection for this viewer and optionally makes it visible. |
1020 |
* Sets a new selection for this viewer and optionally makes it visible. The |
| 1098 |
* The TableViewer implmentation of this method is ineffecient for the |
1021 |
* TableViewer implmentation of this method is ineffecient for the |
| 1099 |
* ILazyContentProvider as lookup is done by indices rather than elements |
1022 |
* ILazyContentProvider as lookup is done by indices rather than elements |
| 1100 |
* and may require population of the entire table in worse case. |
1023 |
* and may require population of the entire table in worse case. |
| 1101 |
* </p> |
1024 |
* </p> |
| 1102 |
* <p> |
1025 |
* <p> |
| 1103 |
* Use Table#setSelection(int[] indices) and Table#showSelection() if |
1026 |
* Use Table#setSelection(int[] indices) and Table#showSelection() if you |
| 1104 |
* you wish to set selection more effeciently when using a ILazyContentProvider. |
1027 |
* wish to set selection more effeciently when using a ILazyContentProvider. |
| 1105 |
* </p> |
1028 |
* </p> |
| 1106 |
* |
1029 |
* |
| 1107 |
* @param selection the new selection |
1030 |
* @param selection |
| 1108 |
* @param reveal <code>true</code> if the selection is to be made |
1031 |
* the new selection |
| 1109 |
* visible, and <code>false</code> otherwise |
1032 |
* @param reveal |
|
|
1033 |
* <code>true</code> if the selection is to be made visible, |
| 1034 |
* and <code>false</code> otherwise |
| 1110 |
* @see Table#setSelection(int[]) |
1035 |
* @see Table#setSelection(int[]) |
| 1111 |
* @see Table#showSelection() |
1036 |
* @see Table#showSelection() |
| 1112 |
*/ |
1037 |
*/ |
|
Lines 1115-1135
Link Here
|
| 1115 |
} |
1040 |
} |
| 1116 |
|
1041 |
|
| 1117 |
/* |
1042 |
/* |
| 1118 |
* (non-Javadoc) |
1043 |
* (non-Javadoc) |
| 1119 |
* @see org.eclipse.jface.viewers.StructuredViewer#setSelectionToWidget(java.util.List, boolean) |
1044 |
* |
|
|
1045 |
* @see org.eclipse.jface.viewers.StructuredViewer#setSelectionToWidget(java.util.List, |
| 1046 |
* boolean) |
| 1120 |
*/ |
1047 |
*/ |
| 1121 |
protected void setSelectionToWidget(List list, boolean reveal) { |
1048 |
protected void setSelectionToWidget(List list, boolean reveal) { |
| 1122 |
|
1049 |
|
| 1123 |
if (list == null) { |
1050 |
if (list == null) { |
| 1124 |
table.deselectAll(); |
1051 |
table.deselectAll(); |
| 1125 |
return; |
1052 |
return; |
| 1126 |
} |
1053 |
} |
| 1127 |
|
1054 |
|
| 1128 |
if(virtualManager != null){ |
1055 |
if (virtualManager != null) { |
| 1129 |
virtualSetSelectionToWidget(list, reveal); |
1056 |
virtualSetSelectionToWidget(list, reveal); |
| 1130 |
return; |
1057 |
return; |
| 1131 |
} |
1058 |
} |
| 1132 |
|
1059 |
|
| 1133 |
int size = list.size(); |
1060 |
int size = list.size(); |
| 1134 |
TableItem[] items = new TableItem[size]; |
1061 |
TableItem[] items = new TableItem[size]; |
| 1135 |
int count = 0; |
1062 |
int count = 0; |
|
Lines 1149-1170
Link Here
|
| 1149 |
if (reveal) { |
1076 |
if (reveal) { |
| 1150 |
table.showSelection(); |
1077 |
table.showSelection(); |
| 1151 |
} |
1078 |
} |
| 1152 |
|
1079 |
|
| 1153 |
} |
1080 |
} |
| 1154 |
|
1081 |
|
| 1155 |
|
|
|
| 1156 |
/** |
1082 |
/** |
| 1157 |
* Set the selection on a virtual table |
1083 |
* Set the selection on a virtual table |
| 1158 |
* @param list The elements to set |
1084 |
* |
| 1159 |
* @param reveal Whether or not reveal the first item. |
1085 |
* @param list |
|
|
1086 |
* The elements to set |
| 1087 |
* @param reveal |
| 1088 |
* Whether or not reveal the first item. |
| 1160 |
*/ |
1089 |
*/ |
| 1161 |
private void virtualSetSelectionToWidget(List list, boolean reveal) { |
1090 |
private void virtualSetSelectionToWidget(List list, boolean reveal) { |
| 1162 |
int size = list.size(); |
1091 |
int size = list.size(); |
| 1163 |
int[] indices = new int[list.size()]; |
1092 |
int[] indices = new int[list.size()]; |
| 1164 |
|
1093 |
|
| 1165 |
TableItem firstItem = null; |
1094 |
TableItem firstItem = null; |
| 1166 |
int count = 0; |
1095 |
int count = 0; |
| 1167 |
HashSet virtualElements = new HashSet(); |
1096 |
HashSet virtualElements = new HashSet(); |
| 1168 |
for (int i = 0; i < size; ++i) { |
1097 |
for (int i = 0; i < size; ++i) { |
| 1169 |
Object o = list.get(i); |
1098 |
Object o = list.get(i); |
| 1170 |
Widget w = findItem(o); |
1099 |
Widget w = findItem(o); |
|
Lines 1178-1214
Link Here
|
| 1178 |
virtualElements.add(o); |
1107 |
virtualElements.add(o); |
| 1179 |
} |
1108 |
} |
| 1180 |
} |
1109 |
} |
| 1181 |
|
1110 |
|
| 1182 |
if(getContentProvider() instanceof ILazyContentProvider){ |
1111 |
if (getContentProvider() instanceof ILazyContentProvider) { |
| 1183 |
ILazyContentProvider provider = |
1112 |
ILazyContentProvider provider = (ILazyContentProvider) getContentProvider(); |
| 1184 |
(ILazyContentProvider) getContentProvider(); |
1113 |
|
| 1185 |
|
1114 |
// 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 |
1115 |
// virtual |
| 1187 |
//This may create all items so it is not a good |
1116 |
// This may create all items so it is not a good |
| 1188 |
//idea in general. |
1117 |
// idea in general. |
| 1189 |
//Use #setSelection (int [] indices,boolean reveal) instead |
1118 |
// Use #setSelection (int [] indices,boolean reveal) instead |
| 1190 |
for (int i = 0; virtualElements.size() > 0 && i < getTable().getItemCount(); i++) { |
1119 |
for (int i = 0; virtualElements.size() > 0 |
|
|
1120 |
&& i < getTable().getItemCount(); i++) { |
| 1191 |
provider.updateElement(i); |
1121 |
provider.updateElement(i); |
| 1192 |
TableItem item = getTable().getItem(i); |
1122 |
TableItem item = getTable().getItem(i); |
| 1193 |
if(virtualElements.contains(item.getData())){ |
1123 |
if (virtualElements.contains(item.getData())) { |
| 1194 |
indices[count++] = i; |
1124 |
indices[count++] = i; |
| 1195 |
virtualElements.remove(item.getData()); |
1125 |
virtualElements.remove(item.getData()); |
| 1196 |
if (firstItem == null) { |
1126 |
if (firstItem == null) { |
| 1197 |
firstItem = item; |
1127 |
firstItem = item; |
| 1198 |
} |
1128 |
} |
| 1199 |
} |
1129 |
} |
| 1200 |
} |
1130 |
} |
| 1201 |
} |
1131 |
} else { |
| 1202 |
else{ |
1132 |
|
| 1203 |
|
1133 |
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 |
1134 |
// have been found |
| 1205 |
//If it is not lazy we can use the cache |
1135 |
// If it is not lazy we can use the cache |
| 1206 |
for (int i = 0; i < virtualManager.cachedElements.length; i++) { |
1136 |
for (int i = 0; i < virtualManager.cachedElements.length; i++) { |
| 1207 |
Object element = virtualManager.cachedElements[i]; |
1137 |
Object element = virtualManager.cachedElements[i]; |
| 1208 |
if(virtualElements.contains(element)){ |
1138 |
if (virtualElements.contains(element)) { |
| 1209 |
TableItem item = getTable().getItem(i); |
1139 |
TableItem item = getTable().getItem(i); |
| 1210 |
item.getText();//Be sure to fire the update |
1140 |
item.getText();// Be sure to fire the update |
| 1211 |
indices[count++] = i; |
1141 |
indices[count++] = i; |
| 1212 |
virtualElements.remove(element); |
1142 |
virtualElements.remove(element); |
| 1213 |
if (firstItem == null) { |
1143 |
if (firstItem == null) { |
| 1214 |
firstItem = item; |
1144 |
firstItem = item; |
|
Lines 1217-1223
Link Here
|
| 1217 |
} |
1147 |
} |
| 1218 |
} |
1148 |
} |
| 1219 |
} |
1149 |
} |
| 1220 |
|
1150 |
|
| 1221 |
if (count < size) { |
1151 |
if (count < size) { |
| 1222 |
System.arraycopy(indices, 0, indices = new int[count], 0, count); |
1152 |
System.arraycopy(indices, 0, indices = new int[count], 0, count); |
| 1223 |
} |
1153 |
} |
|
Lines 1230-1264
Link Here
|
| 1230 |
|
1160 |
|
| 1231 |
/** |
1161 |
/** |
| 1232 |
* Set the item count of the receiver. |
1162 |
* Set the item count of the receiver. |
| 1233 |
* @param count the new table size. |
1163 |
* |
|
|
1164 |
* @param count |
| 1165 |
* the new table size. |
| 1234 |
* |
1166 |
* |
| 1235 |
* @since 3.1 |
1167 |
* @since 3.1 |
| 1236 |
*/ |
1168 |
*/ |
| 1237 |
public void setItemCount(int count){ |
1169 |
public void setItemCount(int count) { |
| 1238 |
getTable().setItemCount(count); |
1170 |
getTable().setItemCount(count); |
| 1239 |
getTable().redraw(); |
1171 |
getTable().redraw(); |
| 1240 |
} |
1172 |
} |
| 1241 |
|
1173 |
|
| 1242 |
/** |
1174 |
/** |
| 1243 |
* Replace the entries starting at index with elements. |
1175 |
* Replace the entries starting at index with elements. This method assumes |
| 1244 |
* This method assumes all of these values are correct |
1176 |
* all of these values are correct and will not call the content provider to |
| 1245 |
* and will not call the content provider to verify. |
1177 |
* verify. <strong>Note that this method will create a TableItem for all of |
| 1246 |
* <strong>Note that this method will create a TableItem |
1178 |
* the elements provided</strong>. |
| 1247 |
* for all of the elements provided</strong>. |
1179 |
* |
| 1248 |
* @param element |
1180 |
* @param element |
| 1249 |
* @param index |
1181 |
* @param index |
| 1250 |
* @see ILazyContentProvider |
1182 |
* @see ILazyContentProvider |
| 1251 |
* |
1183 |
* |
| 1252 |
* @since 3.1 |
1184 |
* @since 3.1 |
| 1253 |
*/ |
1185 |
*/ |
| 1254 |
public void replace(Object element, int index){ |
1186 |
public void replace(Object element, int index) { |
| 1255 |
TableItem item = getTable().getItem(index); |
1187 |
TableItem item = getTable().getItem(index); |
| 1256 |
refreshItem(item, element); |
1188 |
refreshItem(item, element); |
| 1257 |
} |
1189 |
} |
| 1258 |
|
1190 |
|
| 1259 |
/** |
1191 |
/** |
| 1260 |
* Clear the table item at the specified index |
1192 |
* Clear the table item at the specified index |
| 1261 |
* @param index the index of the table item to be cleared |
1193 |
* |
|
|
1194 |
* @param index |
| 1195 |
* the index of the table item to be cleared |
| 1262 |
* |
1196 |
* |
| 1263 |
* @since 3.1 |
1197 |
* @since 3.1 |
| 1264 |
*/ |
1198 |
*/ |
|
Lines 1269-1294
Link Here
|
| 1269 |
} |
1203 |
} |
| 1270 |
table.clear(index); |
1204 |
table.clear(index); |
| 1271 |
} |
1205 |
} |
| 1272 |
|
1206 |
|
| 1273 |
/* (non-Javadoc) |
1207 |
/* |
|
|
1208 |
* (non-Javadoc) |
| 1209 |
* |
| 1274 |
* @see org.eclipse.jface.viewers.StructuredViewer#getRawChildren(java.lang.Object) |
1210 |
* @see org.eclipse.jface.viewers.StructuredViewer#getRawChildren(java.lang.Object) |
| 1275 |
*/ |
1211 |
*/ |
| 1276 |
protected Object[] getRawChildren(Object parent) { |
1212 |
protected Object[] getRawChildren(Object parent) { |
| 1277 |
|
1213 |
|
| 1278 |
Assert.isTrue(!(getContentProvider() instanceof ILazyContentProvider),"Cannot get raw children with an ILazyContentProvider");//$NON-NLS-1$ |
1214 |
Assert.isTrue(!(getContentProvider() instanceof ILazyContentProvider), |
|
|
1215 |
"Cannot get raw children with an ILazyContentProvider");//$NON-NLS-1$ |
| 1279 |
return super.getRawChildren(parent); |
1216 |
return super.getRawChildren(parent); |
| 1280 |
|
1217 |
|
| 1281 |
} |
1218 |
} |
| 1282 |
|
1219 |
|
| 1283 |
/* (non-Javadoc) |
1220 |
/* |
|
|
1221 |
* (non-Javadoc) |
| 1222 |
* |
| 1284 |
* @see org.eclipse.jface.viewers.StructuredViewer#assertContentProviderType(org.eclipse.jface.viewers.IContentProvider) |
1223 |
* @see org.eclipse.jface.viewers.StructuredViewer#assertContentProviderType(org.eclipse.jface.viewers.IContentProvider) |
| 1285 |
*/ |
1224 |
*/ |
| 1286 |
protected void assertContentProviderType(IContentProvider provider) { |
1225 |
protected void assertContentProviderType(IContentProvider provider) { |
| 1287 |
Assert.isTrue(provider instanceof IStructuredContentProvider || |
1226 |
Assert.isTrue(provider instanceof IStructuredContentProvider |
| 1288 |
provider instanceof ILazyContentProvider); |
1227 |
|| provider instanceof ILazyContentProvider); |
| 1289 |
} |
1228 |
} |
| 1290 |
|
1229 |
|
|
|
1230 |
/* (non-Javadoc) |
| 1231 |
* @see org.eclipse.jface.viewers.StructuredViewer#getRowPartFromItem(org.eclipse.swt.widgets.Widget) |
| 1232 |
*/ |
| 1233 |
protected RowPart getRowPartFromItem(Widget item) { |
| 1234 |
RowPart part = (RowPart)item.getData(RowPart.ROWPART_KEY); |
| 1235 |
|
| 1236 |
if( part == null ) { |
| 1237 |
part = new TableRowPart(((TableItem)item)); |
| 1238 |
} |
| 1239 |
|
| 1240 |
return part; |
| 1241 |
} |
| 1242 |
|
| 1243 |
/* (non-Javadoc) |
| 1244 |
* @see org.eclipse.jface.viewers.StructuredViewer#createNewRowPart(org.eclipse.jface.internal.viewers.RowPart, int, int) |
| 1245 |
*/ |
| 1246 |
protected RowPart createNewRowPart(RowPart parent, int style, int rowIndex) { |
| 1247 |
TableItem item; |
| 1248 |
|
| 1249 |
if( rowIndex >= 0 ) { |
| 1250 |
item = new TableItem(table,SWT.NONE,rowIndex); |
| 1251 |
} else { |
| 1252 |
item = new TableItem(table,SWT.NONE); |
| 1253 |
} |
| 1254 |
|
| 1255 |
return getRowPartFromItem(item); |
| 1256 |
} |
| 1257 |
|
| 1258 |
/** |
| 1259 |
* Returns the item at the given display-relative coordinates, or |
| 1260 |
* <code>null</code> if there is no item at that location. |
| 1261 |
* <p> |
| 1262 |
* The default implementation of this method returns <code>null</code>. |
| 1263 |
* </p> |
| 1264 |
* |
| 1265 |
* @param x |
| 1266 |
* horizontal coordinate |
| 1267 |
* @param y |
| 1268 |
* vertical coordinate |
| 1269 |
* @return the item, or <code>null</code> if there is no item at the given |
| 1270 |
* coordinates |
| 1271 |
*/ |
| 1272 |
protected Item getItem(int x, int y) { |
| 1273 |
return table.getItem(new Point(x,y)); |
| 1274 |
} |
| 1275 |
|
| 1276 |
/* (non-Javadoc) |
| 1277 |
* @see org.eclipse.jface.viewers.StructuredViewer#createColumnViewer(org.eclipse.swt.widgets.Widget, org.eclipse.jface.viewers.ViewerLabelProvider) |
| 1278 |
*/ |
| 1279 |
protected ColumnViewerPart createColumnViewer(Widget columnOwner, ViewerLabelProvider labelProvider) { |
| 1280 |
if( columnOwner instanceof TableColumn ) { |
| 1281 |
return new TableColumnViewerPart((TableColumn)columnOwner,labelProvider); |
| 1282 |
} |
| 1283 |
|
| 1284 |
return super.createColumnViewer(columnOwner, labelProvider); |
| 1285 |
} |
| 1291 |
|
1286 |
|
| 1292 |
|
1287 |
|
| 1293 |
} |
1288 |
} |
| 1294 |
|
|
|