Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 47453 Details for
Bug 149193
[Viewers] JFace Table and Tree Viewers need to handle SWT events in an extensible way
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
New Patch to add Tooltip-Support
patch.txt (text/plain), 152.93 KB, created by
Thomas Schindl
on 2006-08-06 15:04:22 EDT
(
hide
)
Description:
New Patch to add Tooltip-Support
Filename:
MIME Type:
Creator:
Thomas Schindl
Created:
2006-08-06 15:04:22 EDT
Size:
152.93 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jface >Index: src/org/eclipse/jface/viewers/TableViewer.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.jface/src/org/eclipse/jface/viewers/TableViewer.java,v >retrieving revision 1.56 >diff -u -r1.56 TableViewer.java >--- src/org/eclipse/jface/viewers/TableViewer.java 15 Jun 2006 22:28:48 -0000 1.56 >+++ src/org/eclipse/jface/viewers/TableViewer.java 6 Aug 2006 19:01:44 -0000 >@@ -7,6 +7,7 @@ > * > * Contributors: > * IBM Corporation - initial API and implementation >+ * Tom Schindl <tom.schindl@bestsolution.at> (bug 83200) > *******************************************************************************/ > > package org.eclipse.jface.viewers; >@@ -15,12 +16,14 @@ > import java.util.HashSet; > import java.util.List; > >+import org.eclipse.jface.internal.viewers.RowPart; > import org.eclipse.jface.util.Assert; > import org.eclipse.swt.SWT; > import org.eclipse.swt.custom.TableEditor; > import org.eclipse.swt.events.MouseAdapter; > import org.eclipse.swt.events.MouseEvent; > import org.eclipse.swt.graphics.Image; >+import org.eclipse.swt.graphics.Point; > import org.eclipse.swt.graphics.Rectangle; > import org.eclipse.swt.widgets.Composite; > import org.eclipse.swt.widgets.Control; >@@ -28,9 +31,11 @@ > import org.eclipse.swt.widgets.Item; > import org.eclipse.swt.widgets.Listener; > import org.eclipse.swt.widgets.Table; >+import org.eclipse.swt.widgets.TableColumn; > import org.eclipse.swt.widgets.TableItem; > import org.eclipse.swt.widgets.Widget; > >+ > /** > * A concrete viewer based on a SWT <code>Table</code> control. > * <p> >@@ -64,178 +69,101 @@ > * @see #internalRefresh(Object, boolean) > */ > public class TableViewer extends StructuredViewer { >- >- private class VirtualManager{ >+ >+ private class VirtualManager { > > /** >- * The currently invisible elements as provided >- * by the content provider or by addition. >- * This will not be populated by an ILazyStructuredContentProvider >- * as an ILazyStructuredContentProvider is only queried >- * on the virtual callback. >+ * The currently invisible elements as provided by the content provider >+ * or by addition. This will not be populated by an >+ * ILazyStructuredContentProvider as an ILazyStructuredContentProvider >+ * is only queried on the virtual callback. > */ > private Object[] cachedElements = new Object[0]; >+ > /** > * Create a new instance of the receiver. >- * >+ * > */ >- public VirtualManager(){ >+ public VirtualManager() { > addTableListener(); > } > >- > /** > * Add the listener for SetData on the table > */ > private void addTableListener() { >- table.addListener(SWT.SetData,new Listener(){ >- /* (non-Javadoc) >+ table.addListener(SWT.SetData, new Listener() { >+ /* >+ * (non-Javadoc) >+ * > * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event) > */ > public void handleEvent(Event event) { > TableItem item = (TableItem) event.item; > final int index = table.indexOf(item); > Object element = resolveElement(index); >- if(element == null){ >- //Didn't find it so make a request >- //Keep looking if it is not in the cache. >+ if (element == null) { >+ // Didn't find it so make a request >+ // Keep looking if it is not in the cache. > IContentProvider contentProvider = getContentProvider(); >- //If we are building lazily then request lookup now >- if(contentProvider instanceof ILazyContentProvider){ >- ((ILazyContentProvider) contentProvider). >- updateElement(index); >+ // If we are building lazily then request lookup now >+ if (contentProvider instanceof ILazyContentProvider) { >+ ((ILazyContentProvider) contentProvider) >+ .updateElement(index); > return; >- } >+ } > } >- >- >- associate(element,item); >- updateItem(item,element); >+ >+ associate(element, item); >+ updateItem(item, element); > } > > }); > } >- >+ > /** >- * Get the element at index.Resolve it lazily if this >- * is available. >+ * Get the element at index.Resolve it lazily if this is available. >+ * > * @param index >- * @return Object or <code>null</code> if it could >- * not be found >+ * @return Object or <code>null</code> if it could not be found > */ > protected Object resolveElement(int index) { >- >+ > Object element = null; >- if(index < cachedElements.length) { >- element = cachedElements[index]; >+ if (index < cachedElements.length) { >+ element = cachedElements[index]; > } >- >+ > return element; > } > > /** > * A non visible item has been added. >+ * > * @param element > * @param index > */ > public void notVisibleAdded(Object element, int index) { >- >+ > int requiredCount = index + 1; >- >- if(requiredCount > getTable().getItemCount()){ >+ >+ if (requiredCount > getTable().getItemCount()) { > getTable().setItemCount(requiredCount); > Object[] newCache = new Object[requiredCount]; >- System.arraycopy(cachedElements, 0, newCache, 0, cachedElements.length); >+ System.arraycopy(cachedElements, 0, newCache, 0, >+ cachedElements.length); > cachedElements = newCache; > } >- >- >+ > cachedElements[index] = element; >- >+ > } >- >+ > } >- >+ > private VirtualManager virtualManager; >- >- /** >- * TableColorAndFontNoOp is an optimization for tables without >- * color and font support. >- * @see ITableColorProvider >- * @see ITableFontProvider >- */ >- private class TableColorAndFontNoOp{ >- >- /** >- * Create a new instance of the receiver. >- * >- */ >- TableColorAndFontNoOp(){ >- >- } >- >- /** >- * Set the fonts and colors for the tableItem if there is a color >- * and font provider available. >- * @param tableItem The item to update. >- * @param element The element being represented >- * @param column The column index >- */ >- public void setFontsAndColors(TableItem tableItem, Object element, int column){ >- } >- >- } > > /** >- * TableColorAndFontCollector is an helper class for color and font >- * support for tables that support the ITableFontProvider and >- * the ITableColorProvider. >- * @see ITableColorProvider >- * @see ITableFontProvider >- */ >- >- private class TableColorAndFontCollector extends TableColorAndFontNoOp{ >- >- ITableFontProvider fontProvider = null; >- ITableColorProvider colorProvider = null; >- >- /** >- * Create an instance of the receiver. Set the color and font >- * providers if provider can be cast to the correct type. >- * @param provider IBaseLabelProvider >- */ >- public TableColorAndFontCollector(IBaseLabelProvider provider){ >- if(provider instanceof ITableFontProvider) { >- fontProvider = (ITableFontProvider) provider; >- } >- if(provider instanceof ITableColorProvider) { >- colorProvider = (ITableColorProvider) provider; >- } >- } >- >- >- /** >- * Set the fonts and colors for the tableItem if there is a color >- * and font provider available. >- * @param tableItem The item to update. >- * @param element The element being represented >- * @param column The column index >- */ >- public void setFontsAndColors(TableItem tableItem, Object element, int column){ >- if (colorProvider != null) { >- tableItem.setBackground(column, colorProvider.getBackground(element, >- column)); >- tableItem.setForeground(column, colorProvider.getForeground(element, >- column)); >- } >- if(fontProvider != null) { >- tableItem.setFont(column,fontProvider.getFont(element,column)); >- } >- } >- >- } >- >- /** > * Internal table viewer implementation. > */ > private TableEditorImpl tableViewerImpl; >@@ -249,12 +177,8 @@ > * This viewer's table editor. > */ > private TableEditor tableEditor; >- >- /** >- * The color and font collector for the cells. >- */ >- private TableColorAndFontNoOp tableColorAndFont = new TableColorAndFontNoOp(); >- >+ >+ > /** > * Creates a table viewer on a newly-created table control under the given > * parent. The table control is created using the SWT style bits >@@ -281,7 +205,7 @@ > * SWT style bits > */ > public TableViewer(Composite parent, int style) { >- this(new Table(parent, style)); >+ this(new Table(parent, style)); > } > > /** >@@ -299,19 +223,19 @@ > initTableViewerImpl(); > initializeVirtualManager(table.getStyle()); > } >- >+ > /** >- * Initialize the virtual manager to manage the virtual state >- * if the table is VIRTUAL. If not use the default no-op >- * version. >+ * Initialize the virtual manager to manage the virtual state if the table >+ * is VIRTUAL. If not use the default no-op version. >+ * > * @param style > */ > private void initializeVirtualManager(int style) { >- if((style & SWT.VIRTUAL) == 0) { >+ if ((style & SWT.VIRTUAL) == 0) { > return; > } >- >- virtualManager = new VirtualManager(); >+ >+ virtualManager = new VirtualManager(); > } > > /** >@@ -330,7 +254,7 @@ > public void add(Object[] elements) { > assertElementsNotNull(elements); > Object[] filtered = filter(elements); >- >+ > for (int i = 0; i < filtered.length; i++) { > Object element = filtered[i]; > int index = indexForElement(element); >@@ -340,17 +264,18 @@ > > /** > * Create a new TableItem at index if required. >+ * > * @param element > * @param index > * > * @since 3.1 > */ > private void createItem(Object element, int index) { >- if(virtualManager == null) { >- updateItem(new TableItem(getTable(), SWT.NONE, index), element); >- } else{ >- virtualManager.notVisibleAdded(element,index); >- >+ if (virtualManager == null) { >+ updateItem(createNewRowPart(null, SWT.NONE, index).getItem(), element); >+ } else { >+ virtualManager.notVisibleAdded(element, index); >+ > } > } > >@@ -382,7 +307,8 @@ > } > > /* >- * (non-Javadoc) >+ * (non-Javadoc) >+ * > * @see org.eclipse.jface.viewers.StructuredViewer#doFindInputItem(java.lang.Object) > */ > protected Widget doFindInputItem(Object element) { >@@ -393,11 +319,12 @@ > } > > /* >- * (non-Javadoc) >+ * (non-Javadoc) >+ * > * @see org.eclipse.jface.viewers.StructuredViewer#doFindItem(java.lang.Object) > */ > protected Widget doFindItem(Object element) { >- >+ > TableItem[] children = table.getItems(); > for (int i = 0; i < children.length; i++) { > TableItem item = children[i]; >@@ -411,8 +338,10 @@ > } > > /* >- * (non-Javadoc) >- * @see org.eclipse.jface.viewers.StructuredViewer#doUpdateItem(org.eclipse.swt.widgets.Widget, java.lang.Object, boolean) >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.jface.viewers.StructuredViewer#doUpdateItem(org.eclipse.swt.widgets.Widget, >+ * java.lang.Object, boolean) > */ > protected void doUpdateItem(Widget widget, Object element, boolean fullMap) { > if (widget instanceof TableItem) { >@@ -422,85 +351,59 @@ > if (fullMap) { > associate(element, item); > } else { >- Object data = item.getData(); >- if (data != null) { >- unmapElement(data, item); >- } >+ Object data = item.getData(); >+ if (data != null) { >+ unmapElement(data, item); >+ } > item.setData(element); > mapElement(element, item); > } > >- IBaseLabelProvider prov = getLabelProvider(); >- ITableLabelProvider tprov = null; >- ILabelProvider lprov = null; >- IViewerLabelProvider vprov = null; >- >- if(prov instanceof ILabelProvider) { >- lprov = (ILabelProvider) prov; >- } >- >- if (prov instanceof IViewerLabelProvider) { >- vprov = (IViewerLabelProvider) prov; >- } >- >- if (prov instanceof ITableLabelProvider) { >- tprov = (ITableLabelProvider) prov; >- } >- > int columnCount = table.getColumnCount(); >- TableItem ti = item; >- getColorAndFontCollector().setFontsAndColors(element); >- >+ if(columnCount == 0) >+ columnCount = 1;//If there are no columns do the first one >+ > // Also enter loop if no columns added. See 1G9WWGZ: JFUIF:WINNT - > // TableViewer with 0 columns does not work > for (int column = 0; column < columnCount || column == 0; column++) { >- // Similar code in TreeViewer.doUpdateItem() >- String text = "";//$NON-NLS-1$ >- Image image = null; >- tableColorAndFont.setFontsAndColors(ti,element,column); >- >- if (tprov == null) { >- if (column == 0) { >- ViewerLabel updateLabel = new ViewerLabel(item >- .getText(), item.getImage()); >- >- if(vprov != null) { >- buildLabel(updateLabel,element,vprov); >- } else{ >- if(lprov != null) { >- buildLabel(updateLabel,element,lprov); >- } >- } >- >-// As it is possible for user code to run the event >- //loop check here. >- if (item.isDisposed()) { >- unmapElement(element, item); >- return; >- } >- >- text = updateLabel.getText(); >- image = updateLabel.getImage(); >- } >- } else { >- text = tprov.getColumnText(element, column); >- image = tprov.getColumnImage(element, column); >- } >+ ColumnViewerPart columnViewer = getColumnViewer(column); >+ columnViewer.refresh( getRowPartFromItem(item),column); > >- //Avoid setting text to null >- if (text == null) { >- text = ""; //$NON-NLS-1$ >- } >- ti.setText(column, text); >- if (ti.getImage(column) != image) { >- ti.setImage(column, image); >+ // As it is possible for user code to run the event >+ // loop check here. >+ if (item.isDisposed()) { >+ unmapElement(element, item); >+ return; > } >+ > } >- >- >- getColorAndFontCollector().applyFontsAndColors(ti); >+ >+ } >+ } >+ >+ protected Widget getColumnViewerOwner(int columnIndex) { >+ if( columnIndex < 0 || columnIndex > getTable().getColumnCount() ) { >+ return null; > } >+ >+ if (getTable().getColumnCount() == 0)// Hang it off the table if it >+ return getTable(); >+ >+ >+ return getTable().getColumn(columnIndex); > } >+ >+ /** >+ * Set the TableColumnViewerPart at columnIndex to be viewerPart. >+ * >+ * @param viewerPart >+ * @param columnIndex >+ */ >+ public void setColumnPart(ColumnViewerPart viewerPart, int columnIndex) { >+ TableColumn column = getTable().getColumn(columnIndex); >+ column.setData(ColumnViewerPart.COLUMN_VIEWER_KEY, viewerPart); >+ } >+ > > /** > * Starts editing the given element. >@@ -544,7 +447,8 @@ > } > > /* >- * (non-Javadoc) >+ * (non-Javadoc) >+ * > * @see org.eclipse.jface.viewers.Viewer#getControl() > */ > public Control getControl() { >@@ -588,11 +492,12 @@ > } > > /* >- * (non-Javadoc) >+ * (non-Javadoc) >+ * > * @see org.eclipse.jface.viewers.StructuredViewer#getSelectionFromWidget() > */ > protected List getSelectionFromWidget() { >- if(virtualManager != null) { >+ if (virtualManager != null) { > return getVirtualSelection(); > } > Widget[] items = table.getSelection(); >@@ -606,50 +511,49 @@ > } > return list; > } >- >+ > /** >- * Get the virtual selection. Avoid calling SWT whenever possible >- * to prevent extra widget creation. >+ * Get the virtual selection. Avoid calling SWT whenever possible to prevent >+ * extra widget creation. >+ * > * @return List of Object > */ > > private List getVirtualSelection() { >- >+ > List result = new ArrayList(); >- int[] selectionIndices = getTable().getSelectionIndices(); >- if(getContentProvider() instanceof ILazyContentProvider){ >+ int[] selectionIndices = getTable().getSelectionIndices(); >+ if (getContentProvider() instanceof ILazyContentProvider) { > ILazyContentProvider lazy = (ILazyContentProvider) getContentProvider(); > for (int i = 0; i < selectionIndices.length; i++) { > int selectionIndex = selectionIndices[i]; >- lazy.updateElement(selectionIndex);//Start the update >+ lazy.updateElement(selectionIndex);// Start the update > Object element = getTable().getItem(selectionIndex).getData(); >- //Only add the element if it got updated. >- //If this is done deferred the selection will >- //be incomplete until selection is finished. >+ // Only add the element if it got updated. >+ // If this is done deferred the selection will >+ // be incomplete until selection is finished. > if (element != null) { > result.add(element); >- } >+ } > } >- } >- else{ >+ } else { > for (int i = 0; i < selectionIndices.length; i++) { > Object element = null; >- //See if it is cached >+ // See if it is cached > int selectionIndex = selectionIndices[i]; >- if (selectionIndex < virtualManager.cachedElements.length){ >+ if (selectionIndex < virtualManager.cachedElements.length) { > element = virtualManager.cachedElements[selectionIndex]; > } >- if (element == null){ >+ if (element == null) { > // Not cached so try the item's data > TableItem item = getTable().getItem(selectionIndex); > element = item.getData(); > } > if (element != null) { > result.add(element); >- } >+ } > } >- >- >+ > } > return result; > } >@@ -664,7 +568,8 @@ > } > > /* >- * (non-Javadoc) >+ * (non-Javadoc) >+ * > * @see org.eclipse.jface.viewers.ContentViewer#hookControl(org.eclipse.swt.widgets.Control) > */ > protected void hookControl(Control control) { >@@ -757,8 +662,10 @@ > } > > /* >- * (non-Javadoc) >- * @see org.eclipse.jface.viewers.Viewer#inputChanged(java.lang.Object, java.lang.Object) >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.jface.viewers.Viewer#inputChanged(java.lang.Object, >+ * java.lang.Object) > */ > protected void inputChanged(Object input, Object oldInput) { > getControl().setRedraw(false); >@@ -795,12 +702,13 @@ > if (position == -1) { > position = table.getItemCount(); > } >- >- createItem(element,position); >+ >+ createItem(element, position); > } > > /* >- * (non-Javadoc) >+ * (non-Javadoc) >+ * > * @see org.eclipse.jface.viewers.StructuredViewer#internalRefresh(java.lang.Object) > */ > protected void internalRefresh(Object element) { >@@ -808,15 +716,17 @@ > } > > /* >- * (non-Javadoc) >- * @see org.eclipse.jface.viewers.StructuredViewer#internalRefresh(java.lang.Object, boolean) >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.jface.viewers.StructuredViewer#internalRefresh(java.lang.Object, >+ * boolean) > */ > protected void internalRefresh(Object element, boolean updateLabels) { > tableViewerImpl.applyEditorValue(); > if (element == null || equals(element, getRoot())) { >- if(virtualManager == null) { >+ if (virtualManager == null) { > internalRefreshAll(updateLabels); >- } else{ >+ } else { > internalVirtualRefreshAll(); > } > } else { >@@ -833,17 +743,17 @@ > * @since 3.1 > */ > private void internalVirtualRefreshAll() { >- >+ > Object root = getRoot(); > IContentProvider contentProvider = getContentProvider(); >- >- //Invalidate for lazy >- if(!(contentProvider instanceof ILazyContentProvider) >+ >+ // Invalidate for lazy >+ if (!(contentProvider instanceof ILazyContentProvider) > && (contentProvider instanceof IStructuredContentProvider)) { >- //Don't cache if the root is null but cache if it is not lazy. >- if(root != null){ >- virtualManager.cachedElements = >- ((IStructuredContentProvider) getContentProvider()).getElements(root); >+ // Don't cache if the root is null but cache if it is not lazy. >+ if (root != null) { >+ virtualManager.cachedElements = ((IStructuredContentProvider) getContentProvider()) >+ .getElements(root); > getTable().setItemCount(virtualManager.cachedElements.length); > } > } >@@ -851,8 +761,9 @@ > } > > /** >- * Refresh all of the elements of the table. update the >- * labels if updatLabels is true; >+ * Refresh all of the elements of the table. update the labels if >+ * updatLabels is true; >+ * > * @param updateLabels > * > * @since 3.1 >@@ -871,10 +782,9 @@ > TableItem[] items = getTable().getItems(); > int min = Math.min(children.length, items.length); > for (int i = 0; i < min; ++i) { >- >- >+ > TableItem item = items[i]; >- >+ > // if the element is unchanged, update its label if appropriate > if (equals(children[i], item.getData())) { > if (updateLabels) { >@@ -893,14 +803,16 @@ > // So, if the object associated with this item has changed, > // just disassociate it for now, and update it below. > item.setText(""); //$NON-NLS-1$ >- item.setImage(new Image[Math.max(1,table.getColumnCount())]);//Clear all images >+ item.setImage(new Image[Math.max(1, table.getColumnCount())]);// Clear >+ // all >+ // images > disassociate(item); > } > } > // dispose of all items beyond the end of the current elements > if (min < items.length) { > for (int i = items.length; --i >= min;) { >- >+ > disassociate(items[i]); > } > table.remove(min, items.length - 1); >@@ -912,7 +824,7 @@ > } > // Update items which were removed above > for (int i = 0; i < min; ++i) { >- >+ > TableItem item = items[i]; > if (item.getData() == null) { > updateItem(item, children[i]); >@@ -920,11 +832,10 @@ > } > // add any remaining elements > for (int i = min; i < children.length; ++i) { >- createItem(children[i],i); >+ createItem(children[i], i); > } > } > >- > /** > * Removes the given elements from this table viewer. > * >@@ -987,9 +898,9 @@ > */ > public void remove(final Object[] elements) { > assertElementsNotNull(elements); >- if (elements.length == 0) { >- return; >- } >+ if (elements.length == 0) { >+ return; >+ } > preservingSelection(new Runnable() { > public void run() { > internalRemove(elements); >@@ -1007,8 +918,8 @@ > * the model. Note that there is another method for efficiently processing > * the simultaneous removal of multiple elements. > * </p> >- * <strong>NOTE:</strong> removing an object from a virtual >- * table will decrement the itemCount. >+ * <strong>NOTE:</strong> removing an object from a virtual table will >+ * decrement the itemCount. > * > * @param element > * the element >@@ -1018,7 +929,8 @@ > } > > /* >- * (non-Javadoc) >+ * (non-Javadoc) >+ * > * @see org.eclipse.jface.viewers.StructuredViewer#reveal(java.lang.Object) > */ > public void reveal(Object element) { >@@ -1079,34 +991,51 @@ > * may also implement {@link IColorProvider} and/or {@link IFontProvider} to > * provide colors and/or fonts. > * </p> >+ * <p> >+ * If the label provider implements the mixin interface ITooltipProvider, it >+ * can provide custom tooltips. >+ * </p> > */ > public void setLabelProvider(IBaseLabelProvider labelProvider) { > Assert.isTrue(labelProvider instanceof ITableLabelProvider > || labelProvider instanceof ILabelProvider); >+ clearColumnParts();//Clear before refresh > super.setLabelProvider(labelProvider); >- if(labelProvider instanceof ITableFontProvider || labelProvider instanceof ITableColorProvider) { >- tableColorAndFont = new TableColorAndFontCollector(labelProvider); >- } else { >- tableColorAndFont = new TableColorAndFontNoOp(); >- } >- > } > > /** >+ * Clear the viewer parts for the columns >+ */ >+ private void clearColumnParts() { >+ TableColumn[] columns = getTable().getColumns(); >+ if(columns.length == 0) >+ getTable().setData(ColumnViewerPart.COLUMN_VIEWER_KEY,null); >+ else{ >+ for (int i = 0; i < columns.length; i++) { >+ columns[i].setData(ColumnViewerPart.COLUMN_VIEWER_KEY,null); >+ >+ } >+ } >+ >+ } >+ >+ /** > * <p> >- * Sets a new selection for this viewer and optionally makes it visible. >- * The TableViewer implmentation of this method is ineffecient for the >+ * Sets a new selection for this viewer and optionally makes it visible. The >+ * TableViewer implmentation of this method is ineffecient for the > * ILazyContentProvider as lookup is done by indices rather than elements >- * and may require population of the entire table in worse case. >+ * and may require population of the entire table in worse case. > * </p> > * <p> >- * Use Table#setSelection(int[] indices) and Table#showSelection() if >- * you wish to set selection more effeciently when using a ILazyContentProvider. >+ * Use Table#setSelection(int[] indices) and Table#showSelection() if you >+ * wish to set selection more effeciently when using a ILazyContentProvider. > * </p> > * >- * @param selection the new selection >- * @param reveal <code>true</code> if the selection is to be made >- * visible, and <code>false</code> otherwise >+ * @param selection >+ * the new selection >+ * @param reveal >+ * <code>true</code> if the selection is to be made visible, >+ * and <code>false</code> otherwise > * @see Table#setSelection(int[]) > * @see Table#showSelection() > */ >@@ -1115,21 +1044,23 @@ > } > > /* >- * (non-Javadoc) >- * @see org.eclipse.jface.viewers.StructuredViewer#setSelectionToWidget(java.util.List, boolean) >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.jface.viewers.StructuredViewer#setSelectionToWidget(java.util.List, >+ * boolean) > */ > protected void setSelectionToWidget(List list, boolean reveal) { >- >+ > if (list == null) { > table.deselectAll(); > return; > } >- >- if(virtualManager != null){ >+ >+ if (virtualManager != null) { > virtualSetSelectionToWidget(list, reveal); > return; > } >- >+ > int size = list.size(); > TableItem[] items = new TableItem[size]; > int count = 0; >@@ -1149,22 +1080,24 @@ > if (reveal) { > table.showSelection(); > } >- >+ > } >- >- >+ > /** > * Set the selection on a virtual table >- * @param list The elements to set >- * @param reveal Whether or not reveal the first item. >+ * >+ * @param list >+ * The elements to set >+ * @param reveal >+ * Whether or not reveal the first item. > */ > private void virtualSetSelectionToWidget(List list, boolean reveal) { > int size = list.size(); > int[] indices = new int[list.size()]; >- >+ > TableItem firstItem = null; > int count = 0; >- HashSet virtualElements = new HashSet(); >+ HashSet virtualElements = new HashSet(); > for (int i = 0; i < size; ++i) { > Object o = list.get(i); > Widget w = findItem(o); >@@ -1178,37 +1111,38 @@ > virtualElements.add(o); > } > } >- >- if(getContentProvider() instanceof ILazyContentProvider){ >- ILazyContentProvider provider = >- (ILazyContentProvider) getContentProvider(); >- >- //Now go through it again until all is done or we are no longer virtual >- //This may create all items so it is not a good >- //idea in general. >- //Use #setSelection (int [] indices,boolean reveal) instead >- for (int i = 0; virtualElements.size() > 0 && i < getTable().getItemCount(); i++) { >+ >+ if (getContentProvider() instanceof ILazyContentProvider) { >+ ILazyContentProvider provider = (ILazyContentProvider) getContentProvider(); >+ >+ // Now go through it again until all is done or we are no longer >+ // virtual >+ // This may create all items so it is not a good >+ // idea in general. >+ // Use #setSelection (int [] indices,boolean reveal) instead >+ for (int i = 0; virtualElements.size() > 0 >+ && i < getTable().getItemCount(); i++) { > provider.updateElement(i); > TableItem item = getTable().getItem(i); >- if(virtualElements.contains(item.getData())){ >- indices[count++] = i; >+ if (virtualElements.contains(item.getData())) { >+ indices[count++] = i; > virtualElements.remove(item.getData()); > if (firstItem == null) { > firstItem = item; > } > } > } >- } >- else{ >- >- if(count != list.size()){//As this is expensive skip it if all have been found >- //If it is not lazy we can use the cache >+ } else { >+ >+ if (count != list.size()) {// As this is expensive skip it if all >+ // have been found >+ // If it is not lazy we can use the cache > for (int i = 0; i < virtualManager.cachedElements.length; i++) { > Object element = virtualManager.cachedElements[i]; >- if(virtualElements.contains(element)){ >+ if (virtualElements.contains(element)) { > TableItem item = getTable().getItem(i); >- item.getText();//Be sure to fire the update >- indices[count++] = i; >+ item.getText();// Be sure to fire the update >+ indices[count++] = i; > virtualElements.remove(element); > if (firstItem == null) { > firstItem = item; >@@ -1217,7 +1151,7 @@ > } > } > } >- >+ > if (count < size) { > System.arraycopy(indices, 0, indices = new int[count], 0, count); > } >@@ -1230,35 +1164,39 @@ > > /** > * Set the item count of the receiver. >- * @param count the new table size. >+ * >+ * @param count >+ * the new table size. > * > * @since 3.1 > */ >- public void setItemCount(int count){ >+ public void setItemCount(int count) { > getTable().setItemCount(count); > getTable().redraw(); > } >- >+ > /** >- * Replace the entries starting at index with elements. >- * This method assumes all of these values are correct >- * and will not call the content provider to verify. >- * <strong>Note that this method will create a TableItem >- * for all of the elements provided</strong>. >+ * Replace the entries starting at index with elements. This method assumes >+ * all of these values are correct and will not call the content provider to >+ * verify. <strong>Note that this method will create a TableItem for all of >+ * the elements provided</strong>. >+ * > * @param element > * @param index > * @see ILazyContentProvider > * > * @since 3.1 > */ >- public void replace(Object element, int index){ >+ public void replace(Object element, int index) { > TableItem item = getTable().getItem(index); > refreshItem(item, element); > } > > /** > * Clear the table item at the specified index >- * @param index the index of the table item to be cleared >+ * >+ * @param index >+ * the index of the table item to be cleared > * > * @since 3.1 > */ >@@ -1269,26 +1207,62 @@ > } > table.clear(index); > } >- >- /* (non-Javadoc) >+ >+ /* >+ * (non-Javadoc) >+ * > * @see org.eclipse.jface.viewers.StructuredViewer#getRawChildren(java.lang.Object) > */ > protected Object[] getRawChildren(Object parent) { > >- Assert.isTrue(!(getContentProvider() instanceof ILazyContentProvider),"Cannot get raw children with an ILazyContentProvider");//$NON-NLS-1$ >+ Assert.isTrue(!(getContentProvider() instanceof ILazyContentProvider), >+ "Cannot get raw children with an ILazyContentProvider");//$NON-NLS-1$ > return super.getRawChildren(parent); >- >+ > } >- >- /* (non-Javadoc) >+ >+ /* >+ * (non-Javadoc) >+ * > * @see org.eclipse.jface.viewers.StructuredViewer#assertContentProviderType(org.eclipse.jface.viewers.IContentProvider) > */ > protected void assertContentProviderType(IContentProvider provider) { >- Assert.isTrue(provider instanceof IStructuredContentProvider || >- provider instanceof ILazyContentProvider); >+ Assert.isTrue(provider instanceof IStructuredContentProvider >+ || provider instanceof ILazyContentProvider); > } > >+ protected RowPart getRowPartFromItem(Widget item) { >+ RowPart part = (RowPart)item.getData(RowPart.ROWPART_KEY); >+ >+ if( part == null ) { >+ part = new TableRowPart(((TableItem)item)); >+ part.associate(); >+ } >+ >+ return part; >+ } >+ >+ protected RowPart createNewRowPart(RowPart parent, int style, int rowIndex) { >+ TableItem item; >+ >+ if( rowIndex >= 0 ) { >+ item = new TableItem(table,SWT.NONE,rowIndex); >+ } else { >+ item = new TableItem(table,SWT.NONE); >+ } >+ >+ return getRowPartFromItem(item); >+ } > >+ public Item getItem(int x, int y) { >+ return table.getItem(new Point(x,y)); >+ } > >+ protected ColumnViewerPart createColumnViewer(Widget columnOwner, ViewerLabelProvider labelProvider) { >+ if( columnOwner instanceof TableColumn ) { >+ return new TableColumnViewerPart((TableColumn)columnOwner,labelProvider); >+ } >+ >+ return super.createColumnViewer(columnOwner, labelProvider); >+ } > } >- >Index: src/org/eclipse/jface/viewers/TreeViewer.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.jface/src/org/eclipse/jface/viewers/TreeViewer.java,v >retrieving revision 1.50 >diff -u -r1.50 TreeViewer.java >--- src/org/eclipse/jface/viewers/TreeViewer.java 30 May 2006 20:15:06 -0000 1.50 >+++ src/org/eclipse/jface/viewers/TreeViewer.java 6 Aug 2006 19:01:45 -0000 >@@ -14,6 +14,7 @@ > import java.util.Iterator; > import java.util.List; > >+import org.eclipse.jface.internal.viewers.RowPart; > import org.eclipse.jface.util.Assert; > import org.eclipse.swt.SWT; > import org.eclipse.swt.custom.TreeEditor; >@@ -22,7 +23,6 @@ > import org.eclipse.swt.events.MouseAdapter; > import org.eclipse.swt.events.MouseEvent; > import org.eclipse.swt.events.TreeListener; >-import org.eclipse.swt.graphics.Image; > import org.eclipse.swt.graphics.Point; > import org.eclipse.swt.graphics.Rectangle; > import org.eclipse.swt.widgets.Composite; >@@ -55,69 +55,6 @@ > public class TreeViewer extends AbstractTreeViewer { > > /** >- * TreeColorAndFontCollector is an helper class for color and font support >- * for trees that support the ITableFontProvider and the >- * ITableColorProvider. >- * >- * @see ITableColorProvider >- * @see ITableFontProvider >- */ >- >- private class TreeColorAndFontCollector { >- >- ITableFontProvider fontProvider = null; >- >- ITableColorProvider colorProvider = null; >- >- /** >- * Create an instance of the receiver. Set the color and font providers >- * if provider can be cast to the correct type. >- * >- * @param provider >- * IBaseLabelProvider >- */ >- public TreeColorAndFontCollector(IBaseLabelProvider provider) { >- if (provider instanceof ITableFontProvider) { >- fontProvider = (ITableFontProvider) provider; >- } >- if (provider instanceof ITableColorProvider) { >- colorProvider = (ITableColorProvider) provider; >- } >- } >- >- /** >- * Create an instance of the receiver with no color and font providers. >- */ >- public TreeColorAndFontCollector() { >- } >- >- /** >- * Set the fonts and colors for the treeItem if there is a color and >- * font provider available. >- * >- * @param treeItem >- * The item to update. >- * @param element >- * The element being represented >- * @param column >- * The column index >- */ >- public void setFontsAndColors(TreeItem treeItem, Object element, >- int column) { >- if (colorProvider != null) { >- treeItem.setBackground(column, colorProvider.getBackground( >- element, column)); >- treeItem.setForeground(column, colorProvider.getForeground( >- element, column)); >- } >- if (fontProvider != null) { >- treeItem.setFont(column, fontProvider.getFont(element, column)); >- } >- } >- >- } >- >- /** > * Internal tree viewer implementation. > */ > private TreeEditorImpl treeViewerImpl; >@@ -133,11 +70,6 @@ > private TreeEditor treeEditor; > > /** >- * The color and font collector for the cells. >- */ >- private TreeColorAndFontCollector treeColorAndFont = new TreeColorAndFontCollector(); >- >- /** > * Flag for whether the tree has been disposed of. > */ > private boolean treeIsDisposed = false; >@@ -207,7 +139,7 @@ > * (non-Javadoc) Method declared in AbstractTreeViewer. > */ > protected void doUpdateItem(final Item item, Object element) { >- if (!(item instanceof TreeItem)) { >+ if (!(item instanceof TreeItem)) { > return; > } > TreeItem treeItem = (TreeItem) item; >@@ -216,116 +148,41 @@ > return; > } > >- getColorAndFontCollector().setFontsAndColors(element); >- >- IBaseLabelProvider prov = getLabelProvider(); >- ITableLabelProvider tprov = null; >- ILabelProvider lprov = null; >- IViewerLabelProvider vprov = null; >- ITreePathLabelProvider pprov = null; >- >- if(prov instanceof ILabelProvider) { >- lprov = (ILabelProvider) prov; >- } >- >- if (prov instanceof IViewerLabelProvider) { >- vprov = (IViewerLabelProvider) prov; >- } >- >- if (prov instanceof ITableLabelProvider) { >- tprov = (ITableLabelProvider) prov; >- } >- >- if (prov instanceof ITreePathLabelProvider) { >- pprov = (ITreePathLabelProvider) prov; >- } >- >- >- int columnCount = tree.getColumnCount(); >- if (columnCount == 0) {// If no columns were created use the label >- // provider >- >- ViewerLabel updateLabel = new ViewerLabel(treeItem.getText(), >- treeItem.getImage()); >- if (pprov != null) { >- TreePath path = getTreePathFromItem(item); >- buildLabel(updateLabel,path,pprov); >- } else >- if(vprov != null) { >- buildLabel(updateLabel,element,vprov); >- } else{ >- if(lprov != null) { >- buildLabel(updateLabel,element,lprov); >- } >- } >+ int columnCount = getTree().getColumnCount(); >+ if(columnCount == 0)//If no columns are created then fake one >+ columnCount = 1; >+ >+ for (int column = 0; column < columnCount; column++) { >+ ColumnViewerPart columnViewer = getColumnViewer(column); >+ columnViewer.refresh(getRowPartFromItem(treeItem),column); > > // As it is possible for user code to run the event > // loop check here. >- if (treeItem.isDisposed()) { >- unmapElement(element, treeItem); >+ if (item.isDisposed()) { >+ unmapElement(element, item); > return; > } > >- if (updateLabel.hasNewText()) { >- treeItem.setText(updateLabel.getText()); >- } >- if (updateLabel.hasNewImage()) { >- treeItem.setImage(updateLabel.getImage()); >- } >- >- if (!updateLabel.hasPendingDecorations()) >- getColorAndFontCollector().applyFontsAndColors(treeItem); >- >- } else {// Use the table based support >- for (int column = 0; column < columnCount; column++) { >- // Similar code in TableViewer.doUpdateItem() >- String text = "";//$NON-NLS-1$ >- Image image = null; >- treeColorAndFont.setFontsAndColors(treeItem, element, column); >- >- if (tprov == null) { >- if (column == 0) { >- ViewerLabel updateLabel = new ViewerLabel(treeItem >- .getText(), treeItem.getImage()); >- if(vprov != null) { >- buildLabel(updateLabel,element,vprov); >- } else{ >- if(lprov != null) { >- buildLabel(updateLabel,element,lprov); >- } >- } >- >- // As it is possible for user code to run the event >- // loop check here. >- if (treeItem.isDisposed()) { >- unmapElement(element, treeItem); >- return; >- } >+ } > >- text = updateLabel.getText(); >- image = updateLabel.getImage(); >- } >- } else { >- text = tprov.getColumnText(element, column); >- image = tprov.getColumnImage(element, column); >- } >+ } > >- // Avoid setting text to null >- if (text == null) { >- text = ""; //$NON-NLS-1$ >- } >- treeItem.setText(column, text); >- if (treeItem.getImage(column) != image) { >- treeItem.setImage(column, image); >- } >- } >- getColorAndFontCollector().applyFontsAndColors(treeItem); >+ protected Widget getColumnViewerOwner(int columnIndex) { >+ if( columnIndex < 0 || columnIndex > getTree().getColumnCount() ) { >+ return null; > } >+ >+ if (getTree().getColumnCount() == 0)// Hang it off the table if it >+ return getTree(); >+ >+ return getTree().getColumn(columnIndex); > } >- >+ > /** > * Override to handle tree paths. >- * @see org.eclipse.jface.viewers.StructuredViewer#buildLabel(org.eclipse.jface.viewers.ViewerLabel, java.lang.Object) >+ * >+ * @see org.eclipse.jface.viewers.StructuredViewer#buildLabel(org.eclipse.jface.viewers.ViewerLabel, >+ * java.lang.Object) > */ > protected void buildLabel(ViewerLabel updateLabel, Object elementOrPath) { > Object element; >@@ -463,7 +320,7 @@ > protected Item getParentItem(Item item) { > return ((TreeItem) item).getParentItem(); > } >- >+ > /* > * (non-Javadoc) Method declared in AbstractTreeViewer. > */ >@@ -494,12 +351,13 @@ > } > }); > if ((treeControl.getStyle() & SWT.VIRTUAL) != 0) { >- treeControl.addDisposeListener(new DisposeListener(){ >+ treeControl.addDisposeListener(new DisposeListener() { > public void widgetDisposed(DisposeEvent e) { > treeIsDisposed = true; > unmapAllElements(); >- }}); >- treeControl.addListener(SWT.SetData, new Listener(){ >+ } >+ }); >+ treeControl.addListener(SWT.SetData, new Listener() { > > public void handleEvent(Event event) { > if (getContentProvider() instanceof ILazyTreeContentProvider) { >@@ -582,19 +440,13 @@ > */ > protected Item newItem(Widget parent, int flags, int ix) { > TreeItem item; >- if (ix >= 0) { >- if (parent instanceof TreeItem) { >- item = new TreeItem((TreeItem) parent, flags, ix); >- } else { >- item = new TreeItem((Tree) parent, flags, ix); >- } >+ >+ if (parent instanceof TreeItem) { >+ item = (TreeItem)createNewRowPart(getRowPartFromItem(parent),flags, ix).getItem(); > } else { >- if (parent instanceof TreeItem) { >- item = new TreeItem((TreeItem) parent, flags); >- } else { >- item = new TreeItem((Tree) parent, flags); >- } >+ item = (TreeItem)createNewRowPart(null,flags, ix).getItem(); > } >+ > return item; > } > >@@ -645,7 +497,7 @@ > */ > protected void setExpanded(Item node, boolean expand) { > ((TreeItem) node).setExpanded(expand); >- if(getContentProvider() instanceof ILazyTreeContentProvider) { >+ if (getContentProvider() instanceof ILazyTreeContentProvider) { > // force repaints to happen > getControl().update(); > } >@@ -661,7 +513,7 @@ > * <code>ITableLabelProvider</code> may also implement > * {@link ITableColorProvider} and/or {@link ITableFontProvider} to provide > * colors and/or fonts. Note that the underlying {@link Tree} must be >- * configured with {@link TreeColumn} objects in this case. >+ * configured with {@link TreeColumn} objects in this case. > * </p> > * <p> > * If the label provider is an <code>ILabelProvider</code>, then it >@@ -674,8 +526,25 @@ > public void setLabelProvider(IBaseLabelProvider labelProvider) { > Assert.isTrue(labelProvider instanceof ITableLabelProvider > || labelProvider instanceof ILabelProvider); >+ clearColumnParts();//Clear before refresh > super.setLabelProvider(labelProvider); >- treeColorAndFont = new TreeColorAndFontCollector(labelProvider); >+ >+ } >+ >+ /** >+ * Clear the viewer parts for the columns >+ */ >+ private void clearColumnParts() { >+ TreeColumn[] columns = getTree().getColumns(); >+ if(columns.length == 0) >+ getTree().setData(ColumnViewerPart.COLUMN_VIEWER_KEY,null); >+ else{ >+ for (int i = 0; i < columns.length; i++) { >+ columns[i].setData(ColumnViewerPart.COLUMN_VIEWER_KEY,null); >+ >+ } >+ } >+ > } > > /* >@@ -705,7 +574,7 @@ > * the array of items > * @return <code>true</code> if the refer to the same elements, > * <code>false</code> otherwise >- * >+ * > * @since 3.1 > */ > protected boolean isSameSelection(List items, Item[] current) { >@@ -725,7 +594,8 @@ > // Go through the items of the current collection > // If there is a mismatch return false > for (int i = 0; i < current.length; i++) { >- if (current[i].getData() == null || !itemSet.containsKey(current[i].getData())) { >+ if (current[i].getData() == null >+ || !itemSet.containsKey(current[i].getData())) { > return false; > } > } >@@ -740,9 +610,11 @@ > getTree().showItem((TreeItem) item); > } > >- >- /* (non-Javadoc) >- * @see org.eclipse.jface.viewers.AbstractTreeViewer#getChild(org.eclipse.swt.widgets.Widget, int) >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.jface.viewers.AbstractTreeViewer#getChild(org.eclipse.swt.widgets.Widget, >+ * int) > */ > protected Item getChild(Widget widget, int index) { > if (widget instanceof TreeItem) { >@@ -753,38 +625,38 @@ > } > return null; > } >- >+ > protected void assertContentProviderType(IContentProvider provider) { >- if(provider instanceof ILazyTreeContentProvider) { >+ if (provider instanceof ILazyTreeContentProvider) { > return; > } > super.assertContentProviderType(provider); > } >- >- protected Object[] getRawChildren(Object parent) { >- if(getContentProvider() instanceof ILazyTreeContentProvider) { >- return new Object[0]; >- } >- return super.getRawChildren(parent); >- } >- >- /** >- * For a TreeViewer with a tree with the VIRTUAL style bit set, set the >- * number of children of the given element. To set the number of children >- * of the invisible root of the tree, the input object is passed as the >- * element. >- * >- * @param element >- * @param count >- * >+ >+ protected Object[] getRawChildren(Object parent) { >+ if (getContentProvider() instanceof ILazyTreeContentProvider) { >+ return new Object[0]; >+ } >+ return super.getRawChildren(parent); >+ } >+ >+ /** >+ * For a TreeViewer with a tree with the VIRTUAL style bit set, set the >+ * number of children of the given element. To set the number of children of >+ * the invisible root of the tree, the input object is passed as the >+ * element. >+ * >+ * @param element >+ * @param count >+ * > * <strong>EXPERIMENTAL</strong>. This class or interface has been added as >- * part of a work in progress. There is no guarantee that this API will remain >- * unchanged during the 3.2 release cycle. Please do not use this API without >- * consulting with the Platform/UI team. >+ * part of a work in progress. There is no guarantee that this API will >+ * remain unchanged during the 3.2 release cycle. Please do not use this API >+ * without consulting with the Platform/UI team. > * </p> >- * >- * @since 3.2 >- */ >+ * >+ * @since 3.2 >+ */ > public void setChildCount(Object element, int count) { > Tree tree = (Tree) doFindInputItem(element); > if (tree != null) { >@@ -793,9 +665,9 @@ > } > Widget[] items = findItems(element); > for (int i = 0; i < items.length; i++) { >- TreeItem treeItem = (TreeItem)items[i]; >+ TreeItem treeItem = (TreeItem) items[i]; > treeItem.setItemCount(count); >- } >+ } > } > > /** >@@ -807,23 +679,27 @@ > * This method should be called by implementers of ILazyTreeContentProvider > * to populate this viewer. > * </p> >- * @param parent the parent of the element that should be updated >- * @param index the index in the parent's children >- * @param element the new element >+ * >+ * @param parent >+ * the parent of the element that should be updated >+ * @param index >+ * the index in the parent's children >+ * @param element >+ * the new element > * > * @see #setChildCount(Object, int) > * @see ILazyTreeContentProvider >- * >+ * > * <strong>EXPERIMENTAL</strong>. This class or interface has been added as >- * part of a work in progress. There is no guarantee that this API will remain >- * unchanged during the 3.2 release cycle. Please do not use this API without >- * consulting with the Platform/UI team. >+ * part of a work in progress. There is no guarantee that this API will >+ * remain unchanged during the 3.2 release cycle. Please do not use this API >+ * without consulting with the Platform/UI team. > * </p> >- * >+ * > * @since 3.2 > */ > public void replace(Object parent, int index, Object element) { >- if(parent.equals(getInput())) { >+ if (parent.equals(getInput())) { > if (index < tree.getItemCount()) { > updateItem(tree.getItem(index), element); > } >@@ -834,81 +710,82 @@ > if (index < parentItem.getItemCount()) { > updateItem(parentItem.getItem(index), element); > } >- } >+ } > } > } >- >- public boolean isExpandable(Object element) { >- if (getContentProvider() instanceof ILazyTreeContentProvider) { >- TreeItem treeItem = (TreeItem) internalExpand(element, false); >- if (treeItem == null) { >- return false; >- } >- virtualMaterializeItem(treeItem); >- return treeItem.getItemCount() > 0; >- } >- return super.isExpandable(element); >- } >- >- protected Object getParentElement(Object element) { >- if(!(element instanceof TreePath) && (getContentProvider() instanceof ILazyTreeContentProvider)) { >- ILazyTreeContentProvider lazyTreeContentProvider = (ILazyTreeContentProvider) getContentProvider(); >- return lazyTreeContentProvider.getParent(element); >- } >- return super.getParentElement(element); >- } >- >- protected void createChildren(Widget widget) { >- if (getContentProvider() instanceof ILazyTreeContentProvider) { >- final Item[] tis = getChildren(widget); >- if (tis != null && tis.length > 0) { >- // children already there, touch them >- for (int i = 0; i < tis.length; i++) { >+ >+ public boolean isExpandable(Object element) { >+ if (getContentProvider() instanceof ILazyTreeContentProvider) { >+ TreeItem treeItem = (TreeItem) internalExpand(element, false); >+ if (treeItem == null) { >+ return false; >+ } >+ virtualMaterializeItem(treeItem); >+ return treeItem.getItemCount() > 0; >+ } >+ return super.isExpandable(element); >+ } >+ >+ protected Object getParentElement(Object element) { >+ if (!(element instanceof TreePath) >+ && (getContentProvider() instanceof ILazyTreeContentProvider)) { >+ ILazyTreeContentProvider lazyTreeContentProvider = (ILazyTreeContentProvider) getContentProvider(); >+ return lazyTreeContentProvider.getParent(element); >+ } >+ return super.getParentElement(element); >+ } >+ >+ protected void createChildren(Widget widget) { >+ if (getContentProvider() instanceof ILazyTreeContentProvider) { >+ final Item[] tis = getChildren(widget); >+ if (tis != null && tis.length > 0) { >+ // children already there, touch them >+ for (int i = 0; i < tis.length; i++) { > tis[i].getText(); > } >- return; >- } >- ILazyTreeContentProvider lazyTreeContentProvider = (ILazyTreeContentProvider) getContentProvider(); >- Object element = widget.getData(); >- if (element == null && widget instanceof TreeItem) { >- // parent has not been materialized >- virtualMaterializeItem((TreeItem) widget); >- // try getting the element now that updateElement was called >- element = widget.getData(); >- } >- TreeItem[] children; >- if (widget instanceof Tree) { >- children = ((Tree) widget).getItems(); >- } else { >- children = ((TreeItem) widget).getItems(); >- } >- if (element != null && children.length > 0) { >- for (int i = 0; i < children.length; i++) { >- lazyTreeContentProvider.updateElement(element, i); >- } >- } >- return; >- } >- super.createChildren(widget); >- } >- >- protected void internalAdd(Widget widget, Object parentElement, >- Object[] childElements) { >- if (getContentProvider() instanceof ILazyTreeContentProvider) { >- if (widget instanceof TreeItem) { >- TreeItem ti = (TreeItem) widget; >- int count = ti.getItemCount() + childElements.length; >+ return; >+ } >+ ILazyTreeContentProvider lazyTreeContentProvider = (ILazyTreeContentProvider) getContentProvider(); >+ Object element = widget.getData(); >+ if (element == null && widget instanceof TreeItem) { >+ // parent has not been materialized >+ virtualMaterializeItem((TreeItem) widget); >+ // try getting the element now that updateElement was called >+ element = widget.getData(); >+ } >+ TreeItem[] children; >+ if (widget instanceof Tree) { >+ children = ((Tree) widget).getItems(); >+ } else { >+ children = ((TreeItem) widget).getItems(); >+ } >+ if (element != null && children.length > 0) { >+ for (int i = 0; i < children.length; i++) { >+ lazyTreeContentProvider.updateElement(element, i); >+ } >+ } >+ return; >+ } >+ super.createChildren(widget); >+ } >+ >+ protected void internalAdd(Widget widget, Object parentElement, >+ Object[] childElements) { >+ if (getContentProvider() instanceof ILazyTreeContentProvider) { >+ if (widget instanceof TreeItem) { >+ TreeItem ti = (TreeItem) widget; >+ int count = ti.getItemCount() + childElements.length; > ti.setItemCount(count); >- ti.clearAll(false); >- } else { >- Tree t = (Tree) widget; >- t.setItemCount(t.getItemCount() + childElements.length); >- t.clearAll(false); >- } >- return; >- } >- super.internalAdd(widget, parentElement, childElements); >- } >+ ti.clearAll(false); >+ } else { >+ Tree t = (Tree) widget; >+ t.setItemCount(t.getItemCount() + childElements.length); >+ t.clearAll(false); >+ } >+ return; >+ } >+ super.internalAdd(widget, parentElement, childElements); >+ } > > private void virtualMaterializeItem(TreeItem treeItem) { > if (treeItem.getData() != null) { >@@ -934,47 +811,55 @@ > lazyTreeContentProvider.updateElement(parentElement, index); > } > } >- >- /* (non-Javadoc) >- * @see org.eclipse.jface.viewers.AbstractTreeViewer#internalRefreshStruct(org.eclipse.swt.widgets.Widget, java.lang.Object, boolean) >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.jface.viewers.AbstractTreeViewer#internalRefreshStruct(org.eclipse.swt.widgets.Widget, >+ * java.lang.Object, boolean) > */ >- protected void internalRefreshStruct(Widget widget, Object element, boolean updateLabels) { >- if (getContentProvider() instanceof ILazyTreeContentProvider) { >- // first phase: update child counts >- virtualRefreshChildCounts(widget, element); >- // second phase: update labels >- if (updateLabels) { >- if (widget instanceof Tree) { >- ((Tree)widget).clearAll(true); >- } else if (widget instanceof TreeItem) { >- ((TreeItem)widget).clearAll(true); >- } >- } >- return; >- } >+ protected void internalRefreshStruct(Widget widget, Object element, >+ boolean updateLabels) { >+ if (getContentProvider() instanceof ILazyTreeContentProvider) { >+ // first phase: update child counts >+ virtualRefreshChildCounts(widget, element); >+ // second phase: update labels >+ if (updateLabels) { >+ if (widget instanceof Tree) { >+ ((Tree) widget).clearAll(true); >+ } else if (widget instanceof TreeItem) { >+ ((TreeItem) widget).clearAll(true); >+ } >+ } >+ return; >+ } > super.internalRefreshStruct(widget, element, updateLabels); > } > > /** >- * Traverses the visible (expanded) part of the tree and updates child counts. >+ * Traverses the visible (expanded) part of the tree and updates child >+ * counts. >+ * > * @param widget > * @param element > * @param updateLabels > */ > private void virtualRefreshChildCounts(Widget widget, Object element) { > ILazyTreeContentProvider lazyTreeContentProvider = (ILazyTreeContentProvider) getContentProvider(); >- if (widget instanceof Tree || ((TreeItem)widget).getExpanded()) { >+ if (widget instanceof Tree || ((TreeItem) widget).getExpanded()) { > // widget shows children - it is safe to call getChildren > if (element != null) { >- lazyTreeContentProvider.updateChildCount(element, getChildren(widget).length); >+ lazyTreeContentProvider.updateChildCount(element, >+ getChildren(widget).length); > } else { > if (widget instanceof Tree) { >- ((Tree)widget).setItemCount(0); >+ ((Tree) widget).setItemCount(0); > } else { >- ((TreeItem)widget).setItemCount(0); >+ ((TreeItem) widget).setItemCount(0); > } > } >- // need to get children again because they might have been updated through a callback to setChildCount. >+ // need to get children again because they might have been updated >+ // through a callback to setChildCount. > Item[] items = getChildren(widget); > for (int i = 0; i < items.length; i++) { > Item item = items[i]; >@@ -985,7 +870,7 @@ > } > } > } >- >+ > /* > * To unmap elements correctly, we need to register a dispose listener with > * the item if the tree is virtual. >@@ -994,7 +879,7 @@ > super.mapElement(element, item); > // make sure to unmap elements if the tree is virtual > if ((getTree().getStyle() & SWT.VIRTUAL) != 0) { >- item.addDisposeListener(new DisposeListener(){ >+ item.addDisposeListener(new DisposeListener() { > public void widgetDisposed(DisposeEvent e) { > if (!treeIsDisposed) { > Object data = item.getData(); >@@ -1002,7 +887,42 @@ > unmapElement(data, item); > } > } >- }}); >+ } >+ }); >+ } >+ } >+ >+ protected RowPart getRowPartFromItem(Widget item) { >+ RowPart part = (RowPart)item.getData(RowPart.ROWPART_KEY); >+ >+ if( part == null ) { >+ part = new TreeRowPart(((TreeItem)item)); >+ part.associate(); >+ } >+ >+ return part; >+ } >+ >+ protected RowPart createNewRowPart(RowPart parent, int style, int rowIndex) { >+ if( parent == null ) { >+ if( rowIndex >= 0 ) { >+ return getRowPartFromItem(new TreeItem(tree,style,rowIndex)); >+ } >+ return getRowPartFromItem(new TreeItem(tree,style)); > } >+ >+ if( rowIndex >= 0 ) { >+ return getRowPartFromItem(new TreeItem((TreeItem)parent.getItem(),SWT.NONE,rowIndex)); >+ } >+ >+ return getRowPartFromItem(new TreeItem((TreeItem)parent.getItem(),SWT.NONE)); >+ } >+ >+ protected ColumnViewerPart createColumnViewer(Widget columnOwner, ViewerLabelProvider labelProvider) { >+ if( columnOwner instanceof TreeColumn ) { >+ return new TreeColumnViewerPart((TreeColumn)columnOwner,labelProvider); >+ } >+ >+ return super.createColumnViewer(columnOwner, labelProvider); > } > } >Index: src/org/eclipse/jface/viewers/TreeEditorImpl.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.jface/src/org/eclipse/jface/viewers/TreeEditorImpl.java,v >retrieving revision 1.7 >diff -u -r1.7 TreeEditorImpl.java >--- src/org/eclipse/jface/viewers/TreeEditorImpl.java 8 May 2006 20:56:56 -0000 1.7 >+++ src/org/eclipse/jface/viewers/TreeEditorImpl.java 6 Aug 2006 19:01:44 -0000 >@@ -21,6 +21,7 @@ > import org.eclipse.swt.widgets.Control; > import org.eclipse.swt.widgets.Display; > import org.eclipse.swt.widgets.Item; >+import org.eclipse.swt.widgets.Tree; > > /** > * Internal tree viewer implementation. >@@ -66,52 +67,48 @@ > } > > private void activateCellEditor() { >- if (cellEditors != null) { >- if (cellEditors[columnNumber] != null && cellModifier != null) { >- Object element = treeItem.getData(); >- String property = columnProperties[columnNumber]; >- if (cellModifier.canModify(element, property)) { >- cellEditor = cellEditors[columnNumber]; >- //tree.showSelection(); >- cellEditor.addListener(cellEditorListener); >- Object value = cellModifier.getValue(element, property); >- cellEditor.setValue(value); >- // Tricky flow of control here: >- // activate() can trigger callback to cellEditorListener which will clear cellEditor >- // so must get control first, but must still call activate() even if there is no control. >- final Control control = cellEditor.getControl(); >- cellEditor.activate(); >- if (control == null) { >- return; >- } >- setLayoutData(cellEditor.getLayoutData()); >- setEditor(control, treeItem, columnNumber); >- cellEditor.setFocus(); >- if (focusListener == null) { >- focusListener = new FocusAdapter() { >- public void focusLost(FocusEvent e) { >- applyEditorValue(); >- } >- }; >+ ColumnViewerPart part = (ColumnViewerPart)((Tree)viewer.getControl()).getColumn(columnNumber).getData(ColumnViewerPart.COLUMN_VIEWER_KEY); >+ Object element = treeItem.getData(); >+ >+ if( part != null && part.getEditingSupport() != null && part.getEditingSupport().canEdit(element) ) { >+ cellEditor = part.getEditingSupport().getCellEditor(element); >+ cellEditor.addListener(cellEditorListener); >+ Object value = part.getEditingSupport().getValue(element); >+ cellEditor.setValue(value); >+ // Tricky flow of control here: >+ // activate() can trigger callback to cellEditorListener which will clear cellEditor >+ // so must get control first, but must still call activate() even if there is no control. >+ final Control control = cellEditor.getControl(); >+ cellEditor.activate(); >+ if (control == null) { >+ return; >+ } >+ setLayoutData(cellEditor.getLayoutData()); >+ setEditor(control, treeItem, columnNumber); >+ cellEditor.setFocus(); >+ if (focusListener == null) { >+ focusListener = new FocusAdapter() { >+ public void focusLost(FocusEvent e) { >+ applyEditorValue(); > } >- control.addFocusListener(focusListener); >- mouseListener = new MouseAdapter() { >- public void mouseDown(MouseEvent e) { >- // time wrap? >- // check for expiration of doubleClickTime >- if (e.time <= doubleClickExpirationTime) { >- control.removeMouseListener(mouseListener); >- cancelEditing(); >- handleDoubleClickEvent(); >- } else if (mouseListener != null) { >- control.removeMouseListener(mouseListener); >- } >- } >- }; >- control.addMouseListener(mouseListener); >- } >+ }; > } >- } >+ control.addFocusListener(focusListener); >+ mouseListener = new MouseAdapter() { >+ public void mouseDown(MouseEvent e) { >+ // time wrap? >+ // check for expiration of doubleClickTime >+ if (e.time <= doubleClickExpirationTime) { >+ control.removeMouseListener(mouseListener); >+ cancelEditing(); >+ handleDoubleClickEvent(); >+ } else if (mouseListener != null) { >+ control.removeMouseListener(mouseListener); >+ } >+ } >+ }; >+ control.addMouseListener(mouseListener); >+ } > } > > /** >@@ -313,13 +310,10 @@ > * by delegating to the cell modifier. > */ > private void saveEditorValue(CellEditor cellEditor, Item treeItem) { >- if (cellModifier != null) { >- String property = null; >- if (columnProperties != null >- && columnNumber < columnProperties.length) { >- property = columnProperties[columnNumber]; >- } >- cellModifier.modify(treeItem, property, cellEditor.getValue()); >+ ColumnViewerPart part = (ColumnViewerPart)treeItem.getData(ColumnViewerPart.COLUMN_VIEWER_KEY); >+ >+ if( part != null && part.getEditingSupport() != null ) { >+ part.getEditingSupport().setValue(treeItem.getData(), cellEditor.getValue()); > } > } > >Index: src/org/eclipse/jface/viewers/DecoratingLabelProvider.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.jface/src/org/eclipse/jface/viewers/DecoratingLabelProvider.java,v >retrieving revision 1.20 >diff -u -r1.20 DecoratingLabelProvider.java >--- src/org/eclipse/jface/viewers/DecoratingLabelProvider.java 19 Apr 2006 21:05:56 -0000 1.20 >+++ src/org/eclipse/jface/viewers/DecoratingLabelProvider.java 6 Aug 2006 19:01:41 -0000 >@@ -22,10 +22,8 @@ > * The decorator decorates the label text, image, font and colors provided by > * the nested label provider. > */ >-public class DecoratingLabelProvider extends LabelProvider implements >- ILabelProvider, IViewerLabelProvider, IColorProvider, IFontProvider, ITreePathLabelProvider { >+public class DecoratingLabelProvider extends TreeColumnViewerLabelProvider { > >- private ILabelProvider provider; > > private ILabelDecorator decorator; > >@@ -44,7 +42,7 @@ > public DecoratingLabelProvider(ILabelProvider provider, > ILabelDecorator decorator) { > Assert.isNotNull(provider); >- this.provider = provider; >+ setProviders(provider); > this.decorator = decorator; > } > >@@ -56,7 +54,7 @@ > */ > public void addListener(ILabelProviderListener listener) { > super.addListener(listener); >- provider.addListener(listener); >+ getLabelProvider().addListener(listener); > if (decorator != null) { > decorator.addListener(listener); > } >@@ -68,7 +66,7 @@ > * disposes both the nested label provider and the label decorator. > */ > public void dispose() { >- provider.dispose(); >+ getLabelProvider().dispose(); > if (decorator != null) { > decorator.dispose(); > } >@@ -82,7 +80,7 @@ > * <code>decorateImage</code> method. > */ > public Image getImage(Object element) { >- Image image = provider.getImage(element); >+ Image image = getLabelProvider().getImage(element); > if (decorator != null) { > if (decorator instanceof LabelDecorator) { > LabelDecorator ld2 = (LabelDecorator) decorator; >@@ -110,15 +108,6 @@ > } > > /** >- * Returns the nested label provider. >- * >- * @return the nested label provider >- */ >- public ILabelProvider getLabelProvider() { >- return provider; >- } >- >- /** > * The <code>DecoratingLabelProvider</code> implementation of this > * <code>ILabelProvider</code> method returns the text label provided > * by the nested label provider's <code>getText</code> method, >@@ -126,7 +115,7 @@ > * <code>decorateText</code> method. > */ > public String getText(Object element) { >- String text = provider.getText(element); >+ String text = getLabelProvider().getText(element); > if (decorator != null) { > if (decorator instanceof LabelDecorator) { > LabelDecorator ld2 = (LabelDecorator) decorator; >@@ -151,7 +140,7 @@ > * decorator returns <code>true</code>. > */ > public boolean isLabelProperty(Object element, String property) { >- if (provider.isLabelProperty(element, property)) { >+ if (getLabelProvider().isLabelProperty(element, property)) { > return true; > } > if (decorator != null && decorator.isLabelProperty(element, property)) { >@@ -168,7 +157,7 @@ > */ > public void removeListener(ILabelProviderListener listener) { > super.removeListener(listener); >- provider.removeListener(listener); >+ getLabelProvider().removeListener(listener); > if (decorator != null) { > decorator.removeListener(listener); > } >@@ -260,36 +249,6 @@ > > } > >- /* (non-Javadoc) >- * @see org.eclipse.jface.viewers.IColorProvider#getBackground(java.lang.Object) >- */ >- public Color getBackground(Object element) { >- if(provider instanceof IColorProvider) { >- return ((IColorProvider) provider).getBackground(element); >- } >- return null; >- } >- >- /* (non-Javadoc) >- * @see org.eclipse.jface.viewers.IFontProvider#getFont(java.lang.Object) >- */ >- public Font getFont(Object element) { >- if(provider instanceof IFontProvider) { >- return ((IFontProvider) provider).getFont(element); >- } >- return null; >- } >- >- /* (non-Javadoc) >- * @see org.eclipse.jface.viewers.IColorProvider#getForeground(java.lang.Object) >- */ >- public Color getForeground(Object element) { >- if(provider instanceof IColorProvider) { >- return ((IColorProvider) provider).getForeground(element); >- } >- return null; >- } >- > /** > * Return the decoration context associated with this label provider. > * It will be passed to the decorator if the decorator is an >@@ -314,8 +273,10 @@ > this.decorationContext = decorationContext; > } > >+ >+ > /* (non-Javadoc) >- * @see org.eclipse.jface.viewers.ITreePathLabelProvider#updateLabel(org.eclipse.jface.viewers.ViewerLabel, org.eclipse.jface.viewers.TreePath) >+ * @see org.eclipse.jface.viewers.TreeViewerLabelProvider#updateLabel(org.eclipse.jface.viewers.ViewerLabel, org.eclipse.jface.viewers.TreePath) > */ > public void updateLabel(ViewerLabel settings, TreePath elementPath) { > ILabelDecorator currentDecorator = getLabelDecorator(); >@@ -338,8 +299,8 @@ > settings.setHasPendingDecorations(!decorationReady); > // update icon and label > >- if (provider instanceof ITreePathLabelProvider) { >- ITreePathLabelProvider pprov = (ITreePathLabelProvider) provider; >+ if (getTreePathProvider() == null) { >+ ITreePathLabelProvider pprov = (ITreePathLabelProvider) getLabelProvider(); > if (decorationReady || oldText == null > || settings.getText().length() == 0) { > pprov.updateLabel(settings, elementPath); >Index: src/org/eclipse/jface/viewers/TableEditorImpl.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.jface/src/org/eclipse/jface/viewers/TableEditorImpl.java,v >retrieving revision 1.7 >diff -u -r1.7 TableEditorImpl.java >--- src/org/eclipse/jface/viewers/TableEditorImpl.java 8 May 2006 20:56:57 -0000 1.7 >+++ src/org/eclipse/jface/viewers/TableEditorImpl.java 6 Aug 2006 19:01:43 -0000 >@@ -21,6 +21,7 @@ > import org.eclipse.swt.widgets.Control; > import org.eclipse.swt.widgets.Display; > import org.eclipse.swt.widgets.Item; >+import org.eclipse.swt.widgets.Table; > > /** > * Internal table viewer implementation. >@@ -66,52 +67,48 @@ > } > > private void activateCellEditor() { >- if (cellEditors != null) { >- if (cellEditors[columnNumber] != null && cellModifier != null) { >- Object element = tableItem.getData(); >- String property = columnProperties[columnNumber]; >- if (cellModifier.canModify(element, property)) { >- cellEditor = cellEditors[columnNumber]; >- //table.showSelection(); >- cellEditor.addListener(cellEditorListener); >- Object value = cellModifier.getValue(element, property); >- cellEditor.setValue(value); >- // Tricky flow of control here: >- // activate() can trigger callback to cellEditorListener which will clear cellEditor >- // so must get control first, but must still call activate() even if there is no control. >- final Control control = cellEditor.getControl(); >- cellEditor.activate(); >- if (control == null) { >- return; >- } >- setLayoutData(cellEditor.getLayoutData()); >- setEditor(control, tableItem, columnNumber); >- cellEditor.setFocus(); >- if (focusListener == null) { >- focusListener = new FocusAdapter() { >- public void focusLost(FocusEvent e) { >- applyEditorValue(); >- } >- }; >+ ColumnViewerPart part = (ColumnViewerPart)((Table)viewer.getControl()).getColumn(columnNumber).getData(ColumnViewerPart.COLUMN_VIEWER_KEY); >+ Object element = tableItem.getData(); >+ >+ if( part != null && part.getEditingSupport() != null && part.getEditingSupport().canEdit(element) ) { >+ cellEditor = part.getEditingSupport().getCellEditor(element); >+ cellEditor.addListener(cellEditorListener); >+ Object value = part.getEditingSupport().getValue(element); >+ cellEditor.setValue(value); >+ // Tricky flow of control here: >+ // activate() can trigger callback to cellEditorListener which will clear cellEditor >+ // so must get control first, but must still call activate() even if there is no control. >+ final Control control = cellEditor.getControl(); >+ cellEditor.activate(); >+ if (control == null) { >+ return; >+ } >+ setLayoutData(cellEditor.getLayoutData()); >+ setEditor(control, tableItem, columnNumber); >+ cellEditor.setFocus(); >+ if (focusListener == null) { >+ focusListener = new FocusAdapter() { >+ public void focusLost(FocusEvent e) { >+ applyEditorValue(); > } >- control.addFocusListener(focusListener); >- mouseListener = new MouseAdapter() { >- public void mouseDown(MouseEvent e) { >- // time wrap? >- // check for expiration of doubleClickTime >- if (e.time <= doubleClickExpirationTime) { >- control.removeMouseListener(mouseListener); >- cancelEditing(); >- handleDoubleClickEvent(); >- } else if (mouseListener != null) { >- control.removeMouseListener(mouseListener); >- } >- } >- }; >- control.addMouseListener(mouseListener); >- } >+ }; > } >- } >+ control.addFocusListener(focusListener); >+ mouseListener = new MouseAdapter() { >+ public void mouseDown(MouseEvent e) { >+ // time wrap? >+ // check for expiration of doubleClickTime >+ if (e.time <= doubleClickExpirationTime) { >+ control.removeMouseListener(mouseListener); >+ cancelEditing(); >+ handleDoubleClickEvent(); >+ } else if (mouseListener != null) { >+ control.removeMouseListener(mouseListener); >+ } >+ } >+ }; >+ control.addMouseListener(mouseListener); >+ } > } > > /** >@@ -217,7 +214,7 @@ > > abstract Rectangle getBounds(Item item, int columnNumber); > >- /** >+/** > * Return the array of CellEditors used in the viewer > * @return the cell editors > */ >@@ -235,14 +232,14 @@ > > abstract int getColumnCount(); > >- /** >+ /** > * Return the properties for the column > * @return the array of column properties > */ > public Object[] getColumnProperties() { > return columnProperties; > } >- >+ > abstract Item[] getSelection(); > > /** >@@ -308,17 +305,11 @@ > * by delegating to the cell modifier. > */ > private void saveEditorValue(CellEditor cellEditor, Item tableItem) { >- if (cellModifier != null) { >- if (!cellEditor.isValueValid()) { >- ///Do what ??? >- } >- String property = null; >- if (columnProperties != null >- && columnNumber < columnProperties.length) { >- property = columnProperties[columnNumber]; >- } >- cellModifier.modify(tableItem, property, cellEditor.getValue()); >- } >+ ColumnViewerPart part = (ColumnViewerPart)tableItem.getData(ColumnViewerPart.COLUMN_VIEWER_KEY); >+ >+ if( part != null && part.getEditingSupport() != null ) { >+ part.getEditingSupport().setValue(tableItem.getData(), cellEditor.getValue()); >+ } > } > > /** >@@ -344,7 +335,7 @@ > public void setColumnProperties(String[] columnProperties) { > this.columnProperties = columnProperties; > } >- >+ > abstract void setEditor(Control w, Item item, int fColumnNumber); > > abstract void setLayoutData(CellEditor.LayoutData layoutData); >Index: src/org/eclipse/jface/viewers/ViewerLabel.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.jface/src/org/eclipse/jface/viewers/ViewerLabel.java,v >retrieving revision 1.11 >diff -u -r1.11 ViewerLabel.java >--- src/org/eclipse/jface/viewers/ViewerLabel.java 8 May 2006 20:56:57 -0000 1.11 >+++ src/org/eclipse/jface/viewers/ViewerLabel.java 6 Aug 2006 19:01:45 -0000 >@@ -13,6 +13,7 @@ > import org.eclipse.swt.graphics.Color; > import org.eclipse.swt.graphics.Font; > import org.eclipse.swt.graphics.Image; >+import org.eclipse.swt.graphics.Point; > > /** > * The ViewerLabel is the class that is passed to a viewer to handle updates of >@@ -43,6 +44,14 @@ > private Image startImage; > > private boolean hasPendingDecorations; >+ >+ private String tooltipText; >+ >+ private Color tooltipForegroundColor; >+ >+ private Color tooltipBackgroundColor; >+ >+ private Point tooltipShift; > > /** > * Create a new instance of the receiver with the supplied >@@ -241,4 +250,88 @@ > /* public */ boolean hasPendingDecorations() { > return hasPendingDecorations; > } >+ >+ /** >+ * @return Returns the tooltipText. >+ */ >+ public String getTooltipText() { >+ return tooltipText; >+ } >+ >+ /** >+ * @param tooltipText The tooltipText to set. >+ */ >+ public void setTooltipText(String tooltipText) { >+ this.tooltipText = tooltipText; >+ } >+ >+ /** >+ * @return Return whether or not the tooltip text has been set. >+ */ >+ public boolean hasNewTooltipText() { >+ return this.tooltipText != null; >+ } >+ >+ /** >+ * @return Returns the tooltipBackgroundColor. >+ */ >+ public Color getTooltipBackgroundColor() { >+ return tooltipBackgroundColor; >+ } >+ >+ /** >+ * @param tooltipBackgroundColor The tooltipBackgroundColor to set. >+ */ >+ public void setTooltipBackgroundColor(Color tooltipBackgroundColor) { >+ this.tooltipBackgroundColor = tooltipBackgroundColor; >+ } >+ >+ /** >+ * @return Return whether or not the tooltip background color has been set. >+ */ >+ public boolean hasNewTooltipBackgroundColor() { >+ return tooltipBackgroundColor != null; >+ } >+ >+ /** >+ * @return Returns the tooltipForegroundColor. >+ */ >+ public Color getTooltipForegroundColor() { >+ return tooltipForegroundColor; >+ } >+ >+ /** >+ * @param tooltipForegroundColor The tooltipForegroundColor to set. >+ */ >+ public void setTooltipForegroundColor(Color tooltipForegroundColor) { >+ this.tooltipForegroundColor = tooltipForegroundColor; >+ } >+ >+ /** >+ * @return Return whether or not the tooltip foreground color has been set. >+ */ >+ public boolean hasNewTooltipForegroundColor() { >+ return tooltipForegroundColor != null; >+ } >+ >+ /** >+ * @return Returns the tooltipShift. >+ */ >+ public Point getTooltipShift() { >+ return tooltipShift; >+ } >+ >+ /** >+ * @param tooltipShift The tooltipShift to set. >+ */ >+ public void setTooltipShift(Point tooltipShift) { >+ this.tooltipShift = tooltipShift; >+ } >+ >+ /** >+ * @return Return whether or not the tooltip shift has been set. >+ */ >+ public boolean hasTooltipShift() { >+ return this.tooltipShift != null; >+ } > } >Index: src/org/eclipse/jface/viewers/StructuredViewer.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.jface/src/org/eclipse/jface/viewers/StructuredViewer.java,v >retrieving revision 1.53 >diff -u -r1.53 StructuredViewer.java >--- src/org/eclipse/jface/viewers/StructuredViewer.java 11 May 2006 05:18:15 -0000 1.53 >+++ src/org/eclipse/jface/viewers/StructuredViewer.java 6 Aug 2006 19:01:43 -0000 >@@ -16,6 +16,7 @@ > import java.util.List; > > import org.eclipse.core.runtime.ListenerList; >+import org.eclipse.jface.internal.viewers.RowPart; > import org.eclipse.jface.util.Assert; > import org.eclipse.jface.util.IOpenEventListener; > import org.eclipse.jface.util.OpenStrategy; >@@ -31,6 +32,7 @@ > import org.eclipse.swt.events.SelectionListener; > import org.eclipse.swt.graphics.Color; > import org.eclipse.swt.graphics.Font; >+import org.eclipse.swt.graphics.Point; > import org.eclipse.swt.widgets.Control; > import org.eclipse.swt.widgets.Item; > import org.eclipse.swt.widgets.TableItem; >@@ -131,6 +133,8 @@ > */ > private static Widget[] NO_WIDGETS = new Widget[0]; > >+ private TooltipSupport tooltipSupport; >+ > /** > * The ColorAndFontCollector is a helper class for viewers > * that have color and font support ad optionally decorators. >@@ -472,6 +476,7 @@ > */ > protected StructuredViewer() { > // do nothing >+ tooltipSupport = new TooltipSupport(this); > } > > /** >@@ -2112,4 +2117,113 @@ > return colorAndFontCollector; > } > >+ /** >+ * Get the cell at this point. >+ * <p><i>Subclasses should overwrite this method and provide a meaningful implementation</i></p> >+ * @param point the point in the viewer where you need to corresponding cell from >+ * @param onlyInSelection search only in selection >+ * @return the cell or if no cell is found at this point >+ */ >+ Cell getCell(Point point) { >+ RowPart row = getRowPart(point); >+ if( row != null ) { >+ return row.getCell(point); >+ } >+ >+ return null; >+ } >+ >+ protected RowPart getRowPart(Point point) { >+ Item item = getItem(point.x, point.y); >+ >+ if( item != null ) { >+ return getRowPartFromItem(item); >+ } >+ >+ return null; >+ } >+ >+ protected RowPart getRowPartFromItem(Widget item) { >+ return (RowPart)item.getData(RowPart.ROWPART_KEY); >+ } >+ >+ protected RowPart createNewRowPart(RowPart parent, int style, int rowIndex) { >+ return null; >+ } >+ >+ protected Widget getColumnViewerOwner(int columnIndex) { >+ return null; >+ } >+ >+ public ICellModifier getCellModifier() { >+ return null; >+ } >+ >+ public CellEditor[] getCellEditors() { >+ return null; >+ } >+ >+ public Object[] getColumnProperties() { >+ return null; >+ } >+ >+ /** >+ * Return the TableColumnViewer at columnIndex >+ * >+ * @param columnIndex >+ * @return TableColumnViewer >+ */ >+ public ColumnViewerPart getColumnViewer(final int columnIndex) { >+ >+ ColumnViewerPart viewer; >+ Widget columnOwner = getColumnViewerOwner(columnIndex); >+ >+ if( columnOwner == null ) { >+ return null; >+ } >+ >+ viewer = (ColumnViewerPart)columnOwner.getData(ColumnViewerPart.COLUMN_VIEWER_KEY); >+ >+ if (viewer == null) { >+ createColumnViewer(columnOwner, ViewerLabelProvider.createViewerLabelProvider(getLabelProvider())); >+ if( getCellModifier() != null ) { >+ viewer.setEditingSupport(new IEditingSupport() { >+ >+ public boolean canEdit(Object element) { >+ return getCellModifier().canModify(element, (String)getColumnProperties()[columnIndex]); >+ } >+ >+ public CellEditor getCellEditor(Object element) { >+ return getCellEditors()[columnIndex]; >+ } >+ >+ public Object getValue(Object element) { >+ return getCellModifier().getValue(element, (String)getColumnProperties()[columnIndex]); >+ } >+ >+ public void setValue(Object element, Object value) { >+ getCellModifier().modify( findItem(element), (String)getColumnProperties()[columnIndex], value); >+ } >+ }); >+ } >+ } >+ >+ // Reset the colum-index because maybe it changed from the last time >+ viewer.getLabelProvider().setColumnIndex(columnIndex); >+ >+ return viewer; >+ } >+ >+ protected ColumnViewerPart createColumnViewer(Widget columnOwner, ViewerLabelProvider labelProvider) { >+ return new ColumnViewerPart(columnOwner, >+ ViewerLabelProvider.createViewerLabelProvider(getLabelProvider())); >+ } >+ >+ public void activateCustomTooltips() { >+ tooltipSupport.activate(); >+ } >+ >+ public void deactivateCustomTooltips() { >+ tooltipSupport.deactivate(); >+ } > } >Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /home/eclipse/org.eclipse.jface/META-INF/MANIFEST.MF,v >retrieving revision 1.20 >diff -u -r1.20 MANIFEST.MF >--- META-INF/MANIFEST.MF 7 Jun 2006 18:21:24 -0000 1.20 >+++ META-INF/MANIFEST.MF 6 Aug 2006 19:01:41 -0000 >@@ -20,6 +20,7 @@ > org.eclipse.jface.fieldassist.images, > org.eclipse.jface.images, > org.eclipse.jface.internal.provisional.action;x-friends:="org.eclipse.ui.workbench", >+ org.eclipse.jface.internal.viewers;x-internal:=true, > org.eclipse.jface.layout, > org.eclipse.jface.menus, > org.eclipse.jface.operation, >Index: src/org/eclipse/jface/viewers/IEditingSupport.java >=================================================================== >RCS file: src/org/eclipse/jface/viewers/IEditingSupport.java >diff -N src/org/eclipse/jface/viewers/IEditingSupport.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/viewers/IEditingSupport.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,55 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ ******************************************************************************/ >+ >+package org.eclipse.jface.viewers; >+ >+/** >+ * @since 3.2 >+ * >+ */ >+public interface IEditingSupport { >+ /** >+ * The editor to be shown >+ * >+ * @param element >+ * the model element >+ * @return the CellEditor >+ */ >+ public CellEditor getCellEditor(Object element); >+ >+ /** >+ * Is the cell editable >+ * >+ * @param element >+ * the model element >+ * @return true if editable >+ */ >+ public boolean canEdit(Object element); >+ >+ /** >+ * Get the value to set to the editor >+ * >+ * @param element >+ * the model element >+ * @return the value shown >+ */ >+ public Object getValue(Object element); >+ >+ /** >+ * Restore the value from the CellEditor >+ * >+ * @param element >+ * the model element >+ * @param value >+ * the new value >+ */ >+ public void setValue(Object element, Object value); >+} >Index: src/org/eclipse/jface/viewers/ColumnViewerPart.java >=================================================================== >RCS file: src/org/eclipse/jface/viewers/ColumnViewerPart.java >diff -N src/org/eclipse/jface/viewers/ColumnViewerPart.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/viewers/ColumnViewerPart.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,152 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ ******************************************************************************/ >+ >+package org.eclipse.jface.viewers; >+ >+import org.eclipse.jface.internal.viewers.RowPart; >+import org.eclipse.jface.util.Policy; >+import org.eclipse.swt.widgets.Widget; >+ >+/** >+ * The ColumnViewerPart is abstract implementation of the column parts. >+ * >+ * @since 3.3 >+ * >+ */ >+public class ColumnViewerPart { >+ >+ private ViewerLabelProvider labelProvider; >+ >+ static String COLUMN_VIEWER_KEY = Policy.JFACE + ".columnViewer";//$NON-NLS-1$ >+ >+ private IEditingSupport editingSupport; >+ >+ /** >+ * Create a new instance of the receiver at columnIndex. >+ * >+ * @param columnOwner >+ * @param provider >+ */ >+ public ColumnViewerPart(Widget columnOwner, ViewerLabelProvider provider) { >+ labelProvider = provider; >+ columnOwner.setData(ColumnViewerPart.COLUMN_VIEWER_KEY, this); >+ } >+ >+ /** >+ * Return the label provider for the receiver. >+ * >+ * @return ViewerLabelProvider >+ */ >+ public ViewerLabelProvider getLabelProvider() { >+ return labelProvider; >+ } >+ >+ /** >+ * @param labelProvider >+ * the new label-provider >+ */ >+ public void setLabelProvider(ViewerLabelProvider labelProvider) { >+ this.labelProvider = labelProvider; >+ } >+ >+ /** >+ * @return Returns the editingSupport. >+ */ >+ public IEditingSupport getEditingSupport() { >+ return editingSupport; >+ } >+ >+ /** >+ * @param editingSupport >+ * The editingSupport to set. >+ */ >+ public void setEditingSupport(IEditingSupport editingSupport) { >+ this.editingSupport = editingSupport; >+ } >+ >+ /** >+ * Refresh the row for the given columnIndex >+ * >+ * @param row >+ * @param element >+ * @param columnIndex >+ */ >+ public void refresh(RowPart row, int columnIndex) { >+ ViewerLabel label = new ViewerLabel(row.getText(columnIndex), row >+ .getImage(columnIndex)); >+ getLabelProvider().updateLabel(label, row.getElement(), columnIndex); >+ >+ row.setBackground(columnIndex, label.getBackground()); >+ row.setForeground(columnIndex, label.getForeground()); >+ row.setFont(columnIndex, label.getFont()); >+ >+ if (label.hasNewText()) >+ row.setText(columnIndex, label.getText()); >+ >+ if (label.hasNewImage()) >+ row.setImage(columnIndex, label.getImage()); >+ } >+ >+ /** >+ * Refresh the TreeItem for element. >+ * >+ * @param item >+ * @param element >+ * @param columnIndex >+ */ >+/* public void refresh(TreeItem item, Object element, int columnIndex) { >+ >+ ViewerLabel label = new ViewerLabel(item.getText(columnIndex), item >+ .getImage(columnIndex)); >+ getLabelProvider().updateLabel(label, element, columnIndex); >+ >+ // We can not make a null check because then we could not >+ // set the items back to default state >+ item.setBackground(columnIndex, label.getBackground()); >+ item.setForeground(columnIndex, label.getForeground()); >+ item.setFont(columnIndex, label.getFont()); >+ >+ if (label.hasNewText()) >+ item.setText(columnIndex, label.getText()); >+ >+ if (label.hasNewImage()) >+ item.setImage(columnIndex, label.getImage()); >+ } >+*/ >+ /** >+ * Refresh the TableItem for element. >+ * >+ * @param item >+ * @param element >+ * @param columnIndex >+ */ >+/* public void refresh(TableItem item, Object element, int columnIndex) { >+ >+ ViewerLabel label = new ViewerLabel(item.getText(columnIndex), item >+ .getImage(columnIndex)); >+ getLabelProvider().updateLabel(label, element, columnIndex); >+ >+ if (label.hasNewBackground()) >+ item.setBackground(columnIndex, label.getBackground()); >+ >+ if (label.hasNewForeground()) >+ item.setForeground(columnIndex, label.getForeground()); >+ >+ if (label.hasNewFont()) >+ item.setFont(columnIndex, label.getFont()); >+ >+ if (label.hasNewText()) >+ item.setText(columnIndex, label.getText()); >+ >+ if (label.hasNewImage()) >+ item.setImage(columnIndex, label.getImage()); >+ }*/ >+} >Index: src/org/eclipse/jface/viewers/TreeColumnViewerLabelProvider.java >=================================================================== >RCS file: src/org/eclipse/jface/viewers/TreeColumnViewerLabelProvider.java >diff -N src/org/eclipse/jface/viewers/TreeColumnViewerLabelProvider.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/viewers/TreeColumnViewerLabelProvider.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,53 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ ******************************************************************************/ >+ >+package org.eclipse.jface.viewers; >+ >+ >+/** >+ * TreeViewerLabelProvider is the ViewerLabelProvider that handles >+ * TreePaths. >+ * @since 3.2 >+ * >+ */ >+public class TreeColumnViewerLabelProvider extends ViewerLabelProvider { >+ private ITreePathLabelProvider treePathProvider; >+ >+ >+ >+ /** >+ * Update the label for the element with TreePath. >+ * @param label >+ * @param elementPath >+ */ >+ public void updateLabel(ViewerLabel label, TreePath elementPath) { >+ treePathProvider.updateLabel(label, elementPath); >+ >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.viewers.ViewerLabelProvider#setProviders(java.lang.Object) >+ */ >+ public void setProviders(Object provider) { >+ super.setProviders(provider); >+ if(provider instanceof ITreePathLabelProvider) >+ treePathProvider = (ITreePathLabelProvider) provider; >+ } >+ >+ /** >+ * Return the ITreePathLabelProvider for the receiver. >+ * @return Returns the treePathProvider. >+ */ >+ public ITreePathLabelProvider getTreePathProvider() { >+ return treePathProvider; >+ } >+ >+} >Index: src/org/eclipse/jface/viewers/TableRowPart.java >=================================================================== >RCS file: src/org/eclipse/jface/viewers/TableRowPart.java >diff -N src/org/eclipse/jface/viewers/TableRowPart.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/viewers/TableRowPart.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,88 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ ******************************************************************************/ >+ >+package org.eclipse.jface.viewers; >+ >+import org.eclipse.swt.graphics.Color; >+import org.eclipse.swt.graphics.Font; >+import org.eclipse.swt.graphics.Image; >+import org.eclipse.swt.graphics.Rectangle; >+import org.eclipse.swt.widgets.TableItem; >+import org.eclipse.swt.widgets.Widget; >+ >+/** >+ * @since 3.2 >+ * >+ */ >+public class TableRowPart extends DefaultRowPartImpl { >+ private TableItem item; >+ >+ public TableRowPart(TableItem item) { >+ this.item = item; >+ } >+ >+ public Rectangle getBounds(int columnIndex) { >+ return item.getBounds(columnIndex); >+ } >+ >+ public Rectangle getBounds() { >+ return item.getBounds(); >+ } >+ >+ public Widget getItem() { >+ return item; >+ } >+ >+ public int getColumnCount() { >+ return item.getParent().getColumnCount(); >+ } >+ >+ public Color getBackground(int columnIndex) { >+ return item.getBackground(columnIndex); >+ } >+ >+ public Font getFont(int columnIndex) { >+ return item.getFont(columnIndex); >+ } >+ >+ public Color getForeground(int columnIndex) { >+ return item.getForeground(columnIndex); >+ } >+ >+ public Image getImage(int columnIndex) { >+ return item.getImage(columnIndex); >+ } >+ >+ public String getText(int columnIndex) { >+ return item.getText(columnIndex); >+ } >+ >+ public void setBackground(int columnIndex, Color color) { >+ item.setBackground(columnIndex, color); >+ } >+ >+ public void setFont(int columnIndex, Font font) { >+ item.setFont(columnIndex, font); >+ } >+ >+ public void setForeground(int columnIndex, Color color) { >+ item.setForeground(columnIndex, color); >+ } >+ >+ public void setImage(int columnIndex, Image image) { >+ item.setImage(columnIndex,image); >+ } >+ >+ public void setText(int columnIndex, String text) { >+ item.setText(columnIndex, text); >+ } >+ >+} >Index: src/org/eclipse/jface/viewers/ITableTooltipLabelProvider.java >=================================================================== >RCS file: src/org/eclipse/jface/viewers/ITableTooltipLabelProvider.java >diff -N src/org/eclipse/jface/viewers/ITableTooltipLabelProvider.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/viewers/ITableTooltipLabelProvider.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,44 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 BestSolution Systemhaus GmbH >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Tom Schind - tom.schindl@bestsolution.at >+ *******************************************************************************/ >+package org.eclipse.jface.viewers; >+ >+import org.eclipse.swt.graphics.Image; >+ >+/** >+ * >+ * @since 3.3 >+ * >+ */ >+public interface ITableTooltipLabelProvider { >+ /** >+ * Returns the tooltip text for the given element and column index, or >+ * <code>null</code> if a custom tooltip should not be displayed. >+ * >+ * @param element >+ * the element for which the tooltip is shown >+ * @param columnIndex >+ * the column index used >+ * @return the text to be displayed in the tooltip, or <code>null</code> >+ * if a custom tooltip should not be displayed >+ */ >+ public String getTooltipText(Object element, int columnIndex); >+ >+ /** >+ * The image displayed in the tooltip >+ * >+ * @param object >+ * the element for which the tooltip is shown >+ * @param columnIndex >+ * the column index used >+ * @return the image displayed if null no image is displayed >+ */ >+ public Image getTooltipImage(Object object, int columnIndex); >+} >Index: src/org/eclipse/jface/viewers/ViewerLabelProvider.java >=================================================================== >RCS file: src/org/eclipse/jface/viewers/ViewerLabelProvider.java >diff -N src/org/eclipse/jface/viewers/ViewerLabelProvider.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/viewers/ViewerLabelProvider.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,395 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ ******************************************************************************/ >+ >+package org.eclipse.jface.viewers; >+ >+import org.eclipse.jface.internal.viewers.ITooltipAddonsProvider; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.graphics.Color; >+import org.eclipse.swt.graphics.Font; >+import org.eclipse.swt.graphics.Image; >+import org.eclipse.swt.graphics.Point; >+ >+/** >+ * @since 3.2 >+ * >+ */ >+public class ViewerLabelProvider extends LabelProvider implements >+ ILabelProvider, IColorProvider, IFontProvider, ITooltipLabelProvider, >+ ITooltipColorProvider, ITooltipFontProvider, ITooltipAddonsProvider { >+ >+ private static ILabelProvider defaultLabelProvider = new LabelProvider() { >+ >+ }; >+ >+ private ILabelProvider labelProvider = defaultLabelProvider; >+ >+ private IColorProvider colorProvider; >+ >+ private IFontProvider fontProvider; >+ >+ private ITooltipLabelProvider tooltipLabelProvider; >+ >+ private ITooltipColorProvider tooltipColorProvider; >+ >+ private ITooltipFontProvider tooltipFontProvider; >+ >+ private ITooltipAddonsProvider tooltipAddonsProvider; >+ >+ private int columnIndex; >+ >+ /** >+ * Create a new instance of the receiver. >+ */ >+ public ViewerLabelProvider() { >+ super(); >+ } >+ >+ /** >+ * Create a new instance of the receiver based on labelProvider. >+ * >+ * @param labelProvider >+ */ >+ public ViewerLabelProvider(IBaseLabelProvider labelProvider) { >+ super(); >+ setProviders(labelProvider); >+ } >+ >+ /** >+ * Create a ViewerLabelProvider for the column at index >+ * >+ * @param columnIndex >+ * @param labelProvider >+ * The labelProvider to convert >+ * @return ViewerLabelProvider >+ */ >+ static ViewerLabelProvider createViewerLabelProvider( >+ IBaseLabelProvider labelProvider) { >+ >+ if (labelProvider instanceof ITableLabelProvider >+ || labelProvider instanceof ITableColorProvider >+ || labelProvider instanceof ITableFontProvider) >+ return new TableColumnViewerLabelProvider(labelProvider); >+ return new ViewerLabelProvider(labelProvider); >+ >+ } >+ >+ private void updateLabel(ViewerLabel label, Object element) { >+ label.setText(labelProvider.getText(element)); >+ label.setImage(labelProvider.getImage(element)); >+ >+ if (colorProvider != null) { >+ label.setBackground(colorProvider.getBackground(element)); >+ label.setForeground(colorProvider.getForeground(element)); >+ } >+ >+ if (fontProvider != null) { >+ label.setFont(fontProvider.getFont(element)); >+ } >+ } >+ >+ /** >+ * Updates the label for the given element and the given index >+ * >+ * @param label >+ * the label to update >+ * @param element >+ * the element >+ * @param columnIndex >+ * the column index >+ */ >+ public void updateLabel(ViewerLabel label, Object element, int columnIndex) { >+ setColumnIndex(columnIndex); >+ updateLabel(label, element); >+ } >+ >+ /** >+ * @param columnIndex the column-index >+ */ >+ public void setColumnIndex(int columnIndex) { >+ this.columnIndex = columnIndex; >+ } >+ >+ /** >+ * @return Returns the column index >+ */ >+ public int getColumnIndex() { >+ return columnIndex; >+ } >+ >+ /** >+ * Set the colorProvider to use for the receiver. >+ * >+ * @param colorProvider >+ * The colorProvider to set. >+ */ >+ public void setColorProvider(IColorProvider colorProvider) { >+ this.colorProvider = colorProvider; >+ } >+ >+ /** >+ * Set the fontProvider to fontProvider. >+ * >+ * @param fontProvider >+ * The fontProvider to set. >+ */ >+ public void setFontProvider(IFontProvider fontProvider) { >+ this.fontProvider = fontProvider; >+ } >+ >+ /** >+ * Set the labelProvider to be provider. >+ * >+ * @param provider >+ * ILabelProvider provider to set. >+ */ >+ public void setLabelProvider(ILabelProvider provider) { >+ this.labelProvider = provider; >+ } >+ >+ /** >+ * Set the tooltip provider >+ * >+ * @param tooltipProvider >+ */ >+ public void setTooltipLabelProvider(ITooltipLabelProvider tooltipProvider) { >+ this.tooltipLabelProvider = tooltipProvider; >+ } >+ >+ /** >+ * Set the tooltip color provider >+ * >+ * @param tooltipColorProvider >+ * ITooltipColorProvider to set >+ */ >+ public void setTooltipColorProvider( >+ ITooltipColorProvider tooltipColorProvider) { >+ this.tooltipColorProvider = tooltipColorProvider; >+ } >+ >+ /** >+ * Set tooltip font provider >+ * >+ * @param tooltipFontProvider >+ * ITooltipFontProvider to set >+ */ >+ public void setTooltipFontProvider(ITooltipFontProvider tooltipFontProvider) { >+ this.tooltipFontProvider = tooltipFontProvider; >+ } >+ >+ /** >+ * Set the tooltip addons provider >+ * >+ * @param tooltipAddonsProvider >+ * ITooltipAddonsProvider to set >+ */ >+ public void setTooltipAddonsProvider( >+ ITooltipAddonsProvider tooltipAddonsProvider) { >+ this.tooltipAddonsProvider = tooltipAddonsProvider; >+ } >+ >+ /** >+ * Set the any providers for the receiver that can be adapted from provider. >+ * >+ * @param provider >+ */ >+ public void setProviders(Object provider) { >+ if (provider instanceof ILabelProvider) >+ labelProvider = (ILabelProvider) provider; >+ >+ if (provider instanceof IColorProvider) >+ colorProvider = (IColorProvider) provider; >+ >+ if (provider instanceof IFontProvider) >+ fontProvider = (IFontProvider) provider; >+ >+ if (provider instanceof ITooltipLabelProvider) >+ tooltipLabelProvider = (ITooltipLabelProvider) provider; >+ >+ if (provider instanceof ITooltipColorProvider) >+ tooltipColorProvider = (ITooltipColorProvider) provider; >+ >+ if (provider instanceof ITooltipFontProvider) >+ tooltipFontProvider = (ITooltipFontProvider) provider; >+ >+ if (provider instanceof ITooltipAddonsProvider) >+ tooltipAddonsProvider = (ITooltipAddonsProvider) provider; >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.jface.viewers.IFontProvider#getFont(java.lang.Object) >+ */ >+ public Font getFont(Object element) { >+ if (fontProvider == null) { >+ return null; >+ } >+ >+ return fontProvider.getFont(element); >+ >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.jface.viewers.IColorProvider#getBackground(java.lang.Object) >+ */ >+ public Color getBackground(Object element) { >+ if (colorProvider == null) { >+ return null; >+ } >+ >+ return colorProvider.getBackground(element); >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.jface.viewers.IColorProvider#getForeground(java.lang.Object) >+ */ >+ public Color getForeground(Object element) { >+ if (colorProvider == null) { >+ return null; >+ } >+ >+ return colorProvider.getForeground(element); >+ } >+ >+ /** >+ * Get the IColorProvider for the receiver. >+ * >+ * @return IColorProvider >+ */ >+ public IColorProvider getColorProvider() { >+ return colorProvider; >+ } >+ >+ /** >+ * Get the IFontProvider for the receiver. >+ * >+ * @return IFontProvider >+ */ >+ public IFontProvider getFontProvider() { >+ return fontProvider; >+ } >+ >+ /** >+ * @return Returns the labelProvider. >+ */ >+ public ILabelProvider getLabelProvider() { >+ return labelProvider; >+ } >+ >+ /** >+ * @return Returns the tooltipColorProvider >+ */ >+ public ITooltipColorProvider getTooltipColorProvider() { >+ return tooltipColorProvider; >+ } >+ >+ /** >+ * @return Returns the tooltipAddonsProvider. >+ */ >+ public ITooltipAddonsProvider getTooltipAddonsProvider() { >+ return tooltipAddonsProvider; >+ } >+ >+ /** >+ * @return Returns the tooltipFontProvider. >+ */ >+ public ITooltipFontProvider getTooltipFontProvider() { >+ return tooltipFontProvider; >+ } >+ >+ /** >+ * @return Returns the tooltipLabelProvider. >+ */ >+ public ITooltipLabelProvider getTooltipLabelProvider() { >+ return tooltipLabelProvider; >+ } >+ >+ public Image getTooltipImage(Object object) { >+ if (tooltipLabelProvider == null) { >+ return null; >+ } >+ >+ return tooltipLabelProvider.getTooltipImage(object); >+ } >+ >+ public String getTooltipText(Object element) { >+ if (tooltipLabelProvider == null) { >+ return null; >+ } >+ >+ return tooltipLabelProvider.getTooltipText(element); >+ } >+ >+ public Color getTooltipBackgroundColor(Object object) { >+ if (tooltipColorProvider == null) { >+ return null; >+ } >+ >+ return tooltipColorProvider.getTooltipBackgroundColor(object); >+ } >+ >+ public Color getTooltipForegroundColor(Object object) { >+ if (tooltipColorProvider == null) { >+ return null; >+ } >+ >+ return tooltipColorProvider.getTooltipForegroundColor(object); >+ } >+ >+ public Font getTooltipFont(Object object) { >+ if (tooltipFontProvider == null) { >+ return null; >+ } >+ >+ return tooltipFontProvider.getTooltipFont(object); >+ } >+ >+ public int getTooltipDisplayDelayTime(Object object) { >+ if (tooltipAddonsProvider == null) { >+ return 0; >+ } >+ >+ return tooltipAddonsProvider.getTooltipDisplayDelayTime(object); >+ } >+ >+ public Point getTooltipShift(Object object) { >+ if (tooltipAddonsProvider == null) { >+ return null; >+ } >+ return tooltipAddonsProvider.getTooltipShift(object); >+ } >+ >+ public int getTooltipTimeDisplayed(Object object) { >+ if (tooltipAddonsProvider == null) { >+ return 0; >+ } >+ return tooltipAddonsProvider.getTooltipTimeDisplayed(object); >+ } >+ >+ public boolean useNativeTooltip(Object object) { >+ if (tooltipAddonsProvider == null) { >+ return false; >+ } >+ return tooltipAddonsProvider.useNativeTooltip(object); >+ } >+ >+ public int getTooltipImageStyle(Object object) { >+ if (tooltipAddonsProvider == null) { >+ return SWT.SHADOW_NONE; >+ } >+ return tooltipAddonsProvider.getTooltipImageStyle(object); >+ } >+} >Index: src/org/eclipse/jface/viewers/TableColumnViewerLabelProvider.java >=================================================================== >RCS file: src/org/eclipse/jface/viewers/TableColumnViewerLabelProvider.java >diff -N src/org/eclipse/jface/viewers/TableColumnViewerLabelProvider.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/viewers/TableColumnViewerLabelProvider.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,178 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ ******************************************************************************/ >+ >+package org.eclipse.jface.viewers; >+ >+import org.eclipse.swt.graphics.Color; >+import org.eclipse.swt.graphics.Font; >+import org.eclipse.swt.graphics.Image; >+ >+/** >+ * TableColumnViewerLabelProvider is the mapping from the table based providers >+ * to the ViewerLabelProvider. >+ * >+ * @since 3.3 >+ * @see ITableLabelProvider >+ * @see ITableColorProvider >+ * @see ITableFontProvider >+ * >+ */ >+class TableColumnViewerLabelProvider extends ViewerLabelProvider { >+ >+ /** >+ * Create a new instance of the receiver. >+ * >+ * @param labelProvider >+ * instance of a table based label provider >+ * @param columnIndex >+ * the index into the table for this column >+ * @see ITableLabelProvider >+ * @see ITableColorProvider >+ * @see ITableFontProvider >+ */ >+ public TableColumnViewerLabelProvider(IBaseLabelProvider labelProvider) { >+ super(labelProvider); >+ >+ if (labelProvider instanceof ITableLabelProvider) >+ setLabelProvider(labelProviderFor((ITableLabelProvider) labelProvider)); >+ >+ if (labelProvider instanceof ITableColorProvider) >+ setColorProvider(colorProviderFor((ITableColorProvider) labelProvider)); >+ >+ if (labelProvider instanceof ITableFontProvider) >+ setFontProvider(fontProviderFor((ITableFontProvider) labelProvider)); >+ >+ if (labelProvider instanceof ITableTooltipLabelProvider) >+ setTooltipLabelProvider(tooltipLabelFor((ITableTooltipLabelProvider) labelProvider)); >+ >+ if(labelProvider instanceof ITableTooltipColorProvider) >+ setTooltipColorProvider(tooltipColorFor((ITableTooltipColorProvider)labelProvider)); >+ >+ if(labelProvider instanceof ITableTooltipFontProvider) >+ setTooltipFontProvider(tooltipFontFor((ITableTooltipFontProvider)labelProvider)); >+ } >+ >+ private ITooltipFontProvider tooltipFontFor(final ITableTooltipFontProvider provider) { >+ return new ITooltipFontProvider() { >+ >+ public Font getTooltipFont(Object object) { >+ return provider.getTooltipFont(object, getColumnIndex()); >+ } >+ }; >+ } >+ >+ private ITooltipColorProvider tooltipColorFor(final ITableTooltipColorProvider provider) { >+ return new ITooltipColorProvider() { >+ >+ public Color getTooltipBackgroundColor(Object object) { >+ return provider.getTooltipBackgroundColor(object, getColumnIndex()); >+ } >+ >+ public Color getTooltipForegroundColor(Object object) { >+ return provider.getTooltipForegroundColor(object, getColumnIndex()); >+ } >+ }; >+ } >+ >+ private ITooltipLabelProvider tooltipLabelFor( >+ final ITableTooltipLabelProvider provider) { >+ return new ITooltipLabelProvider() { >+ >+ public Image getTooltipImage(Object object) { >+ return provider.getTooltipImage(object, getColumnIndex()); >+ } >+ >+ public String getTooltipText(Object element) { >+ return provider.getTooltipText(element, getColumnIndex()); >+ } >+ >+ }; >+ } >+ >+ /** >+ * Return the IFontProvider based on provider at columnIndex. >+ * >+ * @param provider >+ * @param columnIndex >+ * @return IFontProvider >+ */ >+ private IFontProvider fontProviderFor(final ITableFontProvider provider) { >+ return new IFontProvider() { >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.jface.viewers.IFontProvider#getFont(java.lang.Object) >+ */ >+ public Font getFont(Object element) { >+ return provider.getFont(element, getColumnIndex()); >+ } >+ }; >+ } >+ >+ /** >+ * Return the ILabelProvider based on provider at columnIndex. >+ * >+ * @param provider >+ * @param columnIndex >+ * @return ILabelProvider >+ */ >+ private ILabelProvider labelProviderFor(final ITableLabelProvider provider) { >+ return new LabelProvider() { >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object) >+ */ >+ public String getText(Object element) { >+ return provider.getColumnText(element, getColumnIndex()); >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object) >+ */ >+ public Image getImage(Object element) { >+ return provider.getColumnImage(element, getColumnIndex()); >+ } >+ }; >+ } >+ >+ /** >+ * Create an IColorProvider from the ITableColorProvider at columnIndex. >+ * >+ * @param provider >+ * @param columnIndex >+ * @return IColorProvider >+ */ >+ private IColorProvider colorProviderFor(final ITableColorProvider provider) { >+ return new IColorProvider() { >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.jface.viewers.IColorProvider#getBackground(java.lang.Object) >+ */ >+ public Color getBackground(Object element) { >+ return provider.getBackground(element, getColumnIndex()); >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.jface.viewers.IColorProvider#getForeground(java.lang.Object) >+ */ >+ public Color getForeground(Object element) { >+ return provider.getForeground(element, getColumnIndex()); >+ } >+ }; >+ } >+ >+} >Index: src/org/eclipse/jface/internal/viewers/RowPart.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/viewers/RowPart.java >diff -N src/org/eclipse/jface/internal/viewers/RowPart.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/viewers/RowPart.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,87 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ ******************************************************************************/ >+ >+package org.eclipse.jface.internal.viewers; >+ >+import org.eclipse.jface.util.Policy; >+import org.eclipse.jface.viewers.Cell; >+import org.eclipse.swt.graphics.Color; >+import org.eclipse.swt.graphics.Font; >+import org.eclipse.swt.graphics.Image; >+import org.eclipse.swt.graphics.Point; >+import org.eclipse.swt.graphics.Rectangle; >+import org.eclipse.swt.widgets.Widget; >+ >+/** >+ * @since 3.2 >+ * >+ */ >+public abstract class RowPart { >+ public static final String ROWPART_KEY = Policy.JFACE + ".ROWPART"; //$NON-NLS-1$ >+ >+ public abstract Rectangle getBounds(int columnIndex); >+ >+ public abstract Rectangle getBounds(); >+ >+ public abstract Widget getItem(); >+ >+ public abstract int getColumnCount(); >+ >+ public abstract Image getImage(int columnIndex); >+ >+ public abstract void setImage(int columnIndex,Image image); >+ >+ public abstract String getText(int columnIndex); >+ >+ public abstract void setText(int columnIndex,String text); >+ >+ public abstract Color getBackground(int columnIndex); >+ >+ public abstract void setBackground(int columnIndex, Color color); >+ >+ public abstract Color getForeground(int columnIndex); >+ >+ public abstract void setForeground(int columnIndex, Color color); >+ >+ public abstract Font getFont(int columnIndex); >+ >+ public abstract void setFont(int columnIndex,Font font); >+ >+ public Cell getCell(Point point) { >+ int index = getColumIndex(point); >+ >+ if( index >= 0 ) { >+ return new Cell(this,index); >+ } >+ >+ return null; >+ } >+ >+ public int getColumIndex(Point point) { >+ int count = getColumnCount(); >+ >+ for(int i = 0; i < count; i++ ) { >+ if( getBounds(i).contains(point) ) { >+ return i; >+ } >+ } >+ >+ return -1; >+ } >+ >+ public Object getElement() { >+ return getItem().getData(); >+ } >+ >+ public void associate() { >+ getItem().setData(RowPart.ROWPART_KEY, this); >+ } >+} >Index: src/org/eclipse/jface/viewers/DefaultRowPartImpl.java >=================================================================== >RCS file: src/org/eclipse/jface/viewers/DefaultRowPartImpl.java >diff -N src/org/eclipse/jface/viewers/DefaultRowPartImpl.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/viewers/DefaultRowPartImpl.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,85 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ ******************************************************************************/ >+ >+package org.eclipse.jface.viewers; >+ >+import org.eclipse.jface.internal.viewers.RowPart; >+import org.eclipse.swt.graphics.Color; >+import org.eclipse.swt.graphics.Font; >+import org.eclipse.swt.graphics.Image; >+import org.eclipse.swt.graphics.Rectangle; >+import org.eclipse.swt.widgets.Widget; >+ >+/** >+ * @since 3.2 >+ * >+ */ >+public class DefaultRowPartImpl extends RowPart { >+ >+ public Color getBackground(int columnIndex) { >+ return null; >+ } >+ >+ public Rectangle getBounds(int columnIndex) { >+ return null; >+ } >+ >+ public Rectangle getBounds() { >+ return null; >+ } >+ >+ public int getColumnCount() { >+ return 0; >+ } >+ >+ public Font getFont(int columnIndex) { >+ return null; >+ } >+ >+ public Color getForeground(int columnIndex) { >+ return null; >+ } >+ >+ public Image getImage(int columnIndex) { >+ return null; >+ } >+ >+ public Widget getItem() { >+ return null; >+ } >+ >+ public String getText(int columnIndex) { >+ return null; >+ } >+ >+ >+ public void setBackground(int columnIndex, Color color) { >+ >+ } >+ >+ >+ public void setFont(int columnIndex, Font font) { >+ >+ } >+ >+ public void setForeground(int columnIndex, Color color) { >+ >+ } >+ >+ public void setImage(int columnIndex, Image image) { >+ >+ } >+ >+ public void setText(int columnIndex, String text) { >+ >+ } >+ >+} >Index: src/org/eclipse/jface/viewers/ITableTooltipColorProvider.java >=================================================================== >RCS file: src/org/eclipse/jface/viewers/ITableTooltipColorProvider.java >diff -N src/org/eclipse/jface/viewers/ITableTooltipColorProvider.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/viewers/ITableTooltipColorProvider.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,45 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ ******************************************************************************/ >+ >+package org.eclipse.jface.viewers; >+ >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.graphics.Color; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public interface ITableTooltipColorProvider { >+ /** >+ * The foreground color used to display the the text in the tooltip >+ * >+ * @param object >+ * the element for which the tooltip is shown >+ * @param columnIndex >+ * the column index used >+ * @return the color used or <code>null</code> if you want to use the >+ * default color {@link SWT#COLOR_INFO_FOREGROUND} >+ */ >+ public Color getTooltipForegroundColor(Object object, int columnIndex); >+ >+ /** >+ * The background color used for the tooltip >+ * >+ * @param object >+ * the element for which the tooltip is shown >+ * @param columnIndex >+ * the column index used >+ * @return the color used or <code>null</code> if you want to use the >+ */ >+ public Color getTooltipBackgroundColor(Object object, int columnIndex); >+ >+} >Index: src/org/eclipse/jface/viewers/TooltipSupport.java >=================================================================== >RCS file: src/org/eclipse/jface/viewers/TooltipSupport.java >diff -N src/org/eclipse/jface/viewers/TooltipSupport.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/viewers/TooltipSupport.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,187 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ ******************************************************************************/ >+ >+package org.eclipse.jface.viewers; >+ >+import java.util.Timer; >+ >+import org.eclipse.jface.internal.viewers.RowPart; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.custom.CLabel; >+import org.eclipse.swt.graphics.Color; >+import org.eclipse.swt.graphics.Font; >+import org.eclipse.swt.graphics.Image; >+import org.eclipse.swt.graphics.Point; >+import org.eclipse.swt.layout.FillLayout; >+import org.eclipse.swt.widgets.Event; >+import org.eclipse.swt.widgets.Listener; >+import org.eclipse.swt.widgets.Shell; >+ >+/** >+ * @since 3.2 >+ * >+ */ >+public class TooltipSupport { >+ private StructuredViewer viewer; >+ private Listener listener = new MouseListener(); >+ private static final int DEFAULT_SHIFT_X = 10; >+ private static final int DEFAULT_SHIFT_Y = 0; >+ >+ TooltipSupport(StructuredViewer viewer) { >+ this.viewer = viewer; >+ } >+ >+ /** >+ * activate tooltip support for this viewer >+ */ >+ public void activate() { >+ deactivate(); >+ viewer.getControl().addListener(SWT.Dispose, listener); >+ viewer.getControl().addListener(SWT.MouseHover, listener); >+ viewer.getControl().addListener(SWT.MouseMove, listener); >+ viewer.getControl().addListener(SWT.MouseExit, listener); >+ viewer.getControl().addListener(SWT.MouseDown, listener); >+ } >+ >+ /** >+ * deactivate tooltip support for this viewer >+ */ >+ public void deactivate() { >+ viewer.getControl().removeListener(SWT.Dispose, listener); >+ viewer.getControl().removeListener(SWT.MouseHover, listener); >+ viewer.getControl().removeListener(SWT.MouseMove, listener); >+ viewer.getControl().removeListener(SWT.MouseExit, listener); >+ viewer.getControl().removeListener(SWT.MouseDown, listener); >+ } >+ >+ private class MouseListener implements Listener { >+ private Shell tip; >+ private TooltipHideListener hideListener = new TooltipHideListener(); >+ private Timer timer = new Timer(); >+ >+ public void handleEvent(Event event) { >+ switch (event.type) { >+ case SWT.Dispose: >+ if( timer != null ) { >+ timer.cancel(); >+ } >+ case SWT.KeyDown: >+ case SWT.MouseMove: >+ case SWT.MouseDown: >+ disposeTooltip(tip); >+ break; >+ case SWT.MouseHover: >+ Point p = new Point(event.x, event.y); >+ RowPart row = viewer.getRowPart(p); >+ viewer.getControl().setToolTipText(""); //$NON-NLS-1$ >+ >+ if (row != null) { >+ popupTooltip(row, p); >+ } >+ >+ break; >+ } >+ } >+ >+ private void popupTooltip(RowPart row, Point p) { >+ Object element = row.getElement(); >+ disposeTooltip(tip); >+ >+ ColumnViewerPart viewPart = viewer.getColumnViewer(row.getColumIndex(p)); >+ >+ if( viewPart == null ) { >+ return; >+ } >+ >+ ViewerLabelProvider labelProvider = viewPart.getLabelProvider(); >+ >+ String text = labelProvider.getTooltipText(element); >+ >+ if( text != null ) { >+ >+ if( labelProvider.useNativeTooltip(element) ) { >+ viewer.getControl().setToolTipText(text); >+ return; >+ } >+ >+ tip = new Shell(viewer.getControl().getShell(), SWT.ON_TOP | SWT.TOOL); >+ tip.setLayout(new FillLayout()); >+ CLabel label = new CLabel(tip, labelProvider.getTooltipImageStyle(element)); >+ label.setText(text); >+ label.addListener(SWT.MouseExit, hideListener); >+ label.addListener(SWT.MouseDown, hideListener); >+ >+ Image img = labelProvider.getTooltipImage(element); >+ >+ if( img != null) { >+ label.setImage(img); >+ } >+ >+ Color color = labelProvider.getTooltipForegroundColor(element); >+ if( color == null ) { >+ color = viewer.getControl().getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND); >+ } >+ label.setForeground(color); >+ >+ color = labelProvider.getTooltipBackgroundColor(element); >+ if( color == null ) { >+ color = viewer.getControl().getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND); >+ } >+ label.setBackground(color); >+ >+ Font font = labelProvider.getTooltipFont(element); >+ >+ if( font != null ) { >+ label.setFont(font); >+ } >+ >+ Point pt = viewer.getControl().toDisplay(p); >+ Point shift = labelProvider.getTooltipShift(element); >+ >+ if( shift == null ) { >+ pt.x += DEFAULT_SHIFT_X; >+ pt.y += DEFAULT_SHIFT_Y; >+ } else { >+ pt.x += shift.x; >+ pt.y += shift.y; >+ } >+ >+ tip.pack(); >+ tip.setLocation(pt); >+ tip.setVisible(true); >+ } >+ } >+ >+ private void disposeTooltip(Shell tip) { >+ if (tip != null && !tip.isDisposed()) { >+ tip.dispose(); >+ } >+ >+ tip = null; >+ } >+ } >+ >+ private class TooltipHideListener implements Listener { >+ public void handleEvent(Event event) { >+ CLabel label = (CLabel) event.widget; >+ Shell shell = label.getShell(); >+ switch (event.type) { >+ case SWT.MouseDown: >+ viewer.setSelection(new StructuredSelection()); >+ // fall through >+ case SWT.MouseExit: >+ viewer.getControl().setFocus(); >+ shell.dispose(); >+ break; >+ } >+ } >+ } >+} >Index: src/org/eclipse/jface/viewers/ITooltipFontProvider.java >=================================================================== >RCS file: src/org/eclipse/jface/viewers/ITooltipFontProvider.java >diff -N src/org/eclipse/jface/viewers/ITooltipFontProvider.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/viewers/ITooltipFontProvider.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,29 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ ******************************************************************************/ >+ >+package org.eclipse.jface.viewers; >+ >+import org.eclipse.swt.graphics.Font; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public interface ITooltipFontProvider { >+ /** >+ * The font used to display the tooltip >+ * >+ * @param object >+ * the element for which the tooltip is shown >+ * @return the font if null default font is used >+ */ >+ public Font getTooltipFont(Object object); >+} >Index: src/org/eclipse/jface/internal/viewers/ITableTooltipAddonsProvider.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/viewers/ITableTooltipAddonsProvider.java >diff -N src/org/eclipse/jface/internal/viewers/ITableTooltipAddonsProvider.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/viewers/ITableTooltipAddonsProvider.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,79 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ ******************************************************************************/ >+ >+package org.eclipse.jface.internal.viewers; >+ >+import org.eclipse.swt.graphics.Point; >+ >+/** >+ * @since 3.2 >+ * >+ */ >+public interface ITableTooltipAddonsProvider { >+ /** >+ * This is the amount the used to control how much the tooltip is shifted >+ * from the current mouse position >+ * >+ * @param object >+ * the element for which the tooltip is shown >+ * @param columnIndex >+ * the column-index >+ * @return shift of the tooltip >+ */ >+ public Point getTooltipShift(Object object, int columnIndex); >+ >+ /** >+ * If you want your tooltip to be using the native Tooltip you can force >+ * this by returning true from this method. If native tooltips are used only >+ * the text-value is used all other feature are of custom tooltips are not >+ * supported. >+ * >+ * @param object >+ * the element for which the tooltip is shown >+ * @param columnIndex >+ * the column-index >+ * @return true if native tooltips should be used >+ */ >+ public boolean useNativeTooltip(Object object, int columnIndex); >+ >+ /** >+ * The time in milliseconds after the tooltip is hidden >+ * >+ * @param object >+ * the element for which the tooltip is shown >+ * @param columnIndex >+ * the column-index >+ * @return milliseconds >+ */ >+ public int getTooltipTimeDisplayed(Object object, int columnIndex); >+ >+ /** >+ * The time in milliseconds until the tooltip pops up >+ * >+ * @param object >+ * the element for which the tooltip is shown >+ * @param columnIndex >+ * the column-index >+ * @return milliseconds >+ */ >+ public int getTooltipDisplayDelayTime(Object object, int columnIndex); >+ >+ /** >+ * The style used to create the label >+ * >+ * @param object >+ * the element for which the tooltip is shown >+ * @param columnIndex >+ * the column-index >+ * @return style mask >+ */ >+ public int getTooltipImageStyle(Object object, int columnIndex); >+} >Index: src/org/eclipse/jface/internal/viewers/ITooltipAddonsProvider.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/viewers/ITooltipAddonsProvider.java >diff -N src/org/eclipse/jface/internal/viewers/ITooltipAddonsProvider.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/viewers/ITooltipAddonsProvider.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,69 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ ******************************************************************************/ >+ >+package org.eclipse.jface.internal.viewers; >+ >+import org.eclipse.swt.graphics.Point; >+ >+/** >+ * @since 3.2 >+ * >+ */ >+public interface ITooltipAddonsProvider { >+ /** >+ * This is the amount the used to control how much the tooltip is shifted >+ * from the current mouse position >+ * >+ * @param object >+ * the element for which the tooltip is shown >+ * @return shift of the tooltip >+ */ >+ public Point getTooltipShift(Object object); >+ >+ /** >+ * If you want your tooltip to be using the native Tooltip you can force >+ * this by returning true from this method. If native tooltips are used only >+ * the text-value is used all other feature are of custom tooltips are not >+ * supported. >+ * >+ * @param object >+ * the element for which the tooltip is shown >+ * @return true if native tooltips should be used >+ */ >+ public boolean useNativeTooltip(Object object); >+ >+ /** >+ * The time in milliseconds after the tooltip is hidden >+ * >+ * @param object >+ * the element for which the tooltip is shown >+ * @return milliseconds >+ */ >+ public int getTooltipTimeDisplayed(Object object); >+ >+ /** >+ * The time in milliseconds until the tooltip pops up >+ * >+ * @param object >+ * the element for which the tooltip is shown >+ * @return milliseconds >+ */ >+ public int getTooltipDisplayDelayTime(Object object); >+ >+ /** >+ * The style used to create the label >+ * >+ * @param object >+ * the element for which the tooltip is shown >+ * @return style mask >+ */ >+ public int getTooltipImageStyle(Object object); >+} >Index: src/org/eclipse/jface/viewers/TreeRowPart.java >=================================================================== >RCS file: src/org/eclipse/jface/viewers/TreeRowPart.java >diff -N src/org/eclipse/jface/viewers/TreeRowPart.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/viewers/TreeRowPart.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,87 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ ******************************************************************************/ >+ >+package org.eclipse.jface.viewers; >+ >+import org.eclipse.swt.graphics.Color; >+import org.eclipse.swt.graphics.Font; >+import org.eclipse.swt.graphics.Image; >+import org.eclipse.swt.graphics.Rectangle; >+import org.eclipse.swt.widgets.TreeItem; >+import org.eclipse.swt.widgets.Widget; >+ >+/** >+ * @since 3.2 >+ * >+ */ >+public class TreeRowPart extends DefaultRowPartImpl { >+ private TreeItem item; >+ >+ public TreeRowPart(TreeItem item) { >+ this.item = item; >+ } >+ >+ public Rectangle getBounds(int columnIndex) { >+ return item.getBounds(columnIndex); >+ } >+ >+ public Rectangle getBounds() { >+ return item.getBounds(); >+ } >+ >+ public int getColumnCount() { >+ return item.getParent().getItemCount(); >+ } >+ >+ public Widget getItem() { >+ return item; >+ } >+ >+ public Color getBackground(int columnIndex) { >+ return item.getBackground(columnIndex); >+ } >+ >+ public Font getFont(int columnIndex) { >+ return item.getFont(columnIndex); >+ } >+ >+ public Color getForeground(int columnIndex) { >+ return item.getForeground(columnIndex); >+ } >+ >+ public Image getImage(int columnIndex) { >+ return item.getImage(columnIndex); >+ } >+ >+ public String getText(int columnIndex) { >+ return item.getText(columnIndex); >+ } >+ >+ public void setBackground(int columnIndex, Color color) { >+ item.setBackground(columnIndex, color); >+ } >+ >+ public void setFont(int columnIndex, Font font) { >+ item.setFont(columnIndex, font); >+ } >+ >+ public void setForeground(int columnIndex, Color color) { >+ item.setForeground(columnIndex, color); >+ } >+ >+ public void setImage(int columnIndex, Image image) { >+ item.setImage(columnIndex,image); >+ } >+ >+ public void setText(int columnIndex, String text) { >+ item.setText(columnIndex, text); >+ } >+} >Index: src/org/eclipse/jface/viewers/TreeColumnViewerPart.java >=================================================================== >RCS file: src/org/eclipse/jface/viewers/TreeColumnViewerPart.java >diff -N src/org/eclipse/jface/viewers/TreeColumnViewerPart.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/viewers/TreeColumnViewerPart.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,76 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ ******************************************************************************/ >+ >+package org.eclipse.jface.viewers; >+ >+import org.eclipse.swt.widgets.TreeColumn; >+ >+/** >+ * Wrapper class for {@link TreeColumn} >+ * @since 3.3 >+ * >+ */ >+public class TreeColumnViewerPart extends ColumnViewerPart { >+ private TreeColumn column; >+ >+ /** >+ * Create new TableColumnViewerPart. This simply wrapps up a new >+ * {@link TreeColumn#TableColumn(org.eclipse.swt.widgets.Table, int)}. >+ * Before calling {@link TreeViewer#setInput(Object)}} you need to set the >+ * label-provider using >+ * {@link ColumnViewerPart#setLabelProvider(ViewerLabelProvider)} >+ * >+ * @param parent >+ * the table-viewer >+ * @param style >+ * style bits used to create TableColumn {@link TreeColumn} >+ */ >+ public TreeColumnViewerPart(TreeViewer parent, int style) { >+ this(new TreeColumn(parent.getTree(), style),null); >+ } >+ >+ /** >+ * Create new TableColumnViewerPart. This simply wrapps up a new >+ * {@link TableColumn#TableColumn(org.eclipse.swt.widgets.Table, int, int)} >+ * >+ * @param parent >+ * the table-viewer >+ * @param style >+ * style style bits used to create TableColumn >+ * {@link TableColumn} >+ * @param index >+ * the index of the column >+ */ >+ public TreeColumnViewerPart(TreeViewer parent, int style, int index) { >+ this(new TreeColumn(parent.getTree(), style, index),null); >+ } >+ >+ /** >+ * Wrap an existing TableColumn >+ * >+ * @param column >+ * the existing table-column >+ * @param labelProvider >+ * the label provider >+ */ >+ public TreeColumnViewerPart(TreeColumn column, >+ ViewerLabelProvider labelProvider) { >+ super(column,labelProvider); >+ this.column = column; >+ } >+ >+ /** >+ * @return access the underlying tree-column >+ */ >+ public TreeColumn getColumn() { >+ return column; >+ } >+} >Index: src/org/eclipse/jface/viewers/AbstractTooltipProvider.java >=================================================================== >RCS file: src/org/eclipse/jface/viewers/AbstractTooltipProvider.java >diff -N src/org/eclipse/jface/viewers/AbstractTooltipProvider.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/viewers/AbstractTooltipProvider.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,63 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ ******************************************************************************/ >+ >+package org.eclipse.jface.viewers; >+ >+import org.eclipse.jface.internal.viewers.ITooltipAddonsProvider; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.graphics.Color; >+import org.eclipse.swt.graphics.Font; >+import org.eclipse.swt.graphics.Image; >+import org.eclipse.swt.graphics.Point; >+ >+/** >+ * @since 3.2 >+ * >+ */ >+public abstract class AbstractTooltipProvider implements ITooltipLabelProvider, >+ ITooltipFontProvider, ITooltipColorProvider, ITooltipAddonsProvider { >+ >+ public Image getTooltipImage(Object object) { >+ return null; >+ } >+ >+ public Font getTooltipFont(Object object) { >+ return null; >+ } >+ >+ public Color getTooltipBackgroundColor(Object object) { >+ return null; >+ } >+ >+ public Color getTooltipForegroundColor(Object object) { >+ return null; >+ } >+ >+ public int getTooltipDisplayDelayTime(Object object) { >+ return 0; >+ } >+ >+ public Point getTooltipShift(Object object) { >+ return null; >+ } >+ >+ public int getTooltipTimeDisplayed(Object object) { >+ return 0; >+ } >+ >+ public boolean useNativeTooltip(Object object) { >+ return false; >+ } >+ >+ public int getTooltipImageStyle(Object object) { >+ return SWT.SHADOW_NONE; >+ } >+} >Index: src/org/eclipse/jface/viewers/ITableTooltipFontProvider.java >=================================================================== >RCS file: src/org/eclipse/jface/viewers/ITableTooltipFontProvider.java >diff -N src/org/eclipse/jface/viewers/ITableTooltipFontProvider.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/viewers/ITableTooltipFontProvider.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,31 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ ******************************************************************************/ >+ >+package org.eclipse.jface.viewers; >+ >+import org.eclipse.swt.graphics.Font; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public interface ITableTooltipFontProvider { >+ /** >+ * The font used to display the tooltip >+ * >+ * @param object >+ * the element for which the tooltip is shown >+ * @param columnIndex >+ * the column index used >+ * @return the font if null default font is used >+ */ >+ public Font getTooltipFont(Object object, int columnIndex); >+} >Index: src/org/eclipse/jface/viewers/AbstractTableTooltipProvider.java >=================================================================== >RCS file: src/org/eclipse/jface/viewers/AbstractTableTooltipProvider.java >diff -N src/org/eclipse/jface/viewers/AbstractTableTooltipProvider.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/viewers/AbstractTableTooltipProvider.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,64 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ ******************************************************************************/ >+ >+package org.eclipse.jface.viewers; >+ >+import org.eclipse.jface.internal.viewers.ITableTooltipAddonsProvider; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.graphics.Color; >+import org.eclipse.swt.graphics.Font; >+import org.eclipse.swt.graphics.Image; >+import org.eclipse.swt.graphics.Point; >+ >+/** >+ * @since 3.2 >+ * >+ */ >+public abstract class AbstractTableTooltipProvider implements >+ ITableTooltipLabelProvider, ITableTooltipColorProvider, >+ ITableTooltipFontProvider, ITableTooltipAddonsProvider { >+ >+ public Image getTooltipImage(Object object, int columnIndex) { >+ return null; >+ } >+ >+ public Color getTooltipBackgroundColor(Object object, int columnIndex) { >+ return null; >+ } >+ >+ public Color getTooltipForegroundColor(Object object, int columnIndex) { >+ return null; >+ } >+ >+ public Font getTooltipFont(Object object, int columnIndex) { >+ return null; >+ } >+ >+ public int getTooltipDisplayDelayTime(Object object, int columnIndex) { >+ return 0; >+ } >+ >+ public Point getTooltipShift(Object object, int columnIndex) { >+ return null; >+ } >+ >+ public int getTooltipTimeDisplayed(Object object, int columnIndex) { >+ return 0; >+ } >+ >+ public boolean useNativeTooltip(Object object, int columnIndex) { >+ return false; >+ } >+ >+ public int getTooltipImageStyle(Object object, int columnIndex) { >+ return SWT.SHADOW_NONE; >+ } >+} >Index: src/org/eclipse/jface/viewers/TableColumnViewerPart.java >=================================================================== >RCS file: src/org/eclipse/jface/viewers/TableColumnViewerPart.java >diff -N src/org/eclipse/jface/viewers/TableColumnViewerPart.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/viewers/TableColumnViewerPart.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,76 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ ******************************************************************************/ >+ >+package org.eclipse.jface.viewers; >+ >+import org.eclipse.swt.widgets.TableColumn; >+ >+/** >+ * Wrapper class for {@link TableColumn} >+ * @since 3.3 >+ * >+ */ >+public class TableColumnViewerPart extends ColumnViewerPart { >+ private TableColumn column; >+ >+ /** >+ * Create new TableColumnViewerPart. This simply wrapps up a new >+ * {@link TableColumn#TableColumn(org.eclipse.swt.widgets.Table, int)}. >+ * Before calling {@link TableViewer#setInput(Object)}} you need to set the >+ * label-provider using >+ * {@link ColumnViewerPart#setLabelProvider(ViewerLabelProvider)} >+ * >+ * @param parent >+ * the table-viewer >+ * @param style >+ * style bits used to create TableColumn {@link TableColumn} >+ */ >+ public TableColumnViewerPart(TableViewer parent, int style) { >+ this(new TableColumn(parent.getTable(), style),null); >+ } >+ >+ /** >+ * Create new TableColumnViewerPart. This simply wrapps up a new >+ * {@link TableColumn#TableColumn(org.eclipse.swt.widgets.Table, int, int)} >+ * >+ * @param parent >+ * the table-viewer >+ * @param style >+ * style style bits used to create TableColumn >+ * {@link TableColumn} >+ * @param index >+ * the index of the column >+ */ >+ public TableColumnViewerPart(TableViewer parent, int style, int index) { >+ this(new TableColumn(parent.getTable(), style, index),null); >+ } >+ >+ /** >+ * Wrap an existing TableColumn >+ * >+ * @param column >+ * the existing table-column >+ * @param labelProvider >+ * the label provider >+ */ >+ public TableColumnViewerPart(TableColumn column, >+ ViewerLabelProvider labelProvider) { >+ super(column,labelProvider); >+ this.column = column; >+ } >+ >+ /** >+ * @return access the underlying table-column >+ */ >+ public TableColumn getColumn() { >+ return column; >+ } >+} >Index: src/org/eclipse/jface/viewers/ITooltipLabelProvider.java >=================================================================== >RCS file: src/org/eclipse/jface/viewers/ITooltipLabelProvider.java >diff -N src/org/eclipse/jface/viewers/ITooltipLabelProvider.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/viewers/ITooltipLabelProvider.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,40 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 BestSolution Systemhaus GmbH >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Tom Schind - tom.schindl@bestsolution.at >+ *******************************************************************************/ >+package org.eclipse.jface.viewers; >+ >+import org.eclipse.swt.graphics.Image; >+ >+/** >+ * >+ * @since 3.3 >+ * >+ */ >+public interface ITooltipLabelProvider { >+ /** >+ * Returns the tooltip text for the given element and column index, or >+ * <code>null</code> if a custom tooltip should not be displayed. >+ * >+ * @param element >+ * the element for which the tooltip is shown >+ * @return the text to be displayed in the tooltip, or <code>null</code> >+ * if a custom tooltip should not be displayed >+ */ >+ public String getTooltipText(Object element); >+ >+ /** >+ * The image displayed in the tooltip >+ * >+ * @param object >+ * the element for which the tooltip is shown >+ * @return the image displayed if null no image is displayed >+ */ >+ public Image getTooltipImage(Object object); >+} >Index: src/org/eclipse/jface/viewers/Cell.java >=================================================================== >RCS file: src/org/eclipse/jface/viewers/Cell.java >diff -N src/org/eclipse/jface/viewers/Cell.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/viewers/Cell.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,41 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ ******************************************************************************/ >+ >+package org.eclipse.jface.viewers; >+ >+import org.eclipse.jface.internal.viewers.RowPart; >+import org.eclipse.swt.graphics.Rectangle; >+ >+/** >+ * @since 3.2 >+ * >+ */ >+public class Cell { >+ private int columnIndex; >+ private RowPart row; >+ >+ public Cell(RowPart row, int columnIndex) { >+ this.row = row; >+ this.columnIndex = columnIndex; >+ } >+ >+ public int getColumnIndex() { >+ return columnIndex; >+ } >+ >+ public Rectangle getBounds() { >+ return row.getBounds(columnIndex); >+ } >+ >+ public Object getElement() { >+ return row.getElement(); >+ } >+} >Index: src/org/eclipse/jface/viewers/ITooltipColorProvider.java >=================================================================== >RCS file: src/org/eclipse/jface/viewers/ITooltipColorProvider.java >diff -N src/org/eclipse/jface/viewers/ITooltipColorProvider.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/viewers/ITooltipColorProvider.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,42 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ ******************************************************************************/ >+ >+package org.eclipse.jface.viewers; >+ >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.graphics.Color; >+ >+/** >+ * @since 3.2 >+ * >+ */ >+public interface ITooltipColorProvider { >+ /** >+ * The foreground color used to display the the text in the tooltip >+ * >+ * @param object >+ * the element for which the tooltip is shown >+ * @return the color used or <code>null</code> if you want to use the >+ * default color {@link SWT#COLOR_INFO_FOREGROUND} >+ */ >+ public Color getTooltipForegroundColor(Object object); >+ >+ /** >+ * The background color used for the tooltip >+ * >+ * @param object >+ * the element for which the tooltip is shown >+ * >+ * @return the color used or <code>null</code> if you want to use the >+ */ >+ public Color getTooltipBackgroundColor(Object object); >+ >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 149193
:
46241
|
46254
|
46263
|
46677
|
46686
|
47008
|
47350
|
47453
|
47454
|
47472
|
47722
|
47944
|
48028
|
48089