Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 149193 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jface/viewers/TableViewer.java (-347 / +341 lines)
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
(-)src/org/eclipse/jface/viewers/TreeViewer.java (-342 / +274 lines)
Lines 22-28 Link Here
22
import org.eclipse.swt.events.MouseAdapter;
22
import org.eclipse.swt.events.MouseAdapter;
23
import org.eclipse.swt.events.MouseEvent;
23
import org.eclipse.swt.events.MouseEvent;
24
import org.eclipse.swt.events.TreeListener;
24
import org.eclipse.swt.events.TreeListener;
25
import org.eclipse.swt.graphics.Image;
26
import org.eclipse.swt.graphics.Point;
25
import org.eclipse.swt.graphics.Point;
27
import org.eclipse.swt.graphics.Rectangle;
26
import org.eclipse.swt.graphics.Rectangle;
28
import org.eclipse.swt.widgets.Composite;
27
import org.eclipse.swt.widgets.Composite;
Lines 55-123 Link Here
55
public class TreeViewer extends AbstractTreeViewer {
54
public class TreeViewer extends AbstractTreeViewer {
56
55
57
	/**
56
	/**
58
	 * TreeColorAndFontCollector is an helper class for color and font support
59
	 * for trees that support the ITableFontProvider and the
60
	 * ITableColorProvider.
61
	 * 
62
	 * @see ITableColorProvider
63
	 * @see ITableFontProvider
64
	 */
65
66
	private class TreeColorAndFontCollector {
67
68
		ITableFontProvider fontProvider = null;
69
70
		ITableColorProvider colorProvider = null;
71
72
		/**
73
		 * Create an instance of the receiver. Set the color and font providers
74
		 * if provider can be cast to the correct type.
75
		 * 
76
		 * @param provider
77
		 *            IBaseLabelProvider
78
		 */
79
		public TreeColorAndFontCollector(IBaseLabelProvider provider) {
80
			if (provider instanceof ITableFontProvider) {
81
				fontProvider = (ITableFontProvider) provider;
82
			}
83
			if (provider instanceof ITableColorProvider) {
84
				colorProvider = (ITableColorProvider) provider;
85
			}
86
		}
87
88
		/**
89
		 * Create an instance of the receiver with no color and font providers.
90
		 */
91
		public TreeColorAndFontCollector() {
92
		}
93
94
		/**
95
		 * Set the fonts and colors for the treeItem if there is a color and
96
		 * font provider available.
97
		 * 
98
		 * @param treeItem
99
		 *            The item to update.
100
		 * @param element
101
		 *            The element being represented
102
		 * @param column
103
		 *            The column index
104
		 */
105
		public void setFontsAndColors(TreeItem treeItem, Object element,
106
				int column) {
107
			if (colorProvider != null) {
108
				treeItem.setBackground(column, colorProvider.getBackground(
109
						element, column));
110
				treeItem.setForeground(column, colorProvider.getForeground(
111
						element, column));
112
			}
113
			if (fontProvider != null) {
114
				treeItem.setFont(column, fontProvider.getFont(element, column));
115
			}
116
		}
117
118
	}
119
120
	/**
121
	 * Internal tree viewer implementation.
57
	 * Internal tree viewer implementation.
122
	 */
58
	 */
123
	private TreeEditorImpl treeViewerImpl;
59
	private TreeEditorImpl treeViewerImpl;
Lines 133-143 Link Here
133
	private TreeEditor treeEditor;
69
	private TreeEditor treeEditor;
134
70
135
	/**
71
	/**
136
	 * The color and font collector for the cells.
137
	 */
138
	private TreeColorAndFontCollector treeColorAndFont = new TreeColorAndFontCollector();
139
	
140
	/**
141
	 * Flag for whether the tree has been disposed of.
72
	 * Flag for whether the tree has been disposed of.
142
	 */
73
	 */
143
	private boolean treeIsDisposed = false;
74
	private boolean treeIsDisposed = false;
Lines 207-213 Link Here
207
	 * (non-Javadoc) Method declared in AbstractTreeViewer.
138
	 * (non-Javadoc) Method declared in AbstractTreeViewer.
208
	 */
139
	 */
209
	protected void doUpdateItem(final Item item, Object element) {
140
	protected void doUpdateItem(final Item item, Object element) {
210
		if (!(item instanceof TreeItem)) {
141
 		if (!(item instanceof TreeItem)) {
211
			return;
142
			return;
212
		}
143
		}
213
		TreeItem treeItem = (TreeItem) item;
144
		TreeItem treeItem = (TreeItem) item;
Lines 216-331 Link Here
216
			return;
147
			return;
217
		}
148
		}
218
149
219
		getColorAndFontCollector().setFontsAndColors(element);
150
		int columnCount = getTree().getColumnCount();
220
151
		if(columnCount == 0)//If no columns are created then fake one
221
		IBaseLabelProvider prov = getLabelProvider();
152
			columnCount = 1;
222
		ITableLabelProvider tprov = null;
153
223
		ILabelProvider lprov = null;
154
		for (int column = 0; column < columnCount; column++) {
224
		IViewerLabelProvider vprov = null;
155
			ColumnViewerPart columnViewer = getColumnViewer(column);
225
		ITreePathLabelProvider pprov = null;
156
			columnViewer.refresh(getRowPartFromItem(treeItem),column);
226
		
227
		if(prov instanceof ILabelProvider) {
228
			lprov = (ILabelProvider) prov;
229
		}
230
		
231
		if (prov instanceof IViewerLabelProvider) {
232
			vprov = (IViewerLabelProvider) prov;
233
		} 
234
		
235
		if (prov instanceof ITableLabelProvider) {
236
			tprov = (ITableLabelProvider) prov;
237
		}
238
		
239
		if (prov instanceof ITreePathLabelProvider) {
240
			pprov = (ITreePathLabelProvider) prov;
241
		}
242
		
243
		
244
		int columnCount = tree.getColumnCount();
245
		if (columnCount == 0) {// If no columns were created use the label
246
								// provider
247
248
			ViewerLabel updateLabel = new ViewerLabel(treeItem.getText(),
249
					treeItem.getImage());
250
			if (pprov != null) {
251
				TreePath path = getTreePathFromItem(item);
252
				buildLabel(updateLabel,path,pprov);
253
			} else 
254
				if(vprov != null) {
255
					buildLabel(updateLabel,element,vprov);
256
				} else{
257
					if(lprov != null) {
258
						buildLabel(updateLabel,element,lprov);
259
					}
260
				}
261
157
262
			// As it is possible for user code to run the event
158
			// As it is possible for user code to run the event
263
			// loop check here.
159
			// loop check here.
264
			if (treeItem.isDisposed()) {
160
			if (item.isDisposed()) {
265
				unmapElement(element, treeItem);
161
				unmapElement(element, item);
266
				return;
162
				return;
267
			}
163
			}
268
164
269
			if (updateLabel.hasNewText()) {
165
		}
270
				treeItem.setText(updateLabel.getText());
271
			}
272
			if (updateLabel.hasNewImage()) {
273
				treeItem.setImage(updateLabel.getImage());
274
			}
275
			
276
			if (!updateLabel.hasPendingDecorations())
277
				getColorAndFontCollector().applyFontsAndColors(treeItem);
278
279
		} else {// Use the table based support
280
			for (int column = 0; column < columnCount; column++) {
281
				// Similar code in TableViewer.doUpdateItem()
282
				String text = "";//$NON-NLS-1$
283
				Image image = null;
284
				treeColorAndFont.setFontsAndColors(treeItem, element, column);
285
286
				if (tprov == null) {
287
					if (column == 0) {
288
						ViewerLabel updateLabel = new ViewerLabel(treeItem
289
								.getText(), treeItem.getImage());
290
						if(vprov != null) {
291
							buildLabel(updateLabel,element,vprov);
292
						} else{
293
							if(lprov != null) {
294
								buildLabel(updateLabel,element,lprov);
295
							}
296
						}
297
298
						// As it is possible for user code to run the event
299
						// loop check here.
300
						if (treeItem.isDisposed()) {
301
							unmapElement(element, treeItem);
302
							return;
303
						}
304
166
305
						text = updateLabel.getText();
167
	}
306
						image = updateLabel.getImage();
307
					}
308
				} else {
309
					text = tprov.getColumnText(element, column);
310
					image = tprov.getColumnImage(element, column);
311
				}
312
168
313
				// Avoid setting text to null
169
	/* (non-Javadoc)
314
				if (text == null) {
170
	 * @see org.eclipse.jface.viewers.ColumnViewer#getColumnViewerOwner(int)
315
					text = ""; //$NON-NLS-1$
171
	 */
316
				}
172
	protected Widget getColumnViewerOwner(int columnIndex) {
317
				treeItem.setText(column, text);
173
		if( columnIndex < 0 || columnIndex > getTree().getColumnCount() ) {
318
				if (treeItem.getImage(column) != image) {
174
			return null;
319
					treeItem.setImage(column, image);
320
				}
321
			}
322
			getColorAndFontCollector().applyFontsAndColors(treeItem);
323
		}
175
		}
176
		
177
		if (getTree().getColumnCount() == 0)// Hang it off the table if it
178
			return getTree();
179
		
180
		return getTree().getColumn(columnIndex);
324
	}
181
	}
325
	
182
326
	/**
183
	/**
327
	 * Override to handle tree paths.
184
	 * Override to handle tree paths.
328
	 * @see org.eclipse.jface.viewers.StructuredViewer#buildLabel(org.eclipse.jface.viewers.ViewerLabel, java.lang.Object)
185
	 * 
186
	 * @see org.eclipse.jface.viewers.StructuredViewer#buildLabel(org.eclipse.jface.viewers.ViewerLabel,
187
	 *      java.lang.Object)
329
	 */
188
	 */
330
	protected void buildLabel(ViewerLabel updateLabel, Object elementOrPath) {
189
	protected void buildLabel(ViewerLabel updateLabel, Object elementOrPath) {
331
		Object element;
190
		Object element;
Lines 357-377 Link Here
357
		treeViewerImpl.editElement(element, column);
216
		treeViewerImpl.editElement(element, column);
358
	}
217
	}
359
218
360
	/**
219
361
	 * Returns the cell editors of this tree viewer.
220
	/* (non-Javadoc)
362
	 * 
221
	 * @see org.eclipse.jface.viewers.ColumnViewer#getCellEditors()
363
	 * @return the list of cell editors
364
	 * @since 3.1
365
	 */
222
	 */
366
	public CellEditor[] getCellEditors() {
223
	public CellEditor[] getCellEditors() {
367
		return treeViewerImpl.getCellEditors();
224
		return treeViewerImpl.getCellEditors();
368
	}
225
	}
369
226
370
	/**
227
	/* (non-Javadoc)
371
	 * Returns the cell modifier of this tree viewer.
228
	 * @see org.eclipse.jface.viewers.ColumnViewer#getCellModifier()
372
	 * 
373
	 * @return the cell modifier
374
	 * @since 3.1
375
	 */
229
	 */
376
	public ICellModifier getCellModifier() {
230
	public ICellModifier getCellModifier() {
377
		return treeViewerImpl.getCellModifier();
231
		return treeViewerImpl.getCellModifier();
Lines 390-402 Link Here
390
		return null;
244
		return null;
391
	}
245
	}
392
246
393
	/**
247
	/* (non-Javadoc)
394
	 * Returns the column properties of this tree viewer. The properties must
248
	 * @see org.eclipse.jface.viewers.ColumnViewer#getColumnProperties()
395
	 * correspond with the columns of the tree control. They are used to
396
	 * identify the column in a cell modifier.
397
	 * 
398
	 * @return the list of column properties
399
	 * @since 3.1
400
	 */
249
	 */
401
	public Object[] getColumnProperties() {
250
	public Object[] getColumnProperties() {
402
		return treeViewerImpl.getColumnProperties();
251
		return treeViewerImpl.getColumnProperties();
Lines 416-423 Link Here
416
		return ((TreeItem) item).getExpanded();
265
		return ((TreeItem) item).getExpanded();
417
	}
266
	}
418
267
419
	/*
268
	/**
420
	 * (non-Javadoc) Method declared in StructuredViewer.
269
	 * Returns the item at the given display-relative coordinates, or
270
	 * <code>null</code> if there is no item at that location.
271
	 * <p>
272
	 * The default implementation of this method returns <code>null</code>.
273
	 * </p>
274
	 * 
275
	 * @param x
276
	 *            horizontal coordinate
277
	 * @param y
278
	 *            vertical coordinate
279
	 * @return the item, or <code>null</code> if there is no item at the given
280
	 *         coordinates
421
	 */
281
	 */
422
	protected Item getItem(int x, int y) {
282
	protected Item getItem(int x, int y) {
423
		return getTree().getItem(getTree().toControl(new Point(x, y)));
283
		return getTree().getItem(getTree().toControl(new Point(x, y)));
Lines 463-469 Link Here
463
	protected Item getParentItem(Item item) {
323
	protected Item getParentItem(Item item) {
464
		return ((TreeItem) item).getParentItem();
324
		return ((TreeItem) item).getParentItem();
465
	}
325
	}
466
	
326
467
	/*
327
	/*
468
	 * (non-Javadoc) Method declared in AbstractTreeViewer.
328
	 * (non-Javadoc) Method declared in AbstractTreeViewer.
469
	 */
329
	 */
Lines 494-505 Link Here
494
			}
354
			}
495
		});
355
		});
496
		if ((treeControl.getStyle() & SWT.VIRTUAL) != 0) {
356
		if ((treeControl.getStyle() & SWT.VIRTUAL) != 0) {
497
			treeControl.addDisposeListener(new DisposeListener(){
357
			treeControl.addDisposeListener(new DisposeListener() {
498
				public void widgetDisposed(DisposeEvent e) {
358
				public void widgetDisposed(DisposeEvent e) {
499
					treeIsDisposed = true;
359
					treeIsDisposed = true;
500
					unmapAllElements();
360
					unmapAllElements();
501
				}});
361
				}
502
			treeControl.addListener(SWT.SetData, new Listener(){
362
			});
363
			treeControl.addListener(SWT.SetData, new Listener() {
503
364
504
				public void handleEvent(Event event) {
365
				public void handleEvent(Event event) {
505
					if (getContentProvider() instanceof ILazyTreeContentProvider) {
366
					if (getContentProvider() instanceof ILazyTreeContentProvider) {
Lines 582-600 Link Here
582
	 */
443
	 */
583
	protected Item newItem(Widget parent, int flags, int ix) {
444
	protected Item newItem(Widget parent, int flags, int ix) {
584
		TreeItem item;
445
		TreeItem item;
585
		if (ix >= 0) {
446
		
586
			if (parent instanceof TreeItem) {
447
		if (parent instanceof TreeItem) {
587
				item = new TreeItem((TreeItem) parent, flags, ix);
448
			item = (TreeItem)createNewRowPart(getRowPartFromItem(parent),flags, ix).getItem();
588
			} else {
589
				item = new TreeItem((Tree) parent, flags, ix);
590
			}
591
		} else {
449
		} else {
592
			if (parent instanceof TreeItem) {
450
			item = (TreeItem)createNewRowPart(null,flags, ix).getItem();
593
				item = new TreeItem((TreeItem) parent, flags);
594
			} else {
595
				item = new TreeItem((Tree) parent, flags);
596
			}
597
		}
451
		}
452
		
598
		return item;
453
		return item;
599
	}
454
	}
600
455
Lines 645-651 Link Here
645
	 */
500
	 */
646
	protected void setExpanded(Item node, boolean expand) {
501
	protected void setExpanded(Item node, boolean expand) {
647
		((TreeItem) node).setExpanded(expand);
502
		((TreeItem) node).setExpanded(expand);
648
		if(getContentProvider() instanceof ILazyTreeContentProvider) {
503
		if (getContentProvider() instanceof ILazyTreeContentProvider) {
649
			// force repaints to happen
504
			// force repaints to happen
650
			getControl().update();
505
			getControl().update();
651
		}
506
		}
Lines 661-667 Link Here
661
	 * <code>ITableLabelProvider</code> may also implement
516
	 * <code>ITableLabelProvider</code> may also implement
662
	 * {@link ITableColorProvider} and/or {@link ITableFontProvider} to provide
517
	 * {@link ITableColorProvider} and/or {@link ITableFontProvider} to provide
663
	 * colors and/or fonts. Note that the underlying {@link Tree} must be
518
	 * colors and/or fonts. Note that the underlying {@link Tree} must be
664
	 * configured with {@link TreeColumn} objects in this case. 
519
	 * configured with {@link TreeColumn} objects in this case.
665
	 * </p>
520
	 * </p>
666
	 * <p>
521
	 * <p>
667
	 * If the label provider is an <code>ILabelProvider</code>, then it
522
	 * If the label provider is an <code>ILabelProvider</code>, then it
Lines 674-681 Link Here
674
	public void setLabelProvider(IBaseLabelProvider labelProvider) {
529
	public void setLabelProvider(IBaseLabelProvider labelProvider) {
675
		Assert.isTrue(labelProvider instanceof ITableLabelProvider
530
		Assert.isTrue(labelProvider instanceof ITableLabelProvider
676
				|| labelProvider instanceof ILabelProvider);
531
				|| labelProvider instanceof ILabelProvider);
532
		clearColumnParts();//Clear before refresh
677
		super.setLabelProvider(labelProvider);
533
		super.setLabelProvider(labelProvider);
678
		treeColorAndFont = new TreeColorAndFontCollector(labelProvider);
534
		
535
	}
536
537
	/**
538
	 * Clear the viewer parts for the columns
539
	 */
540
	private void clearColumnParts() {
541
		TreeColumn[] columns = getTree().getColumns();
542
		if(columns.length == 0)
543
			getTree().setData(ColumnViewerPart.COLUMN_VIEWER_KEY,null);
544
		else{
545
			for (int i = 0; i < columns.length; i++) {
546
				columns[i].setData(ColumnViewerPart.COLUMN_VIEWER_KEY,null);
547
				
548
			}
549
		}
550
		
679
	}
551
	}
680
552
681
	/*
553
	/*
Lines 705-711 Link Here
705
	 *            the array of items
577
	 *            the array of items
706
	 * @return <code>true</code> if the refer to the same elements,
578
	 * @return <code>true</code> if the refer to the same elements,
707
	 *         <code>false</code> otherwise
579
	 *         <code>false</code> otherwise
708
	 *         
580
	 * 
709
	 * @since 3.1
581
	 * @since 3.1
710
	 */
582
	 */
711
	protected boolean isSameSelection(List items, Item[] current) {
583
	protected boolean isSameSelection(List items, Item[] current) {
Lines 725-731 Link Here
725
		// Go through the items of the current collection
597
		// Go through the items of the current collection
726
		// If there is a mismatch return false
598
		// If there is a mismatch return false
727
		for (int i = 0; i < current.length; i++) {
599
		for (int i = 0; i < current.length; i++) {
728
			if (current[i].getData() == null || !itemSet.containsKey(current[i].getData())) {
600
			if (current[i].getData() == null
601
					|| !itemSet.containsKey(current[i].getData())) {
729
				return false;
602
				return false;
730
			}
603
			}
731
		}
604
		}
Lines 740-748 Link Here
740
		getTree().showItem((TreeItem) item);
613
		getTree().showItem((TreeItem) item);
741
	}
614
	}
742
615
743
616
	/*
744
	/* (non-Javadoc)
617
	 * (non-Javadoc)
745
	 * @see org.eclipse.jface.viewers.AbstractTreeViewer#getChild(org.eclipse.swt.widgets.Widget, int)
618
	 * 
619
	 * @see org.eclipse.jface.viewers.AbstractTreeViewer#getChild(org.eclipse.swt.widgets.Widget,
620
	 *      int)
746
	 */
621
	 */
747
	protected Item getChild(Widget widget, int index) {
622
	protected Item getChild(Widget widget, int index) {
748
		if (widget instanceof TreeItem) {
623
		if (widget instanceof TreeItem) {
Lines 753-790 Link Here
753
		}
628
		}
754
		return null;
629
		return null;
755
	}
630
	}
756
	
631
757
	protected void assertContentProviderType(IContentProvider provider) {
632
	protected void assertContentProviderType(IContentProvider provider) {
758
		if(provider instanceof ILazyTreeContentProvider) {
633
		if (provider instanceof ILazyTreeContentProvider) {
759
			return;
634
			return;
760
		}
635
		}
761
		super.assertContentProviderType(provider);
636
		super.assertContentProviderType(provider);
762
	}
637
	}
763
	
638
764
    protected Object[] getRawChildren(Object parent) {
639
	protected Object[] getRawChildren(Object parent) {
765
    	if(getContentProvider() instanceof ILazyTreeContentProvider) {
640
		if (getContentProvider() instanceof ILazyTreeContentProvider) {
766
    		return new Object[0];
641
			return new Object[0];
767
    	}
642
		}
768
    	return super.getRawChildren(parent);
643
		return super.getRawChildren(parent);
769
    }
644
	}
770
645
771
    /**
646
	/**
772
     * For a TreeViewer with a tree with the VIRTUAL style bit set, set the
647
	 * For a TreeViewer with a tree with the VIRTUAL style bit set, set the
773
     * number of children of the given element. To set the number of children
648
	 * number of children of the given element. To set the number of children of
774
     * of the invisible root of the tree, the input object is passed as the
649
	 * the invisible root of the tree, the input object is passed as the
775
     * element.
650
	 * element.
776
     * 
651
	 * 
777
     * @param element
652
	 * @param element
778
     * @param count
653
	 * @param count
779
     * 
654
	 * 
780
	 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
655
	 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
781
	 * part of a work in progress. There is no guarantee that this API will remain
656
	 * part of a work in progress. There is no guarantee that this API will
782
	 * unchanged during the 3.2 release cycle. Please do not use this API without
657
	 * remain unchanged during the 3.2 release cycle. Please do not use this API
783
	 * consulting with the Platform/UI team.
658
	 * without consulting with the Platform/UI team.
784
	 * </p>
659
	 * </p>
785
     * 
660
	 * 
786
     * @since 3.2
661
	 * @since 3.2
787
     */
662
	 */
788
	public void setChildCount(Object element, int count) {
663
	public void setChildCount(Object element, int count) {
789
		Tree tree = (Tree) doFindInputItem(element);
664
		Tree tree = (Tree) doFindInputItem(element);
790
		if (tree != null) {
665
		if (tree != null) {
Lines 793-801 Link Here
793
		}
668
		}
794
		Widget[] items = findItems(element);
669
		Widget[] items = findItems(element);
795
		for (int i = 0; i < items.length; i++) {
670
		for (int i = 0; i < items.length; i++) {
796
			TreeItem treeItem = (TreeItem)items[i];
671
			TreeItem treeItem = (TreeItem) items[i];
797
			treeItem.setItemCount(count);
672
			treeItem.setItemCount(count);
798
		}		
673
		}
799
	}
674
	}
800
675
801
	/**
676
	/**
Lines 807-829 Link Here
807
	 * This method should be called by implementers of ILazyTreeContentProvider
682
	 * This method should be called by implementers of ILazyTreeContentProvider
808
	 * to populate this viewer.
683
	 * to populate this viewer.
809
	 * </p>
684
	 * </p>
810
	 * @param parent the parent of the element that should be updated
685
	 * 
811
	 * @param index the index in the parent's children
686
	 * @param parent
812
	 * @param element the new element
687
	 *            the parent of the element that should be updated
688
	 * @param index
689
	 *            the index in the parent's children
690
	 * @param element
691
	 *            the new element
813
	 * 
692
	 * 
814
	 * @see #setChildCount(Object, int)
693
	 * @see #setChildCount(Object, int)
815
	 * @see ILazyTreeContentProvider
694
	 * @see ILazyTreeContentProvider
816
     * 
695
	 * 
817
	 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
696
	 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
818
	 * part of a work in progress. There is no guarantee that this API will remain
697
	 * part of a work in progress. There is no guarantee that this API will
819
	 * unchanged during the 3.2 release cycle. Please do not use this API without
698
	 * remain unchanged during the 3.2 release cycle. Please do not use this API
820
	 * consulting with the Platform/UI team.
699
	 * without consulting with the Platform/UI team.
821
	 * </p>
700
	 * </p>
822
     * 
701
	 * 
823
	 * @since 3.2
702
	 * @since 3.2
824
	 */
703
	 */
825
	public void replace(Object parent, int index, Object element) {
704
	public void replace(Object parent, int index, Object element) {
826
		if(parent.equals(getInput())) {
705
		if (parent.equals(getInput())) {
827
			if (index < tree.getItemCount()) {
706
			if (index < tree.getItemCount()) {
828
				updateItem(tree.getItem(index), element);
707
				updateItem(tree.getItem(index), element);
829
			}
708
			}
Lines 834-914 Link Here
834
				if (index < parentItem.getItemCount()) {
713
				if (index < parentItem.getItemCount()) {
835
					updateItem(parentItem.getItem(index), element);
714
					updateItem(parentItem.getItem(index), element);
836
				}
715
				}
837
			}			
716
			}
838
		}
717
		}
839
	}
718
	}
840
	
719
841
    public boolean isExpandable(Object element) {
720
	public boolean isExpandable(Object element) {
842
    	if (getContentProvider() instanceof ILazyTreeContentProvider) {
721
		if (getContentProvider() instanceof ILazyTreeContentProvider) {
843
    		TreeItem treeItem = (TreeItem) internalExpand(element, false);
722
			TreeItem treeItem = (TreeItem) internalExpand(element, false);
844
    		if (treeItem == null) {
723
			if (treeItem == null) {
845
    			return false;
724
				return false;
846
    		}
725
			}
847
    		virtualMaterializeItem(treeItem);
726
			virtualMaterializeItem(treeItem);
848
    		return treeItem.getItemCount() > 0;
727
			return treeItem.getItemCount() > 0;
849
    	}
728
		}
850
    	return super.isExpandable(element);
729
		return super.isExpandable(element);
851
    }
730
	}
852
731
853
    protected Object getParentElement(Object element) {
732
	protected Object getParentElement(Object element) {
854
    	if(!(element instanceof TreePath) && (getContentProvider() instanceof ILazyTreeContentProvider)) {
733
		if (!(element instanceof TreePath)
855
    		ILazyTreeContentProvider lazyTreeContentProvider = (ILazyTreeContentProvider) getContentProvider();
734
				&& (getContentProvider() instanceof ILazyTreeContentProvider)) {
856
    		return lazyTreeContentProvider.getParent(element);
735
			ILazyTreeContentProvider lazyTreeContentProvider = (ILazyTreeContentProvider) getContentProvider();
857
    	}
736
			return lazyTreeContentProvider.getParent(element);
858
        return super.getParentElement(element);
737
		}
859
	}
738
		return super.getParentElement(element);
860
    
739
	}
861
    protected void createChildren(Widget widget) {
740
862
    	if (getContentProvider() instanceof ILazyTreeContentProvider) {
741
	protected void createChildren(Widget widget) {
863
    		final Item[] tis = getChildren(widget);
742
		if (getContentProvider() instanceof ILazyTreeContentProvider) {
864
    		if (tis != null && tis.length > 0) {
743
			final Item[] tis = getChildren(widget);
865
    			// children already there, touch them
744
			if (tis != null && tis.length > 0) {
866
    			for (int i = 0; i < tis.length; i++) {
745
				// children already there, touch them
746
				for (int i = 0; i < tis.length; i++) {
867
					tis[i].getText();
747
					tis[i].getText();
868
				}
748
				}
869
    			return;
749
				return;
870
    		}
750
			}
871
    		ILazyTreeContentProvider lazyTreeContentProvider = (ILazyTreeContentProvider) getContentProvider();
751
			ILazyTreeContentProvider lazyTreeContentProvider = (ILazyTreeContentProvider) getContentProvider();
872
    		Object element = widget.getData();
752
			Object element = widget.getData();
873
    		if (element == null && widget instanceof TreeItem) {
753
			if (element == null && widget instanceof TreeItem) {
874
    			// parent has not been materialized
754
				// parent has not been materialized
875
    			virtualMaterializeItem((TreeItem) widget);
755
				virtualMaterializeItem((TreeItem) widget);
876
    			// try getting the element now that updateElement was called
756
				// try getting the element now that updateElement was called
877
    			element = widget.getData();
757
				element = widget.getData();
878
    		}
758
			}
879
    		TreeItem[] children;
759
			TreeItem[] children;
880
    		if (widget instanceof Tree) {
760
			if (widget instanceof Tree) {
881
    			children = ((Tree) widget).getItems();
761
				children = ((Tree) widget).getItems();
882
    		} else {
762
			} else {
883
    			children = ((TreeItem) widget).getItems();
763
				children = ((TreeItem) widget).getItems();
884
    		}
764
			}
885
    		if (element != null && children.length > 0) {
765
			if (element != null && children.length > 0) {
886
    			for (int i = 0; i < children.length; i++) {
766
				for (int i = 0; i < children.length; i++) {
887
    				lazyTreeContentProvider.updateElement(element, i);
767
					lazyTreeContentProvider.updateElement(element, i);
888
    			}
768
				}
889
    		}
769
			}
890
    		return;
770
			return;
891
    	}
771
		}
892
    	super.createChildren(widget);
772
		super.createChildren(widget);
893
    }
773
	}
894
    
774
895
    protected void internalAdd(Widget widget, Object parentElement,
775
	protected void internalAdd(Widget widget, Object parentElement,
896
    		Object[] childElements) {
776
			Object[] childElements) {
897
    	if (getContentProvider() instanceof ILazyTreeContentProvider) {
777
		if (getContentProvider() instanceof ILazyTreeContentProvider) {
898
    		if (widget instanceof TreeItem) {
778
			if (widget instanceof TreeItem) {
899
    			TreeItem ti = (TreeItem) widget;
779
				TreeItem ti = (TreeItem) widget;
900
    			int count = ti.getItemCount() + childElements.length;
780
				int count = ti.getItemCount() + childElements.length;
901
				ti.setItemCount(count);
781
				ti.setItemCount(count);
902
    			ti.clearAll(false);
782
				ti.clearAll(false);
903
    		} else {
783
			} else {
904
    			Tree t = (Tree) widget;
784
				Tree t = (Tree) widget;
905
    			t.setItemCount(t.getItemCount() + childElements.length);
785
				t.setItemCount(t.getItemCount() + childElements.length);
906
    			t.clearAll(false);
786
				t.clearAll(false);
907
    		}
787
			}
908
    		return;
788
			return;
909
    	}
789
		}
910
    	super.internalAdd(widget, parentElement, childElements);
790
		super.internalAdd(widget, parentElement, childElements);
911
    }
791
	}
912
792
913
	private void virtualMaterializeItem(TreeItem treeItem) {
793
	private void virtualMaterializeItem(TreeItem treeItem) {
914
		if (treeItem.getData() != null) {
794
		if (treeItem.getData() != null) {
Lines 934-980 Link Here
934
			lazyTreeContentProvider.updateElement(parentElement, index);
814
			lazyTreeContentProvider.updateElement(parentElement, index);
935
		}
815
		}
936
	}
816
	}
937
	
817
938
	/* (non-Javadoc)
818
	/*
939
	 * @see org.eclipse.jface.viewers.AbstractTreeViewer#internalRefreshStruct(org.eclipse.swt.widgets.Widget, java.lang.Object, boolean)
819
	 * (non-Javadoc)
820
	 * 
821
	 * @see org.eclipse.jface.viewers.AbstractTreeViewer#internalRefreshStruct(org.eclipse.swt.widgets.Widget,
822
	 *      java.lang.Object, boolean)
940
	 */
823
	 */
941
	protected void internalRefreshStruct(Widget widget, Object element, boolean updateLabels) {
824
	protected void internalRefreshStruct(Widget widget, Object element,
942
    	if (getContentProvider() instanceof ILazyTreeContentProvider) {
825
			boolean updateLabels) {
943
    		// first phase: update child counts
826
		if (getContentProvider() instanceof ILazyTreeContentProvider) {
944
    		virtualRefreshChildCounts(widget, element);
827
			// first phase: update child counts
945
    		// second phase: update labels
828
			virtualRefreshChildCounts(widget, element);
946
    		if (updateLabels) {
829
			// second phase: update labels
947
    			if (widget instanceof Tree) {
830
			if (updateLabels) {
948
    				((Tree)widget).clearAll(true);
831
				if (widget instanceof Tree) {
949
    			} else if (widget instanceof TreeItem) {
832
					((Tree) widget).clearAll(true);
950
    				((TreeItem)widget).clearAll(true);
833
				} else if (widget instanceof TreeItem) {
951
    			}
834
					((TreeItem) widget).clearAll(true);
952
    		}
835
				}
953
    		return;
836
			}
954
    	}
837
			return;
838
		}
955
		super.internalRefreshStruct(widget, element, updateLabels);
839
		super.internalRefreshStruct(widget, element, updateLabels);
956
	}
840
	}
957
841
958
	/**
842
	/**
959
	 * Traverses the visible (expanded) part of the tree and updates child counts.
843
	 * Traverses the visible (expanded) part of the tree and updates child
844
	 * counts.
845
	 * 
960
	 * @param widget
846
	 * @param widget
961
	 * @param element
847
	 * @param element
962
	 * @param updateLabels
848
	 * @param updateLabels
963
	 */
849
	 */
964
	private void virtualRefreshChildCounts(Widget widget, Object element) {
850
	private void virtualRefreshChildCounts(Widget widget, Object element) {
965
		ILazyTreeContentProvider lazyTreeContentProvider = (ILazyTreeContentProvider) getContentProvider();
851
		ILazyTreeContentProvider lazyTreeContentProvider = (ILazyTreeContentProvider) getContentProvider();
966
		if (widget instanceof Tree || ((TreeItem)widget).getExpanded()) {
852
		if (widget instanceof Tree || ((TreeItem) widget).getExpanded()) {
967
			// widget shows children - it is safe to call getChildren
853
			// widget shows children - it is safe to call getChildren
968
			if (element != null) {
854
			if (element != null) {
969
				lazyTreeContentProvider.updateChildCount(element, getChildren(widget).length);
855
				lazyTreeContentProvider.updateChildCount(element,
856
						getChildren(widget).length);
970
			} else {
857
			} else {
971
				if (widget instanceof Tree) {
858
				if (widget instanceof Tree) {
972
					((Tree)widget).setItemCount(0);
859
					((Tree) widget).setItemCount(0);
973
				} else {
860
				} else {
974
					((TreeItem)widget).setItemCount(0);
861
					((TreeItem) widget).setItemCount(0);
975
				}
862
				}
976
			}
863
			}
977
			// need to get children again because they might have been updated through a callback to setChildCount.
864
			// need to get children again because they might have been updated
865
			// through a callback to setChildCount.
978
			Item[] items = getChildren(widget);
866
			Item[] items = getChildren(widget);
979
			for (int i = 0; i < items.length; i++) {
867
			for (int i = 0; i < items.length; i++) {
980
				Item item = items[i];
868
				Item item = items[i];
Lines 985-991 Link Here
985
			}
873
			}
986
		}
874
		}
987
	}
875
	}
988
	
876
989
	/*
877
	/*
990
	 * To unmap elements correctly, we need to register a dispose listener with
878
	 * To unmap elements correctly, we need to register a dispose listener with
991
	 * the item if the tree is virtual.
879
	 * the item if the tree is virtual.
Lines 994-1000 Link Here
994
		super.mapElement(element, item);
882
		super.mapElement(element, item);
995
		// make sure to unmap elements if the tree is virtual
883
		// make sure to unmap elements if the tree is virtual
996
		if ((getTree().getStyle() & SWT.VIRTUAL) != 0) {
884
		if ((getTree().getStyle() & SWT.VIRTUAL) != 0) {
997
			item.addDisposeListener(new DisposeListener(){
885
			item.addDisposeListener(new DisposeListener() {
998
				public void widgetDisposed(DisposeEvent e) {
886
				public void widgetDisposed(DisposeEvent e) {
999
					if (!treeIsDisposed) {
887
					if (!treeIsDisposed) {
1000
						Object data = item.getData();
888
						Object data = item.getData();
Lines 1002-1008 Link Here
1002
							unmapElement(data, item);
890
							unmapElement(data, item);
1003
						}
891
						}
1004
					}
892
					}
1005
				}});
893
				}
894
			});
1006
		}
895
		}
1007
	}
896
	}
897
	
898
	/* (non-Javadoc)
899
	 * @see org.eclipse.jface.viewers.ColumnViewer#getRowPartFromItem(org.eclipse.swt.widgets.Widget)
900
	 */
901
	protected RowPart getRowPartFromItem(Widget item) {
902
		RowPart part = (RowPart)item.getData(RowPart.ROWPART_KEY);
903
		
904
		if( part == null ) {
905
			part = new TreeRowPart(((TreeItem)item));
906
		}
907
		
908
		return part;
909
	}
910
		
911
	/**
912
	 * Create a new RowPart at rowIndex
913
	 * @param parent
914
	 * @param style
915
	 * @param rowIndex
916
	 * @return RowPart
917
	 */
918
	private RowPart createNewRowPart(RowPart parent, int style, int rowIndex) {
919
		if( parent == null ) {
920
			if( rowIndex >= 0 ) {
921
				return getRowPartFromItem(new TreeItem(tree,style,rowIndex));
922
			}
923
			return getRowPartFromItem(new TreeItem(tree,style));
924
		}
925
		
926
		if( rowIndex >= 0 ) {
927
			return getRowPartFromItem(new TreeItem((TreeItem)parent.getItem(),SWT.NONE,rowIndex));
928
		}
929
		
930
		return getRowPartFromItem(new TreeItem((TreeItem)parent.getItem(),SWT.NONE));
931
	}
932
	
933
	protected ColumnViewerPart createColumnViewer(Widget columnOwner, ViewerLabelProvider labelProvider) {
934
		if( columnOwner instanceof TreeColumn ) {
935
			return new TreeColumnViewerPart((TreeColumn)columnOwner,labelProvider);
936
		}
937
		
938
		return super.createColumnViewer(columnOwner, labelProvider);
939
	}
1008
}
940
}
(-)src/org/eclipse/jface/viewers/AbstractTreeViewer.java (-1 / +1 lines)
Lines 54-60 Link Here
54
 * @see TreeViewer
54
 * @see TreeViewer
55
 * @see TableTreeViewer
55
 * @see TableTreeViewer
56
 */
56
 */
57
public abstract class AbstractTreeViewer extends StructuredViewer {
57
public abstract class AbstractTreeViewer extends ColumnViewer {
58
58
59
    /**
59
    /**
60
     * Constant indicating that all levels of the tree should be expanded or
60
     * Constant indicating that all levels of the tree should be expanded or
(-)src/org/eclipse/jface/viewers/TreeEditorImpl.java (-53 / +46 lines)
Lines 49-57 Link Here
49
49
50
    private int doubleClickExpirationTime;
50
    private int doubleClickExpirationTime;
51
51
52
    private StructuredViewer viewer;
52
    private ColumnViewer viewer;
53
53
54
    TreeEditorImpl(StructuredViewer viewer) {
54
    TreeEditorImpl(ColumnViewer viewer) {
55
        this.viewer = viewer;
55
        this.viewer = viewer;
56
        initCellEditorListener();
56
        initCellEditorListener();
57
    }
57
    }
Lines 66-117 Link Here
66
    }
66
    }
67
67
68
    private void activateCellEditor() {
68
    private void activateCellEditor() {
69
        if (cellEditors != null) {
69
    	ColumnViewerPart part = viewer.getColumnViewer(columnNumber);
70
            if (cellEditors[columnNumber] != null && cellModifier != null) {
70
    	Object element = treeItem.getData();
71
                Object element = treeItem.getData();
71
    	
72
                String property = columnProperties[columnNumber];
72
    	if( part != null && part.getEditingSupport() != null && part.getEditingSupport().canEdit(element) ) {
73
                if (cellModifier.canModify(element, property)) {
73
    		cellEditor = part.getEditingSupport().getCellEditor(element);
74
                    cellEditor = cellEditors[columnNumber];
74
    		cellEditor.addListener(cellEditorListener);
75
                    //tree.showSelection();
75
            Object value = part.getEditingSupport().getValue(element);
76
                    cellEditor.addListener(cellEditorListener);
76
            cellEditor.setValue(value);
77
                    Object value = cellModifier.getValue(element, property);
77
            // Tricky flow of control here:
78
                    cellEditor.setValue(value);
78
            // activate() can trigger callback to cellEditorListener which will clear cellEditor
79
                    // Tricky flow of control here:
79
            // so must get control first, but must still call activate() even if there is no control.
80
                    // activate() can trigger callback to cellEditorListener which will clear cellEditor
80
            final Control control = cellEditor.getControl();
81
                    // so must get control first, but must still call activate() even if there is no control.
81
            cellEditor.activate();
82
                    final Control control = cellEditor.getControl();
82
            if (control == null) {
83
                    cellEditor.activate();
83
				return;
84
                    if (control == null) {
84
			}
85
						return;
85
            setLayoutData(cellEditor.getLayoutData());
86
					}
86
            setEditor(control, treeItem, columnNumber);
87
                    setLayoutData(cellEditor.getLayoutData());
87
            cellEditor.setFocus();
88
                    setEditor(control, treeItem, columnNumber);
88
            if (focusListener == null) {
89
                    cellEditor.setFocus();
89
                focusListener = new FocusAdapter() {
90
                    if (focusListener == null) {
90
                    public void focusLost(FocusEvent e) {
91
                        focusListener = new FocusAdapter() {
91
                        applyEditorValue();
92
                            public void focusLost(FocusEvent e) {
93
                                applyEditorValue();
94
                            }
95
                        };
96
                    }
92
                    }
97
                    control.addFocusListener(focusListener);
93
                };
98
                    mouseListener = new MouseAdapter() {
99
                        public void mouseDown(MouseEvent e) {
100
                            // time wrap?	
101
                            // check for expiration of doubleClickTime
102
                            if (e.time <= doubleClickExpirationTime) {
103
                                control.removeMouseListener(mouseListener);
104
                                cancelEditing();
105
                                handleDoubleClickEvent();
106
                            } else if (mouseListener != null) {
107
                                control.removeMouseListener(mouseListener);
108
                            }
109
                        }
110
                    };
111
                    control.addMouseListener(mouseListener);
112
                }
113
            }
94
            }
114
        }
95
            control.addFocusListener(focusListener);
96
            mouseListener = new MouseAdapter() {
97
                public void mouseDown(MouseEvent e) {
98
                    // time wrap?	
99
                    // check for expiration of doubleClickTime
100
                    if (e.time <= doubleClickExpirationTime) {
101
                        control.removeMouseListener(mouseListener);
102
                        cancelEditing();
103
                        handleDoubleClickEvent();
104
                    } else if (mouseListener != null) {
105
                        control.removeMouseListener(mouseListener);
106
                    }
107
                }
108
            };
109
            control.addMouseListener(mouseListener);
110
    	}
115
    }
111
    }
116
112
117
    /**
113
    /**
Lines 313-325 Link Here
313
     * by delegating to the cell modifier.
309
     * by delegating to the cell modifier.
314
     */
310
     */
315
    private void saveEditorValue(CellEditor cellEditor, Item treeItem) {
311
    private void saveEditorValue(CellEditor cellEditor, Item treeItem) {
316
        if (cellModifier != null) {
312
    	ColumnViewerPart part = (ColumnViewerPart)treeItem.getData(ColumnViewerPart.COLUMN_VIEWER_KEY);
317
            String property = null;
313
    	
318
            if (columnProperties != null
314
    	if( part != null && part.getEditingSupport() != null ) {
319
                    && columnNumber < columnProperties.length) {
315
        	part.getEditingSupport().setValue(treeItem.getData(), cellEditor.getValue());
320
				property = columnProperties[columnNumber];
321
			}
322
            cellModifier.modify(treeItem, property, cellEditor.getValue());
323
        }
316
        }
324
    }
317
    }
325
318
(-)src/org/eclipse/jface/viewers/DecoratingLabelProvider.java (-52 / +13 lines)
Lines 22-31 Link Here
22
 * The decorator decorates the label text, image, font and colors provided by 
22
 * The decorator decorates the label text, image, font and colors provided by 
23
 * the nested label provider.
23
 * the nested label provider.
24
 */
24
 */
25
public class DecoratingLabelProvider extends LabelProvider implements
25
public class DecoratingLabelProvider extends TreeColumnViewerLabelProvider  {
26
        ILabelProvider, IViewerLabelProvider, IColorProvider, IFontProvider, ITreePathLabelProvider {
27
		
26
		
28
    private ILabelProvider provider;
29
27
30
    private ILabelDecorator decorator;
28
    private ILabelDecorator decorator;
31
29
Lines 43-50 Link Here
43
     */
41
     */
44
    public DecoratingLabelProvider(ILabelProvider provider,
42
    public DecoratingLabelProvider(ILabelProvider provider,
45
            ILabelDecorator decorator) {
43
            ILabelDecorator decorator) {
44
        super(provider);
46
        Assert.isNotNull(provider);
45
        Assert.isNotNull(provider);
47
        this.provider = provider;
48
        this.decorator = decorator;
46
        this.decorator = decorator;
49
    }
47
    }
50
48
Lines 56-62 Link Here
56
     */
54
     */
57
    public void addListener(ILabelProviderListener listener) {
55
    public void addListener(ILabelProviderListener listener) {
58
        super.addListener(listener);
56
        super.addListener(listener);
59
        provider.addListener(listener);
57
        getLabelProvider().addListener(listener);
60
        if (decorator != null) {
58
        if (decorator != null) {
61
            decorator.addListener(listener);
59
            decorator.addListener(listener);
62
        }
60
        }
Lines 68-74 Link Here
68
     * disposes both the nested label provider and the label decorator.
66
     * disposes both the nested label provider and the label decorator.
69
     */
67
     */
70
    public void dispose() {
68
    public void dispose() {
71
        provider.dispose();
69
        getLabelProvider().dispose();
72
        if (decorator != null) {
70
        if (decorator != null) {
73
            decorator.dispose();
71
            decorator.dispose();
74
        }
72
        }
Lines 82-88 Link Here
82
     * <code>decorateImage</code> method.
80
     * <code>decorateImage</code> method.
83
     */
81
     */
84
    public Image getImage(Object element) {
82
    public Image getImage(Object element) {
85
        Image image = provider.getImage(element);
83
        Image image = getLabelProvider().getImage(element);
86
        if (decorator != null) {
84
        if (decorator != null) {
87
        	if (decorator instanceof LabelDecorator) {
85
        	if (decorator instanceof LabelDecorator) {
88
				LabelDecorator ld2 = (LabelDecorator) decorator;
86
				LabelDecorator ld2 = (LabelDecorator) decorator;
Lines 110-124 Link Here
110
    }
108
    }
111
109
112
    /**
110
    /**
113
     * Returns the nested label provider.
114
     *
115
     * @return the nested label provider
116
     */
117
    public ILabelProvider getLabelProvider() {
118
        return provider;
119
    }
120
121
    /**
122
     * The <code>DecoratingLabelProvider</code> implementation of this 
111
     * The <code>DecoratingLabelProvider</code> implementation of this 
123
     * <code>ILabelProvider</code> method returns the text label provided
112
     * <code>ILabelProvider</code> method returns the text label provided
124
     * by the nested label provider's <code>getText</code> method, 
113
     * by the nested label provider's <code>getText</code> method, 
Lines 126-132 Link Here
126
     * <code>decorateText</code> method.
115
     * <code>decorateText</code> method.
127
     */
116
     */
128
    public String getText(Object element) {
117
    public String getText(Object element) {
129
        String text = provider.getText(element);
118
        String text = getLabelProvider().getText(element);
130
        if (decorator != null) {
119
        if (decorator != null) {
131
        	if (decorator instanceof LabelDecorator) {
120
        	if (decorator instanceof LabelDecorator) {
132
				LabelDecorator ld2 = (LabelDecorator) decorator;
121
				LabelDecorator ld2 = (LabelDecorator) decorator;
Lines 151-157 Link Here
151
     * decorator returns <code>true</code>.
140
     * decorator returns <code>true</code>.
152
     */
141
     */
153
    public boolean isLabelProperty(Object element, String property) {
142
    public boolean isLabelProperty(Object element, String property) {
154
        if (provider.isLabelProperty(element, property)) {
143
        if (getLabelProvider().isLabelProperty(element, property)) {
155
			return true;
144
			return true;
156
		}
145
		}
157
        if (decorator != null && decorator.isLabelProperty(element, property)) {
146
        if (decorator != null && decorator.isLabelProperty(element, property)) {
Lines 168-174 Link Here
168
     */
157
     */
169
    public void removeListener(ILabelProviderListener listener) {
158
    public void removeListener(ILabelProviderListener listener) {
170
        super.removeListener(listener);
159
        super.removeListener(listener);
171
        provider.removeListener(listener);
160
        getLabelProvider().removeListener(listener);
172
        if (decorator != null) {
161
        if (decorator != null) {
173
            decorator.removeListener(listener);
162
            decorator.removeListener(listener);
174
        }
163
        }
Lines 260-295 Link Here
260
		
249
		
261
	}
250
	}
262
	
251
	
263
	/* (non-Javadoc)
264
	 * @see org.eclipse.jface.viewers.IColorProvider#getBackground(java.lang.Object)
265
	 */
266
	public Color getBackground(Object element) {
267
		if(provider instanceof IColorProvider) {
268
			return ((IColorProvider) provider).getBackground(element);
269
		}
270
		return null;
271
	}
272
	
273
	/* (non-Javadoc)
274
	 * @see org.eclipse.jface.viewers.IFontProvider#getFont(java.lang.Object)
275
	 */
276
	public Font getFont(Object element) {
277
		if(provider instanceof IFontProvider) {
278
			return ((IFontProvider) provider).getFont(element);
279
		}
280
		return null;
281
	}
282
	
283
	/* (non-Javadoc)
284
	 * @see org.eclipse.jface.viewers.IColorProvider#getForeground(java.lang.Object)
285
	 */
286
	public Color getForeground(Object element) {
287
		if(provider instanceof IColorProvider) {
288
			return ((IColorProvider) provider).getForeground(element);
289
		}
290
		return null;
291
	}
292
293
    /**
252
    /**
294
     * Return the decoration context associated with this label provider.
253
     * Return the decoration context associated with this label provider.
295
     * It will be passed to the decorator if the decorator is an 
254
     * It will be passed to the decorator if the decorator is an 
Lines 314-321 Link Here
314
		this.decorationContext = decorationContext;
273
		this.decorationContext = decorationContext;
315
	}
274
	}
316
275
276
	
277
317
	/* (non-Javadoc)
278
	/* (non-Javadoc)
318
	 * @see org.eclipse.jface.viewers.ITreePathLabelProvider#updateLabel(org.eclipse.jface.viewers.ViewerLabel, org.eclipse.jface.viewers.TreePath)
279
	 * @see org.eclipse.jface.viewers.TreeViewerLabelProvider#updateLabel(org.eclipse.jface.viewers.ViewerLabel, org.eclipse.jface.viewers.TreePath)
319
	 */
280
	 */
320
	public void updateLabel(ViewerLabel settings, TreePath elementPath) {
281
	public void updateLabel(ViewerLabel settings, TreePath elementPath) {
321
        ILabelDecorator currentDecorator = getLabelDecorator();
282
        ILabelDecorator currentDecorator = getLabelDecorator();
Lines 338-345 Link Here
338
        settings.setHasPendingDecorations(!decorationReady);
299
        settings.setHasPendingDecorations(!decorationReady);
339
        // update icon and label
300
        // update icon and label
340
301
341
        if (provider instanceof ITreePathLabelProvider) {
302
        if (getTreePathProvider() == null) {
342
			ITreePathLabelProvider pprov = (ITreePathLabelProvider) provider;
303
			ITreePathLabelProvider pprov = (ITreePathLabelProvider) getLabelProvider();
343
			if (decorationReady || oldText == null
304
			if (decorationReady || oldText == null
344
	                || settings.getText().length() == 0) {
305
	                || settings.getText().length() == 0) {
345
				pprov.updateLabel(settings, elementPath);
306
				pprov.updateLabel(settings, elementPath);
(-)src/org/eclipse/jface/viewers/TableEditorImpl.java (-62 / +52 lines)
Lines 49-57 Link Here
49
49
50
    private int doubleClickExpirationTime;
50
    private int doubleClickExpirationTime;
51
51
52
    private StructuredViewer viewer;
52
    private ColumnViewer viewer;
53
53
54
    TableEditorImpl(StructuredViewer viewer) {
54
    TableEditorImpl(ColumnViewer viewer) {
55
        this.viewer = viewer;
55
        this.viewer = viewer;
56
        initCellEditorListener();
56
        initCellEditorListener();
57
    }
57
    }
Lines 61-117 Link Here
61
     * 
61
     * 
62
     * @return the viewer
62
     * @return the viewer
63
     */
63
     */
64
    public StructuredViewer getViewer() {
64
    public ColumnViewer getViewer() {
65
        return viewer;
65
        return viewer;
66
    }
66
    }
67
67
68
    private void activateCellEditor() {
68
    private void activateCellEditor() {
69
        if (cellEditors != null) {
69
    	ColumnViewerPart part = viewer.getColumnViewer(columnNumber);
70
            if (cellEditors[columnNumber] != null && cellModifier != null) {
70
    	Object element = tableItem.getData();
71
                Object element = tableItem.getData();
71
    	
72
                String property = columnProperties[columnNumber];
72
    	if( part != null && part.getEditingSupport() != null && part.getEditingSupport().canEdit(element) ) {
73
                if (cellModifier.canModify(element, property)) {
73
    		cellEditor = part.getEditingSupport().getCellEditor(element);
74
                    cellEditor = cellEditors[columnNumber];
74
    		cellEditor.addListener(cellEditorListener);
75
                    //table.showSelection();
75
            Object value = part.getEditingSupport().getValue(element);
76
                    cellEditor.addListener(cellEditorListener);
76
            cellEditor.setValue(value);
77
                    Object value = cellModifier.getValue(element, property);
77
            // Tricky flow of control here:
78
                    cellEditor.setValue(value);
78
            // activate() can trigger callback to cellEditorListener which will clear cellEditor
79
                    // Tricky flow of control here:
79
            // so must get control first, but must still call activate() even if there is no control.
80
                    // activate() can trigger callback to cellEditorListener which will clear cellEditor
80
            final Control control = cellEditor.getControl();
81
                    // so must get control first, but must still call activate() even if there is no control.
81
            cellEditor.activate();
82
                    final Control control = cellEditor.getControl();
82
            if (control == null) {
83
                    cellEditor.activate();
83
				return;
84
                    if (control == null) {
84
			}
85
						return;
85
            setLayoutData(cellEditor.getLayoutData());
86
					}
86
            setEditor(control, tableItem, columnNumber);
87
                    setLayoutData(cellEditor.getLayoutData());
87
            cellEditor.setFocus();
88
                    setEditor(control, tableItem, columnNumber);
88
            if (focusListener == null) {
89
                    cellEditor.setFocus();
89
                focusListener = new FocusAdapter() {
90
                    if (focusListener == null) {
90
                    public void focusLost(FocusEvent e) {
91
                        focusListener = new FocusAdapter() {
91
                        applyEditorValue();
92
                            public void focusLost(FocusEvent e) {
93
                                applyEditorValue();
94
                            }
95
                        };
96
                    }
92
                    }
97
                    control.addFocusListener(focusListener);
93
                };
98
                    mouseListener = new MouseAdapter() {
99
                        public void mouseDown(MouseEvent e) {
100
                            // time wrap?	
101
                            // check for expiration of doubleClickTime
102
                            if (e.time <= doubleClickExpirationTime) {
103
                                control.removeMouseListener(mouseListener);
104
                                cancelEditing();
105
                                handleDoubleClickEvent();
106
                            } else if (mouseListener != null) {
107
                                control.removeMouseListener(mouseListener);
108
                            }
109
                        }
110
                    };
111
                    control.addMouseListener(mouseListener);
112
                }
113
            }
94
            }
114
        }
95
            control.addFocusListener(focusListener);
96
            mouseListener = new MouseAdapter() {
97
                public void mouseDown(MouseEvent e) {
98
                    // time wrap?	
99
                    // check for expiration of doubleClickTime
100
                    if (e.time <= doubleClickExpirationTime) {
101
                        control.removeMouseListener(mouseListener);
102
                        cancelEditing();
103
                        handleDoubleClickEvent();
104
                    } else if (mouseListener != null) {
105
                        control.removeMouseListener(mouseListener);
106
                    }
107
                }
108
            };
109
            control.addMouseListener(mouseListener);
110
    	}    	
115
    }
111
    }
116
112
117
    /**
113
    /**
Lines 217-223 Link Here
217
213
218
    abstract Rectangle getBounds(Item item, int columnNumber);
214
    abstract Rectangle getBounds(Item item, int columnNumber);
219
215
220
    /**
216
/**
221
     * Return the array of CellEditors used in the viewer
217
     * Return the array of CellEditors used in the viewer
222
     * @return the cell editors
218
     * @return the cell editors
223
     */
219
     */
Lines 235-248 Link Here
235
231
236
    abstract int getColumnCount();
232
    abstract int getColumnCount();
237
233
238
    /**
234
	/**
239
     * Return the properties for the column
235
     * Return the properties for the column
240
     * @return the array of column properties
236
     * @return the array of column properties
241
     */
237
     */
242
    public Object[] getColumnProperties() {
238
    public Object[] getColumnProperties() {
243
        return columnProperties;
239
        return columnProperties;
244
    }
240
    }
245
241
    
246
    abstract Item[] getSelection();
242
    abstract Item[] getSelection();
247
243
248
    /**
244
    /**
Lines 308-324 Link Here
308
     * by delegating to the cell modifier.
304
     * by delegating to the cell modifier.
309
     */
305
     */
310
    private void saveEditorValue(CellEditor cellEditor, Item tableItem) {
306
    private void saveEditorValue(CellEditor cellEditor, Item tableItem) {
311
        if (cellModifier != null) {
307
    	ColumnViewerPart part = (ColumnViewerPart)tableItem.getData(ColumnViewerPart.COLUMN_VIEWER_KEY);
312
            if (!cellEditor.isValueValid()) {
308
    	
313
                ///Do what ???
309
        if( part != null && part.getEditingSupport() != null ) {
314
            }
310
        	part.getEditingSupport().setValue(tableItem.getData(), cellEditor.getValue());
315
            String property = null;
311
        }        
316
            if (columnProperties != null
317
                    && columnNumber < columnProperties.length) {
318
				property = columnProperties[columnNumber];
319
			}
320
            cellModifier.modify(tableItem, property, cellEditor.getValue());
321
        }
322
    }
312
    }
323
313
324
    /**
314
    /**
Lines 344-350 Link Here
344
    public void setColumnProperties(String[] columnProperties) {
334
    public void setColumnProperties(String[] columnProperties) {
345
        this.columnProperties = columnProperties;
335
        this.columnProperties = columnProperties;
346
    }
336
    }
347
337
    
348
    abstract void setEditor(Control w, Item item, int fColumnNumber);
338
    abstract void setEditor(Control w, Item item, int fColumnNumber);
349
339
350
    abstract void setLayoutData(CellEditor.LayoutData layoutData);
340
    abstract void setLayoutData(CellEditor.LayoutData layoutData);
(-)src/org/eclipse/jface/viewers/TableTreeViewer.java (+7 lines)
Lines 519-522 Link Here
519
    protected void showItem(Item item) {
519
    protected void showItem(Item item) {
520
        getTableTree().showItem((TableTreeItem) item);
520
        getTableTree().showItem((TableTreeItem) item);
521
    }
521
    }
522
    
523
    /* (non-Javadoc)
524
     * @see org.eclipse.jface.viewers.ColumnViewer#getColumnViewerOwner(int)
525
     */
526
    protected Widget getColumnViewerOwner(int columnIndex) {
527
    	return null;
528
    }
522
}
529
}
(-)src/org/eclipse/jface/viewers/ViewerLabel.java (+93 lines)
Lines 13-18 Link Here
13
import org.eclipse.swt.graphics.Color;
13
import org.eclipse.swt.graphics.Color;
14
import org.eclipse.swt.graphics.Font;
14
import org.eclipse.swt.graphics.Font;
15
import org.eclipse.swt.graphics.Image;
15
import org.eclipse.swt.graphics.Image;
16
import org.eclipse.swt.graphics.Point;
16
17
17
/**
18
/**
18
 * The ViewerLabel is the class that is passed to a viewer to handle updates of
19
 * The ViewerLabel is the class that is passed to a viewer to handle updates of
Lines 43-48 Link Here
43
	private Image startImage;
44
	private Image startImage;
44
45
45
	private boolean hasPendingDecorations;
46
	private boolean hasPendingDecorations;
47
	
48
	private String tooltipText;
49
	
50
	private Color tooltipForegroundColor;
51
	
52
	private Color tooltipBackgroundColor;
53
	
54
	private Point tooltipShift;
46
55
47
	/**
56
	/**
48
	 * Create a new instance of the receiver with the supplied
57
	 * Create a new instance of the receiver with the supplied
Lines 241-244 Link Here
241
	/* public */ boolean hasPendingDecorations() {
250
	/* public */ boolean hasPendingDecorations() {
242
		return hasPendingDecorations;
251
		return hasPendingDecorations;
243
	}
252
	}
253
254
	/**
255
	 * @return Returns the tooltipText.
256
	 */
257
	public String getTooltipText() {
258
		return tooltipText;
259
	}
260
261
	/**
262
	 * @param tooltipText The tooltipText to set.
263
	 */
264
	public void setTooltipText(String tooltipText) {
265
		this.tooltipText = tooltipText;
266
	}
267
	
268
	/**
269
	 * @return Return whether or not the tooltip text has been set.
270
	 */
271
	public boolean hasNewTooltipText() {
272
		return this.tooltipText != null;
273
	}
274
275
	/**
276
	 * @return Returns the tooltipBackgroundColor.
277
	 */
278
	public Color getTooltipBackgroundColor() {
279
		return tooltipBackgroundColor;
280
	}
281
282
	/**
283
	 * @param tooltipBackgroundColor The tooltipBackgroundColor to set.
284
	 */
285
	public void setTooltipBackgroundColor(Color tooltipBackgroundColor) {
286
		this.tooltipBackgroundColor = tooltipBackgroundColor;
287
	}
288
289
	/**
290
	 * @return Return whether or not the tooltip background color has been set.
291
	 */
292
	public boolean hasNewTooltipBackgroundColor() {
293
		return tooltipBackgroundColor != null;
294
	}
295
	
296
	/**
297
	 * @return Returns the tooltipForegroundColor.
298
	 */
299
	public Color getTooltipForegroundColor() {
300
		return tooltipForegroundColor;
301
	}
302
303
	/**
304
	 * @param tooltipForegroundColor The tooltipForegroundColor to set.
305
	 */
306
	public void setTooltipForegroundColor(Color tooltipForegroundColor) {
307
		this.tooltipForegroundColor = tooltipForegroundColor;
308
	}
309
	
310
	/**
311
	 * @return Return whether or not the tooltip foreground color has been set.
312
	 */
313
	public boolean hasNewTooltipForegroundColor() {
314
		return tooltipForegroundColor != null;
315
	}
316
317
	/**
318
	 * @return Returns the tooltipShift.
319
	 */
320
	public Point getTooltipShift() {
321
		return tooltipShift;
322
	}
323
324
	/**
325
	 * @param tooltipShift The tooltipShift to set.
326
	 */
327
	public void setTooltipShift(Point tooltipShift) {
328
		this.tooltipShift = tooltipShift;
329
	}
330
	
331
	/**
332
	 * @return Return whether or not the tooltip shift has been set.
333
	 */
334
	public boolean hasTooltipShift() {
335
		return this.tooltipShift != null;
336
	}
244
}
337
}
(-)src/org/eclipse/jface/viewers/ColumnViewerPart.java (+158 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *     Tom Shindl <tom.schindl@bestsolution.at> - initial API and implementation
11
 ******************************************************************************/
12
13
package org.eclipse.jface.viewers;
14
15
import org.eclipse.jface.util.Policy;
16
import org.eclipse.swt.widgets.Widget;
17
18
/**
19
 * The ColumnViewerPart is abstract implementation of the column parts.
20
 * <strong>EXPERIMENTAL</strong> This class or interface has been added as
21
 * part of a work in progress. This API may change at any given time. Please 
22
 * do not use this API without consulting with the Platform/UI team.
23
 * 
24
 * @since 3.3
25
 * 
26
 */
27
public class ColumnViewerPart {
28
29
	private ViewerLabelProvider labelProvider;
30
31
	static String COLUMN_VIEWER_KEY = Policy.JFACE + ".columnViewer";//$NON-NLS-1$
32
33
	private EditingSupport editingSupport;
34
	
35
	
36
	
37
38
	/**
39
	 * Create a new instance of the receiver at columnIndex.
40
	 * 
41
	 * @param columnOwner
42
	 * @param provider
43
	 */
44
	public ColumnViewerPart(Widget columnOwner, ViewerLabelProvider provider) {
45
		labelProvider = provider;
46
		columnOwner.setData(ColumnViewerPart.COLUMN_VIEWER_KEY, this);
47
	}
48
49
	/**
50
	 * Return the label provider for the receiver.
51
	 * 
52
	 * @return ViewerLabelProvider
53
	 */
54
	public ViewerLabelProvider getLabelProvider() {
55
		return labelProvider;
56
	}
57
58
	/**
59
	 * @param labelProvider
60
	 *            the new label-provider
61
	 */
62
	public void setLabelProvider(ViewerLabelProvider labelProvider) {
63
		this.labelProvider = labelProvider;
64
	}
65
66
	/**
67
	 * @return Returns the editingSupport.
68
	 */
69
	EditingSupport getEditingSupport() {
70
		return editingSupport;
71
	}
72
73
	/**
74
	 * @param editingSupport
75
	 *            The editingSupport to set.
76
	 */
77
	void setEditingSupport(EditingSupport editingSupport) {
78
		this.editingSupport = editingSupport;
79
	}
80
81
	/**
82
	 * Refresh the row for the given columnIndex
83
	 * 
84
	 * @param row
85
	 * @param element
86
	 * @param columnIndex
87
	 */
88
	public void refresh(RowPart row, int columnIndex) {
89
		ViewerLabel label = new ViewerLabel(row.getText(columnIndex), row
90
				.getImage(columnIndex));
91
		getLabelProvider().updateLabel(label, row.getItem().getData(), columnIndex);
92
93
		row.setBackground(columnIndex, label.getBackground());
94
		row.setForeground(columnIndex, label.getForeground());
95
		row.setFont(columnIndex, label.getFont());
96
97
		if (label.hasNewText())
98
			row.setText(columnIndex, label.getText());
99
100
		if (label.hasNewImage())
101
			row.setImage(columnIndex, label.getImage());
102
	}
103
104
	/**
105
	 * Refresh the TreeItem for element.
106
	 * 
107
	 * @param item
108
	 * @param element
109
	 * @param columnIndex
110
	 */
111
/*	public void refresh(TreeItem item, Object element, int columnIndex) {
112
113
		ViewerLabel label = new ViewerLabel(item.getText(columnIndex), item
114
				.getImage(columnIndex));
115
		getLabelProvider().updateLabel(label, element, columnIndex);
116
117
		// We can not make a null check because then we could not
118
		// set the items back to default state
119
		item.setBackground(columnIndex, label.getBackground());
120
		item.setForeground(columnIndex, label.getForeground());
121
		item.setFont(columnIndex, label.getFont());
122
123
		if (label.hasNewText())
124
			item.setText(columnIndex, label.getText());
125
126
		if (label.hasNewImage())
127
			item.setImage(columnIndex, label.getImage());
128
	}
129
*/
130
	/**
131
	 * Refresh the TableItem for element.
132
	 * 
133
	 * @param item
134
	 * @param element
135
	 * @param columnIndex
136
	 */
137
/*	public void refresh(TableItem item, Object element, int columnIndex) {
138
139
		ViewerLabel label = new ViewerLabel(item.getText(columnIndex), item
140
				.getImage(columnIndex));
141
		getLabelProvider().updateLabel(label, element, columnIndex);
142
143
		if (label.hasNewBackground())
144
			item.setBackground(columnIndex, label.getBackground());
145
146
		if (label.hasNewForeground())
147
			item.setForeground(columnIndex, label.getForeground());
148
149
		if (label.hasNewFont())
150
			item.setFont(columnIndex, label.getFont());
151
152
		if (label.hasNewText())
153
			item.setText(columnIndex, label.getText());
154
155
		if (label.hasNewImage())
156
			item.setImage(columnIndex, label.getImage());
157
	}*/
158
}
(-)src/org/eclipse/jface/viewers/ColumnViewer.java (+218 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *     Tom Shindl <tom.schindl@bestsolution.at> - initial API and implementation
11
 ******************************************************************************/
12
13
package org.eclipse.jface.viewers;
14
15
import org.eclipse.swt.graphics.Point;
16
import org.eclipse.swt.widgets.Item;
17
import org.eclipse.swt.widgets.Widget;
18
19
/**
20
 * The ColumnViewer is the abstract superclass of viewers that jave columns
21
 * (TreeViewer and TableViewer).
22
 * 
23
 * @since 3.3 <strong>EXPERIMENTAL</strong> This class or interface has been
24
 *        added as part of a work in progress. This API may change at any given
25
 *        time. Please do not use this API without consulting with the
26
 *        Platform/UI team.
27
 * 
28
 */
29
abstract class ColumnViewer extends StructuredViewer {
30
31
	private TooltipSupport tooltipSupport;
32
33
	/**
34
	 * Create a new instance of the receiver.
35
	 */
36
	public ColumnViewer() {
37
		super();
38
		tooltipSupport = new TooltipSupport(this);
39
	}
40
41
	/**
42
	 * Get the cell at this point.
43
	 * <p>
44
	 * <i>Subclasses should overwrite this method and provide a meaningful
45
	 * implementation</i>
46
	 * </p>
47
	 * 
48
	 * @param point
49
	 *            the point in the viewer where you need to corresponding cell
50
	 *            from
51
	 * @param onlyInSelection
52
	 *            search only in selection
53
	 * @return the cell or if no cell is found at this point
54
	 */
55
	Cell getCell(Point point) {
56
		RowPart row = getRowPart(point);
57
		if (row != null) {
58
			return row.getCell(point);
59
		}
60
61
		return null;
62
	}
63
64
	/**
65
	 * Get the RowPart at point.
66
	 * 
67
	 * @param point
68
	 * @return RowPart
69
	 */
70
	protected RowPart getRowPart(Point point) {
71
		Item item = getItem(point.x, point.y);
72
73
		if (item != null) {
74
			return getRowPartFromItem(item);
75
		}
76
77
		return null;
78
	}
79
80
	protected RowPart getRowPartFromItem(Widget item) {
81
		return (RowPart) item.getData(RowPart.ROWPART_KEY);
82
	}
83
84
	/**
85
	 * Get the widget for the column at columnIndex.
86
	 * 
87
	 * @param columnIndex
88
	 * @return Widget
89
	 */
90
	protected abstract Widget getColumnViewerOwner(int columnIndex);
91
92
	/**
93
	 * Returns the cell modifier of this viewer.
94
	 * 
95
	 * @return the cell modifier
96
	 * @since 3.1 (in subclasses, added in 3.3 to abstract class)
97
	 */
98
	public abstract ICellModifier getCellModifier();
99
100
	/**
101
	 * Return the CellEditors for the receiver.
102
	 * 
103
	 * @return CellEditor[]
104
	 * @since 3.1 (in subclasses, added in 3.3 to abstract class)
105
	 */
106
	public abstract CellEditor[] getCellEditors();
107
108
	/**
109
	 * Returns the column properties of this table viewer. The properties must
110
	 * correspond with the columns of the table control. They are used to
111
	 * identify the column in a cell modifier.
112
	 * 
113
	 * @return the list of column properties
114
	 * @since 3.1 (in subclasses, added in 3.3 to abstract class)
115
	 */
116
	public abstract Object[] getColumnProperties();
117
118
	/**
119
	 * Return the TableColumnViewer at columnIndex
120
	 * 
121
	 * @param columnIndex
122
	 * @return TableColumnViewer
123
	 */
124
	public ColumnViewerPart getColumnViewer(final int columnIndex) {
125
126
		ColumnViewerPart viewer;
127
		Widget columnOwner = getColumnViewerOwner(columnIndex);
128
129
		if (columnOwner == null) {
130
			return null;
131
		}
132
133
		viewer = (ColumnViewerPart) columnOwner
134
				.getData(ColumnViewerPart.COLUMN_VIEWER_KEY);
135
136
		if (viewer == null) {
137
			viewer = createColumnViewer(columnOwner, ViewerLabelProvider
138
					.createViewerLabelProvider(getLabelProvider()));
139
			if (getCellModifier() != null) {
140
				viewer.setEditingSupport(new EditingSupport() {
141
142
					/*
143
					 * (non-Javadoc)
144
					 * 
145
					 * @see org.eclipse.jface.viewers.EditingSupport#canEdit(java.lang.Object)
146
					 */
147
					public boolean canEdit(Object element) {
148
						return getCellModifier().canModify(element,
149
								(String) getColumnProperties()[columnIndex]);
150
					}
151
152
					/*
153
					 * (non-Javadoc)
154
					 * 
155
					 * @see org.eclipse.jface.viewers.EditingSupport#getCellEditor(java.lang.Object)
156
					 */
157
					public CellEditor getCellEditor(Object element) {
158
						return getCellEditors()[columnIndex];
159
					}
160
161
					/*
162
					 * (non-Javadoc)
163
					 * 
164
					 * @see org.eclipse.jface.viewers.EditingSupport#getValue(java.lang.Object)
165
					 */
166
					public Object getValue(Object element) {
167
						return getCellModifier().getValue(element,
168
								(String) getColumnProperties()[columnIndex]);
169
					}
170
171
					/*
172
					 * (non-Javadoc)
173
					 * 
174
					 * @see org.eclipse.jface.viewers.EditingSupport#setValue(java.lang.Object,
175
					 *      java.lang.Object)
176
					 */
177
					public void setValue(Object element, Object value) {
178
						getCellModifier().modify(findItem(element),
179
								(String) getColumnProperties()[columnIndex],
180
								value);
181
					}
182
				});
183
			}
184
		}
185
186
		// Reset the colum-index because maybe it changed from the last time
187
		viewer.getLabelProvider().setColumnIndex(columnIndex);
188
189
		return viewer;
190
	}
191
192
	/**
193
	 * Create a ColumnViewerPart for the columnOwner.
194
	 * 
195
	 * @param columnOwner
196
	 * @param labelProvider
197
	 * @return ColumnViewerPart
198
	 */
199
	protected ColumnViewerPart createColumnViewer(Widget columnOwner,
200
			ViewerLabelProvider labelProvider) {
201
		return new ColumnViewerPart(columnOwner, labelProvider);
202
	}
203
204
	/**
205
	 * Activate the tooltip support.
206
	 */
207
	public void activateCustomTooltips() {
208
		tooltipSupport.activate();
209
	}
210
211
	/**
212
	 * Deactivate the tooltip support.
213
	 */
214
	public void deactivateCustomTooltips() {
215
		tooltipSupport.deactivate();
216
	}
217
218
}
(-)src/org/eclipse/jface/viewers/TreeColumnViewerLabelProvider.java (+64 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *     Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
11
 ******************************************************************************/
12
13
package org.eclipse.jface.viewers;
14
15
16
/**
17
 * TreeViewerLabelProvider is the ViewerLabelProvider that handles
18
 * TreePaths.
19
 * @since 3.3
20
 * <strong>EXPERIMENTAL</strong> This class or interface has been added as
21
 * part of a work in progress. This API may change at any given time. Please 
22
 * do not use this API without consulting with the Platform/UI team.
23
 *
24
 */
25
public class TreeColumnViewerLabelProvider extends TableColumnViewerLabelProvider {
26
	 private ITreePathLabelProvider treePathProvider;	
27
	
28
	
29
	/**
30
	 * Create a new instance of the receiver with the supplied labelProvider.
31
	 * @param labelProvider
32
	 */
33
	public TreeColumnViewerLabelProvider(IBaseLabelProvider labelProvider) {
34
		super(labelProvider);
35
	}
36
37
	/**
38
	 * Update the label for the element with TreePath.
39
	 * @param label
40
	 * @param elementPath
41
	 */
42
	public void updateLabel(ViewerLabel label, TreePath elementPath) {
43
		treePathProvider.updateLabel(label, elementPath);
44
45
	}
46
	
47
	/* (non-Javadoc)
48
	 * @see org.eclipse.jface.viewers.ViewerLabelProvider#setProviders(java.lang.Object)
49
	 */
50
	public void setProviders(Object provider) {
51
		super.setProviders(provider);
52
		if(provider instanceof ITreePathLabelProvider)
53
			treePathProvider = (ITreePathLabelProvider) provider;
54
	}
55
56
	/**
57
	 * Return the ITreePathLabelProvider for the receiver.
58
	 * @return Returns the treePathProvider.
59
	 */
60
	public ITreePathLabelProvider getTreePathProvider() {
61
		return treePathProvider;
62
	}
63
64
}
(-)src/org/eclipse/jface/viewers/TableRowPart.java (+141 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * @since 3.3
9
 * Contributors:
10
 *     IBM Corporation - initial API and implementation
11
 *     Tom Shindl <tom.schindl@bestsolution.at> - initial API and implementation
12
 ******************************************************************************/
13
14
package org.eclipse.jface.viewers;
15
16
import org.eclipse.swt.graphics.Color;
17
import org.eclipse.swt.graphics.Font;
18
import org.eclipse.swt.graphics.Image;
19
import org.eclipse.swt.graphics.Rectangle;
20
import org.eclipse.swt.widgets.Item;
21
import org.eclipse.swt.widgets.TableItem;
22
23
/**
24
 * TableRowPart is the Table specific implementation of RowPart
25
 * @since 3.3
26
 * <strong>EXPERIMENTAL</strong> This class or interface has been added as
27
 * part of a work in progress. This API may change at any given time. Please 
28
 * do not use this API without consulting with the Platform/UI team.
29
 *
30
 */
31
public class TableRowPart extends RowPart {
32
	private TableItem item;
33
	
34
	/**
35
	 * Create a new instance of the receiver from item.
36
	 * @param item
37
	 */
38
	TableRowPart(TableItem item) {
39
		super(item);
40
		this.item = item;
41
	}
42
	
43
	/* (non-Javadoc)
44
	 * @see org.eclipse.jface.viewers.RowPart#getBounds(int)
45
	 */
46
	public Rectangle getBounds(int columnIndex) {
47
		return item.getBounds(columnIndex);
48
	}
49
50
	/* (non-Javadoc)
51
	 * @see org.eclipse.jface.viewers.RowPart#getBounds()
52
	 */
53
	public Rectangle getBounds() {
54
		return item.getBounds();
55
	}
56
57
	/* (non-Javadoc)
58
	 * @see org.eclipse.jface.viewers.RowPart#getItem()
59
	 */
60
	public Item getItem() {
61
		return item;
62
	}
63
64
	/* (non-Javadoc)
65
	 * @see org.eclipse.jface.viewers.RowPart#getColumnCount()
66
	 */
67
	public int getColumnCount() {
68
		return item.getParent().getColumnCount();
69
	}
70
71
	/* (non-Javadoc)
72
	 * @see org.eclipse.jface.viewers.RowPart#getBackground(int)
73
	 */
74
	public Color getBackground(int columnIndex) {
75
		return item.getBackground(columnIndex);
76
	}
77
78
	/* (non-Javadoc)
79
	 * @see org.eclipse.jface.viewers.RowPart#getFont(int)
80
	 */
81
	public Font getFont(int columnIndex) {
82
		return item.getFont(columnIndex);
83
	}
84
85
	/* (non-Javadoc)
86
	 * @see org.eclipse.jface.viewers.RowPart#getForeground(int)
87
	 */
88
	public Color getForeground(int columnIndex) {
89
		return item.getForeground(columnIndex);
90
	}
91
92
	/* (non-Javadoc)
93
	 * @see org.eclipse.jface.viewers.RowPart#getImage(int)
94
	 */
95
	public Image getImage(int columnIndex) {
96
		return item.getImage(columnIndex);
97
	}
98
99
	/* (non-Javadoc)
100
	 * @see org.eclipse.jface.viewers.RowPart#getText(int)
101
	 */
102
	public String getText(int columnIndex) {
103
		return item.getText(columnIndex);
104
	}
105
106
	/* (non-Javadoc)
107
	 * @see org.eclipse.jface.viewers.RowPart#setBackground(int, org.eclipse.swt.graphics.Color)
108
	 */
109
	public void setBackground(int columnIndex, Color color) {
110
		item.setBackground(columnIndex, color);
111
	}
112
113
	/* (non-Javadoc)
114
	 * @see org.eclipse.jface.viewers.RowPart#setFont(int, org.eclipse.swt.graphics.Font)
115
	 */
116
	public void setFont(int columnIndex, Font font) {
117
		item.setFont(columnIndex, font);
118
	}
119
120
	/* (non-Javadoc)
121
	 * @see org.eclipse.jface.viewers.RowPart#setForeground(int, org.eclipse.swt.graphics.Color)
122
	 */
123
	public void setForeground(int columnIndex, Color color) {
124
		item.setForeground(columnIndex, color);
125
	}
126
127
	/* (non-Javadoc)
128
	 * @see org.eclipse.jface.viewers.RowPart#setImage(int, org.eclipse.swt.graphics.Image)
129
	 */
130
	public void setImage(int columnIndex, Image image) {
131
		item.setImage(columnIndex,image);
132
	}
133
134
	/* (non-Javadoc)
135
	 * @see org.eclipse.jface.viewers.RowPart#setText(int, java.lang.String)
136
	 */
137
	public void setText(int columnIndex, String text) {
138
		item.setText(columnIndex, text);
139
	}
140
141
}
(-)src/org/eclipse/jface/viewers/TableColumnViewerLabelProvider.java (+139 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.viewers;
13
14
import org.eclipse.swt.graphics.Color;
15
import org.eclipse.swt.graphics.Font;
16
import org.eclipse.swt.graphics.Image;
17
18
/**
19
 * TableColumnViewerLabelProvider is the mapping from the table based providers
20
 * to the ViewerLabelProvider.
21
 * 
22
 * <strong>EXPERIMENTAL</strong> This class or interface has been added as
23
 * part of a work in progress. This API may change at any given time. Please 
24
 * do not use this API without consulting with the Platform/UI team.
25
 * @since 3.3
26
 * Contributors:
27
 *     IBM Corporation - initial API and implementation
28
 *     Tom Shindl <tom.schindl@bestsolution.at> - initial API and implementation
29
 * @see ITableLabelProvider
30
 * @see ITableColorProvider
31
 * @see ITableFontProvider
32
 * 
33
 */
34
class TableColumnViewerLabelProvider extends ViewerLabelProvider {
35
	
36
	/**
37
	 * Create a new instance of the receiver.
38
	 * 
39
	 * @param labelProvider
40
	 *            instance of a table based label provider
41
	 * @param columnIndex
42
	 *            the index into the table for this column
43
	 * @see ITableLabelProvider
44
	 * @see ITableColorProvider
45
	 * @see ITableFontProvider
46
	 */
47
	public TableColumnViewerLabelProvider(IBaseLabelProvider labelProvider) {
48
		super(labelProvider);
49
50
		if (labelProvider instanceof ITableLabelProvider)
51
			setLabelProvider(labelProviderFor((ITableLabelProvider) labelProvider));
52
53
		if (labelProvider instanceof ITableColorProvider)
54
			setColorProvider(colorProviderFor((ITableColorProvider) labelProvider));
55
56
		if (labelProvider instanceof ITableFontProvider)
57
			setFontProvider(fontProviderFor((ITableFontProvider) labelProvider));
58
	}
59
60
61
	/**
62
	 * Return the IFontProvider based on provider at columnIndex.
63
	 * 
64
	 * @param provider
65
	 * @param columnIndex
66
	 * @return IFontProvider
67
	 */
68
	private IFontProvider fontProviderFor(final ITableFontProvider provider) {
69
		return new IFontProvider() {
70
			/*
71
			 * (non-Javadoc)
72
			 * 
73
			 * @see org.eclipse.jface.viewers.IFontProvider#getFont(java.lang.Object)
74
			 */
75
			public Font getFont(Object element) {
76
				return provider.getFont(element, getColumnIndex());
77
			}
78
		};
79
	}
80
81
	/**
82
	 * Return the ILabelProvider based on provider at columnIndex.
83
	 * 
84
	 * @param provider
85
	 * @param columnIndex
86
	 * @return ILabelProvider
87
	 */
88
	private ILabelProvider labelProviderFor(final ITableLabelProvider provider) {
89
		return new LabelProvider() {
90
			/*
91
			 * (non-Javadoc)
92
			 * 
93
			 * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
94
			 */
95
			public String getText(Object element) {
96
				return provider.getColumnText(element, getColumnIndex());
97
			}
98
99
			/*
100
			 * (non-Javadoc)
101
			 * 
102
			 * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object)
103
			 */
104
			public Image getImage(Object element) {
105
				return provider.getColumnImage(element, getColumnIndex());
106
			}
107
		};
108
	}
109
110
	/**
111
	 * Create an IColorProvider from the ITableColorProvider at columnIndex.
112
	 * 
113
	 * @param provider
114
	 * @param columnIndex
115
	 * @return IColorProvider
116
	 */
117
	private IColorProvider colorProviderFor(final ITableColorProvider provider) {
118
		return new IColorProvider() {
119
			/*
120
			 * (non-Javadoc)
121
			 * 
122
			 * @see org.eclipse.jface.viewers.IColorProvider#getBackground(java.lang.Object)
123
			 */
124
			public Color getBackground(Object element) {
125
				return provider.getBackground(element, getColumnIndex());
126
			}
127
128
			/*
129
			 * (non-Javadoc)
130
			 * 
131
			 * @see org.eclipse.jface.viewers.IColorProvider#getForeground(java.lang.Object)
132
			 */
133
			public Color getForeground(Object element) {
134
				return provider.getForeground(element, getColumnIndex());
135
			}
136
		};
137
	}
138
139
}
(-)src/org/eclipse/jface/viewers/ViewerLabelProvider.java (+424 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *     Tom Shindl <tom.schindl@bestsolution.at> - initial API and implementation
11
 ******************************************************************************/
12
13
package org.eclipse.jface.viewers;
14
15
import org.eclipse.swt.SWT;
16
import org.eclipse.swt.graphics.Color;
17
import org.eclipse.swt.graphics.Font;
18
import org.eclipse.swt.graphics.Image;
19
import org.eclipse.swt.graphics.Point;
20
21
/**
22
 * The ViewerLabelProvider is an abstract implementation of a 
23
 * label provider for structured viewers.
24
 * @since 3.3
25
 * <strong>EXPERIMENTAL</strong> This class or interface has been added as
26
 * part of a work in progress. This API may change at any given time. Please 
27
 * do not use this API without consulting with the Platform/UI team.
28
 */
29
public class ViewerLabelProvider extends LabelProvider implements
30
		ILabelProvider, IColorProvider, IFontProvider {
31
32
	private static ILabelProvider defaultLabelProvider = new LabelProvider() {
33
34
	};
35
36
	private ILabelProvider labelProvider = defaultLabelProvider;
37
38
	private IColorProvider colorProvider;
39
40
	private IFontProvider fontProvider;
41
42
	private int columnIndex;
43
44
	/**
45
	 * Create a new instance of the receiver.
46
	 */
47
	public ViewerLabelProvider() {
48
		super();
49
	}
50
51
	/**
52
	 * Create a new instance of the receiver based on labelProvider.
53
	 * 
54
	 * @param labelProvider
55
	 */
56
	public ViewerLabelProvider(IBaseLabelProvider labelProvider) {
57
		super();
58
		setProviders(labelProvider);
59
	}
60
61
	/**
62
	 * Create a ViewerLabelProvider for the column at index
63
	 * 
64
	 * @param columnIndex
65
	 * @param labelProvider
66
	 *            The labelProvider to convert
67
	 * @return ViewerLabelProvider
68
	 */
69
	static ViewerLabelProvider createViewerLabelProvider(
70
			IBaseLabelProvider labelProvider) {
71
72
		if (labelProvider instanceof ITableLabelProvider
73
				|| labelProvider instanceof ITableColorProvider
74
				|| labelProvider instanceof ITableFontProvider)
75
			return new TableColumnViewerLabelProvider(labelProvider);
76
		return new ViewerLabelProvider(labelProvider);
77
78
	}
79
80
	private void updateLabel(ViewerLabel label, Object element) {
81
		label.setText(labelProvider.getText(element));
82
		label.setImage(labelProvider.getImage(element));
83
84
		if (colorProvider != null) {
85
			label.setBackground(colorProvider.getBackground(element));
86
			label.setForeground(colorProvider.getForeground(element));
87
		}
88
89
		if (fontProvider != null) {
90
			label.setFont(fontProvider.getFont(element));
91
		}
92
	}
93
94
	/**
95
	 * Updates the label for the given element and the given index
96
	 * 
97
	 * @param label
98
	 *            the label to update
99
	 * @param element
100
	 *            the element
101
	 * @param columnIndex
102
	 *            the column index
103
	 */
104
	public void updateLabel(ViewerLabel label, Object element, int columnIndex) {
105
		setColumnIndex(columnIndex);
106
		updateLabel(label, element);
107
	}
108
109
	/**
110
	 * @param columnIndex
111
	 *            the column-index
112
	 */
113
	public void setColumnIndex(int columnIndex) {
114
		this.columnIndex = columnIndex;
115
	}
116
117
	/**
118
	 * @return Returns the column index
119
	 */
120
	public int getColumnIndex() {
121
		return columnIndex;
122
	}
123
124
	/**
125
	 * Set the colorProvider to use for the receiver.
126
	 * 
127
	 * @param colorProvider
128
	 *            The colorProvider to set.
129
	 */
130
	public void setColorProvider(IColorProvider colorProvider) {
131
		this.colorProvider = colorProvider;
132
	}
133
134
	/**
135
	 * Set the fontProvider to fontProvider.
136
	 * 
137
	 * @param fontProvider
138
	 *            The fontProvider to set.
139
	 */
140
	public void setFontProvider(IFontProvider fontProvider) {
141
		this.fontProvider = fontProvider;
142
	}
143
144
	/**
145
	 * Set the labelProvider to be provider.
146
	 * 
147
	 * @param provider
148
	 *            ILabelProvider provider to set.
149
	 */
150
	public void setLabelProvider(ILabelProvider provider) {
151
		this.labelProvider = provider;
152
	}
153
154
	/**
155
	 * Set the any providers for the receiver that can be adapted from provider.
156
	 * 
157
	 * @param provider
158
	 */
159
	public void setProviders(Object provider) {
160
		if (provider instanceof ILabelProvider)
161
			setLabelProvider((ILabelProvider) provider);
162
163
		if (provider instanceof IColorProvider)
164
			colorProvider = (IColorProvider) provider;
165
166
		if (provider instanceof IFontProvider)
167
			fontProvider = (IFontProvider) provider;
168
169
	}
170
171
	/*
172
	 * (non-Javadoc)
173
	 * 
174
	 * @see org.eclipse.jface.viewers.IFontProvider#getFont(java.lang.Object)
175
	 */
176
	public Font getFont(Object element) {
177
		if (fontProvider == null) {
178
			return null;
179
		}
180
181
		return fontProvider.getFont(element);
182
183
	}
184
185
	/*
186
	 * (non-Javadoc)
187
	 * 
188
	 * @see org.eclipse.jface.viewers.IColorProvider#getBackground(java.lang.Object)
189
	 */
190
	public Color getBackground(Object element) {
191
		if (colorProvider == null) {
192
			return null;
193
		}
194
195
		return colorProvider.getBackground(element);
196
	}
197
198
	/*
199
	 * (non-Javadoc)
200
	 * 
201
	 * @see org.eclipse.jface.viewers.IColorProvider#getForeground(java.lang.Object)
202
	 */
203
	public Color getForeground(Object element) {
204
		if (colorProvider == null) {
205
			return null;
206
		}
207
208
		return colorProvider.getForeground(element);
209
	}
210
211
	/**
212
	 * Get the IColorProvider for the receiver.
213
	 * 
214
	 * @return IColorProvider
215
	 */
216
	public IColorProvider getColorProvider() {
217
		return colorProvider;
218
	}
219
220
	/**
221
	 * Get the IFontProvider for the receiver.
222
	 * 
223
	 * @return IFontProvider
224
	 */
225
	public IFontProvider getFontProvider() {
226
		return fontProvider;
227
	}
228
229
	/**
230
	 * @return Returns the labelProvider.
231
	 */
232
	public ILabelProvider getLabelProvider() {
233
		return labelProvider;
234
	}
235
236
	/**
237
	 * The image displayed in the tooltip
238
	 * 
239
	 * @param object
240
	 *            the element for which the tooltip is shown
241
	 * @return the image displayed if null no image is displayed
242
	 */
243
244
	public Image getTooltipImage(Object object) {
245
		return null;
246
	}
247
248
	/**
249
	 * Returns the tooltip text for the given element and column index, or
250
	 * <code>null</code> if a custom tooltip should not be displayed.
251
	 * 
252
	 * @param element
253
	 *            the element for which the tooltip is shown
254
	 * @return the text to be displayed in the tooltip, or <code>null</code>
255
	 *         if a custom tooltip should not be displayed
256
	 */
257
	public String getTooltipText(Object element) {
258
		return null;
259
	}
260
261
	/**
262
	 * The background color used for the tooltip
263
	 * 
264
	 * @param object
265
	 *            the element for which the tooltip is shown
266
	 * 
267
	 * @return the color used or <code>null</code> if you want to use the
268
	 */
269
	public Color getTooltipBackgroundColor(Object object) {
270
		return null;
271
	}
272
273
	/**
274
	 * The foreground color used to display the the text in the tooltip
275
	 * 
276
	 * @param object
277
	 *            the element for which the tooltip is shown
278
	 * @return the color used or <code>null</code> if you want to use the
279
	 *         default color {@link SWT#COLOR_INFO_FOREGROUND}
280
	 */
281
	public Color getTooltipForegroundColor(Object object) {
282
		return null;
283
	}
284
285
	/**
286
	 * The font used to display the tooltip
287
	 * 
288
	 * @param object
289
	 *            the element for which the tooltip is shown
290
	 * @return the font if null default font is used
291
	 */
292
	public Font getTooltipFont(Object object) {
293
		return null;
294
	}
295
296
	/**
297
	 * This is the amount the used to control how much the tooltip is shifted
298
	 * from the current mouse position
299
	 * 
300
	 * @param object
301
	 *            the element for which the tooltip is shown
302
	 * @param columnIndex
303
	 *            the column-index
304
	 * @return shift of the tooltip
305
	 */
306
	public Point getTooltipShift(Object object, int columnIndex) {
307
		return null;
308
	}
309
310
	/**
311
	 * If you want your tooltip to be using the native Tooltip you can force
312
	 * this by returning true from this method. If native tooltips are used only
313
	 * the text-value is used all other feature are of custom tooltips are not
314
	 * supported.
315
	 * 
316
	 * @param object
317
	 *            the element for which the tooltip is shown
318
	 * @param columnIndex
319
	 *            the column-index
320
	 * @return true if native tooltips should be used
321
	 */
322
	public boolean useNativeTooltip(Object object, int columnIndex) {
323
		return false;
324
	}
325
326
	/**
327
	 * The time in milliseconds after the tooltip is hidden
328
	 * 
329
	 * @param object
330
	 *            the element for which the tooltip is shown
331
	 * @param columnIndex
332
	 *            the column-index
333
	 * @return milliseconds
334
	 */
335
	public int getTooltipTimeDisplayed(Object object, int columnIndex) {
336
		return 0;
337
	}
338
339
	/**
340
	 * The time in milliseconds until the tooltip pops up
341
	 * 
342
	 * @param object
343
	 *            the element for which the tooltip is shown
344
	 * @param columnIndex
345
	 *            the column-index
346
	 * @return milliseconds
347
	 */
348
	public int getTooltipDisplayDelayTime(Object object, int columnIndex) {
349
		return 0;
350
	}
351
352
	/**
353
	 * The style used to create the label
354
	 * 
355
	 * @param object
356
	 *            the element for which the tooltip is shown
357
	 * @param columnIndex
358
	 *            the column-index
359
	 * @return style mask
360
	 */
361
	public int getTooltipImageStyle(Object object, int columnIndex) {
362
		return SWT.SHADOW_NONE;
363
	}
364
365
	/**
366
	 * This is the amount the used to control how much the tooltip is shifted
367
	 * from the current mouse position
368
	 * 
369
	 * @param object
370
	 *            the element for which the tooltip is shown
371
	 * @return shift of the tooltip
372
	 */
373
	public Point getTooltipShift(Object object) {
374
		return null;
375
	}
376
377
	/**
378
	 * If you want your tooltip to be using the native Tooltip you can force
379
	 * this by returning true from this method. If native tooltips are used only
380
	 * the text-value is used all other feature are of custom tooltips are not
381
	 * supported.
382
	 * 
383
	 * @param object
384
	 *            the element for which the tooltip is shown
385
	 * @return true if native tooltips should be used
386
	 */
387
	public boolean useNativeTooltip(Object object) {
388
		return false;
389
	}
390
391
	/**
392
	 * The time in milliseconds after the tooltip is hidden
393
	 * 
394
	 * @param object
395
	 *            the element for which the tooltip is shown
396
	 * @return milliseconds
397
	 */
398
	public int getTooltipTimeDisplayed(Object object) {
399
		return 0;
400
	}
401
402
	/**
403
	 * The time in milliseconds until the tooltip pops up
404
	 * 
405
	 * @param object
406
	 *            the element for which the tooltip is shown
407
	 * @return milliseconds
408
	 */
409
	public int getTooltipDisplayDelayTime(Object object) {
410
		return 0;
411
	}
412
413
	/**
414
	 * The style used to create the label
415
	 * 
416
	 * @param object
417
	 *            the element for which the tooltip is shown
418
	 * @return style mask
419
	 */
420
	public int getTooltipImageStyle(Object object) {
421
		return SWT.SHADOW_NONE;
422
	}
423
424
}
(-)src/org/eclipse/jface/viewers/TooltipSupport.java (+212 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *     Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
11
 ******************************************************************************/
12
13
package org.eclipse.jface.viewers;
14
15
import java.util.Timer;
16
17
import org.eclipse.swt.SWT;
18
import org.eclipse.swt.custom.CLabel;
19
import org.eclipse.swt.graphics.Color;
20
import org.eclipse.swt.graphics.Font;
21
import org.eclipse.swt.graphics.Image;
22
import org.eclipse.swt.graphics.Point;
23
import org.eclipse.swt.layout.FillLayout;
24
import org.eclipse.swt.widgets.Event;
25
import org.eclipse.swt.widgets.Listener;
26
import org.eclipse.swt.widgets.Shell;
27
28
/**
29
 * The TooltipSupport is the class that provides tooltips for
30
 * ColumnViewers.
31
 * @since 3.3
32
 * <strong>EXPERIMENTAL</strong> This class or interface has been added as
33
 * part of a work in progress. This API may change at any given time. Please 
34
 * do not use this API without consulting with the Platform/UI team.
35
 *
36
 */
37
class TooltipSupport {
38
	private ColumnViewer viewer;
39
	private Listener listener = new MouseListener();
40
	private static final int DEFAULT_SHIFT_X = 10;
41
	private static final int DEFAULT_SHIFT_Y = 0;
42
	
43
	TooltipSupport(ColumnViewer viewer) {
44
		this.viewer = viewer;
45
	}
46
	
47
	/**
48
	 * activate tooltip support for this viewer
49
	 */
50
	public void activate() {
51
		deactivate();
52
		viewer.getControl().addListener(SWT.Dispose, listener);
53
		viewer.getControl().addListener(SWT.MouseHover, listener);
54
		viewer.getControl().addListener(SWT.MouseMove, listener);
55
		viewer.getControl().addListener(SWT.MouseExit, listener);
56
		viewer.getControl().addListener(SWT.MouseDown, listener);
57
	}
58
	
59
	/**
60
	 * deactivate tooltip support for this viewer
61
	 */
62
	public void deactivate() {
63
		viewer.getControl().removeListener(SWT.Dispose, listener);
64
		viewer.getControl().removeListener(SWT.MouseHover, listener);
65
		viewer.getControl().removeListener(SWT.MouseMove, listener);
66
		viewer.getControl().removeListener(SWT.MouseExit, listener);
67
		viewer.getControl().removeListener(SWT.MouseDown, listener);
68
	}
69
	
70
	private class MouseListener implements Listener {
71
		private Shell tip;
72
		private TooltipHideListener hideListener = new TooltipHideListener();
73
		private Timer timer = new Timer();
74
		
75
		/* (non-Javadoc)
76
		 * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
77
		 */
78
		public void handleEvent(Event event) {
79
			switch (event.type) {
80
			case SWT.Dispose:
81
				if( timer != null ) {
82
					timer.cancel();
83
				}
84
			case SWT.KeyDown:
85
			case SWT.MouseMove:
86
			case SWT.MouseDown:
87
				disposeTooltip(tip);
88
				break;
89
			case SWT.MouseHover:
90
				Point p = new Point(event.x, event.y);
91
				RowPart row = viewer.getRowPart(p);
92
				viewer.getControl().setToolTipText(""); //$NON-NLS-1$
93
94
				if (row != null) {
95
					popupTooltip(row, p);
96
				}
97
98
				break;
99
			}
100
		}
101
		
102
		/**
103
		 * Popup a tooltip for the row at Point p.
104
		 * @param row
105
		 * @param p
106
		 */
107
		private void popupTooltip(RowPart row, Point p) {
108
			Object element = row.getItem().getData();
109
			disposeTooltip(tip);
110
111
			ColumnViewerPart viewPart = viewer.getColumnViewer(row.getColumnIndex(p));
112
			
113
			if( viewPart == null ) {
114
				return;
115
			}
116
			
117
			ViewerLabelProvider labelProvider = viewPart.getLabelProvider();
118
			
119
			String text = labelProvider.getTooltipText(element);
120
			
121
			if( text != null ) {
122
				
123
				if( labelProvider.useNativeTooltip(element) ) {
124
					viewer.getControl().setToolTipText(text);
125
					return;
126
				}
127
				
128
				tip = new Shell(viewer.getControl().getShell(), SWT.ON_TOP | SWT.TOOL);
129
				tip.setLayout(new FillLayout());
130
				CLabel label = new CLabel(tip, labelProvider.getTooltipImageStyle(element));
131
				label.setText(text);
132
				label.addListener(SWT.MouseExit, hideListener);
133
				label.addListener(SWT.MouseDown, hideListener);
134
				
135
				Image img =  labelProvider.getTooltipImage(element);
136
				
137
				if( img != null) {
138
					label.setImage(img);
139
				}
140
				
141
				Color color = labelProvider.getTooltipForegroundColor(element);
142
				if( color == null ) {
143
					color = viewer.getControl().getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND);
144
				}
145
				label.setForeground(color);
146
				
147
				color = labelProvider.getTooltipBackgroundColor(element);
148
				if( color == null ) {
149
					color = viewer.getControl().getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND);
150
				}
151
				label.setBackground(color);
152
				
153
				Font font = labelProvider.getTooltipFont(element);
154
				
155
				if( font != null ) {
156
					label.setFont(font);
157
				}
158
				
159
				Point pt = viewer.getControl().toDisplay(p);
160
				Point shift = labelProvider.getTooltipShift(element);
161
				
162
				if( shift == null ) {
163
					pt.x += DEFAULT_SHIFT_X;
164
					pt.y += DEFAULT_SHIFT_Y;
165
				} else {
166
					pt.x += shift.x;
167
					pt.y += shift.y;
168
				}
169
				
170
				tip.pack();
171
				tip.setLocation(pt);
172
				tip.setVisible(true);
173
			}
174
		}
175
		
176
		/**
177
		 * Dispose the tooltip.
178
		 * @param tip
179
		 */
180
		private void disposeTooltip(Shell tip) {
181
			if (tip != null && !tip.isDisposed()) {
182
				tip.dispose();
183
			}
184
185
			tip = null;
186
		}
187
	}
188
	
189
	/**
190
	 * TooltipHideListener is a listener for tooltip removal.
191
	 * @since 3.3
192
	 *
193
	 */
194
	private class TooltipHideListener implements Listener {
195
		/* (non-Javadoc)
196
		 * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
197
		 */
198
		public void handleEvent(Event event) {
199
			CLabel label = (CLabel) event.widget;
200
			Shell shell = label.getShell();
201
			switch (event.type) {
202
			case SWT.MouseDown:
203
				viewer.setSelection(new StructuredSelection());
204
				// fall through
205
			case SWT.MouseExit:
206
				viewer.getControl().setFocus();
207
				shell.dispose();
208
				break;
209
			}
210
		}
211
	}
212
}
(-)src/org/eclipse/jface/viewers/EditingSupport.java (+62 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.viewers;
13
14
/**
15
 * EditingSupport is the abstract superclass of the support for cell editing.
16
 * <strong>EXPERIMENTAL</strong> This class or interface has been added as
17
 * part of a work in progress. This API may change at any given time. Please 
18
 * do not use this API without consulting with the Platform/UI team.
19
 * @since 3.3
20
 * Contributors:
21
 *     IBM Corporation - initial API and implementation
22
 *     Tom Shindl <tom.schindl@bestsolution.at> - initial API and implementation
23
 * 
24
 */
25
abstract class EditingSupport {
26
	/**
27
	 * The editor to be shown
28
	 * 
29
	 * @param element
30
	 *            the model element
31
	 * @return the CellEditor
32
	 */
33
	abstract CellEditor getCellEditor(Object element);
34
35
	/**
36
	 * Is the cell editable
37
	 * 
38
	 * @param element
39
	 *            the model element
40
	 * @return true if editable
41
	 */
42
	abstract boolean canEdit(Object element);
43
44
	/**
45
	 * Get the value to set to the editor
46
	 * 
47
	 * @param element
48
	 *            the model element
49
	 * @return the value shown
50
	 */
51
	abstract Object getValue(Object element);
52
53
	/**
54
	 * Restore the value from the CellEditor
55
	 * 
56
	 * @param element
57
	 *            the model element
58
	 * @param value
59
	 *            the new value
60
	 */
61
	abstract void setValue(Object element, Object value);
62
}
(-)src/org/eclipse/jface/viewers/TreeColumnViewerPart.java (+80 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.viewers;
13
14
import org.eclipse.swt.widgets.TreeColumn;
15
16
/**
17
 * Wrapper class for {@link TreeColumn}
18
 * @since 3.3
19
 * <strong>EXPERIMENTAL</strong> This class or interface has been added as
20
 * part of a work in progress. This API may change at any given time. Please 
21
 * do not use this API without consulting with the Platform/UI team.
22
23
 * 
24
 */
25
public class TreeColumnViewerPart extends ColumnViewerPart {
26
	private TreeColumn column;
27
28
	/**
29
	 * Create new TableColumnViewerPart. This simply wrapps up a new
30
	 * {@link TreeColumn#TableColumn(org.eclipse.swt.widgets.Table, int)}.
31
	 * Before calling {@link TreeViewer#setInput(Object)}} you need to set the
32
	 * label-provider using
33
	 * {@link ColumnViewerPart#setLabelProvider(ViewerLabelProvider)}
34
	 * 
35
	 * @param parent
36
	 *            the table-viewer
37
	 * @param style
38
	 *            style bits used to create TableColumn {@link TreeColumn}
39
	 */
40
	public TreeColumnViewerPart(TreeViewer parent, int style) {
41
		this(new TreeColumn(parent.getTree(), style),null);
42
	}
43
44
	/**
45
	 * Create new TableColumnViewerPart. This simply wrapps up a new
46
	 * {@link TableColumn#TableColumn(org.eclipse.swt.widgets.Table, int, int)}
47
	 * 
48
	 * @param parent
49
	 *            the table-viewer
50
	 * @param style
51
	 *            style style bits used to create TableColumn
52
	 *            {@link TableColumn}
53
	 * @param index
54
	 *            the index of the column
55
	 */
56
	public TreeColumnViewerPart(TreeViewer parent, int style, int index) {
57
		this(new TreeColumn(parent.getTree(), style, index),null);
58
	}
59
60
	/**
61
	 * Wrap an existing TableColumn
62
	 * 
63
	 * @param column
64
	 *            the existing table-column
65
	 * @param labelProvider
66
	 *            the label provider
67
	 */
68
	public TreeColumnViewerPart(TreeColumn column,
69
			ViewerLabelProvider labelProvider) {
70
		super(column,labelProvider);
71
		this.column = column;
72
	}
73
74
	/**
75
	 * @return access the underlying tree-column
76
	 */
77
	public TreeColumn getColumn() {
78
		return column;
79
	}
80
}
(-)src/org/eclipse/jface/viewers/TreeRowPart.java (+139 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *     Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
11
 ******************************************************************************/
12
13
package org.eclipse.jface.viewers;
14
15
import org.eclipse.swt.graphics.Color;
16
import org.eclipse.swt.graphics.Font;
17
import org.eclipse.swt.graphics.Image;
18
import org.eclipse.swt.graphics.Rectangle;
19
import org.eclipse.swt.widgets.Item;
20
import org.eclipse.swt.widgets.TreeItem;
21
22
/**
23
 * TreeRowPart is the Tree implementation of RowPart.
24
 * @since 3.3
25
 * <strong>EXPERIMENTAL</strong> This class or interface has been added as
26
 * part of a work in progress. This API may change at any given time. Please 
27
 * do not use this API without consulting with the Platform/UI team.
28
 *
29
 */
30
public class TreeRowPart extends RowPart {
31
	private TreeItem item;
32
	
33
	/**
34
	 * Create a new instance of the receiver.
35
	 * @param item
36
	 */
37
	TreeRowPart(TreeItem item) {
38
		super(item);
39
		this.item = item;
40
	}
41
	
42
	/* (non-Javadoc)
43
	 * @see org.eclipse.jface.viewers.RowPart#getBounds(int)
44
	 */
45
	public Rectangle getBounds(int columnIndex) {
46
		return item.getBounds(columnIndex);
47
	}
48
49
	/* (non-Javadoc)
50
	 * @see org.eclipse.jface.viewers.RowPart#getBounds()
51
	 */
52
	public Rectangle getBounds() {
53
		return item.getBounds();
54
	}
55
56
	/* (non-Javadoc)
57
	 * @see org.eclipse.jface.viewers.RowPart#getColumnCount()
58
	 */
59
	public int getColumnCount() {
60
		return item.getParent().getItemCount();
61
	}
62
63
	/* (non-Javadoc)
64
	 * @see org.eclipse.jface.viewers.RowPart#getItem()
65
	 */
66
	public Item getItem() {
67
		return item;
68
	}
69
70
	/* (non-Javadoc)
71
	 * @see org.eclipse.jface.viewers.RowPart#getBackground(int)
72
	 */
73
	public Color getBackground(int columnIndex) {
74
		return item.getBackground(columnIndex);
75
	}
76
77
	/* (non-Javadoc)
78
	 * @see org.eclipse.jface.viewers.RowPart#getFont(int)
79
	 */
80
	public Font getFont(int columnIndex) {
81
		return item.getFont(columnIndex);
82
	}
83
84
	/* (non-Javadoc)
85
	 * @see org.eclipse.jface.viewers.RowPart#getForeground(int)
86
	 */
87
	public Color getForeground(int columnIndex) {
88
		return item.getForeground(columnIndex);
89
	}
90
91
	/* (non-Javadoc)
92
	 * @see org.eclipse.jface.viewers.RowPart#getImage(int)
93
	 */
94
	public Image getImage(int columnIndex) {
95
		return item.getImage(columnIndex);
96
	}
97
98
	/* (non-Javadoc)
99
	 * @see org.eclipse.jface.viewers.RowPart#getText(int)
100
	 */
101
	public String getText(int columnIndex) {
102
		return item.getText(columnIndex);
103
	}
104
105
	/* (non-Javadoc)
106
	 * @see org.eclipse.jface.viewers.RowPart#setBackground(int, org.eclipse.swt.graphics.Color)
107
	 */
108
	public void setBackground(int columnIndex, Color color) {
109
		item.setBackground(columnIndex, color);
110
	}
111
112
	/* (non-Javadoc)
113
	 * @see org.eclipse.jface.viewers.RowPart#setFont(int, org.eclipse.swt.graphics.Font)
114
	 */
115
	public void setFont(int columnIndex, Font font) {
116
		item.setFont(columnIndex, font);
117
	}
118
119
	/* (non-Javadoc)
120
	 * @see org.eclipse.jface.viewers.RowPart#setForeground(int, org.eclipse.swt.graphics.Color)
121
	 */
122
	public void setForeground(int columnIndex, Color color) {
123
		item.setForeground(columnIndex, color);
124
	}
125
126
	/* (non-Javadoc)
127
	 * @see org.eclipse.jface.viewers.RowPart#setImage(int, org.eclipse.swt.graphics.Image)
128
	 */
129
	public void setImage(int columnIndex, Image image) {
130
		item.setImage(columnIndex,image);
131
	}
132
133
	/* (non-Javadoc)
134
	 * @see org.eclipse.jface.viewers.RowPart#setText(int, java.lang.String)
135
	 */
136
	public void setText(int columnIndex, String text) {
137
		item.setText(columnIndex, text);
138
	}
139
}
(-)src/org/eclipse/jface/viewers/RowPart.java (+186 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *     Tom Shindl <tom.schindl@bestsolution.at> - initial API and implementation
11
 ******************************************************************************/
12
13
package org.eclipse.jface.viewers;
14
15
import org.eclipse.jface.util.Policy;
16
import org.eclipse.swt.events.DisposeEvent;
17
import org.eclipse.swt.events.DisposeListener;
18
import org.eclipse.swt.graphics.Color;
19
import org.eclipse.swt.graphics.Font;
20
import org.eclipse.swt.graphics.Image;
21
import org.eclipse.swt.graphics.Point;
22
import org.eclipse.swt.graphics.Rectangle;
23
import org.eclipse.swt.widgets.Item;
24
25
/**
26
 * RowPart is the abstract superclass of the part that represents items in a 
27
 * Table or Tree.
28
 * @since 3.3
29
 * <strong>EXPERIMENTAL</strong> This class or interface has been added as
30
 * part of a work in progress. This API may change at any given time. Please 
31
 * do not use this API without consulting with the Platform/UI team.
32
 * 
33
 */
34
public abstract class RowPart {
35
	/**
36
	 * Key used to reference RowPart in the widgets data-map
37
	 */
38
	public static final String ROWPART_KEY = Policy.JFACE + ".ROWPART"; //$NON-NLS-1$
39
		
40
	/**
41
	 * Create a new instance of the receiver.
42
	 * @param item
43
	 */
44
	RowPart(final Item item) {
45
		item.setData(RowPart.ROWPART_KEY, this);
46
		item.addDisposeListener(new DisposeListener() {
47
48
			/* (non-Javadoc)
49
			 * @see org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse.swt.events.DisposeEvent)
50
			 */
51
			public void widgetDisposed(DisposeEvent e) {
52
				item.setData(ROWPART_KEY, null);
53
			}
54
			
55
		});
56
	}
57
	
58
	/**
59
	 * Get the bounds of the entry at the columnIndex,
60
	 * @param columnIndex
61
	 * @return Rectangle
62
	 */
63
	public abstract Rectangle getBounds(int columnIndex);
64
65
	/**
66
	 * Return the bounds for the whole item.
67
	 * @return Rectangle
68
	 */
69
	public abstract Rectangle getBounds();
70
71
	/**
72
	 * Return the item for the receiver.
73
	 * @return Item
74
	 */
75
	public abstract Item getItem();
76
77
	/**
78
	 * Return the number of columns for the receiver.
79
	 * @return int
80
	 */
81
	public abstract int getColumnCount();
82
	
83
	/**
84
	 * Return the image at the columnIndex.
85
	 * @param columnIndex
86
	 * @return Image
87
	 */
88
	public abstract Image getImage(int columnIndex);
89
	
90
	/**
91
	 * Set the image at the columnIndex
92
	 * @param columnIndex
93
	 * @param image
94
	 */
95
	public abstract void setImage(int columnIndex,Image image);
96
	
97
	/**
98
	 * Get the text at the columnIndex.
99
	 * @param columnIndex
100
	 * @return String
101
	 */
102
	public abstract String getText(int columnIndex);
103
	
104
	/**
105
	 * Set the text at the columnIndex
106
	 * @param columnIndex
107
	 * @param text
108
	 */
109
	public abstract void setText(int columnIndex,String text);
110
	
111
	/**
112
	 * Get the background at the columnIndex,
113
	 * @param columnIndex
114
	 * @return Color
115
	 */
116
	public abstract Color getBackground(int columnIndex);
117
	
118
	/**
119
	 * Set the background at the columnIndex.
120
	 * @param columnIndex
121
	 * @param color
122
	 */
123
	public abstract void setBackground(int columnIndex, Color color);
124
	
125
	/**
126
	 * Get the foreground at the columnIndex.
127
	 * @param columnIndex
128
	 * @return Color
129
	 */
130
	public abstract Color getForeground(int columnIndex);
131
	
132
	/**
133
	 * Set the foreground at the columnIndex.
134
	 * @param columnIndex
135
	 * @param color
136
	 */
137
	public abstract void setForeground(int columnIndex, Color color);
138
	
139
	/**
140
	 * Get the font at the columnIndex.
141
	 * @param columnIndex
142
	 * @return Font
143
	 */
144
	public abstract Font getFont(int columnIndex);
145
	
146
	/**
147
	 * Set the font at the columnIndex.
148
	 * @param columnIndex
149
	 * @param font
150
	 */
151
	public abstract void setFont(int columnIndex,Font font);
152
	
153
	
154
	/**
155
	 * Get the Cell at point.
156
	 * @param point
157
	 * @return Cell
158
	 */
159
	public Cell getCell(Point point) {
160
		int index = getColumnIndex(point);
161
		
162
		if( index >= 0 ) {
163
			return new Cell(this,index);
164
		}
165
166
		return null;
167
	}
168
	
169
	/**
170
	 * Get the columnIndex of the point.
171
	 * @param point
172
	 * @return the column index or -1 if it cannot be found.
173
	 */
174
	public int getColumnIndex(Point point) {
175
		int count = getColumnCount();
176
		
177
		for(int i = 0; i < count; i++ ) {
178
			if( getBounds(i).contains(point) ) {
179
				return i;
180
			}
181
		}
182
		
183
		return -1;
184
	}
185
	
186
}
(-)src/org/eclipse/jface/viewers/Cell.java (+62 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *     Tom Shindl <tom.schindl@bestsolution.at> - initial API and implementation
11
 ******************************************************************************/
12
13
package org.eclipse.jface.viewers;
14
15
import org.eclipse.swt.graphics.Rectangle;
16
17
/**
18
 * The Cell is the JFace representation of a cell entry in a RowPart.
19
 * @since 3.3
20
 * <strong>EXPERIMENTAL</strong> This class or interface has been added as
21
 * part of a work in progress. This API may change at any given time. Please 
22
 * do not use this API without consulting with the Platform/UI team.
23
 *
24
 */
25
public class Cell {
26
	private int columnIndex;
27
	private RowPart row;
28
	
29
	/**
30
	 * Create a new instance of the receiver on the row.
31
	 * @param row
32
	 * @param columnIndex
33
	 */
34
	public Cell(RowPart row, int columnIndex) {
35
		this.row = row;
36
		this.columnIndex = columnIndex;
37
	}
38
	
39
	/**
40
	 * Get the index of the cell.
41
	 * @return int
42
	 */
43
	public int getColumnIndex() {
44
		return columnIndex;
45
	}
46
	
47
	/**
48
	 * Get the bounds of the cell.
49
	 * @return Rectangle
50
	 */
51
	public Rectangle getBounds() {
52
		return row.getBounds(columnIndex);
53
	}
54
	
55
	/**
56
	 * Get the element this row represents.
57
	 * @return Object
58
	 */
59
	public Object getElement() {
60
		return row.getItem().getData();
61
	}
62
}
(-)src/org/eclipse/jface/viewers/TableColumnViewerPart.java (+82 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.viewers;
13
14
import org.eclipse.swt.widgets.TableColumn;
15
16
/**
17
 * Wrapper class for {@link TableColumn}
18
 * <strong>EXPERIMENTAL</strong> This class or interface has been added as
19
 * part of a work in progress. This API may change at any given time. Please 
20
 * do not use this API without consulting with the Platform/UI team.
21
 * @since 3.3
22
 * Contributors:
23
 *     IBM Corporation - initial API and implementation
24
 *     Tom Shindl <tom.schindl@bestsolution.at> - initial API and implementation
25
 * 
26
 */
27
public class TableColumnViewerPart extends ColumnViewerPart {
28
	private TableColumn column;
29
30
	/**
31
	 * Create new TableColumnViewerPart. This simply wrapps up a new
32
	 * {@link TableColumn#TableColumn(org.eclipse.swt.widgets.Table, int)}.
33
	 * Before calling {@link TableViewer#setInput(Object)}} you need to set the
34
	 * label-provider using
35
	 * {@link ColumnViewerPart#setLabelProvider(ViewerLabelProvider)}
36
	 * 
37
	 * @param parent
38
	 *            the table-viewer
39
	 * @param style
40
	 *            style bits used to create TableColumn {@link TableColumn}
41
	 */
42
	public TableColumnViewerPart(TableViewer parent, int style) {
43
		this(new TableColumn(parent.getTable(), style),null);
44
	}
45
46
	/**
47
	 * Create new TableColumnViewerPart. This simply wrapps up a new
48
	 * {@link TableColumn#TableColumn(org.eclipse.swt.widgets.Table, int, int)}
49
	 * 
50
	 * @param parent
51
	 *            the table-viewer
52
	 * @param style
53
	 *            style style bits used to create TableColumn
54
	 *            {@link TableColumn}
55
	 * @param index
56
	 *            the index of the column
57
	 */
58
	public TableColumnViewerPart(TableViewer parent, int style, int index) {
59
		this(new TableColumn(parent.getTable(), style, index),null);
60
	}
61
62
	/**
63
	 * Wrap an existing TableColumn
64
	 * 
65
	 * @param column
66
	 *            the existing table-column
67
	 * @param labelProvider
68
	 *            the label provider
69
	 */
70
	public TableColumnViewerPart(TableColumn column,
71
			ViewerLabelProvider labelProvider) {
72
		super(column,labelProvider);
73
		this.column = column;
74
	}
75
76
	/**
77
	 * @return access the underlying table-column
78
	 */
79
	public TableColumn getColumn() {
80
		return column;
81
	}
82
}

Return to bug 149193