### Eclipse Workspace Patch 1.0 #P org.eclipse.ui.navigator Index: src/org/eclipse/ui/navigator/CommonViewer.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.navigator/src/org/eclipse/ui/navigator/CommonViewer.java,v retrieving revision 1.22 diff -u -r1.22 CommonViewer.java --- src/org/eclipse/ui/navigator/CommonViewer.java 20 Jun 2006 17:42:04 -0000 1.22 +++ src/org/eclipse/ui/navigator/CommonViewer.java 31 Jul 2006 10:14:09 -0000 @@ -12,6 +12,7 @@ import java.util.ArrayList; import java.util.Iterator; +import java.util.List; import org.eclipse.jface.viewers.DecoratingLabelProvider; import org.eclipse.jface.viewers.IBaseLabelProvider; @@ -23,6 +24,7 @@ import org.eclipse.jface.viewers.ViewerSorter; import org.eclipse.swt.dnd.DND; import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Widget; import org.eclipse.ui.PlatformUI; @@ -41,13 +43,17 @@ *

* Clients may extend this class. *

- * + *

+ * Note that as of 3.2.1 and 3.3, the common viewer caches its selection. + * Clients must not set the selection of the viewer's tree control directly. + *

* * @since 3.2 */ public class CommonViewer extends TreeViewer { private final NavigatorContentService contentService; + private ISelection cachedSelection; /** *

@@ -211,6 +217,7 @@ if (contentService != null) { contentService.dispose(); } + clearSelectionCache(); } /** @@ -346,6 +353,69 @@ } } } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.AbstractTreeViewer#setSelectionToWidget(java.util.List, boolean) + */ + protected void setSelectionToWidget(List v, boolean reveal) { + clearSelectionCache(); + super.setSelectionToWidget(v, reveal); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.AbstractTreeViewer#handleDoubleSelect(org.eclipse.swt.events.SelectionEvent) + */ + protected void handleDoubleSelect(SelectionEvent event) { + clearSelectionCache(); + super.handleDoubleSelect(event); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.StructuredViewer#handleOpen(org.eclipse.swt.events.SelectionEvent) + */ + protected void handleOpen(SelectionEvent event) { + clearSelectionCache(); + super.handleOpen(event); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.StructuredViewer#handlePostSelect(org.eclipse.swt.events.SelectionEvent) + */ + protected void handlePostSelect(SelectionEvent e) { + clearSelectionCache(); + super.handlePostSelect(e); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.StructuredViewer#handleSelect(org.eclipse.swt.events.SelectionEvent) + */ + protected void handleSelect(SelectionEvent event) { + clearSelectionCache(); + super.handleSelect(event); + } + + /** + * Clears the selection cache. + */ + private void clearSelectionCache() { + cachedSelection = null; + } + + /** + * Returns the current selection. + *

+ * Note that as of 3.2.1 and 3.3, the common viewer caches its selection. + * Clients must not set the selection of the viewer's tree control directly. + *

+ * + * @see org.eclipse.jface.viewers.AbstractTreeViewer#getSelection() + */ + public ISelection getSelection() { + if (cachedSelection == null) { + cachedSelection = super.getSelection(); + } + return cachedSelection; + } /* * (non-Javadoc)