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 (-333 / +307 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 15-26 Link Here
15
import java.util.HashSet;
16
import java.util.HashSet;
16
import java.util.List;
17
import java.util.List;
17
18
19
import org.eclipse.jface.internal.viewers.RowPart;
18
import org.eclipse.jface.util.Assert;
20
import org.eclipse.jface.util.Assert;
19
import org.eclipse.swt.SWT;
21
import org.eclipse.swt.SWT;
20
import org.eclipse.swt.custom.TableEditor;
22
import org.eclipse.swt.custom.TableEditor;
21
import org.eclipse.swt.events.MouseAdapter;
23
import org.eclipse.swt.events.MouseAdapter;
22
import org.eclipse.swt.events.MouseEvent;
24
import org.eclipse.swt.events.MouseEvent;
23
import org.eclipse.swt.graphics.Image;
25
import org.eclipse.swt.graphics.Image;
26
import org.eclipse.swt.graphics.Point;
24
import org.eclipse.swt.graphics.Rectangle;
27
import org.eclipse.swt.graphics.Rectangle;
25
import org.eclipse.swt.widgets.Composite;
28
import org.eclipse.swt.widgets.Composite;
26
import org.eclipse.swt.widgets.Control;
29
import org.eclipse.swt.widgets.Control;
Lines 28-36 Link Here
28
import org.eclipse.swt.widgets.Item;
31
import org.eclipse.swt.widgets.Item;
29
import org.eclipse.swt.widgets.Listener;
32
import org.eclipse.swt.widgets.Listener;
30
import org.eclipse.swt.widgets.Table;
33
import org.eclipse.swt.widgets.Table;
34
import org.eclipse.swt.widgets.TableColumn;
31
import org.eclipse.swt.widgets.TableItem;
35
import org.eclipse.swt.widgets.TableItem;
32
import org.eclipse.swt.widgets.Widget;
36
import org.eclipse.swt.widgets.Widget;
33
37
38
34
/**
39
/**
35
 * A concrete viewer based on a SWT <code>Table</code> control.
40
 * A concrete viewer based on a SWT <code>Table</code> control.
36
 * <p>
41
 * <p>
Lines 64-241 Link Here
64
 * @see #internalRefresh(Object, boolean)
69
 * @see #internalRefresh(Object, boolean)
65
 */
70
 */
66
public class TableViewer extends StructuredViewer {
71
public class TableViewer extends StructuredViewer {
67
		
72
68
	private class VirtualManager{
73
	private class VirtualManager {
69
74
70
		/**
75
		/**
71
		 * The currently invisible elements as provided 
76
		 * The currently invisible elements as provided by the content provider
72
		 * by the content provider or by addition.
77
		 * or by addition. This will not be populated by an
73
		 * This will not be populated by an ILazyStructuredContentProvider
78
		 * ILazyStructuredContentProvider as an ILazyStructuredContentProvider
74
		 * as an ILazyStructuredContentProvider is only queried
79
		 * is only queried on the virtual callback.
75
		 * on the virtual callback.
76
		 */
80
		 */
77
		private Object[] cachedElements = new Object[0];
81
		private Object[] cachedElements = new Object[0];
82
78
		/**
83
		/**
79
		 * Create a new instance of the receiver.
84
		 * Create a new instance of the receiver.
80
		 *
85
		 * 
81
		 */
86
		 */
82
		public VirtualManager(){
87
		public VirtualManager() {
83
			addTableListener();
88
			addTableListener();
84
		}
89
		}
85
90
86
		
87
		/**
91
		/**
88
		 * Add the listener for SetData on the table
92
		 * Add the listener for SetData on the table
89
		 */
93
		 */
90
		private void addTableListener() {
94
		private void addTableListener() {
91
			table.addListener(SWT.SetData,new Listener(){
95
			table.addListener(SWT.SetData, new Listener() {
92
				/* (non-Javadoc)
96
				/*
97
				 * (non-Javadoc)
98
				 * 
93
				 * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
99
				 * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
94
				 */
100
				 */
95
				public void handleEvent(Event event) {
101
				public void handleEvent(Event event) {
96
					TableItem item = (TableItem) event.item;
102
					TableItem item = (TableItem) event.item;
97
					final int index = table.indexOf(item);
103
					final int index = table.indexOf(item);
98
					Object element = resolveElement(index);
104
					Object element = resolveElement(index);
99
					if(element == null){
105
					if (element == null) {
100
						//Didn't find it so make a request
106
						// Didn't find it so make a request
101
						//Keep looking if it is not in the cache.
107
						// Keep looking if it is not in the cache.
102
						IContentProvider contentProvider = getContentProvider();
108
						IContentProvider contentProvider = getContentProvider();
103
						//If we are building lazily then request lookup now
109
						// If we are building lazily then request lookup now
104
						if(contentProvider instanceof ILazyContentProvider){
110
						if (contentProvider instanceof ILazyContentProvider) {
105
							((ILazyContentProvider) contentProvider).
111
							((ILazyContentProvider) contentProvider)
106
								updateElement(index);
112
									.updateElement(index);
107
							return;
113
							return;
108
						}	
114
						}
109
					}
115
					}
110
						
116
111
					
117
					associate(element, item);
112
					associate(element,item);
118
					updateItem(item, element);
113
					updateItem(item,element);
114
				}
119
				}
115
120
116
			});
121
			});
117
		}
122
		}
118
		
123
119
		/**
124
		/**
120
		 * Get the element at index.Resolve it lazily if this
125
		 * Get the element at index.Resolve it lazily if this is available.
121
		 * is available.
126
		 * 
122
		 * @param index
127
		 * @param index
123
		 * @return Object or <code>null</code> if it could
128
		 * @return Object or <code>null</code> if it could not be found
124
		 * not be found
125
		 */
129
		 */
126
		protected Object resolveElement(int index) {
130
		protected Object resolveElement(int index) {
127
			
131
128
			Object element = null;
132
			Object element = null;
129
			if(index < cachedElements.length) {
133
			if (index < cachedElements.length) {
130
				element =  cachedElements[index];
134
				element = cachedElements[index];
131
			}
135
			}
132
			
136
133
			return element;
137
			return element;
134
		}
138
		}
135
139
136
		/**
140
		/**
137
		 * A non visible item has been added.
141
		 * A non visible item has been added.
142
		 * 
138
		 * @param element
143
		 * @param element
139
		 * @param index
144
		 * @param index
140
		 */
145
		 */
141
		public void notVisibleAdded(Object element, int index) {
146
		public void notVisibleAdded(Object element, int index) {
142
			
147
143
			int requiredCount = index + 1;
148
			int requiredCount = index + 1;
144
			
149
145
			if(requiredCount > getTable().getItemCount()){
150
			if (requiredCount > getTable().getItemCount()) {
146
				getTable().setItemCount(requiredCount);
151
				getTable().setItemCount(requiredCount);
147
				Object[] newCache = new Object[requiredCount];
152
				Object[] newCache = new Object[requiredCount];
148
				System.arraycopy(cachedElements, 0, newCache, 0, cachedElements.length);
153
				System.arraycopy(cachedElements, 0, newCache, 0,
154
						cachedElements.length);
149
				cachedElements = newCache;
155
				cachedElements = newCache;
150
			}
156
			}
151
			
157
152
			
153
			cachedElements[index] = element;
158
			cachedElements[index] = element;
154
			
159
155
		}
160
		}
156
		
161
157
	}
162
	}
158
	
163
159
	private VirtualManager virtualManager;
164
	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
165
189
	/**
166
	/**
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.
167
	 * Internal table viewer implementation.
240
	 */
168
	 */
241
	private TableEditorImpl tableViewerImpl;
169
	private TableEditorImpl tableViewerImpl;
Lines 249-260 Link Here
249
	 * This viewer's table editor.
177
	 * This viewer's table editor.
250
	 */
178
	 */
251
	private TableEditor tableEditor;
179
	private TableEditor tableEditor;
252
	
180
253
	/**
181
254
	 * The color and font collector for the cells.
255
	 */
256
	private TableColorAndFontNoOp tableColorAndFont = new TableColorAndFontNoOp();
257
	
258
	/**
182
	/**
259
	 * Creates a table viewer on a newly-created table control under the given
183
	 * 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
184
	 * parent. The table control is created using the SWT style bits
Lines 281-287 Link Here
281
	 *            SWT style bits
205
	 *            SWT style bits
282
	 */
206
	 */
283
	public TableViewer(Composite parent, int style) {
207
	public TableViewer(Composite parent, int style) {
284
		this(new Table(parent, style));			
208
		this(new Table(parent, style));
285
	}
209
	}
286
210
287
	/**
211
	/**
Lines 299-317 Link Here
299
		initTableViewerImpl();
223
		initTableViewerImpl();
300
		initializeVirtualManager(table.getStyle());
224
		initializeVirtualManager(table.getStyle());
301
	}
225
	}
302
	
226
303
	/**
227
	/**
304
	 * Initialize the virtual manager to manage the virtual state
228
	 * 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
229
	 * is VIRTUAL. If not use the default no-op version.
306
	 * version.
230
	 * 
307
	 * @param style
231
	 * @param style
308
	 */
232
	 */
309
	private void initializeVirtualManager(int style) {
233
	private void initializeVirtualManager(int style) {
310
		if((style & SWT.VIRTUAL) == 0) {
234
		if ((style & SWT.VIRTUAL) == 0) {
311
			return;
235
			return;
312
		}
236
		}
313
			
237
314
		virtualManager = new VirtualManager();	
238
		virtualManager = new VirtualManager();
315
	}
239
	}
316
240
317
	/**
241
	/**
Lines 330-336 Link Here
330
	public void add(Object[] elements) {
254
	public void add(Object[] elements) {
331
		assertElementsNotNull(elements);
255
		assertElementsNotNull(elements);
332
		Object[] filtered = filter(elements);
256
		Object[] filtered = filter(elements);
333
		
257
334
		for (int i = 0; i < filtered.length; i++) {
258
		for (int i = 0; i < filtered.length; i++) {
335
			Object element = filtered[i];
259
			Object element = filtered[i];
336
			int index = indexForElement(element);
260
			int index = indexForElement(element);
Lines 340-356 Link Here
340
264
341
	/**
265
	/**
342
	 * Create a new TableItem at index if required.
266
	 * Create a new TableItem at index if required.
267
	 * 
343
	 * @param element
268
	 * @param element
344
	 * @param index
269
	 * @param index
345
	 * 
270
	 * 
346
	 * @since 3.1
271
	 * @since 3.1
347
	 */
272
	 */
348
	private void createItem(Object element, int index) {
273
	private void createItem(Object element, int index) {
349
		if(virtualManager == null) {
274
		if (virtualManager == null) {
350
			updateItem(new TableItem(getTable(), SWT.NONE, index), element);
275
			updateItem(createNewRowPart(null, SWT.NONE, index).getItem(), element);
351
		} else{
276
		} else {
352
			virtualManager.notVisibleAdded(element,index);
277
			virtualManager.notVisibleAdded(element, index);
353
			
278
354
		}
279
		}
355
	}
280
	}
356
281
Lines 382-388 Link Here
382
	}
307
	}
383
308
384
	/*
309
	/*
385
	 *  (non-Javadoc)
310
	 * (non-Javadoc)
311
	 * 
386
	 * @see org.eclipse.jface.viewers.StructuredViewer#doFindInputItem(java.lang.Object)
312
	 * @see org.eclipse.jface.viewers.StructuredViewer#doFindInputItem(java.lang.Object)
387
	 */
313
	 */
388
	protected Widget doFindInputItem(Object element) {
314
	protected Widget doFindInputItem(Object element) {
Lines 393-403 Link Here
393
	}
319
	}
394
320
395
	/*
321
	/*
396
	 *  (non-Javadoc)
322
	 * (non-Javadoc)
323
	 * 
397
	 * @see org.eclipse.jface.viewers.StructuredViewer#doFindItem(java.lang.Object)
324
	 * @see org.eclipse.jface.viewers.StructuredViewer#doFindItem(java.lang.Object)
398
	 */
325
	 */
399
	protected Widget doFindItem(Object element) {
326
	protected Widget doFindItem(Object element) {
400
		
327
401
		TableItem[] children = table.getItems();
328
		TableItem[] children = table.getItems();
402
		for (int i = 0; i < children.length; i++) {
329
		for (int i = 0; i < children.length; i++) {
403
			TableItem item = children[i];
330
			TableItem item = children[i];
Lines 411-418 Link Here
411
	}
338
	}
412
339
413
	/*
340
	/*
414
	 *  (non-Javadoc)
341
	 * (non-Javadoc)
415
	 * @see org.eclipse.jface.viewers.StructuredViewer#doUpdateItem(org.eclipse.swt.widgets.Widget, java.lang.Object, boolean)
342
	 * 
343
	 * @see org.eclipse.jface.viewers.StructuredViewer#doUpdateItem(org.eclipse.swt.widgets.Widget,
344
	 *      java.lang.Object, boolean)
416
	 */
345
	 */
417
	protected void doUpdateItem(Widget widget, Object element, boolean fullMap) {
346
	protected void doUpdateItem(Widget widget, Object element, boolean fullMap) {
418
		if (widget instanceof TableItem) {
347
		if (widget instanceof TableItem) {
Lines 422-506 Link Here
422
			if (fullMap) {
351
			if (fullMap) {
423
				associate(element, item);
352
				associate(element, item);
424
			} else {
353
			} else {
425
            	Object data = item.getData();
354
				Object data = item.getData();
426
            	if (data != null) {
355
				if (data != null) {
427
            		unmapElement(data, item);
356
					unmapElement(data, item);
428
            	}
357
				}
429
				item.setData(element);
358
				item.setData(element);
430
				mapElement(element, item);
359
				mapElement(element, item);
431
			}
360
			}
432
361
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();
362
			int columnCount = table.getColumnCount();
451
			TableItem ti = item;
363
			if(columnCount == 0)
452
			getColorAndFontCollector().setFontsAndColors(element);
364
				columnCount = 1;//If there are no columns do the first one 
453
			
365
454
			// Also enter loop if no columns added. See 1G9WWGZ: JFUIF:WINNT -
366
			// Also enter loop if no columns added. See 1G9WWGZ: JFUIF:WINNT -
455
			// TableViewer with 0 columns does not work
367
			// TableViewer with 0 columns does not work
456
			for (int column = 0; column < columnCount || column == 0; column++) {
368
			for (int column = 0; column < columnCount || column == 0; column++) {
457
				// Similar code in TreeViewer.doUpdateItem()
369
				ColumnViewerPart columnViewer = getColumnViewer(column);
458
				String text = "";//$NON-NLS-1$
370
				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
371
490
				//Avoid setting text to null
372
				// As it is possible for user code to run the event
491
				if (text == null) {
373
				// loop check here.
492
					text = ""; //$NON-NLS-1$
374
				if (item.isDisposed()) {
493
				}
375
					unmapElement(element, item);
494
				ti.setText(column, text);
376
					return;
495
				if (ti.getImage(column) != image) {
496
					ti.setImage(column, image);
497
				}
377
				}
378
498
			}
379
			}
499
			
380
500
			
381
		}
501
			getColorAndFontCollector().applyFontsAndColors(ti);
382
	}
383
384
	protected Widget getColumnViewerOwner(int columnIndex) {
385
		if( columnIndex < 0 || columnIndex > getTable().getColumnCount() ) {
386
			return null;
502
		}
387
		}
388
		
389
		if (getTable().getColumnCount() == 0)// Hang it off the table if it
390
			return getTable();
391
		
392
		
393
		return getTable().getColumn(columnIndex);
503
	}
394
	}
395
	
396
	/**
397
	 * Set the TableColumnViewerPart at columnIndex to be viewerPart.
398
	 * 
399
	 * @param viewerPart
400
	 * @param columnIndex
401
	 */
402
	public void setColumnPart(ColumnViewerPart viewerPart, int columnIndex) {
403
		TableColumn column = getTable().getColumn(columnIndex);
404
		column.setData(ColumnViewerPart.COLUMN_VIEWER_KEY, viewerPart);
405
	}
406
504
407
505
	/**
408
	/**
506
	 * Starts editing the given element.
409
	 * Starts editing the given element.
Lines 544-550 Link Here
544
	}
447
	}
545
448
546
	/*
449
	/*
547
	 *  (non-Javadoc)
450
	 * (non-Javadoc)
451
	 * 
548
	 * @see org.eclipse.jface.viewers.Viewer#getControl()
452
	 * @see org.eclipse.jface.viewers.Viewer#getControl()
549
	 */
453
	 */
550
	public Control getControl() {
454
	public Control getControl() {
Lines 588-598 Link Here
588
	}
492
	}
589
493
590
	/*
494
	/*
591
	 *  (non-Javadoc)
495
	 * (non-Javadoc)
496
	 * 
592
	 * @see org.eclipse.jface.viewers.StructuredViewer#getSelectionFromWidget()
497
	 * @see org.eclipse.jface.viewers.StructuredViewer#getSelectionFromWidget()
593
	 */
498
	 */
594
	protected List getSelectionFromWidget() {
499
	protected List getSelectionFromWidget() {
595
		if(virtualManager != null) {
500
		if (virtualManager != null) {
596
			return getVirtualSelection();
501
			return getVirtualSelection();
597
		}
502
		}
598
		Widget[] items = table.getSelection();
503
		Widget[] items = table.getSelection();
Lines 606-655 Link Here
606
		}
511
		}
607
		return list;
512
		return list;
608
	}
513
	}
609
	
514
610
	/**
515
	/**
611
	 * Get the virtual selection. Avoid calling SWT whenever possible
516
	 * Get the virtual selection. Avoid calling SWT whenever possible to prevent
612
	 * to prevent extra widget creation.
517
	 * extra widget creation.
518
	 * 
613
	 * @return List of Object
519
	 * @return List of Object
614
	 */
520
	 */
615
521
616
	private List getVirtualSelection() {
522
	private List getVirtualSelection() {
617
		
523
618
		List result = new ArrayList();
524
		List result = new ArrayList();
619
		int[] selectionIndices = getTable().getSelectionIndices(); 
525
		int[] selectionIndices = getTable().getSelectionIndices();
620
		if(getContentProvider() instanceof ILazyContentProvider){
526
		if (getContentProvider() instanceof ILazyContentProvider) {
621
			ILazyContentProvider lazy = (ILazyContentProvider) getContentProvider();
527
			ILazyContentProvider lazy = (ILazyContentProvider) getContentProvider();
622
			for (int i = 0; i < selectionIndices.length; i++) {
528
			for (int i = 0; i < selectionIndices.length; i++) {
623
				int selectionIndex = selectionIndices[i];
529
				int selectionIndex = selectionIndices[i];
624
				lazy.updateElement(selectionIndex);//Start the update
530
				lazy.updateElement(selectionIndex);// Start the update
625
				Object element = getTable().getItem(selectionIndex).getData();
531
				Object element = getTable().getItem(selectionIndex).getData();
626
				//Only add the element if it got updated.
532
				// Only add the element if it got updated.
627
				//If this is done deferred the selection will
533
				// If this is done deferred the selection will
628
				//be incomplete until selection is finished.
534
				// be incomplete until selection is finished.
629
				if (element != null) {
535
				if (element != null) {
630
					result.add(element);
536
					result.add(element);
631
				}				
537
				}
632
			}
538
			}
633
		}
539
		} else {
634
		else{
635
			for (int i = 0; i < selectionIndices.length; i++) {
540
			for (int i = 0; i < selectionIndices.length; i++) {
636
				Object element = null;
541
				Object element = null;
637
				//See if it is cached
542
				// See if it is cached
638
				int selectionIndex = selectionIndices[i];
543
				int selectionIndex = selectionIndices[i];
639
				if (selectionIndex < virtualManager.cachedElements.length){
544
				if (selectionIndex < virtualManager.cachedElements.length) {
640
					element = virtualManager.cachedElements[selectionIndex];
545
					element = virtualManager.cachedElements[selectionIndex];
641
				}
546
				}
642
				if (element == null){
547
				if (element == null) {
643
					// Not cached so try the item's data
548
					// Not cached so try the item's data
644
					TableItem item = getTable().getItem(selectionIndex);
549
					TableItem item = getTable().getItem(selectionIndex);
645
					element = item.getData();
550
					element = item.getData();
646
				}
551
				}
647
				if (element != null) {
552
				if (element != null) {
648
					result.add(element);
553
					result.add(element);
649
				}				
554
				}
650
			}
555
			}
651
			
556
652
			
653
		}
557
		}
654
		return result;
558
		return result;
655
	}
559
	}
Lines 664-670 Link Here
664
	}
568
	}
665
569
666
	/*
570
	/*
667
	 *  (non-Javadoc)
571
	 * (non-Javadoc)
572
	 * 
668
	 * @see org.eclipse.jface.viewers.ContentViewer#hookControl(org.eclipse.swt.widgets.Control)
573
	 * @see org.eclipse.jface.viewers.ContentViewer#hookControl(org.eclipse.swt.widgets.Control)
669
	 */
574
	 */
670
	protected void hookControl(Control control) {
575
	protected void hookControl(Control control) {
Lines 757-764 Link Here
757
	}
662
	}
758
663
759
	/*
664
	/*
760
	 *  (non-Javadoc)
665
	 * (non-Javadoc)
761
	 * @see org.eclipse.jface.viewers.Viewer#inputChanged(java.lang.Object, java.lang.Object)
666
	 * 
667
	 * @see org.eclipse.jface.viewers.Viewer#inputChanged(java.lang.Object,
668
	 *      java.lang.Object)
762
	 */
669
	 */
763
	protected void inputChanged(Object input, Object oldInput) {
670
	protected void inputChanged(Object input, Object oldInput) {
764
		getControl().setRedraw(false);
671
		getControl().setRedraw(false);
Lines 795-806 Link Here
795
		if (position == -1) {
702
		if (position == -1) {
796
			position = table.getItemCount();
703
			position = table.getItemCount();
797
		}
704
		}
798
		
705
799
		createItem(element,position);
706
		createItem(element, position);
800
	}
707
	}
801
708
802
	/*
709
	/*
803
	 *  (non-Javadoc)
710
	 * (non-Javadoc)
711
	 * 
804
	 * @see org.eclipse.jface.viewers.StructuredViewer#internalRefresh(java.lang.Object)
712
	 * @see org.eclipse.jface.viewers.StructuredViewer#internalRefresh(java.lang.Object)
805
	 */
713
	 */
806
	protected void internalRefresh(Object element) {
714
	protected void internalRefresh(Object element) {
Lines 808-822 Link Here
808
	}
716
	}
809
717
810
	/*
718
	/*
811
	 *  (non-Javadoc)
719
	 * (non-Javadoc)
812
	 * @see org.eclipse.jface.viewers.StructuredViewer#internalRefresh(java.lang.Object, boolean)
720
	 * 
721
	 * @see org.eclipse.jface.viewers.StructuredViewer#internalRefresh(java.lang.Object,
722
	 *      boolean)
813
	 */
723
	 */
814
	protected void internalRefresh(Object element, boolean updateLabels) {
724
	protected void internalRefresh(Object element, boolean updateLabels) {
815
		tableViewerImpl.applyEditorValue();
725
		tableViewerImpl.applyEditorValue();
816
		if (element == null || equals(element, getRoot())) {
726
		if (element == null || equals(element, getRoot())) {
817
			if(virtualManager == null) {
727
			if (virtualManager == null) {
818
				internalRefreshAll(updateLabels);
728
				internalRefreshAll(updateLabels);
819
			} else{
729
			} else {
820
				internalVirtualRefreshAll();
730
				internalVirtualRefreshAll();
821
			}
731
			}
822
		} else {
732
		} else {
Lines 833-849 Link Here
833
	 * @since 3.1
743
	 * @since 3.1
834
	 */
744
	 */
835
	private void internalVirtualRefreshAll() {
745
	private void internalVirtualRefreshAll() {
836
		
746
837
		Object root = getRoot();
747
		Object root = getRoot();
838
		IContentProvider contentProvider = getContentProvider();
748
		IContentProvider contentProvider = getContentProvider();
839
		
749
840
		//Invalidate for lazy
750
		// Invalidate for lazy
841
		if(!(contentProvider instanceof ILazyContentProvider) 
751
		if (!(contentProvider instanceof ILazyContentProvider)
842
				&& (contentProvider instanceof IStructuredContentProvider)) {
752
				&& (contentProvider instanceof IStructuredContentProvider)) {
843
			//Don't cache if the root is null but cache if it is not lazy.
753
			// Don't cache if the root is null but cache if it is not lazy.
844
			if(root != null){
754
			if (root != null) {
845
				virtualManager.cachedElements = 
755
				virtualManager.cachedElements = ((IStructuredContentProvider) getContentProvider())
846
					((IStructuredContentProvider) getContentProvider()).getElements(root);
756
						.getElements(root);
847
				getTable().setItemCount(virtualManager.cachedElements.length);
757
				getTable().setItemCount(virtualManager.cachedElements.length);
848
			}
758
			}
849
		}
759
		}
Lines 851-858 Link Here
851
	}
761
	}
852
762
853
	/**
763
	/**
854
	 * Refresh all of the elements of the table. update the
764
	 * Refresh all of the elements of the table. update the labels if
855
	 * labels if updatLabels is true;
765
	 * updatLabels is true;
766
	 * 
856
	 * @param updateLabels
767
	 * @param updateLabels
857
	 * 
768
	 * 
858
	 * @since 3.1
769
	 * @since 3.1
Lines 871-880 Link Here
871
		TableItem[] items = getTable().getItems();
782
		TableItem[] items = getTable().getItems();
872
		int min = Math.min(children.length, items.length);
783
		int min = Math.min(children.length, items.length);
873
		for (int i = 0; i < min; ++i) {
784
		for (int i = 0; i < min; ++i) {
874
			
785
875
			
876
			TableItem item = items[i];
786
			TableItem item = items[i];
877
				
787
878
			// if the element is unchanged, update its label if appropriate
788
			// if the element is unchanged, update its label if appropriate
879
			if (equals(children[i], item.getData())) {
789
			if (equals(children[i], item.getData())) {
880
				if (updateLabels) {
790
				if (updateLabels) {
Lines 893-906 Link Here
893
				// So, if the object associated with this item has changed,
803
				// So, if the object associated with this item has changed,
894
				// just disassociate it for now, and update it below.
804
				// just disassociate it for now, and update it below.
895
				item.setText(""); //$NON-NLS-1$
805
				item.setText(""); //$NON-NLS-1$
896
				item.setImage(new Image[Math.max(1,table.getColumnCount())]);//Clear all images
806
				item.setImage(new Image[Math.max(1, table.getColumnCount())]);// Clear
807
				// all
808
				// images
897
				disassociate(item);
809
				disassociate(item);
898
			}
810
			}
899
		}
811
		}
900
		// dispose of all items beyond the end of the current elements
812
		// dispose of all items beyond the end of the current elements
901
		if (min < items.length) {
813
		if (min < items.length) {
902
			for (int i = items.length; --i >= min;) {
814
			for (int i = items.length; --i >= min;) {
903
				
815
904
				disassociate(items[i]);
816
				disassociate(items[i]);
905
			}
817
			}
906
			table.remove(min, items.length - 1);
818
			table.remove(min, items.length - 1);
Lines 912-918 Link Here
912
		}
824
		}
913
		// Update items which were removed above
825
		// Update items which were removed above
914
		for (int i = 0; i < min; ++i) {
826
		for (int i = 0; i < min; ++i) {
915
							
827
916
			TableItem item = items[i];
828
			TableItem item = items[i];
917
			if (item.getData() == null) {
829
			if (item.getData() == null) {
918
				updateItem(item, children[i]);
830
				updateItem(item, children[i]);
Lines 920-930 Link Here
920
		}
832
		}
921
		// add any remaining elements
833
		// add any remaining elements
922
		for (int i = min; i < children.length; ++i) {
834
		for (int i = min; i < children.length; ++i) {
923
			createItem(children[i],i);
835
			createItem(children[i], i);
924
		}
836
		}
925
	}
837
	}
926
838
927
928
	/**
839
	/**
929
	 * Removes the given elements from this table viewer.
840
	 * Removes the given elements from this table viewer.
930
	 * 
841
	 * 
Lines 987-995 Link Here
987
	 */
898
	 */
988
	public void remove(final Object[] elements) {
899
	public void remove(final Object[] elements) {
989
		assertElementsNotNull(elements);
900
		assertElementsNotNull(elements);
990
        if (elements.length == 0) {
901
		if (elements.length == 0) {
991
        	return;
902
			return;
992
        }
903
		}
993
		preservingSelection(new Runnable() {
904
		preservingSelection(new Runnable() {
994
			public void run() {
905
			public void run() {
995
				internalRemove(elements);
906
				internalRemove(elements);
Lines 1007-1014 Link Here
1007
	 * the model. Note that there is another method for efficiently processing
918
	 * the model. Note that there is another method for efficiently processing
1008
	 * the simultaneous removal of multiple elements.
919
	 * the simultaneous removal of multiple elements.
1009
	 * </p>
920
	 * </p>
1010
	 * <strong>NOTE:</strong> removing an object from a virtual
921
	 * <strong>NOTE:</strong> removing an object from a virtual table will
1011
	 * table will decrement the itemCount.
922
	 * decrement the itemCount.
1012
	 * 
923
	 * 
1013
	 * @param element
924
	 * @param element
1014
	 *            the element
925
	 *            the element
Lines 1018-1024 Link Here
1018
	}
929
	}
1019
930
1020
	/*
931
	/*
1021
	 *  (non-Javadoc)
932
	 * (non-Javadoc)
933
	 * 
1022
	 * @see org.eclipse.jface.viewers.StructuredViewer#reveal(java.lang.Object)
934
	 * @see org.eclipse.jface.viewers.StructuredViewer#reveal(java.lang.Object)
1023
	 */
935
	 */
1024
	public void reveal(Object element) {
936
	public void reveal(Object element) {
Lines 1079-1112 Link Here
1079
	 * may also implement {@link IColorProvider} and/or {@link IFontProvider} to
991
	 * may also implement {@link IColorProvider} and/or {@link IFontProvider} to
1080
	 * provide colors and/or fonts.
992
	 * provide colors and/or fonts.
1081
	 * </p>
993
	 * </p>
994
	 * <p>
995
	 * If the label provider implements the mixin interface ITooltipProvider, it
996
	 * can provide custom tooltips.
997
	 * </p>
1082
	 */
998
	 */
1083
	public void setLabelProvider(IBaseLabelProvider labelProvider) {
999
	public void setLabelProvider(IBaseLabelProvider labelProvider) {
1084
		Assert.isTrue(labelProvider instanceof ITableLabelProvider
1000
		Assert.isTrue(labelProvider instanceof ITableLabelProvider
1085
				|| labelProvider instanceof ILabelProvider);
1001
				|| labelProvider instanceof ILabelProvider);
1002
		clearColumnParts();//Clear before refresh
1086
		super.setLabelProvider(labelProvider);
1003
		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
	}
1004
	}
1094
	
1005
	
1095
	/**
1006
	/**
1007
	 * Clear the viewer parts for the columns
1008
	 */
1009
	private void clearColumnParts() {
1010
		TableColumn[] columns = getTable().getColumns();
1011
		if(columns.length == 0)
1012
			getTable().setData(ColumnViewerPart.COLUMN_VIEWER_KEY,null);
1013
		else{
1014
			for (int i = 0; i < columns.length; i++) {
1015
				columns[i].setData(ColumnViewerPart.COLUMN_VIEWER_KEY,null);
1016
				
1017
			}
1018
		}
1019
		
1020
	}
1021
1022
	/**
1096
	 * <p>
1023
	 * <p>
1097
	 * Sets a new selection for this viewer and optionally makes it visible.
1024
	 * Sets a new selection for this viewer and optionally makes it visible. The
1098
	 * The TableViewer implmentation of this method is ineffecient for the
1025
	 * TableViewer implmentation of this method is ineffecient for the
1099
	 * ILazyContentProvider as lookup is done by indices rather than elements
1026
	 * ILazyContentProvider as lookup is done by indices rather than elements
1100
	 * and may require population of the entire table in worse case. 
1027
	 * and may require population of the entire table in worse case.
1101
	 * </p>
1028
	 * </p>
1102
	 * <p>
1029
	 * <p>
1103
	 * Use Table#setSelection(int[] indices) and Table#showSelection() if
1030
	 * Use Table#setSelection(int[] indices) and Table#showSelection() if you
1104
	 * you wish to set selection more effeciently when using a ILazyContentProvider.
1031
	 * wish to set selection more effeciently when using a ILazyContentProvider.
1105
	 * </p>
1032
	 * </p>
1106
	 * 
1033
	 * 
1107
	 * @param selection the new selection
1034
	 * @param selection
1108
     * @param reveal <code>true</code> if the selection is to be made
1035
	 *            the new selection
1109
     *   visible, and <code>false</code> otherwise
1036
	 * @param reveal
1037
	 *            <code>true</code> if the selection is to be made visible,
1038
	 *            and <code>false</code> otherwise
1110
	 * @see Table#setSelection(int[])
1039
	 * @see Table#setSelection(int[])
1111
	 * @see Table#showSelection()
1040
	 * @see Table#showSelection()
1112
	 */
1041
	 */
Lines 1115-1135 Link Here
1115
	}
1044
	}
1116
1045
1117
	/*
1046
	/*
1118
	 *  (non-Javadoc)
1047
	 * (non-Javadoc)
1119
	 * @see org.eclipse.jface.viewers.StructuredViewer#setSelectionToWidget(java.util.List, boolean)
1048
	 * 
1049
	 * @see org.eclipse.jface.viewers.StructuredViewer#setSelectionToWidget(java.util.List,
1050
	 *      boolean)
1120
	 */
1051
	 */
1121
	protected void setSelectionToWidget(List list, boolean reveal) {
1052
	protected void setSelectionToWidget(List list, boolean reveal) {
1122
		
1053
1123
		if (list == null) {
1054
		if (list == null) {
1124
			table.deselectAll();
1055
			table.deselectAll();
1125
			return;
1056
			return;
1126
		}
1057
		}
1127
		
1058
1128
		if(virtualManager != null){
1059
		if (virtualManager != null) {
1129
			virtualSetSelectionToWidget(list, reveal);
1060
			virtualSetSelectionToWidget(list, reveal);
1130
			return;
1061
			return;
1131
		}
1062
		}
1132
		
1063
1133
		int size = list.size();
1064
		int size = list.size();
1134
		TableItem[] items = new TableItem[size];
1065
		TableItem[] items = new TableItem[size];
1135
		int count = 0;
1066
		int count = 0;
Lines 1149-1170 Link Here
1149
		if (reveal) {
1080
		if (reveal) {
1150
			table.showSelection();
1081
			table.showSelection();
1151
		}
1082
		}
1152
			
1083
1153
	}
1084
	}
1154
	
1085
1155
	
1156
	/**
1086
	/**
1157
	 * Set the selection on a virtual table
1087
	 * Set the selection on a virtual table
1158
	 * @param list The elements to set
1088
	 * 
1159
	 * @param reveal Whether or not reveal the first item.
1089
	 * @param list
1090
	 *            The elements to set
1091
	 * @param reveal
1092
	 *            Whether or not reveal the first item.
1160
	 */
1093
	 */
1161
	private void virtualSetSelectionToWidget(List list, boolean reveal) {
1094
	private void virtualSetSelectionToWidget(List list, boolean reveal) {
1162
		int size = list.size();
1095
		int size = list.size();
1163
		int[] indices = new int[list.size()];
1096
		int[] indices = new int[list.size()];
1164
		
1097
1165
		TableItem firstItem = null;
1098
		TableItem firstItem = null;
1166
		int count = 0;
1099
		int count = 0;
1167
		HashSet virtualElements = new HashSet(); 
1100
		HashSet virtualElements = new HashSet();
1168
		for (int i = 0; i < size; ++i) {
1101
		for (int i = 0; i < size; ++i) {
1169
			Object o = list.get(i);
1102
			Object o = list.get(i);
1170
			Widget w = findItem(o);
1103
			Widget w = findItem(o);
Lines 1178-1214 Link Here
1178
				virtualElements.add(o);
1111
				virtualElements.add(o);
1179
			}
1112
			}
1180
		}
1113
		}
1181
		
1114
1182
		if(getContentProvider() instanceof ILazyContentProvider){
1115
		if (getContentProvider() instanceof ILazyContentProvider) {
1183
			ILazyContentProvider provider = 
1116
			ILazyContentProvider provider = (ILazyContentProvider) getContentProvider();
1184
				(ILazyContentProvider) getContentProvider();
1117
1185
		
1118
			// 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
1119
			// virtual
1187
			//This may create all items so it is not a good
1120
			// This may create all items so it is not a good
1188
			//idea in general.
1121
			// idea in general.
1189
			//Use #setSelection (int [] indices,boolean reveal) instead
1122
			// Use #setSelection (int [] indices,boolean reveal) instead
1190
			for (int i = 0; virtualElements.size() > 0 && i < getTable().getItemCount(); i++) {
1123
			for (int i = 0; virtualElements.size() > 0
1124
					&& i < getTable().getItemCount(); i++) {
1191
				provider.updateElement(i);
1125
				provider.updateElement(i);
1192
				TableItem item = getTable().getItem(i);
1126
				TableItem item = getTable().getItem(i);
1193
				if(virtualElements.contains(item.getData())){
1127
				if (virtualElements.contains(item.getData())) {
1194
					indices[count++] = i;	
1128
					indices[count++] = i;
1195
					virtualElements.remove(item.getData());
1129
					virtualElements.remove(item.getData());
1196
					if (firstItem == null) {
1130
					if (firstItem == null) {
1197
						firstItem = item;
1131
						firstItem = item;
1198
					}
1132
					}
1199
				}
1133
				}
1200
			}
1134
			}
1201
		}
1135
		} else {
1202
		else{
1136
1203
			
1137
			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
1138
				// have been found
1205
				//If it is not lazy we can use the cache
1139
				// If it is not lazy we can use the cache
1206
				for (int i = 0; i < virtualManager.cachedElements.length; i++) {
1140
				for (int i = 0; i < virtualManager.cachedElements.length; i++) {
1207
					Object element = virtualManager.cachedElements[i];
1141
					Object element = virtualManager.cachedElements[i];
1208
					if(virtualElements.contains(element)){
1142
					if (virtualElements.contains(element)) {
1209
						TableItem item = getTable().getItem(i);
1143
						TableItem item = getTable().getItem(i);
1210
						item.getText();//Be sure to fire the update
1144
						item.getText();// Be sure to fire the update
1211
						indices[count++] = i;	
1145
						indices[count++] = i;
1212
						virtualElements.remove(element);
1146
						virtualElements.remove(element);
1213
						if (firstItem == null) {
1147
						if (firstItem == null) {
1214
							firstItem = item;
1148
							firstItem = item;
Lines 1217-1223 Link Here
1217
				}
1151
				}
1218
			}
1152
			}
1219
		}
1153
		}
1220
		
1154
1221
		if (count < size) {
1155
		if (count < size) {
1222
			System.arraycopy(indices, 0, indices = new int[count], 0, count);
1156
			System.arraycopy(indices, 0, indices = new int[count], 0, count);
1223
		}
1157
		}
Lines 1230-1264 Link Here
1230
1164
1231
	/**
1165
	/**
1232
	 * Set the item count of the receiver.
1166
	 * Set the item count of the receiver.
1233
	 * @param count the new table size.
1167
	 * 
1168
	 * @param count
1169
	 *            the new table size.
1234
	 * 
1170
	 * 
1235
	 * @since 3.1
1171
	 * @since 3.1
1236
	 */
1172
	 */
1237
	public void setItemCount(int count){
1173
	public void setItemCount(int count) {
1238
		getTable().setItemCount(count);
1174
		getTable().setItemCount(count);
1239
		getTable().redraw();
1175
		getTable().redraw();
1240
	}
1176
	}
1241
	
1177
1242
	/**
1178
	/**
1243
	 * Replace the entries starting at index with elements.
1179
	 * Replace the entries starting at index with elements. This method assumes
1244
	 * This method assumes all of these values are correct
1180
	 * all of these values are correct and will not call the content provider to
1245
	 * and will not call the content provider to verify.
1181
	 * verify. <strong>Note that this method will create a TableItem for all of
1246
	 * <strong>Note that this method will create a TableItem
1182
	 * the elements provided</strong>.
1247
	 * for all of the elements provided</strong>.
1183
	 * 
1248
	 * @param element
1184
	 * @param element
1249
	 * @param index
1185
	 * @param index
1250
	 * @see ILazyContentProvider
1186
	 * @see ILazyContentProvider
1251
	 * 
1187
	 * 
1252
	 * @since 3.1
1188
	 * @since 3.1
1253
	 */
1189
	 */
1254
	public void replace(Object element, int index){
1190
	public void replace(Object element, int index) {
1255
		TableItem item = getTable().getItem(index);
1191
		TableItem item = getTable().getItem(index);
1256
		refreshItem(item, element);
1192
		refreshItem(item, element);
1257
	}
1193
	}
1258
1194
1259
	/**
1195
	/**
1260
	 * Clear the table item at the specified index
1196
	 * Clear the table item at the specified index
1261
	 * @param index the index of the table item to be cleared
1197
	 * 
1198
	 * @param index
1199
	 *            the index of the table item to be cleared
1262
	 * 
1200
	 * 
1263
	 * @since 3.1
1201
	 * @since 3.1
1264
	 */
1202
	 */
Lines 1269-1294 Link Here
1269
		}
1207
		}
1270
		table.clear(index);
1208
		table.clear(index);
1271
	}
1209
	}
1272
	
1210
1273
	/* (non-Javadoc)
1211
	/*
1212
	 * (non-Javadoc)
1213
	 * 
1274
	 * @see org.eclipse.jface.viewers.StructuredViewer#getRawChildren(java.lang.Object)
1214
	 * @see org.eclipse.jface.viewers.StructuredViewer#getRawChildren(java.lang.Object)
1275
	 */
1215
	 */
1276
	protected Object[] getRawChildren(Object parent) {
1216
	protected Object[] getRawChildren(Object parent) {
1277
1217
1278
		Assert.isTrue(!(getContentProvider() instanceof ILazyContentProvider),"Cannot get raw children with an ILazyContentProvider");//$NON-NLS-1$
1218
		Assert.isTrue(!(getContentProvider() instanceof ILazyContentProvider),
1219
				"Cannot get raw children with an ILazyContentProvider");//$NON-NLS-1$
1279
		return super.getRawChildren(parent);
1220
		return super.getRawChildren(parent);
1280
	
1221
1281
	}
1222
	}
1282
	
1223
1283
	/* (non-Javadoc)
1224
	/*
1225
	 * (non-Javadoc)
1226
	 * 
1284
	 * @see org.eclipse.jface.viewers.StructuredViewer#assertContentProviderType(org.eclipse.jface.viewers.IContentProvider)
1227
	 * @see org.eclipse.jface.viewers.StructuredViewer#assertContentProviderType(org.eclipse.jface.viewers.IContentProvider)
1285
	 */
1228
	 */
1286
	protected void assertContentProviderType(IContentProvider provider) {
1229
	protected void assertContentProviderType(IContentProvider provider) {
1287
		Assert.isTrue(provider instanceof IStructuredContentProvider ||
1230
		Assert.isTrue(provider instanceof IStructuredContentProvider
1288
				provider instanceof ILazyContentProvider);
1231
				|| provider instanceof ILazyContentProvider);
1289
	}
1232
	}
1290
	
1233
	
1234
	protected RowPart getRowPartFromItem(Widget item) {
1235
		RowPart part = (RowPart)item.getData(RowPart.ROWPART_KEY);
1236
		
1237
		if( part == null ) {
1238
			part = new TableRowPart(((TableItem)item));
1239
			part.associate();
1240
		}
1241
		
1242
		return part;
1243
	}
1244
		
1245
	protected RowPart createNewRowPart(RowPart parent, int style, int rowIndex) {
1246
		TableItem item;
1247
		
1248
		if( rowIndex >= 0 ) {
1249
			item = new TableItem(table,SWT.NONE,rowIndex);
1250
		} else {
1251
			item = new TableItem(table,SWT.NONE);
1252
		}
1253
		
1254
		return getRowPartFromItem(item);
1255
	}
1291
	
1256
	
1257
	public Item getItem(int x, int y) {
1258
		return table.getItem(new Point(x,y));
1259
	}
1292
	
1260
	
1261
	protected ColumnViewerPart createColumnViewer(Widget columnOwner, ViewerLabelProvider labelProvider) {
1262
		if( columnOwner instanceof TableColumn ) {
1263
			return new TableColumnViewerPart((TableColumn)columnOwner,labelProvider);
1264
		}
1265
		
1266
		return super.createColumnViewer(columnOwner, labelProvider);
1267
	}
1293
}
1268
}
1294
(-)src/org/eclipse/jface/viewers/TreeViewer.java (-323 / +243 lines)
Lines 14-19 Link Here
14
import java.util.Iterator;
14
import java.util.Iterator;
15
import java.util.List;
15
import java.util.List;
16
16
17
import org.eclipse.jface.internal.viewers.RowPart;
17
import org.eclipse.jface.util.Assert;
18
import org.eclipse.jface.util.Assert;
18
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.custom.TreeEditor;
20
import org.eclipse.swt.custom.TreeEditor;
Lines 22-28 Link Here
22
import org.eclipse.swt.events.MouseAdapter;
23
import org.eclipse.swt.events.MouseAdapter;
23
import org.eclipse.swt.events.MouseEvent;
24
import org.eclipse.swt.events.MouseEvent;
24
import org.eclipse.swt.events.TreeListener;
25
import org.eclipse.swt.events.TreeListener;
25
import org.eclipse.swt.graphics.Image;
26
import org.eclipse.swt.graphics.Point;
26
import org.eclipse.swt.graphics.Point;
27
import org.eclipse.swt.graphics.Rectangle;
27
import org.eclipse.swt.graphics.Rectangle;
28
import org.eclipse.swt.widgets.Composite;
28
import org.eclipse.swt.widgets.Composite;
Lines 55-123 Link Here
55
public class TreeViewer extends AbstractTreeViewer {
55
public class TreeViewer extends AbstractTreeViewer {
56
56
57
	/**
57
	/**
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.
58
	 * Internal tree viewer implementation.
122
	 */
59
	 */
123
	private TreeEditorImpl treeViewerImpl;
60
	private TreeEditorImpl treeViewerImpl;
Lines 133-143 Link Here
133
	private TreeEditor treeEditor;
70
	private TreeEditor treeEditor;
134
71
135
	/**
72
	/**
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.
73
	 * Flag for whether the tree has been disposed of.
142
	 */
74
	 */
143
	private boolean treeIsDisposed = false;
75
	private boolean treeIsDisposed = false;
Lines 207-213 Link Here
207
	 * (non-Javadoc) Method declared in AbstractTreeViewer.
139
	 * (non-Javadoc) Method declared in AbstractTreeViewer.
208
	 */
140
	 */
209
	protected void doUpdateItem(final Item item, Object element) {
141
	protected void doUpdateItem(final Item item, Object element) {
210
		if (!(item instanceof TreeItem)) {
142
 		if (!(item instanceof TreeItem)) {
211
			return;
143
			return;
212
		}
144
		}
213
		TreeItem treeItem = (TreeItem) item;
145
		TreeItem treeItem = (TreeItem) item;
Lines 216-331 Link Here
216
			return;
148
			return;
217
		}
149
		}
218
150
219
		getColorAndFontCollector().setFontsAndColors(element);
151
		int columnCount = getTree().getColumnCount();
220
152
		if(columnCount == 0)//If no columns are created then fake one
221
		IBaseLabelProvider prov = getLabelProvider();
153
			columnCount = 1;
222
		ITableLabelProvider tprov = null;
154
223
		ILabelProvider lprov = null;
155
		for (int column = 0; column < columnCount; column++) {
224
		IViewerLabelProvider vprov = null;
156
			ColumnViewerPart columnViewer = getColumnViewer(column);
225
		ITreePathLabelProvider pprov = null;
157
			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
158
262
			// As it is possible for user code to run the event
159
			// As it is possible for user code to run the event
263
			// loop check here.
160
			// loop check here.
264
			if (treeItem.isDisposed()) {
161
			if (item.isDisposed()) {
265
				unmapElement(element, treeItem);
162
				unmapElement(element, item);
266
				return;
163
				return;
267
			}
164
			}
268
165
269
			if (updateLabel.hasNewText()) {
166
		}
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
167
305
						text = updateLabel.getText();
168
	}
306
						image = updateLabel.getImage();
307
					}
308
				} else {
309
					text = tprov.getColumnText(element, column);
310
					image = tprov.getColumnImage(element, column);
311
				}
312
169
313
				// Avoid setting text to null
170
	protected Widget getColumnViewerOwner(int columnIndex) {
314
				if (text == null) {
171
		if( columnIndex < 0 || columnIndex > getTree().getColumnCount() ) {
315
					text = ""; //$NON-NLS-1$
172
			return null;
316
				}
317
				treeItem.setText(column, text);
318
				if (treeItem.getImage(column) != image) {
319
					treeItem.setImage(column, image);
320
				}
321
			}
322
			getColorAndFontCollector().applyFontsAndColors(treeItem);
323
		}
173
		}
174
		
175
		if (getTree().getColumnCount() == 0)// Hang it off the table if it
176
			return getTree();
177
		
178
		return getTree().getColumn(columnIndex);
324
	}
179
	}
325
	
180
326
	/**
181
	/**
327
	 * Override to handle tree paths.
182
	 * Override to handle tree paths.
328
	 * @see org.eclipse.jface.viewers.StructuredViewer#buildLabel(org.eclipse.jface.viewers.ViewerLabel, java.lang.Object)
183
	 * 
184
	 * @see org.eclipse.jface.viewers.StructuredViewer#buildLabel(org.eclipse.jface.viewers.ViewerLabel,
185
	 *      java.lang.Object)
329
	 */
186
	 */
330
	protected void buildLabel(ViewerLabel updateLabel, Object elementOrPath) {
187
	protected void buildLabel(ViewerLabel updateLabel, Object elementOrPath) {
331
		Object element;
188
		Object element;
Lines 463-469 Link Here
463
	protected Item getParentItem(Item item) {
320
	protected Item getParentItem(Item item) {
464
		return ((TreeItem) item).getParentItem();
321
		return ((TreeItem) item).getParentItem();
465
	}
322
	}
466
	
323
467
	/*
324
	/*
468
	 * (non-Javadoc) Method declared in AbstractTreeViewer.
325
	 * (non-Javadoc) Method declared in AbstractTreeViewer.
469
	 */
326
	 */
Lines 494-505 Link Here
494
			}
351
			}
495
		});
352
		});
496
		if ((treeControl.getStyle() & SWT.VIRTUAL) != 0) {
353
		if ((treeControl.getStyle() & SWT.VIRTUAL) != 0) {
497
			treeControl.addDisposeListener(new DisposeListener(){
354
			treeControl.addDisposeListener(new DisposeListener() {
498
				public void widgetDisposed(DisposeEvent e) {
355
				public void widgetDisposed(DisposeEvent e) {
499
					treeIsDisposed = true;
356
					treeIsDisposed = true;
500
					unmapAllElements();
357
					unmapAllElements();
501
				}});
358
				}
502
			treeControl.addListener(SWT.SetData, new Listener(){
359
			});
360
			treeControl.addListener(SWT.SetData, new Listener() {
503
361
504
				public void handleEvent(Event event) {
362
				public void handleEvent(Event event) {
505
					if (getContentProvider() instanceof ILazyTreeContentProvider) {
363
					if (getContentProvider() instanceof ILazyTreeContentProvider) {
Lines 582-600 Link Here
582
	 */
440
	 */
583
	protected Item newItem(Widget parent, int flags, int ix) {
441
	protected Item newItem(Widget parent, int flags, int ix) {
584
		TreeItem item;
442
		TreeItem item;
585
		if (ix >= 0) {
443
		
586
			if (parent instanceof TreeItem) {
444
		if (parent instanceof TreeItem) {
587
				item = new TreeItem((TreeItem) parent, flags, ix);
445
			item = (TreeItem)createNewRowPart(getRowPartFromItem(parent),flags, ix).getItem();
588
			} else {
589
				item = new TreeItem((Tree) parent, flags, ix);
590
			}
591
		} else {
446
		} else {
592
			if (parent instanceof TreeItem) {
447
			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
		}
448
		}
449
		
598
		return item;
450
		return item;
599
	}
451
	}
600
452
Lines 645-651 Link Here
645
	 */
497
	 */
646
	protected void setExpanded(Item node, boolean expand) {
498
	protected void setExpanded(Item node, boolean expand) {
647
		((TreeItem) node).setExpanded(expand);
499
		((TreeItem) node).setExpanded(expand);
648
		if(getContentProvider() instanceof ILazyTreeContentProvider) {
500
		if (getContentProvider() instanceof ILazyTreeContentProvider) {
649
			// force repaints to happen
501
			// force repaints to happen
650
			getControl().update();
502
			getControl().update();
651
		}
503
		}
Lines 661-667 Link Here
661
	 * <code>ITableLabelProvider</code> may also implement
513
	 * <code>ITableLabelProvider</code> may also implement
662
	 * {@link ITableColorProvider} and/or {@link ITableFontProvider} to provide
514
	 * {@link ITableColorProvider} and/or {@link ITableFontProvider} to provide
663
	 * colors and/or fonts. Note that the underlying {@link Tree} must be
515
	 * colors and/or fonts. Note that the underlying {@link Tree} must be
664
	 * configured with {@link TreeColumn} objects in this case. 
516
	 * configured with {@link TreeColumn} objects in this case.
665
	 * </p>
517
	 * </p>
666
	 * <p>
518
	 * <p>
667
	 * If the label provider is an <code>ILabelProvider</code>, then it
519
	 * If the label provider is an <code>ILabelProvider</code>, then it
Lines 674-681 Link Here
674
	public void setLabelProvider(IBaseLabelProvider labelProvider) {
526
	public void setLabelProvider(IBaseLabelProvider labelProvider) {
675
		Assert.isTrue(labelProvider instanceof ITableLabelProvider
527
		Assert.isTrue(labelProvider instanceof ITableLabelProvider
676
				|| labelProvider instanceof ILabelProvider);
528
				|| labelProvider instanceof ILabelProvider);
529
		clearColumnParts();//Clear before refresh
677
		super.setLabelProvider(labelProvider);
530
		super.setLabelProvider(labelProvider);
678
		treeColorAndFont = new TreeColorAndFontCollector(labelProvider);
531
		
532
	}
533
534
	/**
535
	 * Clear the viewer parts for the columns
536
	 */
537
	private void clearColumnParts() {
538
		TreeColumn[] columns = getTree().getColumns();
539
		if(columns.length == 0)
540
			getTree().setData(ColumnViewerPart.COLUMN_VIEWER_KEY,null);
541
		else{
542
			for (int i = 0; i < columns.length; i++) {
543
				columns[i].setData(ColumnViewerPart.COLUMN_VIEWER_KEY,null);
544
				
545
			}
546
		}
547
		
679
	}
548
	}
680
549
681
	/*
550
	/*
Lines 705-711 Link Here
705
	 *            the array of items
574
	 *            the array of items
706
	 * @return <code>true</code> if the refer to the same elements,
575
	 * @return <code>true</code> if the refer to the same elements,
707
	 *         <code>false</code> otherwise
576
	 *         <code>false</code> otherwise
708
	 *         
577
	 * 
709
	 * @since 3.1
578
	 * @since 3.1
710
	 */
579
	 */
711
	protected boolean isSameSelection(List items, Item[] current) {
580
	protected boolean isSameSelection(List items, Item[] current) {
Lines 725-731 Link Here
725
		// Go through the items of the current collection
594
		// Go through the items of the current collection
726
		// If there is a mismatch return false
595
		// If there is a mismatch return false
727
		for (int i = 0; i < current.length; i++) {
596
		for (int i = 0; i < current.length; i++) {
728
			if (current[i].getData() == null || !itemSet.containsKey(current[i].getData())) {
597
			if (current[i].getData() == null
598
					|| !itemSet.containsKey(current[i].getData())) {
729
				return false;
599
				return false;
730
			}
600
			}
731
		}
601
		}
Lines 740-748 Link Here
740
		getTree().showItem((TreeItem) item);
610
		getTree().showItem((TreeItem) item);
741
	}
611
	}
742
612
743
613
	/*
744
	/* (non-Javadoc)
614
	 * (non-Javadoc)
745
	 * @see org.eclipse.jface.viewers.AbstractTreeViewer#getChild(org.eclipse.swt.widgets.Widget, int)
615
	 * 
616
	 * @see org.eclipse.jface.viewers.AbstractTreeViewer#getChild(org.eclipse.swt.widgets.Widget,
617
	 *      int)
746
	 */
618
	 */
747
	protected Item getChild(Widget widget, int index) {
619
	protected Item getChild(Widget widget, int index) {
748
		if (widget instanceof TreeItem) {
620
		if (widget instanceof TreeItem) {
Lines 753-790 Link Here
753
		}
625
		}
754
		return null;
626
		return null;
755
	}
627
	}
756
	
628
757
	protected void assertContentProviderType(IContentProvider provider) {
629
	protected void assertContentProviderType(IContentProvider provider) {
758
		if(provider instanceof ILazyTreeContentProvider) {
630
		if (provider instanceof ILazyTreeContentProvider) {
759
			return;
631
			return;
760
		}
632
		}
761
		super.assertContentProviderType(provider);
633
		super.assertContentProviderType(provider);
762
	}
634
	}
763
	
635
764
    protected Object[] getRawChildren(Object parent) {
636
	protected Object[] getRawChildren(Object parent) {
765
    	if(getContentProvider() instanceof ILazyTreeContentProvider) {
637
		if (getContentProvider() instanceof ILazyTreeContentProvider) {
766
    		return new Object[0];
638
			return new Object[0];
767
    	}
639
		}
768
    	return super.getRawChildren(parent);
640
		return super.getRawChildren(parent);
769
    }
641
	}
770
642
771
    /**
643
	/**
772
     * For a TreeViewer with a tree with the VIRTUAL style bit set, set the
644
	 * 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
645
	 * 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
646
	 * the invisible root of the tree, the input object is passed as the
775
     * element.
647
	 * element.
776
     * 
648
	 * 
777
     * @param element
649
	 * @param element
778
     * @param count
650
	 * @param count
779
     * 
651
	 * 
780
	 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
652
	 * <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
653
	 * 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
654
	 * remain unchanged during the 3.2 release cycle. Please do not use this API
783
	 * consulting with the Platform/UI team.
655
	 * without consulting with the Platform/UI team.
784
	 * </p>
656
	 * </p>
785
     * 
657
	 * 
786
     * @since 3.2
658
	 * @since 3.2
787
     */
659
	 */
788
	public void setChildCount(Object element, int count) {
660
	public void setChildCount(Object element, int count) {
789
		Tree tree = (Tree) doFindInputItem(element);
661
		Tree tree = (Tree) doFindInputItem(element);
790
		if (tree != null) {
662
		if (tree != null) {
Lines 793-801 Link Here
793
		}
665
		}
794
		Widget[] items = findItems(element);
666
		Widget[] items = findItems(element);
795
		for (int i = 0; i < items.length; i++) {
667
		for (int i = 0; i < items.length; i++) {
796
			TreeItem treeItem = (TreeItem)items[i];
668
			TreeItem treeItem = (TreeItem) items[i];
797
			treeItem.setItemCount(count);
669
			treeItem.setItemCount(count);
798
		}		
670
		}
799
	}
671
	}
800
672
801
	/**
673
	/**
Lines 807-829 Link Here
807
	 * This method should be called by implementers of ILazyTreeContentProvider
679
	 * This method should be called by implementers of ILazyTreeContentProvider
808
	 * to populate this viewer.
680
	 * to populate this viewer.
809
	 * </p>
681
	 * </p>
810
	 * @param parent the parent of the element that should be updated
682
	 * 
811
	 * @param index the index in the parent's children
683
	 * @param parent
812
	 * @param element the new element
684
	 *            the parent of the element that should be updated
685
	 * @param index
686
	 *            the index in the parent's children
687
	 * @param element
688
	 *            the new element
813
	 * 
689
	 * 
814
	 * @see #setChildCount(Object, int)
690
	 * @see #setChildCount(Object, int)
815
	 * @see ILazyTreeContentProvider
691
	 * @see ILazyTreeContentProvider
816
     * 
692
	 * 
817
	 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
693
	 * <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
694
	 * 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
695
	 * remain unchanged during the 3.2 release cycle. Please do not use this API
820
	 * consulting with the Platform/UI team.
696
	 * without consulting with the Platform/UI team.
821
	 * </p>
697
	 * </p>
822
     * 
698
	 * 
823
	 * @since 3.2
699
	 * @since 3.2
824
	 */
700
	 */
825
	public void replace(Object parent, int index, Object element) {
701
	public void replace(Object parent, int index, Object element) {
826
		if(parent.equals(getInput())) {
702
		if (parent.equals(getInput())) {
827
			if (index < tree.getItemCount()) {
703
			if (index < tree.getItemCount()) {
828
				updateItem(tree.getItem(index), element);
704
				updateItem(tree.getItem(index), element);
829
			}
705
			}
Lines 834-914 Link Here
834
				if (index < parentItem.getItemCount()) {
710
				if (index < parentItem.getItemCount()) {
835
					updateItem(parentItem.getItem(index), element);
711
					updateItem(parentItem.getItem(index), element);
836
				}
712
				}
837
			}			
713
			}
838
		}
714
		}
839
	}
715
	}
840
	
716
841
    public boolean isExpandable(Object element) {
717
	public boolean isExpandable(Object element) {
842
    	if (getContentProvider() instanceof ILazyTreeContentProvider) {
718
		if (getContentProvider() instanceof ILazyTreeContentProvider) {
843
    		TreeItem treeItem = (TreeItem) internalExpand(element, false);
719
			TreeItem treeItem = (TreeItem) internalExpand(element, false);
844
    		if (treeItem == null) {
720
			if (treeItem == null) {
845
    			return false;
721
				return false;
846
    		}
722
			}
847
    		virtualMaterializeItem(treeItem);
723
			virtualMaterializeItem(treeItem);
848
    		return treeItem.getItemCount() > 0;
724
			return treeItem.getItemCount() > 0;
849
    	}
725
		}
850
    	return super.isExpandable(element);
726
		return super.isExpandable(element);
851
    }
727
	}
852
728
853
    protected Object getParentElement(Object element) {
729
	protected Object getParentElement(Object element) {
854
    	if(!(element instanceof TreePath) && (getContentProvider() instanceof ILazyTreeContentProvider)) {
730
		if (!(element instanceof TreePath)
855
    		ILazyTreeContentProvider lazyTreeContentProvider = (ILazyTreeContentProvider) getContentProvider();
731
				&& (getContentProvider() instanceof ILazyTreeContentProvider)) {
856
    		return lazyTreeContentProvider.getParent(element);
732
			ILazyTreeContentProvider lazyTreeContentProvider = (ILazyTreeContentProvider) getContentProvider();
857
    	}
733
			return lazyTreeContentProvider.getParent(element);
858
        return super.getParentElement(element);
734
		}
859
	}
735
		return super.getParentElement(element);
860
    
736
	}
861
    protected void createChildren(Widget widget) {
737
862
    	if (getContentProvider() instanceof ILazyTreeContentProvider) {
738
	protected void createChildren(Widget widget) {
863
    		final Item[] tis = getChildren(widget);
739
		if (getContentProvider() instanceof ILazyTreeContentProvider) {
864
    		if (tis != null && tis.length > 0) {
740
			final Item[] tis = getChildren(widget);
865
    			// children already there, touch them
741
			if (tis != null && tis.length > 0) {
866
    			for (int i = 0; i < tis.length; i++) {
742
				// children already there, touch them
743
				for (int i = 0; i < tis.length; i++) {
867
					tis[i].getText();
744
					tis[i].getText();
868
				}
745
				}
869
    			return;
746
				return;
870
    		}
747
			}
871
    		ILazyTreeContentProvider lazyTreeContentProvider = (ILazyTreeContentProvider) getContentProvider();
748
			ILazyTreeContentProvider lazyTreeContentProvider = (ILazyTreeContentProvider) getContentProvider();
872
    		Object element = widget.getData();
749
			Object element = widget.getData();
873
    		if (element == null && widget instanceof TreeItem) {
750
			if (element == null && widget instanceof TreeItem) {
874
    			// parent has not been materialized
751
				// parent has not been materialized
875
    			virtualMaterializeItem((TreeItem) widget);
752
				virtualMaterializeItem((TreeItem) widget);
876
    			// try getting the element now that updateElement was called
753
				// try getting the element now that updateElement was called
877
    			element = widget.getData();
754
				element = widget.getData();
878
    		}
755
			}
879
    		TreeItem[] children;
756
			TreeItem[] children;
880
    		if (widget instanceof Tree) {
757
			if (widget instanceof Tree) {
881
    			children = ((Tree) widget).getItems();
758
				children = ((Tree) widget).getItems();
882
    		} else {
759
			} else {
883
    			children = ((TreeItem) widget).getItems();
760
				children = ((TreeItem) widget).getItems();
884
    		}
761
			}
885
    		if (element != null && children.length > 0) {
762
			if (element != null && children.length > 0) {
886
    			for (int i = 0; i < children.length; i++) {
763
				for (int i = 0; i < children.length; i++) {
887
    				lazyTreeContentProvider.updateElement(element, i);
764
					lazyTreeContentProvider.updateElement(element, i);
888
    			}
765
				}
889
    		}
766
			}
890
    		return;
767
			return;
891
    	}
768
		}
892
    	super.createChildren(widget);
769
		super.createChildren(widget);
893
    }
770
	}
894
    
771
895
    protected void internalAdd(Widget widget, Object parentElement,
772
	protected void internalAdd(Widget widget, Object parentElement,
896
    		Object[] childElements) {
773
			Object[] childElements) {
897
    	if (getContentProvider() instanceof ILazyTreeContentProvider) {
774
		if (getContentProvider() instanceof ILazyTreeContentProvider) {
898
    		if (widget instanceof TreeItem) {
775
			if (widget instanceof TreeItem) {
899
    			TreeItem ti = (TreeItem) widget;
776
				TreeItem ti = (TreeItem) widget;
900
    			int count = ti.getItemCount() + childElements.length;
777
				int count = ti.getItemCount() + childElements.length;
901
				ti.setItemCount(count);
778
				ti.setItemCount(count);
902
    			ti.clearAll(false);
779
				ti.clearAll(false);
903
    		} else {
780
			} else {
904
    			Tree t = (Tree) widget;
781
				Tree t = (Tree) widget;
905
    			t.setItemCount(t.getItemCount() + childElements.length);
782
				t.setItemCount(t.getItemCount() + childElements.length);
906
    			t.clearAll(false);
783
				t.clearAll(false);
907
    		}
784
			}
908
    		return;
785
			return;
909
    	}
786
		}
910
    	super.internalAdd(widget, parentElement, childElements);
787
		super.internalAdd(widget, parentElement, childElements);
911
    }
788
	}
912
789
913
	private void virtualMaterializeItem(TreeItem treeItem) {
790
	private void virtualMaterializeItem(TreeItem treeItem) {
914
		if (treeItem.getData() != null) {
791
		if (treeItem.getData() != null) {
Lines 934-980 Link Here
934
			lazyTreeContentProvider.updateElement(parentElement, index);
811
			lazyTreeContentProvider.updateElement(parentElement, index);
935
		}
812
		}
936
	}
813
	}
937
	
814
938
	/* (non-Javadoc)
815
	/*
939
	 * @see org.eclipse.jface.viewers.AbstractTreeViewer#internalRefreshStruct(org.eclipse.swt.widgets.Widget, java.lang.Object, boolean)
816
	 * (non-Javadoc)
817
	 * 
818
	 * @see org.eclipse.jface.viewers.AbstractTreeViewer#internalRefreshStruct(org.eclipse.swt.widgets.Widget,
819
	 *      java.lang.Object, boolean)
940
	 */
820
	 */
941
	protected void internalRefreshStruct(Widget widget, Object element, boolean updateLabels) {
821
	protected void internalRefreshStruct(Widget widget, Object element,
942
    	if (getContentProvider() instanceof ILazyTreeContentProvider) {
822
			boolean updateLabels) {
943
    		// first phase: update child counts
823
		if (getContentProvider() instanceof ILazyTreeContentProvider) {
944
    		virtualRefreshChildCounts(widget, element);
824
			// first phase: update child counts
945
    		// second phase: update labels
825
			virtualRefreshChildCounts(widget, element);
946
    		if (updateLabels) {
826
			// second phase: update labels
947
    			if (widget instanceof Tree) {
827
			if (updateLabels) {
948
    				((Tree)widget).clearAll(true);
828
				if (widget instanceof Tree) {
949
    			} else if (widget instanceof TreeItem) {
829
					((Tree) widget).clearAll(true);
950
    				((TreeItem)widget).clearAll(true);
830
				} else if (widget instanceof TreeItem) {
951
    			}
831
					((TreeItem) widget).clearAll(true);
952
    		}
832
				}
953
    		return;
833
			}
954
    	}
834
			return;
835
		}
955
		super.internalRefreshStruct(widget, element, updateLabels);
836
		super.internalRefreshStruct(widget, element, updateLabels);
956
	}
837
	}
957
838
958
	/**
839
	/**
959
	 * Traverses the visible (expanded) part of the tree and updates child counts.
840
	 * Traverses the visible (expanded) part of the tree and updates child
841
	 * counts.
842
	 * 
960
	 * @param widget
843
	 * @param widget
961
	 * @param element
844
	 * @param element
962
	 * @param updateLabels
845
	 * @param updateLabels
963
	 */
846
	 */
964
	private void virtualRefreshChildCounts(Widget widget, Object element) {
847
	private void virtualRefreshChildCounts(Widget widget, Object element) {
965
		ILazyTreeContentProvider lazyTreeContentProvider = (ILazyTreeContentProvider) getContentProvider();
848
		ILazyTreeContentProvider lazyTreeContentProvider = (ILazyTreeContentProvider) getContentProvider();
966
		if (widget instanceof Tree || ((TreeItem)widget).getExpanded()) {
849
		if (widget instanceof Tree || ((TreeItem) widget).getExpanded()) {
967
			// widget shows children - it is safe to call getChildren
850
			// widget shows children - it is safe to call getChildren
968
			if (element != null) {
851
			if (element != null) {
969
				lazyTreeContentProvider.updateChildCount(element, getChildren(widget).length);
852
				lazyTreeContentProvider.updateChildCount(element,
853
						getChildren(widget).length);
970
			} else {
854
			} else {
971
				if (widget instanceof Tree) {
855
				if (widget instanceof Tree) {
972
					((Tree)widget).setItemCount(0);
856
					((Tree) widget).setItemCount(0);
973
				} else {
857
				} else {
974
					((TreeItem)widget).setItemCount(0);
858
					((TreeItem) widget).setItemCount(0);
975
				}
859
				}
976
			}
860
			}
977
			// need to get children again because they might have been updated through a callback to setChildCount.
861
			// need to get children again because they might have been updated
862
			// through a callback to setChildCount.
978
			Item[] items = getChildren(widget);
863
			Item[] items = getChildren(widget);
979
			for (int i = 0; i < items.length; i++) {
864
			for (int i = 0; i < items.length; i++) {
980
				Item item = items[i];
865
				Item item = items[i];
Lines 985-991 Link Here
985
			}
870
			}
986
		}
871
		}
987
	}
872
	}
988
	
873
989
	/*
874
	/*
990
	 * To unmap elements correctly, we need to register a dispose listener with
875
	 * To unmap elements correctly, we need to register a dispose listener with
991
	 * the item if the tree is virtual.
876
	 * the item if the tree is virtual.
Lines 994-1000 Link Here
994
		super.mapElement(element, item);
879
		super.mapElement(element, item);
995
		// make sure to unmap elements if the tree is virtual
880
		// make sure to unmap elements if the tree is virtual
996
		if ((getTree().getStyle() & SWT.VIRTUAL) != 0) {
881
		if ((getTree().getStyle() & SWT.VIRTUAL) != 0) {
997
			item.addDisposeListener(new DisposeListener(){
882
			item.addDisposeListener(new DisposeListener() {
998
				public void widgetDisposed(DisposeEvent e) {
883
				public void widgetDisposed(DisposeEvent e) {
999
					if (!treeIsDisposed) {
884
					if (!treeIsDisposed) {
1000
						Object data = item.getData();
885
						Object data = item.getData();
Lines 1002-1008 Link Here
1002
							unmapElement(data, item);
887
							unmapElement(data, item);
1003
						}
888
						}
1004
					}
889
					}
1005
				}});
890
				}
891
			});
892
		}
893
	}
894
	
895
	protected RowPart getRowPartFromItem(Widget item) {
896
		RowPart part = (RowPart)item.getData(RowPart.ROWPART_KEY);
897
		
898
		if( part == null ) {
899
			part = new TreeRowPart(((TreeItem)item));
900
			part.associate();
901
		}
902
		
903
		return part;
904
	}
905
		
906
	protected RowPart createNewRowPart(RowPart parent, int style, int rowIndex) {
907
		if( parent == null ) {
908
			if( rowIndex >= 0 ) {
909
				return getRowPartFromItem(new TreeItem(tree,style,rowIndex));
910
			}
911
			return getRowPartFromItem(new TreeItem(tree,style));
1006
		}
912
		}
913
		
914
		if( rowIndex >= 0 ) {
915
			return getRowPartFromItem(new TreeItem((TreeItem)parent.getItem(),SWT.NONE,rowIndex));
916
		}
917
		
918
		return getRowPartFromItem(new TreeItem((TreeItem)parent.getItem(),SWT.NONE));
919
	}
920
	
921
	protected ColumnViewerPart createColumnViewer(Widget columnOwner, ViewerLabelProvider labelProvider) {
922
		if( columnOwner instanceof TreeColumn ) {
923
			return new TreeColumnViewerPart((TreeColumn)columnOwner,labelProvider);
924
		}
925
		
926
		return super.createColumnViewer(columnOwner, labelProvider);
1007
	}
927
	}
1008
}
928
}
(-)src/org/eclipse/jface/viewers/TreeEditorImpl.java (-51 / +45 lines)
Lines 21-26 Link Here
21
import org.eclipse.swt.widgets.Control;
21
import org.eclipse.swt.widgets.Control;
22
import org.eclipse.swt.widgets.Display;
22
import org.eclipse.swt.widgets.Display;
23
import org.eclipse.swt.widgets.Item;
23
import org.eclipse.swt.widgets.Item;
24
import org.eclipse.swt.widgets.Tree;
24
25
25
/**
26
/**
26
 * Internal tree viewer implementation.
27
 * Internal tree viewer implementation.
Lines 66-117 Link Here
66
    }
67
    }
67
68
68
    private void activateCellEditor() {
69
    private void activateCellEditor() {
69
        if (cellEditors != null) {
70
    	ColumnViewerPart part = (ColumnViewerPart)((Tree)viewer.getControl()).getColumn(columnNumber).getData(ColumnViewerPart.COLUMN_VIEWER_KEY);
70
            if (cellEditors[columnNumber] != null && cellModifier != null) {
71
    	Object element = treeItem.getData();
71
                Object element = treeItem.getData();
72
    	
72
                String property = columnProperties[columnNumber];
73
    	if( part != null && part.getEditingSupport() != null && part.getEditingSupport().canEdit(element) ) {
73
                if (cellModifier.canModify(element, property)) {
74
    		cellEditor = part.getEditingSupport().getCellEditor(element);
74
                    cellEditor = cellEditors[columnNumber];
75
    		cellEditor.addListener(cellEditorListener);
75
                    //tree.showSelection();
76
            Object value = part.getEditingSupport().getValue(element);
76
                    cellEditor.addListener(cellEditorListener);
77
            cellEditor.setValue(value);
77
                    Object value = cellModifier.getValue(element, property);
78
            // Tricky flow of control here:
78
                    cellEditor.setValue(value);
79
            // activate() can trigger callback to cellEditorListener which will clear cellEditor
79
                    // Tricky flow of control here:
80
            // 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
81
            final Control control = cellEditor.getControl();
81
                    // so must get control first, but must still call activate() even if there is no control.
82
            cellEditor.activate();
82
                    final Control control = cellEditor.getControl();
83
            if (control == null) {
83
                    cellEditor.activate();
84
				return;
84
                    if (control == null) {
85
			}
85
						return;
86
            setLayoutData(cellEditor.getLayoutData());
86
					}
87
            setEditor(control, treeItem, columnNumber);
87
                    setLayoutData(cellEditor.getLayoutData());
88
            cellEditor.setFocus();
88
                    setEditor(control, treeItem, columnNumber);
89
            if (focusListener == null) {
89
                    cellEditor.setFocus();
90
                focusListener = new FocusAdapter() {
90
                    if (focusListener == null) {
91
                    public void focusLost(FocusEvent e) {
91
                        focusListener = new FocusAdapter() {
92
                        applyEditorValue();
92
                            public void focusLost(FocusEvent e) {
93
                                applyEditorValue();
94
                            }
95
                        };
96
                    }
93
                    }
97
                    control.addFocusListener(focusListener);
94
                };
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
            }
95
            }
114
        }
96
            control.addFocusListener(focusListener);
97
            mouseListener = new MouseAdapter() {
98
                public void mouseDown(MouseEvent e) {
99
                    // time wrap?	
100
                    // check for expiration of doubleClickTime
101
                    if (e.time <= doubleClickExpirationTime) {
102
                        control.removeMouseListener(mouseListener);
103
                        cancelEditing();
104
                        handleDoubleClickEvent();
105
                    } else if (mouseListener != null) {
106
                        control.removeMouseListener(mouseListener);
107
                    }
108
                }
109
            };
110
            control.addMouseListener(mouseListener);
111
    	}
115
    }
112
    }
116
113
117
    /**
114
    /**
Lines 313-325 Link Here
313
     * by delegating to the cell modifier.
310
     * by delegating to the cell modifier.
314
     */
311
     */
315
    private void saveEditorValue(CellEditor cellEditor, Item treeItem) {
312
    private void saveEditorValue(CellEditor cellEditor, Item treeItem) {
316
        if (cellModifier != null) {
313
    	ColumnViewerPart part = (ColumnViewerPart)treeItem.getData(ColumnViewerPart.COLUMN_VIEWER_KEY);
317
            String property = null;
314
    	
318
            if (columnProperties != null
315
    	if( part != null && part.getEditingSupport() != null ) {
319
                    && columnNumber < columnProperties.length) {
316
        	part.getEditingSupport().setValue(treeItem.getData(), cellEditor.getValue());
320
				property = columnProperties[columnNumber];
321
			}
322
            cellModifier.modify(treeItem, property, cellEditor.getValue());
323
        }
317
        }
324
    }
318
    }
325
319
(-)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 44-50 Link Here
44
    public DecoratingLabelProvider(ILabelProvider provider,
42
    public DecoratingLabelProvider(ILabelProvider provider,
45
            ILabelDecorator decorator) {
43
            ILabelDecorator decorator) {
46
        Assert.isNotNull(provider);
44
        Assert.isNotNull(provider);
47
        this.provider = provider;
45
        setProviders(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 (-59 / +50 lines)
Lines 21-26 Link Here
21
import org.eclipse.swt.widgets.Control;
21
import org.eclipse.swt.widgets.Control;
22
import org.eclipse.swt.widgets.Display;
22
import org.eclipse.swt.widgets.Display;
23
import org.eclipse.swt.widgets.Item;
23
import org.eclipse.swt.widgets.Item;
24
import org.eclipse.swt.widgets.Table;
24
25
25
/**
26
/**
26
 * Internal table viewer implementation.
27
 * Internal table viewer implementation.
Lines 66-117 Link Here
66
    }
67
    }
67
68
68
    private void activateCellEditor() {
69
    private void activateCellEditor() {
69
        if (cellEditors != null) {
70
    	ColumnViewerPart part = (ColumnViewerPart)((Table)viewer.getControl()).getColumn(columnNumber).getData(ColumnViewerPart.COLUMN_VIEWER_KEY);
70
            if (cellEditors[columnNumber] != null && cellModifier != null) {
71
    	Object element = tableItem.getData();
71
                Object element = tableItem.getData();
72
    	
72
                String property = columnProperties[columnNumber];
73
    	if( part != null && part.getEditingSupport() != null && part.getEditingSupport().canEdit(element) ) {
73
                if (cellModifier.canModify(element, property)) {
74
    		cellEditor = part.getEditingSupport().getCellEditor(element);
74
                    cellEditor = cellEditors[columnNumber];
75
    		cellEditor.addListener(cellEditorListener);
75
                    //table.showSelection();
76
            Object value = part.getEditingSupport().getValue(element);
76
                    cellEditor.addListener(cellEditorListener);
77
            cellEditor.setValue(value);
77
                    Object value = cellModifier.getValue(element, property);
78
            // Tricky flow of control here:
78
                    cellEditor.setValue(value);
79
            // activate() can trigger callback to cellEditorListener which will clear cellEditor
79
                    // Tricky flow of control here:
80
            // 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
81
            final Control control = cellEditor.getControl();
81
                    // so must get control first, but must still call activate() even if there is no control.
82
            cellEditor.activate();
82
                    final Control control = cellEditor.getControl();
83
            if (control == null) {
83
                    cellEditor.activate();
84
				return;
84
                    if (control == null) {
85
			}
85
						return;
86
            setLayoutData(cellEditor.getLayoutData());
86
					}
87
            setEditor(control, tableItem, columnNumber);
87
                    setLayoutData(cellEditor.getLayoutData());
88
            cellEditor.setFocus();
88
                    setEditor(control, tableItem, columnNumber);
89
            if (focusListener == null) {
89
                    cellEditor.setFocus();
90
                focusListener = new FocusAdapter() {
90
                    if (focusListener == null) {
91
                    public void focusLost(FocusEvent e) {
91
                        focusListener = new FocusAdapter() {
92
                        applyEditorValue();
92
                            public void focusLost(FocusEvent e) {
93
                                applyEditorValue();
94
                            }
95
                        };
96
                    }
93
                    }
97
                    control.addFocusListener(focusListener);
94
                };
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
            }
95
            }
114
        }
96
            control.addFocusListener(focusListener);
97
            mouseListener = new MouseAdapter() {
98
                public void mouseDown(MouseEvent e) {
99
                    // time wrap?	
100
                    // check for expiration of doubleClickTime
101
                    if (e.time <= doubleClickExpirationTime) {
102
                        control.removeMouseListener(mouseListener);
103
                        cancelEditing();
104
                        handleDoubleClickEvent();
105
                    } else if (mouseListener != null) {
106
                        control.removeMouseListener(mouseListener);
107
                    }
108
                }
109
            };
110
            control.addMouseListener(mouseListener);
111
    	}    	
115
    }
112
    }
116
113
117
    /**
114
    /**
Lines 217-223 Link Here
217
214
218
    abstract Rectangle getBounds(Item item, int columnNumber);
215
    abstract Rectangle getBounds(Item item, int columnNumber);
219
216
220
    /**
217
/**
221
     * Return the array of CellEditors used in the viewer
218
     * Return the array of CellEditors used in the viewer
222
     * @return the cell editors
219
     * @return the cell editors
223
     */
220
     */
Lines 235-248 Link Here
235
232
236
    abstract int getColumnCount();
233
    abstract int getColumnCount();
237
234
238
    /**
235
	/**
239
     * Return the properties for the column
236
     * Return the properties for the column
240
     * @return the array of column properties
237
     * @return the array of column properties
241
     */
238
     */
242
    public Object[] getColumnProperties() {
239
    public Object[] getColumnProperties() {
243
        return columnProperties;
240
        return columnProperties;
244
    }
241
    }
245
242
    
246
    abstract Item[] getSelection();
243
    abstract Item[] getSelection();
247
244
248
    /**
245
    /**
Lines 308-324 Link Here
308
     * by delegating to the cell modifier.
305
     * by delegating to the cell modifier.
309
     */
306
     */
310
    private void saveEditorValue(CellEditor cellEditor, Item tableItem) {
307
    private void saveEditorValue(CellEditor cellEditor, Item tableItem) {
311
        if (cellModifier != null) {
308
    	ColumnViewerPart part = (ColumnViewerPart)tableItem.getData(ColumnViewerPart.COLUMN_VIEWER_KEY);
312
            if (!cellEditor.isValueValid()) {
309
    	
313
                ///Do what ???
310
        if( part != null && part.getEditingSupport() != null ) {
314
            }
311
        	part.getEditingSupport().setValue(tableItem.getData(), cellEditor.getValue());
315
            String property = null;
312
        }        
316
            if (columnProperties != null
317
                    && columnNumber < columnProperties.length) {
318
				property = columnProperties[columnNumber];
319
			}
320
            cellModifier.modify(tableItem, property, cellEditor.getValue());
321
        }
322
    }
313
    }
323
314
324
    /**
315
    /**
Lines 344-350 Link Here
344
    public void setColumnProperties(String[] columnProperties) {
335
    public void setColumnProperties(String[] columnProperties) {
345
        this.columnProperties = columnProperties;
336
        this.columnProperties = columnProperties;
346
    }
337
    }
347
338
    
348
    abstract void setEditor(Control w, Item item, int fColumnNumber);
339
    abstract void setEditor(Control w, Item item, int fColumnNumber);
349
340
350
    abstract void setLayoutData(CellEditor.LayoutData layoutData);
341
    abstract void setLayoutData(CellEditor.LayoutData layoutData);
(-)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/StructuredViewer.java (+114 lines)
Lines 16-21 Link Here
16
import java.util.List;
16
import java.util.List;
17
17
18
import org.eclipse.core.runtime.ListenerList;
18
import org.eclipse.core.runtime.ListenerList;
19
import org.eclipse.jface.internal.viewers.RowPart;
19
import org.eclipse.jface.util.Assert;
20
import org.eclipse.jface.util.Assert;
20
import org.eclipse.jface.util.IOpenEventListener;
21
import org.eclipse.jface.util.IOpenEventListener;
21
import org.eclipse.jface.util.OpenStrategy;
22
import org.eclipse.jface.util.OpenStrategy;
Lines 31-36 Link Here
31
import org.eclipse.swt.events.SelectionListener;
32
import org.eclipse.swt.events.SelectionListener;
32
import org.eclipse.swt.graphics.Color;
33
import org.eclipse.swt.graphics.Color;
33
import org.eclipse.swt.graphics.Font;
34
import org.eclipse.swt.graphics.Font;
35
import org.eclipse.swt.graphics.Point;
34
import org.eclipse.swt.widgets.Control;
36
import org.eclipse.swt.widgets.Control;
35
import org.eclipse.swt.widgets.Item;
37
import org.eclipse.swt.widgets.Item;
36
import org.eclipse.swt.widgets.TableItem;
38
import org.eclipse.swt.widgets.TableItem;
Lines 131-136 Link Here
131
	 */
133
	 */
132
	private static Widget[] NO_WIDGETS = new Widget[0];
134
	private static Widget[] NO_WIDGETS = new Widget[0];
133
135
136
	private TooltipSupport tooltipSupport;
137
	
134
	/**
138
	/**
135
	 * The ColorAndFontCollector is a helper class for viewers
139
	 * The ColorAndFontCollector is a helper class for viewers
136
	 * that have color and font support ad optionally decorators.
140
	 * that have color and font support ad optionally decorators.
Lines 472-477 Link Here
472
	 */
476
	 */
473
	protected StructuredViewer() {
477
	protected StructuredViewer() {
474
		// do nothing
478
		// do nothing
479
		tooltipSupport = new TooltipSupport(this);
475
	}
480
	}
476
481
477
	/**
482
	/**
Lines 2112-2115 Link Here
2112
		return colorAndFontCollector;
2117
		return colorAndFontCollector;
2113
	}
2118
	}
2114
2119
2120
	/**
2121
	 * Get the cell at this point.
2122
	 * <p><i>Subclasses should overwrite this method and provide a meaningful implementation</i></p>
2123
	 * @param point the point in the viewer where you need to corresponding cell from
2124
	 * @param onlyInSelection search only in selection
2125
	 * @return the cell or if no cell is found at this point
2126
	 */
2127
	Cell getCell(Point point) {
2128
		RowPart row = getRowPart(point);
2129
		if( row != null ) {
2130
			return row.getCell(point);
2131
		}
2132
		
2133
		return null;
2134
	}
2135
	
2136
	protected RowPart getRowPart(Point point) {
2137
		Item item = getItem(point.x, point.y);
2138
		
2139
		if( item != null ) {
2140
			return getRowPartFromItem(item);
2141
		}
2142
		
2143
		return null;
2144
	}
2145
	
2146
	protected RowPart getRowPartFromItem(Widget item) {
2147
		return (RowPart)item.getData(RowPart.ROWPART_KEY);
2148
	}
2149
	
2150
	protected RowPart createNewRowPart(RowPart parent, int style, int rowIndex) {
2151
		return null;
2152
	}
2153
	
2154
	protected Widget getColumnViewerOwner(int columnIndex) {
2155
		return null;
2156
	}
2157
	
2158
	public ICellModifier getCellModifier() {
2159
		return null;
2160
	}
2161
	
2162
	public CellEditor[] getCellEditors() {
2163
		return null;
2164
	}
2165
	
2166
	public Object[] getColumnProperties() {
2167
		return null;
2168
	}
2169
	
2170
	/**
2171
	 * Return the TableColumnViewer at columnIndex
2172
	 * 
2173
	 * @param columnIndex
2174
	 * @return TableColumnViewer
2175
	 */
2176
	public ColumnViewerPart getColumnViewer(final int columnIndex) {
2177
2178
		ColumnViewerPart viewer;
2179
		Widget columnOwner = getColumnViewerOwner(columnIndex);
2180
		
2181
		if( columnOwner == null ) {
2182
			return null;
2183
		}
2184
		
2185
		viewer = (ColumnViewerPart)columnOwner.getData(ColumnViewerPart.COLUMN_VIEWER_KEY);
2186
2187
		if (viewer == null) {
2188
			createColumnViewer(columnOwner, ViewerLabelProvider.createViewerLabelProvider(getLabelProvider()));
2189
			if( getCellModifier() != null ) {
2190
				viewer.setEditingSupport(new IEditingSupport() {
2191
2192
					public boolean canEdit(Object element) {
2193
						return getCellModifier().canModify(element, (String)getColumnProperties()[columnIndex]);
2194
					}
2195
2196
					public CellEditor getCellEditor(Object element) {
2197
						return getCellEditors()[columnIndex];
2198
					}
2199
2200
					public Object getValue(Object element) {
2201
						return getCellModifier().getValue(element, (String)getColumnProperties()[columnIndex]);
2202
					}
2203
2204
					public void setValue(Object element, Object value) {
2205
						getCellModifier().modify( findItem(element), (String)getColumnProperties()[columnIndex], value);
2206
					}
2207
				});
2208
			}
2209
		}
2210
		
2211
		// Reset the colum-index because maybe it changed from the last time 
2212
		viewer.getLabelProvider().setColumnIndex(columnIndex);
2213
		
2214
		return viewer;
2215
	}
2216
	
2217
	protected ColumnViewerPart createColumnViewer(Widget columnOwner, ViewerLabelProvider labelProvider) {
2218
		return new ColumnViewerPart(columnOwner,
2219
				ViewerLabelProvider.createViewerLabelProvider(getLabelProvider()));
2220
	}
2221
	
2222
	public void activateCustomTooltips() {
2223
		tooltipSupport.activate();
2224
	}
2225
	
2226
	public void deactivateCustomTooltips() {
2227
		tooltipSupport.deactivate();
2228
	}
2115
}
2229
}
(-)META-INF/MANIFEST.MF (+1 lines)
Lines 20-25 Link Here
20
 org.eclipse.jface.fieldassist.images,
20
 org.eclipse.jface.fieldassist.images,
21
 org.eclipse.jface.images,
21
 org.eclipse.jface.images,
22
 org.eclipse.jface.internal.provisional.action;x-friends:="org.eclipse.ui.workbench",
22
 org.eclipse.jface.internal.provisional.action;x-friends:="org.eclipse.ui.workbench",
23
 org.eclipse.jface.internal.viewers;x-internal:=true,
23
 org.eclipse.jface.layout,
24
 org.eclipse.jface.layout,
24
 org.eclipse.jface.menus,
25
 org.eclipse.jface.menus,
25
 org.eclipse.jface.operation,
26
 org.eclipse.jface.operation,
(-)src/org/eclipse/jface/viewers/IEditingSupport.java (+55 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
 * @since 3.2
16
 * 
17
 */
18
public interface IEditingSupport {
19
	/**
20
	 * The editor to be shown
21
	 * 
22
	 * @param element
23
	 *            the model element
24
	 * @return the CellEditor
25
	 */
26
	public CellEditor getCellEditor(Object element);
27
28
	/**
29
	 * Is the cell editable
30
	 * 
31
	 * @param element
32
	 *            the model element
33
	 * @return true if editable
34
	 */
35
	public boolean canEdit(Object element);
36
37
	/**
38
	 * Get the value to set to the editor
39
	 * 
40
	 * @param element
41
	 *            the model element
42
	 * @return the value shown
43
	 */
44
	public Object getValue(Object element);
45
46
	/**
47
	 * Restore the value from the CellEditor
48
	 * 
49
	 * @param element
50
	 *            the model element
51
	 * @param value
52
	 *            the new value
53
	 */
54
	public void setValue(Object element, Object value);
55
}
(-)src/org/eclipse/jface/viewers/ColumnViewerPart.java (+152 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.jface.internal.viewers.RowPart;
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
 * 
21
 * @since 3.3
22
 * 
23
 */
24
public class ColumnViewerPart {
25
26
	private ViewerLabelProvider labelProvider;
27
28
	static String COLUMN_VIEWER_KEY = Policy.JFACE + ".columnViewer";//$NON-NLS-1$
29
30
	private IEditingSupport editingSupport;
31
32
	/**
33
	 * Create a new instance of the receiver at columnIndex.
34
	 * 
35
	 * @param columnOwner
36
	 * @param provider
37
	 */
38
	public ColumnViewerPart(Widget columnOwner, ViewerLabelProvider provider) {
39
		labelProvider = provider;
40
		columnOwner.setData(ColumnViewerPart.COLUMN_VIEWER_KEY, this);
41
	}
42
43
	/**
44
	 * Return the label provider for the receiver.
45
	 * 
46
	 * @return ViewerLabelProvider
47
	 */
48
	public ViewerLabelProvider getLabelProvider() {
49
		return labelProvider;
50
	}
51
52
	/**
53
	 * @param labelProvider
54
	 *            the new label-provider
55
	 */
56
	public void setLabelProvider(ViewerLabelProvider labelProvider) {
57
		this.labelProvider = labelProvider;
58
	}
59
60
	/**
61
	 * @return Returns the editingSupport.
62
	 */
63
	public IEditingSupport getEditingSupport() {
64
		return editingSupport;
65
	}
66
67
	/**
68
	 * @param editingSupport
69
	 *            The editingSupport to set.
70
	 */
71
	public void setEditingSupport(IEditingSupport editingSupport) {
72
		this.editingSupport = editingSupport;
73
	}
74
75
	/**
76
	 * Refresh the row for the given columnIndex
77
	 * 
78
	 * @param row
79
	 * @param element
80
	 * @param columnIndex
81
	 */
82
	public void refresh(RowPart row, int columnIndex) {
83
		ViewerLabel label = new ViewerLabel(row.getText(columnIndex), row
84
				.getImage(columnIndex));
85
		getLabelProvider().updateLabel(label, row.getElement(), columnIndex);
86
87
		row.setBackground(columnIndex, label.getBackground());
88
		row.setForeground(columnIndex, label.getForeground());
89
		row.setFont(columnIndex, label.getFont());
90
91
		if (label.hasNewText())
92
			row.setText(columnIndex, label.getText());
93
94
		if (label.hasNewImage())
95
			row.setImage(columnIndex, label.getImage());
96
	}
97
98
	/**
99
	 * Refresh the TreeItem for element.
100
	 * 
101
	 * @param item
102
	 * @param element
103
	 * @param columnIndex
104
	 */
105
/*	public void refresh(TreeItem item, Object element, int columnIndex) {
106
107
		ViewerLabel label = new ViewerLabel(item.getText(columnIndex), item
108
				.getImage(columnIndex));
109
		getLabelProvider().updateLabel(label, element, columnIndex);
110
111
		// We can not make a null check because then we could not
112
		// set the items back to default state
113
		item.setBackground(columnIndex, label.getBackground());
114
		item.setForeground(columnIndex, label.getForeground());
115
		item.setFont(columnIndex, label.getFont());
116
117
		if (label.hasNewText())
118
			item.setText(columnIndex, label.getText());
119
120
		if (label.hasNewImage())
121
			item.setImage(columnIndex, label.getImage());
122
	}
123
*/
124
	/**
125
	 * Refresh the TableItem for element.
126
	 * 
127
	 * @param item
128
	 * @param element
129
	 * @param columnIndex
130
	 */
131
/*	public void refresh(TableItem item, Object element, int columnIndex) {
132
133
		ViewerLabel label = new ViewerLabel(item.getText(columnIndex), item
134
				.getImage(columnIndex));
135
		getLabelProvider().updateLabel(label, element, columnIndex);
136
137
		if (label.hasNewBackground())
138
			item.setBackground(columnIndex, label.getBackground());
139
140
		if (label.hasNewForeground())
141
			item.setForeground(columnIndex, label.getForeground());
142
143
		if (label.hasNewFont())
144
			item.setFont(columnIndex, label.getFont());
145
146
		if (label.hasNewText())
147
			item.setText(columnIndex, label.getText());
148
149
		if (label.hasNewImage())
150
			item.setImage(columnIndex, label.getImage());
151
	}*/
152
}
(-)src/org/eclipse/jface/viewers/TreeColumnViewerLabelProvider.java (+53 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
/**
16
 * TreeViewerLabelProvider is the ViewerLabelProvider that handles
17
 * TreePaths.
18
 * @since 3.2
19
 *
20
 */
21
public class TreeColumnViewerLabelProvider extends ViewerLabelProvider {
22
	 private ITreePathLabelProvider treePathProvider;
23
	
24
	
25
	
26
	/**
27
	 * Update the label for the element with TreePath.
28
	 * @param label
29
	 * @param elementPath
30
	 */
31
	public void updateLabel(ViewerLabel label, TreePath elementPath) {
32
		treePathProvider.updateLabel(label, elementPath);
33
34
	}
35
	
36
	/* (non-Javadoc)
37
	 * @see org.eclipse.jface.viewers.ViewerLabelProvider#setProviders(java.lang.Object)
38
	 */
39
	public void setProviders(Object provider) {
40
		super.setProviders(provider);
41
		if(provider instanceof ITreePathLabelProvider)
42
			treePathProvider = (ITreePathLabelProvider) provider;
43
	}
44
45
	/**
46
	 * Return the ITreePathLabelProvider for the receiver.
47
	 * @return Returns the treePathProvider.
48
	 */
49
	public ITreePathLabelProvider getTreePathProvider() {
50
		return treePathProvider;
51
	}
52
53
}
(-)src/org/eclipse/jface/viewers/TableRowPart.java (+88 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
import org.eclipse.swt.graphics.Rectangle;
18
import org.eclipse.swt.widgets.TableItem;
19
import org.eclipse.swt.widgets.Widget;
20
21
/**
22
 * @since 3.2
23
 *
24
 */
25
public class TableRowPart extends DefaultRowPartImpl {
26
	private TableItem item;
27
	
28
	public TableRowPart(TableItem item) {
29
		this.item = item;
30
	}
31
	
32
	public Rectangle getBounds(int columnIndex) {
33
		return item.getBounds(columnIndex);
34
	}
35
36
	public Rectangle getBounds() {
37
		return item.getBounds();
38
	}
39
40
	public Widget getItem() {
41
		return item;
42
	}
43
44
	public int getColumnCount() {
45
		return item.getParent().getColumnCount();
46
	}
47
48
	public Color getBackground(int columnIndex) {
49
		return item.getBackground(columnIndex);
50
	}
51
52
	public Font getFont(int columnIndex) {
53
		return item.getFont(columnIndex);
54
	}
55
56
	public Color getForeground(int columnIndex) {
57
		return item.getForeground(columnIndex);
58
	}
59
60
	public Image getImage(int columnIndex) {
61
		return item.getImage(columnIndex);
62
	}
63
64
	public String getText(int columnIndex) {
65
		return item.getText(columnIndex);
66
	}
67
68
	public void setBackground(int columnIndex, Color color) {
69
		item.setBackground(columnIndex, color);
70
	}
71
72
	public void setFont(int columnIndex, Font font) {
73
		item.setFont(columnIndex, font);
74
	}
75
76
	public void setForeground(int columnIndex, Color color) {
77
		item.setForeground(columnIndex, color);
78
	}
79
80
	public void setImage(int columnIndex, Image image) {
81
		item.setImage(columnIndex,image);
82
	}
83
84
	public void setText(int columnIndex, String text) {
85
		item.setText(columnIndex, text);
86
	}
87
88
}
(-)src/org/eclipse/jface/viewers/ITableTooltipLabelProvider.java (+44 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 BestSolution Systemhaus GmbH
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
 *     Tom Schind - tom.schindl@bestsolution.at
10
 *******************************************************************************/
11
package org.eclipse.jface.viewers;
12
13
import org.eclipse.swt.graphics.Image;
14
15
/**
16
 * 
17
 * @since 3.3
18
 * 
19
 */
20
public interface ITableTooltipLabelProvider {
21
	/**
22
	 * Returns the tooltip text for the given element and column index, or
23
	 * <code>null</code> if a custom tooltip should not be displayed.
24
	 * 
25
	 * @param element
26
	 *            the element for which the tooltip is shown
27
	 * @param columnIndex
28
	 *            the column index used
29
	 * @return the text to be displayed in the tooltip, or <code>null</code>
30
	 *         if a custom tooltip should not be displayed
31
	 */
32
	public String getTooltipText(Object element, int columnIndex);
33
34
	/**
35
	 * The image displayed in the tooltip
36
	 * 
37
	 * @param object
38
	 *            the element for which the tooltip is shown
39
	 * @param columnIndex
40
	 *            the column index used
41
	 * @return the image displayed if null no image is displayed
42
	 */
43
	public Image getTooltipImage(Object object, int columnIndex);
44
}
(-)src/org/eclipse/jface/viewers/ViewerLabelProvider.java (+395 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.jface.internal.viewers.ITooltipAddonsProvider;
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
 * @since 3.2
23
 * 
24
 */
25
public class ViewerLabelProvider extends LabelProvider implements
26
		ILabelProvider, IColorProvider, IFontProvider, ITooltipLabelProvider,
27
		ITooltipColorProvider, ITooltipFontProvider, ITooltipAddonsProvider {
28
29
	private static ILabelProvider defaultLabelProvider = new LabelProvider() {
30
31
	};
32
33
	private ILabelProvider labelProvider = defaultLabelProvider;
34
35
	private IColorProvider colorProvider;
36
37
	private IFontProvider fontProvider;
38
39
	private ITooltipLabelProvider tooltipLabelProvider;
40
41
	private ITooltipColorProvider tooltipColorProvider;
42
43
	private ITooltipFontProvider tooltipFontProvider;
44
45
	private ITooltipAddonsProvider tooltipAddonsProvider;
46
	
47
	private int columnIndex;
48
49
	/**
50
	 * Create a new instance of the receiver.
51
	 */
52
	public ViewerLabelProvider() {
53
		super();
54
	}
55
56
	/**
57
	 * Create a new instance of the receiver based on labelProvider.
58
	 * 
59
	 * @param labelProvider
60
	 */
61
	public ViewerLabelProvider(IBaseLabelProvider labelProvider) {
62
		super();
63
		setProviders(labelProvider);
64
	}
65
66
	/**
67
	 * Create a ViewerLabelProvider for the column at index
68
	 * 
69
	 * @param columnIndex
70
	 * @param labelProvider
71
	 *            The labelProvider to convert
72
	 * @return ViewerLabelProvider
73
	 */
74
	static ViewerLabelProvider createViewerLabelProvider(
75
			IBaseLabelProvider labelProvider) {
76
77
		if (labelProvider instanceof ITableLabelProvider
78
				|| labelProvider instanceof ITableColorProvider
79
				|| labelProvider instanceof ITableFontProvider)
80
			return new TableColumnViewerLabelProvider(labelProvider);
81
		return new ViewerLabelProvider(labelProvider);
82
83
	}
84
85
	private void updateLabel(ViewerLabel label, Object element) {
86
		label.setText(labelProvider.getText(element));
87
		label.setImage(labelProvider.getImage(element));
88
89
		if (colorProvider != null) {
90
			label.setBackground(colorProvider.getBackground(element));
91
			label.setForeground(colorProvider.getForeground(element));
92
		}
93
94
		if (fontProvider != null) {
95
			label.setFont(fontProvider.getFont(element));
96
		}
97
	}
98
99
	/**
100
	 * Updates the label for the given element and the given index
101
	 * 
102
	 * @param label
103
	 *            the label to update
104
	 * @param element
105
	 *            the element
106
	 * @param columnIndex
107
	 *            the column index
108
	 */
109
	public void updateLabel(ViewerLabel label, Object element, int columnIndex) {
110
		setColumnIndex(columnIndex);
111
		updateLabel(label, element);
112
	}
113
114
	/**
115
	 * @param columnIndex the column-index
116
	 */
117
	public void setColumnIndex(int columnIndex) {
118
		this.columnIndex = columnIndex;
119
	}
120
	
121
	/**
122
	 * @return Returns the column index
123
	 */
124
	public int getColumnIndex() {
125
		return columnIndex;
126
	}
127
	
128
	/**
129
	 * Set the colorProvider to use for the receiver.
130
	 * 
131
	 * @param colorProvider
132
	 *            The colorProvider to set.
133
	 */
134
	public void setColorProvider(IColorProvider colorProvider) {
135
		this.colorProvider = colorProvider;
136
	}
137
138
	/**
139
	 * Set the fontProvider to fontProvider.
140
	 * 
141
	 * @param fontProvider
142
	 *            The fontProvider to set.
143
	 */
144
	public void setFontProvider(IFontProvider fontProvider) {
145
		this.fontProvider = fontProvider;
146
	}
147
148
	/**
149
	 * Set the labelProvider to be provider.
150
	 * 
151
	 * @param provider
152
	 *            ILabelProvider provider to set.
153
	 */
154
	public void setLabelProvider(ILabelProvider provider) {
155
		this.labelProvider = provider;
156
	}
157
158
	/**
159
	 * Set the tooltip provider
160
	 * 
161
	 * @param tooltipProvider
162
	 */
163
	public void setTooltipLabelProvider(ITooltipLabelProvider tooltipProvider) {
164
		this.tooltipLabelProvider = tooltipProvider;
165
	}
166
167
	/**
168
	 * Set the tooltip color provider
169
	 * 
170
	 * @param tooltipColorProvider
171
	 *            ITooltipColorProvider to set
172
	 */
173
	public void setTooltipColorProvider(
174
			ITooltipColorProvider tooltipColorProvider) {
175
		this.tooltipColorProvider = tooltipColorProvider;
176
	}
177
178
	/**
179
	 * Set tooltip font provider
180
	 * 
181
	 * @param tooltipFontProvider
182
	 *            ITooltipFontProvider to set
183
	 */
184
	public void setTooltipFontProvider(ITooltipFontProvider tooltipFontProvider) {
185
		this.tooltipFontProvider = tooltipFontProvider;
186
	}
187
188
	/**
189
	 * Set the tooltip addons provider
190
	 * 
191
	 * @param tooltipAddonsProvider
192
	 *            ITooltipAddonsProvider to set
193
	 */
194
	public void setTooltipAddonsProvider(
195
			ITooltipAddonsProvider tooltipAddonsProvider) {
196
		this.tooltipAddonsProvider = tooltipAddonsProvider;
197
	}
198
199
	/**
200
	 * Set the any providers for the receiver that can be adapted from provider.
201
	 * 
202
	 * @param provider
203
	 */
204
	public void setProviders(Object provider) {
205
		if (provider instanceof ILabelProvider)
206
			labelProvider = (ILabelProvider) provider;
207
208
		if (provider instanceof IColorProvider)
209
			colorProvider = (IColorProvider) provider;
210
211
		if (provider instanceof IFontProvider)
212
			fontProvider = (IFontProvider) provider;
213
214
		if (provider instanceof ITooltipLabelProvider)
215
			tooltipLabelProvider = (ITooltipLabelProvider) provider;
216
217
		if (provider instanceof ITooltipColorProvider)
218
			tooltipColorProvider = (ITooltipColorProvider) provider;
219
220
		if (provider instanceof ITooltipFontProvider)
221
			tooltipFontProvider = (ITooltipFontProvider) provider;
222
223
		if (provider instanceof ITooltipAddonsProvider)
224
			tooltipAddonsProvider = (ITooltipAddonsProvider) provider;
225
	}
226
227
	/*
228
	 * (non-Javadoc)
229
	 * 
230
	 * @see org.eclipse.jface.viewers.IFontProvider#getFont(java.lang.Object)
231
	 */
232
	public Font getFont(Object element) {
233
		if (fontProvider == null) {
234
			return null;
235
		}
236
237
		return fontProvider.getFont(element);
238
239
	}
240
241
	/*
242
	 * (non-Javadoc)
243
	 * 
244
	 * @see org.eclipse.jface.viewers.IColorProvider#getBackground(java.lang.Object)
245
	 */
246
	public Color getBackground(Object element) {
247
		if (colorProvider == null) {
248
			return null;
249
		}
250
251
		return colorProvider.getBackground(element);
252
	}
253
254
	/*
255
	 * (non-Javadoc)
256
	 * 
257
	 * @see org.eclipse.jface.viewers.IColorProvider#getForeground(java.lang.Object)
258
	 */
259
	public Color getForeground(Object element) {
260
		if (colorProvider == null) {
261
			return null;
262
		}
263
264
		return colorProvider.getForeground(element);
265
	}
266
267
	/**
268
	 * Get the IColorProvider for the receiver.
269
	 * 
270
	 * @return IColorProvider
271
	 */
272
	public IColorProvider getColorProvider() {
273
		return colorProvider;
274
	}
275
276
	/**
277
	 * Get the IFontProvider for the receiver.
278
	 * 
279
	 * @return IFontProvider
280
	 */
281
	public IFontProvider getFontProvider() {
282
		return fontProvider;
283
	}
284
285
	/**
286
	 * @return Returns the labelProvider.
287
	 */
288
	public ILabelProvider getLabelProvider() {
289
		return labelProvider;
290
	}
291
292
	/**
293
	 * @return Returns the tooltipColorProvider
294
	 */
295
	public ITooltipColorProvider getTooltipColorProvider() {
296
		return tooltipColorProvider;
297
	}
298
	
299
	/**
300
	 * @return Returns the tooltipAddonsProvider.
301
	 */
302
	public ITooltipAddonsProvider getTooltipAddonsProvider() {
303
		return tooltipAddonsProvider;
304
	}
305
306
	/**
307
	 * @return Returns the tooltipFontProvider.
308
	 */
309
	public ITooltipFontProvider getTooltipFontProvider() {
310
		return tooltipFontProvider;
311
	}
312
313
	/**
314
	 * @return Returns the tooltipLabelProvider.
315
	 */
316
	public ITooltipLabelProvider getTooltipLabelProvider() {
317
		return tooltipLabelProvider;
318
	}
319
320
	public Image getTooltipImage(Object object) {
321
		if (tooltipLabelProvider == null) {
322
			return null;
323
		}
324
325
		return tooltipLabelProvider.getTooltipImage(object);
326
	}
327
328
	public String getTooltipText(Object element) {
329
		if (tooltipLabelProvider == null) {
330
			return null;
331
		}
332
333
		return tooltipLabelProvider.getTooltipText(element);
334
	}
335
336
	public Color getTooltipBackgroundColor(Object object) {
337
		if (tooltipColorProvider == null) {
338
			return null;
339
		}
340
341
		return tooltipColorProvider.getTooltipBackgroundColor(object);
342
	}
343
344
	public Color getTooltipForegroundColor(Object object) {
345
		if (tooltipColorProvider == null) {
346
			return null;
347
		}
348
349
		return tooltipColorProvider.getTooltipForegroundColor(object);
350
	}
351
352
	public Font getTooltipFont(Object object) {
353
		if (tooltipFontProvider == null) {
354
			return null;
355
		}
356
357
		return tooltipFontProvider.getTooltipFont(object);
358
	}
359
360
	public int getTooltipDisplayDelayTime(Object object) {
361
		if (tooltipAddonsProvider == null) {
362
			return 0;
363
		}
364
365
		return tooltipAddonsProvider.getTooltipDisplayDelayTime(object);
366
	}
367
368
	public Point getTooltipShift(Object object) {
369
		if (tooltipAddonsProvider == null) {
370
			return null;
371
		}
372
		return tooltipAddonsProvider.getTooltipShift(object);
373
	}
374
375
	public int getTooltipTimeDisplayed(Object object) {
376
		if (tooltipAddonsProvider == null) {
377
			return 0;
378
		}
379
		return tooltipAddonsProvider.getTooltipTimeDisplayed(object);
380
	}
381
382
	public boolean useNativeTooltip(Object object) {
383
		if (tooltipAddonsProvider == null) {
384
			return false;
385
		}
386
		return tooltipAddonsProvider.useNativeTooltip(object);
387
	}
388
389
	public int getTooltipImageStyle(Object object) {
390
		if (tooltipAddonsProvider == null) {
391
			return SWT.SHADOW_NONE;
392
		}
393
		return tooltipAddonsProvider.getTooltipImageStyle(object);
394
	}
395
}
(-)src/org/eclipse/jface/viewers/TableColumnViewerLabelProvider.java (+178 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
 * @since 3.3
23
 * @see ITableLabelProvider
24
 * @see ITableColorProvider
25
 * @see ITableFontProvider
26
 * 
27
 */
28
class TableColumnViewerLabelProvider extends ViewerLabelProvider {
29
	
30
	/**
31
	 * Create a new instance of the receiver.
32
	 * 
33
	 * @param labelProvider
34
	 *            instance of a table based label provider
35
	 * @param columnIndex
36
	 *            the index into the table for this column
37
	 * @see ITableLabelProvider
38
	 * @see ITableColorProvider
39
	 * @see ITableFontProvider
40
	 */
41
	public TableColumnViewerLabelProvider(IBaseLabelProvider labelProvider) {
42
		super(labelProvider);
43
44
		if (labelProvider instanceof ITableLabelProvider)
45
			setLabelProvider(labelProviderFor((ITableLabelProvider) labelProvider));
46
47
		if (labelProvider instanceof ITableColorProvider)
48
			setColorProvider(colorProviderFor((ITableColorProvider) labelProvider));
49
50
		if (labelProvider instanceof ITableFontProvider)
51
			setFontProvider(fontProviderFor((ITableFontProvider) labelProvider));
52
53
		if (labelProvider instanceof ITableTooltipLabelProvider)
54
			setTooltipLabelProvider(tooltipLabelFor((ITableTooltipLabelProvider) labelProvider));
55
		
56
		if(labelProvider instanceof ITableTooltipColorProvider)
57
			setTooltipColorProvider(tooltipColorFor((ITableTooltipColorProvider)labelProvider));
58
		
59
		if(labelProvider instanceof ITableTooltipFontProvider)
60
			setTooltipFontProvider(tooltipFontFor((ITableTooltipFontProvider)labelProvider));
61
	}
62
63
	private ITooltipFontProvider tooltipFontFor(final ITableTooltipFontProvider provider) {
64
		return new ITooltipFontProvider() {
65
66
			public Font getTooltipFont(Object object) {
67
				return provider.getTooltipFont(object, getColumnIndex());
68
			}
69
		};
70
	}
71
	
72
	private ITooltipColorProvider tooltipColorFor(final ITableTooltipColorProvider provider) {
73
		return new ITooltipColorProvider() {
74
75
			public Color getTooltipBackgroundColor(Object object) {
76
				return provider.getTooltipBackgroundColor(object, getColumnIndex());
77
			}
78
79
			public Color getTooltipForegroundColor(Object object) {
80
				return provider.getTooltipForegroundColor(object, getColumnIndex());
81
			}
82
		};
83
	}
84
	
85
	private ITooltipLabelProvider tooltipLabelFor(
86
			final ITableTooltipLabelProvider provider) {
87
		return new ITooltipLabelProvider() {
88
89
			public Image getTooltipImage(Object object) {
90
				return provider.getTooltipImage(object, getColumnIndex());
91
			}
92
93
			public String getTooltipText(Object element) {
94
				return provider.getTooltipText(element, getColumnIndex());
95
			}
96
97
		};
98
	}
99
100
	/**
101
	 * Return the IFontProvider based on provider at columnIndex.
102
	 * 
103
	 * @param provider
104
	 * @param columnIndex
105
	 * @return IFontProvider
106
	 */
107
	private IFontProvider fontProviderFor(final ITableFontProvider provider) {
108
		return new IFontProvider() {
109
			/*
110
			 * (non-Javadoc)
111
			 * 
112
			 * @see org.eclipse.jface.viewers.IFontProvider#getFont(java.lang.Object)
113
			 */
114
			public Font getFont(Object element) {
115
				return provider.getFont(element, getColumnIndex());
116
			}
117
		};
118
	}
119
120
	/**
121
	 * Return the ILabelProvider based on provider at columnIndex.
122
	 * 
123
	 * @param provider
124
	 * @param columnIndex
125
	 * @return ILabelProvider
126
	 */
127
	private ILabelProvider labelProviderFor(final ITableLabelProvider provider) {
128
		return new LabelProvider() {
129
			/*
130
			 * (non-Javadoc)
131
			 * 
132
			 * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
133
			 */
134
			public String getText(Object element) {
135
				return provider.getColumnText(element, getColumnIndex());
136
			}
137
138
			/*
139
			 * (non-Javadoc)
140
			 * 
141
			 * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object)
142
			 */
143
			public Image getImage(Object element) {
144
				return provider.getColumnImage(element, getColumnIndex());
145
			}
146
		};
147
	}
148
149
	/**
150
	 * Create an IColorProvider from the ITableColorProvider at columnIndex.
151
	 * 
152
	 * @param provider
153
	 * @param columnIndex
154
	 * @return IColorProvider
155
	 */
156
	private IColorProvider colorProviderFor(final ITableColorProvider provider) {
157
		return new IColorProvider() {
158
			/*
159
			 * (non-Javadoc)
160
			 * 
161
			 * @see org.eclipse.jface.viewers.IColorProvider#getBackground(java.lang.Object)
162
			 */
163
			public Color getBackground(Object element) {
164
				return provider.getBackground(element, getColumnIndex());
165
			}
166
167
			/*
168
			 * (non-Javadoc)
169
			 * 
170
			 * @see org.eclipse.jface.viewers.IColorProvider#getForeground(java.lang.Object)
171
			 */
172
			public Color getForeground(Object element) {
173
				return provider.getForeground(element, getColumnIndex());
174
			}
175
		};
176
	}
177
178
}
(-)src/org/eclipse/jface/internal/viewers/RowPart.java (+87 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.internal.viewers;
13
14
import org.eclipse.jface.util.Policy;
15
import org.eclipse.jface.viewers.Cell;
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
import org.eclipse.swt.graphics.Rectangle;
21
import org.eclipse.swt.widgets.Widget;
22
23
/**
24
 * @since 3.2
25
 * 
26
 */
27
public abstract class RowPart {
28
	public static final String ROWPART_KEY = Policy.JFACE + ".ROWPART"; //$NON-NLS-1$
29
	
30
	public abstract Rectangle getBounds(int columnIndex);
31
32
	public abstract Rectangle getBounds();
33
34
	public abstract Widget getItem();
35
36
	public abstract int getColumnCount();
37
	
38
	public abstract Image getImage(int columnIndex);
39
	
40
	public abstract void setImage(int columnIndex,Image image);
41
	
42
	public abstract String getText(int columnIndex);
43
	
44
	public abstract void setText(int columnIndex,String text);
45
	
46
	public abstract Color getBackground(int columnIndex);
47
	
48
	public abstract void setBackground(int columnIndex, Color color);
49
	
50
	public abstract Color getForeground(int columnIndex);
51
	
52
	public abstract void setForeground(int columnIndex, Color color);
53
	
54
	public abstract Font getFont(int columnIndex);
55
	
56
	public abstract void setFont(int columnIndex,Font font);
57
	
58
	public Cell getCell(Point point) {
59
		int index = getColumIndex(point);
60
		
61
		if( index >= 0 ) {
62
			return new Cell(this,index);
63
		}
64
65
		return null;
66
	}
67
	
68
	public int getColumIndex(Point point) {
69
		int count = getColumnCount();
70
		
71
		for(int i = 0; i < count; i++ ) {
72
			if( getBounds(i).contains(point) ) {
73
				return i;
74
			}
75
		}
76
		
77
		return -1;
78
	}
79
	
80
	public Object getElement() {
81
		return getItem().getData();
82
	}
83
	
84
	public void associate() {
85
		getItem().setData(RowPart.ROWPART_KEY, this);
86
	}
87
}
(-)src/org/eclipse/jface/viewers/DefaultRowPartImpl.java (+85 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.jface.internal.viewers.RowPart;
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.Widget;
20
21
/**
22
 * @since 3.2
23
 *
24
 */
25
public class DefaultRowPartImpl extends RowPart {
26
27
	public Color getBackground(int columnIndex) {
28
		return null;
29
	}
30
31
	public Rectangle getBounds(int columnIndex) {
32
		return null;
33
	}
34
35
	public Rectangle getBounds() {
36
		return null;
37
	}
38
39
	public int getColumnCount() {
40
		return 0;
41
	}
42
43
	public Font getFont(int columnIndex) {
44
		return null;
45
	}
46
47
	public Color getForeground(int columnIndex) {
48
		return null;
49
	}
50
51
	public Image getImage(int columnIndex) {
52
		return null;
53
	}
54
55
	public Widget getItem() {
56
		return null;
57
	}
58
59
	public String getText(int columnIndex) {
60
		return null;
61
	}
62
63
64
	public void setBackground(int columnIndex, Color color) {
65
		
66
	}
67
68
69
	public void setFont(int columnIndex, Font font) {
70
		
71
	}
72
73
	public void setForeground(int columnIndex, Color color) {
74
		
75
	}
76
77
	public void setImage(int columnIndex, Image image) {
78
		
79
	}
80
81
	public void setText(int columnIndex, String text) {
82
		
83
	}
84
	
85
}
(-)src/org/eclipse/jface/viewers/ITableTooltipColorProvider.java (+45 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.SWT;
15
import org.eclipse.swt.graphics.Color;
16
17
/**
18
 * @since 3.3
19
 * 
20
 */
21
public interface ITableTooltipColorProvider {
22
	/**
23
	 * The foreground color used to display the the text in the tooltip
24
	 * 
25
	 * @param object
26
	 *            the element for which the tooltip is shown
27
	 * @param columnIndex
28
	 *            the column index used
29
	 * @return the color used or <code>null</code> if you want to use the
30
	 *         default color {@link SWT#COLOR_INFO_FOREGROUND}
31
	 */
32
	public Color getTooltipForegroundColor(Object object, int columnIndex);
33
34
	/**
35
	 * The background color used for the tooltip
36
	 * 
37
	 * @param object
38
	 *            the element for which the tooltip is shown
39
	 * @param columnIndex
40
	 *            the column index used
41
	 * @return the color used or <code>null</code> if you want to use the
42
	 */
43
	public Color getTooltipBackgroundColor(Object object, int columnIndex);
44
45
}
(-)src/org/eclipse/jface/viewers/TooltipSupport.java (+187 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 java.util.Timer;
15
16
import org.eclipse.jface.internal.viewers.RowPart;
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
 * @since 3.2
30
 *
31
 */
32
public class TooltipSupport {
33
	private StructuredViewer viewer;
34
	private Listener listener = new MouseListener();
35
	private static final int DEFAULT_SHIFT_X = 10;
36
	private static final int DEFAULT_SHIFT_Y = 0;
37
	
38
	TooltipSupport(StructuredViewer viewer) {
39
		this.viewer = viewer;
40
	}
41
	
42
	/**
43
	 * activate tooltip support for this viewer
44
	 */
45
	public void activate() {
46
		deactivate();
47
		viewer.getControl().addListener(SWT.Dispose, listener);
48
		viewer.getControl().addListener(SWT.MouseHover, listener);
49
		viewer.getControl().addListener(SWT.MouseMove, listener);
50
		viewer.getControl().addListener(SWT.MouseExit, listener);
51
		viewer.getControl().addListener(SWT.MouseDown, listener);
52
	}
53
	
54
	/**
55
	 * deactivate tooltip support for this viewer
56
	 */
57
	public void deactivate() {
58
		viewer.getControl().removeListener(SWT.Dispose, listener);
59
		viewer.getControl().removeListener(SWT.MouseHover, listener);
60
		viewer.getControl().removeListener(SWT.MouseMove, listener);
61
		viewer.getControl().removeListener(SWT.MouseExit, listener);
62
		viewer.getControl().removeListener(SWT.MouseDown, listener);
63
	}
64
	
65
	private class MouseListener implements Listener {
66
		private Shell tip;
67
		private TooltipHideListener hideListener = new TooltipHideListener();
68
		private Timer timer = new Timer();
69
		
70
		public void handleEvent(Event event) {
71
			switch (event.type) {
72
			case SWT.Dispose:
73
				if( timer != null ) {
74
					timer.cancel();
75
				}
76
			case SWT.KeyDown:
77
			case SWT.MouseMove:
78
			case SWT.MouseDown:
79
				disposeTooltip(tip);
80
				break;
81
			case SWT.MouseHover:
82
				Point p = new Point(event.x, event.y);
83
				RowPart row = viewer.getRowPart(p);
84
				viewer.getControl().setToolTipText(""); //$NON-NLS-1$
85
86
				if (row != null) {
87
					popupTooltip(row, p);
88
				}
89
90
				break;
91
			}
92
		}
93
		
94
		private void popupTooltip(RowPart row, Point p) {
95
			Object element = row.getElement();
96
			disposeTooltip(tip);
97
98
			ColumnViewerPart viewPart = viewer.getColumnViewer(row.getColumIndex(p));
99
			
100
			if( viewPart == null ) {
101
				return;
102
			}
103
			
104
			ViewerLabelProvider labelProvider = viewPart.getLabelProvider();
105
			
106
			String text = labelProvider.getTooltipText(element);
107
			
108
			if( text != null ) {
109
				
110
				if( labelProvider.useNativeTooltip(element) ) {
111
					viewer.getControl().setToolTipText(text);
112
					return;
113
				}
114
				
115
				tip = new Shell(viewer.getControl().getShell(), SWT.ON_TOP | SWT.TOOL);
116
				tip.setLayout(new FillLayout());
117
				CLabel label = new CLabel(tip, labelProvider.getTooltipImageStyle(element));
118
				label.setText(text);
119
				label.addListener(SWT.MouseExit, hideListener);
120
				label.addListener(SWT.MouseDown, hideListener);
121
				
122
				Image img =  labelProvider.getTooltipImage(element);
123
				
124
				if( img != null) {
125
					label.setImage(img);
126
				}
127
				
128
				Color color = labelProvider.getTooltipForegroundColor(element);
129
				if( color == null ) {
130
					color = viewer.getControl().getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND);
131
				}
132
				label.setForeground(color);
133
				
134
				color = labelProvider.getTooltipBackgroundColor(element);
135
				if( color == null ) {
136
					color = viewer.getControl().getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND);
137
				}
138
				label.setBackground(color);
139
				
140
				Font font = labelProvider.getTooltipFont(element);
141
				
142
				if( font != null ) {
143
					label.setFont(font);
144
				}
145
				
146
				Point pt = viewer.getControl().toDisplay(p);
147
				Point shift = labelProvider.getTooltipShift(element);
148
				
149
				if( shift == null ) {
150
					pt.x += DEFAULT_SHIFT_X;
151
					pt.y += DEFAULT_SHIFT_Y;
152
				} else {
153
					pt.x += shift.x;
154
					pt.y += shift.y;
155
				}
156
				
157
				tip.pack();
158
				tip.setLocation(pt);
159
				tip.setVisible(true);
160
			}
161
		}
162
		
163
		private void disposeTooltip(Shell tip) {
164
			if (tip != null && !tip.isDisposed()) {
165
				tip.dispose();
166
			}
167
168
			tip = null;
169
		}
170
	}
171
	
172
	private class TooltipHideListener implements Listener {
173
		public void handleEvent(Event event) {
174
			CLabel label = (CLabel) event.widget;
175
			Shell shell = label.getShell();
176
			switch (event.type) {
177
			case SWT.MouseDown:
178
				viewer.setSelection(new StructuredSelection());
179
				// fall through
180
			case SWT.MouseExit:
181
				viewer.getControl().setFocus();
182
				shell.dispose();
183
				break;
184
			}
185
		}
186
	}
187
}
(-)src/org/eclipse/jface/viewers/ITooltipFontProvider.java (+29 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.Font;
15
16
/**
17
 * @since 3.3
18
 *
19
 */
20
public interface ITooltipFontProvider {
21
	/**
22
	 * The font used to display the tooltip
23
	 * 
24
	 * @param object
25
	 *            the element for which the tooltip is shown
26
	 * @return the font if null default font is used
27
	 */
28
	public Font getTooltipFont(Object object);
29
}
(-)src/org/eclipse/jface/internal/viewers/ITableTooltipAddonsProvider.java (+79 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.internal.viewers;
13
14
import org.eclipse.swt.graphics.Point;
15
16
/**
17
 * @since 3.2
18
 * 
19
 */
20
public interface ITableTooltipAddonsProvider {
21
	/**
22
	 * This is the amount the used to control how much the tooltip is shifted
23
	 * from the current mouse position
24
	 * 
25
	 * @param object
26
	 *            the element for which the tooltip is shown
27
	 * @param columnIndex
28
	 *            the column-index
29
	 * @return shift of the tooltip
30
	 */
31
	public Point getTooltipShift(Object object, int columnIndex);
32
33
	/**
34
	 * If you want your tooltip to be using the native Tooltip you can force
35
	 * this by returning true from this method. If native tooltips are used only
36
	 * the text-value is used all other feature are of custom tooltips are not
37
	 * supported.
38
	 * 
39
	 * @param object
40
	 *            the element for which the tooltip is shown
41
	 * @param columnIndex
42
	 *            the column-index
43
	 * @return true if native tooltips should be used
44
	 */
45
	public boolean useNativeTooltip(Object object, int columnIndex);
46
47
	/**
48
	 * The time in milliseconds after the tooltip is hidden
49
	 * 
50
	 * @param object
51
	 *            the element for which the tooltip is shown
52
	 * @param columnIndex
53
	 *            the column-index
54
	 * @return milliseconds
55
	 */
56
	public int getTooltipTimeDisplayed(Object object, int columnIndex);
57
58
	/**
59
	 * The time in milliseconds until the tooltip pops up
60
	 * 
61
	 * @param object
62
	 *            the element for which the tooltip is shown
63
	 * @param columnIndex
64
	 *            the column-index
65
	 * @return milliseconds
66
	 */
67
	public int getTooltipDisplayDelayTime(Object object, int columnIndex);
68
69
	/**
70
	 * The style used to create the label
71
	 * 
72
	 * @param object
73
	 *            the element for which the tooltip is shown
74
	 * @param columnIndex
75
	 *            the column-index
76
	 * @return style mask
77
	 */
78
	public int getTooltipImageStyle(Object object, int columnIndex);
79
}
(-)src/org/eclipse/jface/internal/viewers/ITooltipAddonsProvider.java (+69 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.internal.viewers;
13
14
import org.eclipse.swt.graphics.Point;
15
16
/**
17
 * @since 3.2
18
 * 
19
 */
20
public interface ITooltipAddonsProvider {
21
	/**
22
	 * This is the amount the used to control how much the tooltip is shifted
23
	 * from the current mouse position
24
	 * 
25
	 * @param object
26
	 *            the element for which the tooltip is shown
27
	 * @return shift of the tooltip
28
	 */
29
	public Point getTooltipShift(Object object);
30
31
	/**
32
	 * If you want your tooltip to be using the native Tooltip you can force
33
	 * this by returning true from this method. If native tooltips are used only
34
	 * the text-value is used all other feature are of custom tooltips are not
35
	 * supported.
36
	 * 
37
	 * @param object
38
	 *            the element for which the tooltip is shown
39
	 * @return true if native tooltips should be used
40
	 */
41
	public boolean useNativeTooltip(Object object);
42
43
	/**
44
	 * The time in milliseconds after the tooltip is hidden
45
	 * 
46
	 * @param object
47
	 *            the element for which the tooltip is shown
48
	 * @return milliseconds
49
	 */
50
	public int getTooltipTimeDisplayed(Object object);
51
52
	/**
53
	 * The time in milliseconds until the tooltip pops up
54
	 * 
55
	 * @param object
56
	 *            the element for which the tooltip is shown
57
	 * @return milliseconds
58
	 */
59
	public int getTooltipDisplayDelayTime(Object object);
60
61
	/**
62
	 * The style used to create the label
63
	 * 
64
	 * @param object
65
	 *            the element for which the tooltip is shown
66
	 * @return style mask
67
	 */
68
	public int getTooltipImageStyle(Object object);
69
}
(-)src/org/eclipse/jface/viewers/TreeRowPart.java (+87 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
import org.eclipse.swt.graphics.Rectangle;
18
import org.eclipse.swt.widgets.TreeItem;
19
import org.eclipse.swt.widgets.Widget;
20
21
/**
22
 * @since 3.2
23
 *
24
 */
25
public class TreeRowPart extends DefaultRowPartImpl {
26
	private TreeItem item;
27
	
28
	public TreeRowPart(TreeItem item) {
29
		this.item = item;
30
	}
31
	
32
	public Rectangle getBounds(int columnIndex) {
33
		return item.getBounds(columnIndex);
34
	}
35
36
	public Rectangle getBounds() {
37
		return item.getBounds();
38
	}
39
40
	public int getColumnCount() {
41
		return item.getParent().getItemCount();
42
	}
43
44
	public Widget getItem() {
45
		return item;
46
	}
47
48
	public Color getBackground(int columnIndex) {
49
		return item.getBackground(columnIndex);
50
	}
51
52
	public Font getFont(int columnIndex) {
53
		return item.getFont(columnIndex);
54
	}
55
56
	public Color getForeground(int columnIndex) {
57
		return item.getForeground(columnIndex);
58
	}
59
60
	public Image getImage(int columnIndex) {
61
		return item.getImage(columnIndex);
62
	}
63
64
	public String getText(int columnIndex) {
65
		return item.getText(columnIndex);
66
	}
67
68
	public void setBackground(int columnIndex, Color color) {
69
		item.setBackground(columnIndex, color);
70
	}
71
72
	public void setFont(int columnIndex, Font font) {
73
		item.setFont(columnIndex, font);
74
	}
75
76
	public void setForeground(int columnIndex, Color color) {
77
		item.setForeground(columnIndex, color);
78
	}
79
80
	public void setImage(int columnIndex, Image image) {
81
		item.setImage(columnIndex,image);
82
	}
83
84
	public void setText(int columnIndex, String text) {
85
		item.setText(columnIndex, text);
86
	}
87
}
(-)src/org/eclipse/jface/viewers/TreeColumnViewerPart.java (+76 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
 * 
20
 */
21
public class TreeColumnViewerPart extends ColumnViewerPart {
22
	private TreeColumn column;
23
24
	/**
25
	 * Create new TableColumnViewerPart. This simply wrapps up a new
26
	 * {@link TreeColumn#TableColumn(org.eclipse.swt.widgets.Table, int)}.
27
	 * Before calling {@link TreeViewer#setInput(Object)}} you need to set the
28
	 * label-provider using
29
	 * {@link ColumnViewerPart#setLabelProvider(ViewerLabelProvider)}
30
	 * 
31
	 * @param parent
32
	 *            the table-viewer
33
	 * @param style
34
	 *            style bits used to create TableColumn {@link TreeColumn}
35
	 */
36
	public TreeColumnViewerPart(TreeViewer parent, int style) {
37
		this(new TreeColumn(parent.getTree(), style),null);
38
	}
39
40
	/**
41
	 * Create new TableColumnViewerPart. This simply wrapps up a new
42
	 * {@link TableColumn#TableColumn(org.eclipse.swt.widgets.Table, int, int)}
43
	 * 
44
	 * @param parent
45
	 *            the table-viewer
46
	 * @param style
47
	 *            style style bits used to create TableColumn
48
	 *            {@link TableColumn}
49
	 * @param index
50
	 *            the index of the column
51
	 */
52
	public TreeColumnViewerPart(TreeViewer parent, int style, int index) {
53
		this(new TreeColumn(parent.getTree(), style, index),null);
54
	}
55
56
	/**
57
	 * Wrap an existing TableColumn
58
	 * 
59
	 * @param column
60
	 *            the existing table-column
61
	 * @param labelProvider
62
	 *            the label provider
63
	 */
64
	public TreeColumnViewerPart(TreeColumn column,
65
			ViewerLabelProvider labelProvider) {
66
		super(column,labelProvider);
67
		this.column = column;
68
	}
69
70
	/**
71
	 * @return access the underlying tree-column
72
	 */
73
	public TreeColumn getColumn() {
74
		return column;
75
	}
76
}
(-)src/org/eclipse/jface/viewers/AbstractTooltipProvider.java (+63 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.jface.internal.viewers.ITooltipAddonsProvider;
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
 * @since 3.2
23
 * 
24
 */
25
public abstract class AbstractTooltipProvider implements ITooltipLabelProvider,
26
		ITooltipFontProvider, ITooltipColorProvider, ITooltipAddonsProvider {
27
28
	public Image getTooltipImage(Object object) {
29
		return null;
30
	}
31
32
	public Font getTooltipFont(Object object) {
33
		return null;
34
	}
35
36
	public Color getTooltipBackgroundColor(Object object) {
37
		return null;
38
	}
39
40
	public Color getTooltipForegroundColor(Object object) {
41
		return null;
42
	}
43
44
	public int getTooltipDisplayDelayTime(Object object) {
45
		return 0;
46
	}
47
48
	public Point getTooltipShift(Object object) {
49
		return null;
50
	}
51
52
	public int getTooltipTimeDisplayed(Object object) {
53
		return 0;
54
	}
55
56
	public boolean useNativeTooltip(Object object) {
57
		return false;
58
	}
59
	
60
	public int getTooltipImageStyle(Object object) {
61
		return SWT.SHADOW_NONE;
62
	}
63
}
(-)src/org/eclipse/jface/viewers/ITableTooltipFontProvider.java (+31 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.Font;
15
16
/**
17
 * @since 3.3
18
 * 
19
 */
20
public interface ITableTooltipFontProvider {
21
	/**
22
	 * The font used to display the tooltip
23
	 * 
24
	 * @param object
25
	 *            the element for which the tooltip is shown
26
	 * @param columnIndex
27
	 *            the column index used
28
	 * @return the font if null default font is used
29
	 */
30
	public Font getTooltipFont(Object object, int columnIndex);
31
}
(-)src/org/eclipse/jface/viewers/AbstractTableTooltipProvider.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
 ******************************************************************************/
11
12
package org.eclipse.jface.viewers;
13
14
import org.eclipse.jface.internal.viewers.ITableTooltipAddonsProvider;
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
 * @since 3.2
23
 * 
24
 */
25
public abstract class AbstractTableTooltipProvider implements
26
		ITableTooltipLabelProvider, ITableTooltipColorProvider,
27
		ITableTooltipFontProvider, ITableTooltipAddonsProvider {
28
29
	public Image getTooltipImage(Object object, int columnIndex) {
30
		return null;
31
	}
32
33
	public Color getTooltipBackgroundColor(Object object, int columnIndex) {
34
		return null;
35
	}
36
37
	public Color getTooltipForegroundColor(Object object, int columnIndex) {
38
		return null;
39
	}
40
41
	public Font getTooltipFont(Object object, int columnIndex) {
42
		return null;
43
	}
44
45
	public int getTooltipDisplayDelayTime(Object object, int columnIndex) {
46
		return 0;
47
	}
48
49
	public Point getTooltipShift(Object object, int columnIndex) {
50
		return null;
51
	}
52
53
	public int getTooltipTimeDisplayed(Object object, int columnIndex) {
54
		return 0;
55
	}
56
57
	public boolean useNativeTooltip(Object object, int columnIndex) {
58
		return false;
59
	}
60
61
	public int getTooltipImageStyle(Object object, int columnIndex) {
62
		return SWT.SHADOW_NONE;
63
	}	
64
}
(-)src/org/eclipse/jface/viewers/TableColumnViewerPart.java (+76 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
 * @since 3.3
19
 * 
20
 */
21
public class TableColumnViewerPart extends ColumnViewerPart {
22
	private TableColumn column;
23
24
	/**
25
	 * Create new TableColumnViewerPart. This simply wrapps up a new
26
	 * {@link TableColumn#TableColumn(org.eclipse.swt.widgets.Table, int)}.
27
	 * Before calling {@link TableViewer#setInput(Object)}} you need to set the
28
	 * label-provider using
29
	 * {@link ColumnViewerPart#setLabelProvider(ViewerLabelProvider)}
30
	 * 
31
	 * @param parent
32
	 *            the table-viewer
33
	 * @param style
34
	 *            style bits used to create TableColumn {@link TableColumn}
35
	 */
36
	public TableColumnViewerPart(TableViewer parent, int style) {
37
		this(new TableColumn(parent.getTable(), style),null);
38
	}
39
40
	/**
41
	 * Create new TableColumnViewerPart. This simply wrapps up a new
42
	 * {@link TableColumn#TableColumn(org.eclipse.swt.widgets.Table, int, int)}
43
	 * 
44
	 * @param parent
45
	 *            the table-viewer
46
	 * @param style
47
	 *            style style bits used to create TableColumn
48
	 *            {@link TableColumn}
49
	 * @param index
50
	 *            the index of the column
51
	 */
52
	public TableColumnViewerPart(TableViewer parent, int style, int index) {
53
		this(new TableColumn(parent.getTable(), style, index),null);
54
	}
55
56
	/**
57
	 * Wrap an existing TableColumn
58
	 * 
59
	 * @param column
60
	 *            the existing table-column
61
	 * @param labelProvider
62
	 *            the label provider
63
	 */
64
	public TableColumnViewerPart(TableColumn column,
65
			ViewerLabelProvider labelProvider) {
66
		super(column,labelProvider);
67
		this.column = column;
68
	}
69
70
	/**
71
	 * @return access the underlying table-column
72
	 */
73
	public TableColumn getColumn() {
74
		return column;
75
	}
76
}
(-)src/org/eclipse/jface/viewers/ITooltipLabelProvider.java (+40 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 BestSolution Systemhaus GmbH
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
 *     Tom Schind - tom.schindl@bestsolution.at
10
 *******************************************************************************/
11
package org.eclipse.jface.viewers;
12
13
import org.eclipse.swt.graphics.Image;
14
15
/**
16
 * 
17
 * @since 3.3
18
 *
19
 */
20
public interface ITooltipLabelProvider {
21
	/**
22
	 * Returns the tooltip text for the given element and column index, or
23
	 * <code>null</code> if a custom tooltip should not be displayed.
24
	 * 
25
	 * @param element
26
	 *            the element for which the tooltip is shown
27
	 * @return the text to be displayed in the tooltip, or <code>null</code>
28
	 *         if a custom tooltip should not be displayed
29
	 */
30
	public String getTooltipText(Object element);
31
32
	/**
33
	 * The image displayed in the tooltip
34
	 * 
35
	 * @param object
36
	 *            the element for which the tooltip is shown
37
	 * @return the image displayed if null no image is displayed
38
	 */
39
	public Image getTooltipImage(Object object);
40
}
(-)src/org/eclipse/jface/viewers/Cell.java (+41 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.jface.internal.viewers.RowPart;
15
import org.eclipse.swt.graphics.Rectangle;
16
17
/**
18
 * @since 3.2
19
 *
20
 */
21
public class Cell {
22
	private int columnIndex;
23
	private RowPart row;
24
	
25
	public Cell(RowPart row, int columnIndex) {
26
		this.row = row;
27
		this.columnIndex = columnIndex;
28
	}
29
	
30
	public int getColumnIndex() {
31
		return columnIndex;
32
	}
33
	
34
	public Rectangle getBounds() {
35
		return row.getBounds(columnIndex);
36
	}
37
	
38
	public Object getElement() {
39
		return row.getElement();
40
	}
41
}
(-)src/org/eclipse/jface/viewers/ITooltipColorProvider.java (+42 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.SWT;
15
import org.eclipse.swt.graphics.Color;
16
17
/**
18
 * @since 3.2
19
 *
20
 */
21
public interface ITooltipColorProvider {
22
	/**
23
	 * The foreground color used to display the the text in the tooltip
24
	 * 
25
	 * @param object
26
	 *            the element for which the tooltip is shown
27
	 * @return the color used or <code>null</code> if you want to use the
28
	 *         default color {@link SWT#COLOR_INFO_FOREGROUND}
29
	 */
30
	public Color getTooltipForegroundColor(Object object);
31
32
	/**
33
	 * The background color used for the tooltip
34
	 * 
35
	 * @param object
36
	 *            the element for which the tooltip is shown
37
	 * 
38
	 * @return the color used or <code>null</code> if you want to use the
39
	 */
40
	public Color getTooltipBackgroundColor(Object object);
41
42
}

Return to bug 149193