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 108725 Details for
Bug 224692
Support SWT.VIRTUAL style in GalleryTreeViewer
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.
Virtual content support for GalleryTreeViewer
LazyGalleryTreeViewer.patch (text/plain), 29.21 KB, created by
Peter Centgraf
on 2008-07-30 04:56:45 EDT
(
hide
)
Description:
Virtual content support for GalleryTreeViewer
Filename:
MIME Type:
Creator:
Peter Centgraf
Created:
2008-07-30 04:56:45 EDT
Size:
29.21 KB
patch
obsolete
>Index: src/org/eclipse/nebula/jface/galleryviewer/GalleryTreeViewer.java >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.swt.nebula/org.eclipse.nebula.widgets.gallery/src/org/eclipse/nebula/jface/galleryviewer/GalleryTreeViewer.java,v >retrieving revision 1.5 >diff -u -r1.5 GalleryTreeViewer.java >--- src/org/eclipse/nebula/jface/galleryviewer/GalleryTreeViewer.java 15 Jun 2008 11:52:19 -0000 1.5 >+++ src/org/eclipse/nebula/jface/galleryviewer/GalleryTreeViewer.java 30 Jul 2008 08:54:18 -0000 >@@ -16,13 +16,18 @@ > import java.util.LinkedList; > import java.util.List; > >+import org.eclipse.jface.util.Policy; > import org.eclipse.jface.viewers.AbstractTreeViewer; > import org.eclipse.jface.viewers.ColumnViewerEditor; > import org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent; > import org.eclipse.jface.viewers.IContentProvider; >+import org.eclipse.jface.viewers.ILazyTreeContentProvider; >+import org.eclipse.jface.viewers.ILazyTreePathContentProvider; >+import org.eclipse.jface.viewers.ISelection; > import org.eclipse.jface.viewers.IStructuredContentProvider; > import org.eclipse.jface.viewers.ITreeContentProvider; > import org.eclipse.jface.viewers.ITreePathContentProvider; >+import org.eclipse.jface.viewers.TreeExpansionEvent; > import org.eclipse.jface.viewers.TreePath; > import org.eclipse.jface.viewers.TreeSelection; > import org.eclipse.jface.viewers.ViewerCell; >@@ -32,11 +37,16 @@ > import org.eclipse.nebula.widgets.gallery.Gallery; > import org.eclipse.nebula.widgets.gallery.GalleryItem; > import org.eclipse.swt.SWT; >+import org.eclipse.swt.events.DisposeEvent; >+import org.eclipse.swt.events.DisposeListener; >+import org.eclipse.swt.events.TreeEvent; > import org.eclipse.swt.events.TreeListener; > import org.eclipse.swt.graphics.Point; > import org.eclipse.swt.widgets.Composite; > import org.eclipse.swt.widgets.Control; >+import org.eclipse.swt.widgets.Event; > import org.eclipse.swt.widgets.Item; >+import org.eclipse.swt.widgets.Listener; > import org.eclipse.swt.widgets.Widget; > > /** >@@ -46,6 +56,16 @@ > */ > public class GalleryTreeViewer extends AbstractTreeViewer { > >+ /** >+ * Key for storing DisposeListener instance on GalleryItems. >+ * Needed for VIRTUAL support. >+ */ >+ private static final String VIRTUAL_DISPOSE_KEY = Policy.JFACE >+ + ".DISPOSE_LISTENER"; //$NON-NLS-1$ >+ >+ /** >+ * This viewer's control >+ */ > protected Gallery gallery; > > /** >@@ -59,6 +79,24 @@ > private GalleryViewerRow cachedRow; > > /** >+ * Flag for whether the gallery has been disposed of. >+ * Needed for VIRTUAL support. >+ */ >+ private boolean galleryIsDisposed = false; >+ >+ /** >+ * Flag to cache type check for ILazyTreeContentProvider || ILazyTreePathContentProvider. >+ * Needed for VIRTUAL support. >+ */ >+ private boolean contentProviderIsLazy; >+ >+ /** >+ * Flag to cache type check for ILazyTreePathContentProvider specifically. >+ * Needed for VIRTUAL support. >+ */ >+ private boolean contentProviderIsTreeBased; >+ >+ /** > * Creates a gallery viewer on a newly-created gallery control under the > * given parent. The gallery control is created using the SWT style bits > * <code>MULTI, V_SCROLL,</code> and <code>BORDER</code>. The viewer >@@ -87,7 +125,6 @@ > gallery = new Gallery(parent, style); > gallery.setGroupRenderer(new DefaultGalleryGroupRenderer()); > gallery.setItemRenderer(new DefaultGalleryItemRenderer()); >- super.setAutoExpandLevel(ALL_LEVELS); > > hookControl(gallery); > } >@@ -103,7 +140,6 @@ > public GalleryTreeViewer(Gallery gallery) { > super(); > this.gallery = gallery; >- super.setAutoExpandLevel(ALL_LEVELS); > > hookControl(gallery); > } >@@ -212,6 +248,8 @@ > return new GalleryItem[0]; > } > >+ // TODO: verify that Gallery never returns disposed elements in the selection >+ // TODO: remove this loop when above is true > List notDisposed = new ArrayList(selection.length); > for (int i = 0; i < selection.length; i++) { > if (!selection[i].isDisposed()) { >@@ -253,10 +291,6 @@ > ((Gallery) control).removeAll(); > } > >- public void setAutoExpandLevel(int level) { >- throw new UnsupportedOperationException("Gallery must be fully expanded."); >- } >- > /** > * <p> > * Gallery expects contents to have exactly 2 levels of hierarchy, with >@@ -275,6 +309,11 @@ > * <code>getGallery().setGroupRenderer(new NoGroupRenderer());</code> > */ > public void setContentProvider(IContentProvider provider) { >+ // The two variable assignments are necessary for SWT.VIRTUAL support >+ contentProviderIsLazy = (provider instanceof ILazyTreeContentProvider) >+ || (provider instanceof ILazyTreePathContentProvider); >+ contentProviderIsTreeBased = provider instanceof ILazyTreePathContentProvider; >+ > if (provider instanceof IStructuredContentProvider && !(provider instanceof ITreeContentProvider || provider instanceof ITreePathContentProvider)) { > // Wrap a table-style contents with a single root node. > super.setContentProvider(new FlatTreeContentProvider((IStructuredContentProvider) provider)); >@@ -291,10 +330,10 @@ > */ > protected void setExpanded(Item item, boolean expand) { > ((GalleryItem) item).setExpanded(expand); >- // if (contentProviderIsLazy) { >- // // force repaints to happen >- // getControl().update(); >- // } >+ if (contentProviderIsLazy) { >+ // force repaints to happen >+ getControl().update(); >+ } > } > > /* >@@ -364,8 +403,9 @@ > * @since 3.2 > */ > public void setChildCount(final Object elementOrTreePath, final int count) { >- // if (isBusy()) >- // return; >+ // TODO: determine why this method call is necessary and replace it with API >+// if (isBusy()) >+// return; > preservingSelection(new Runnable() { > public void run() { > if (internalIsInputOrEmptyPath(elementOrTreePath)) { >@@ -431,6 +471,7 @@ > * @since 3.3 > */ > public void remove(final Object parentOrTreePath, final int index) { >+ // TODO: determine why this method call is necessary and replace it with API > // if (isBusy()) > // return; > final List oldSelection = new LinkedList(Arrays.asList(((TreeSelection) getSelection()).getPaths())); >@@ -500,5 +541,697 @@ > super.editElement(element, column); > } > } >+ >+ >+ >+ /* Code for SWT.VIRTUAL support goes below this line */ >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.jface.viewers.AbstractTreeViewer#hookControl(org.eclipse.swt.widgets.Control) >+ */ >+ protected void hookControl(Control control) { >+ super.hookControl(control); >+ Gallery galleryControl = (Gallery) control; >+ >+ if ((galleryControl.getStyle() & SWT.VIRTUAL) != 0) { >+ galleryControl.addDisposeListener(new DisposeListener() { >+ public void widgetDisposed(DisposeEvent e) { >+ galleryIsDisposed = true; >+ unmapAllElements(); >+ } >+ }); >+ >+ galleryControl.addListener(SWT.SetData, new Listener() { >+ public void handleEvent(Event event) { >+ if (contentProviderIsLazy) { >+ GalleryItem item = (GalleryItem) event.item; >+ GalleryItem parentItem = item.getParentItem(); >+ int index = event.index; >+ virtualLazyUpdateWidget( >+ parentItem == null ? (Widget) getGallery() >+ : parentItem, index); >+ } >+ } >+ >+ }); >+ } >+ } >+ >+ /** >+ * Allow any of ITreeContentProvider, ITreePathContentProvider, >+ * ILazyTreeContentProvider, or ILazyTreePathContentProvider. >+ */ >+ protected void assertContentProviderType(IContentProvider provider) { >+ if (provider instanceof ILazyTreeContentProvider >+ || provider instanceof ILazyTreePathContentProvider) { >+ return; >+ } >+ super.assertContentProviderType(provider); >+ } >+ >+ protected Object[] getRawChildren(Object parent) { >+ if (contentProviderIsLazy) { >+ return new Object[0]; >+ } >+ return super.getRawChildren(parent); >+ } >+ >+// void preservingSelection(Runnable updateCode, boolean reveal) { >+// if (preservingSelection){ >+// // avoid preserving the selection if called reentrantly, >+// // see bug 172640 >+// updateCode.run(); >+// return; >+// } >+// preservingSelection = true; >+// try { >+// super.preservingSelection(updateCode, reveal); >+// } finally { >+// preservingSelection = false; >+// } >+// } >+ >+ /** >+ * For a GalleryTreeViewer with a Gallery with the VIRTUAL style bit set, replace the >+ * given parent's child at index with the given element. If the given parent >+ * is this viewer's input or an empty tree path, this will replace the root >+ * element at the given index. >+ * <p> >+ * This method should be called by implementers of ILazyTreeContentProvider >+ * to populate this viewer. >+ * </p> >+ * >+ * @param parentElementOrTreePath >+ * the parent of the element that should be updated, or the tree >+ * path to that parent >+ * @param index >+ * the index in the parent's children >+ * @param element >+ * the new element >+ * >+ * @see #setChildCount(Object, int) >+ * @see ILazyTreeContentProvider >+ * @see ILazyTreePathContentProvider >+ * >+ * @since 3.2 >+ */ >+ public void replace(final Object parentElementOrTreePath, final int index, >+ final Object element) { >+ // TODO: determine why this method call is necessary and replace it with API >+// if (isBusy()) >+// return; >+ Item[] selectedItems = getSelection(getControl()); >+ TreeSelection selection = (TreeSelection) getSelection(); >+ Widget[] itemsToDisassociate; >+ if (parentElementOrTreePath instanceof TreePath) { >+ TreePath elementPath = ((TreePath) parentElementOrTreePath) >+ .createChildPath(element); >+ itemsToDisassociate = internalFindItems(elementPath); >+ } else { >+ itemsToDisassociate = internalFindItems(element); >+ } >+ if (internalIsInputOrEmptyPath(parentElementOrTreePath)) { >+ if (index < gallery.getItemCount()) { >+ GalleryItem item = gallery.getItem(index); >+ selection = adjustSelectionForReplace(selectedItems, selection, item, element, getRoot()); >+ // disassociate any different item that represents the >+ // same element under the same parent (the tree) >+ for (int i = 0; i < itemsToDisassociate.length; i++) { >+ if (itemsToDisassociate[i] instanceof GalleryItem) { >+ GalleryItem itemToDisassociate = (GalleryItem) itemsToDisassociate[i]; >+ if (itemToDisassociate != item >+ && itemToDisassociate.getParentItem() == null) { >+ int indexToDisassociate = getGallery().indexOf( >+ itemToDisassociate); >+ disassociate(itemToDisassociate); >+ getGallery().clear(indexToDisassociate, true); >+ } >+ } >+ } >+ Object oldData = item.getData(); >+ updateItem(item, element); >+ if (!this.equals(oldData, element)) { >+ item.clearAll(true); >+ } >+ } >+ } else { >+ Widget[] parentItems = internalFindItems(parentElementOrTreePath); >+ for (int i = 0; i < parentItems.length; i++) { >+ GalleryItem parentItem = (GalleryItem) parentItems[i]; >+ if (index < parentItem.getItemCount()) { >+ GalleryItem item = parentItem.getItem(index); >+ selection = adjustSelectionForReplace(selectedItems, selection, item, element, parentItem.getData()); >+ // disassociate any different item that represents the >+ // same element under the same parent (the tree) >+ for (int j = 0; j < itemsToDisassociate.length; j++) { >+ if (itemsToDisassociate[j] instanceof GalleryItem) { >+ GalleryItem itemToDisassociate = (GalleryItem) itemsToDisassociate[j]; >+ if (itemToDisassociate != item >+ && itemToDisassociate.getParentItem() == parentItem) { >+ disassociate(itemToDisassociate); >+ >+ // Simulate parentItem.clear(indexToDisassociate, true) >+ itemToDisassociate.clearAll(true); >+ itemToDisassociate.clear(); >+ } >+ } >+ } >+ Object oldData = item.getData(); >+ updateItem(item, element); >+ if (!this.equals(oldData, element)) { >+ item.clearAll(true); >+ } >+ } >+ } >+ } >+ // Restore the selection if we are not already in a nested preservingSelection: >+ if (!preservingSelection) { >+ setSelectionToWidget(selection, false); >+ // send out notification if old and new differ >+ ISelection newSelection = getSelection(); >+ if (!newSelection.equals(selection)) { >+ handleInvalidSelection(selection, newSelection); >+ } >+ } >+ } >+ >+ /** >+ * Fix for bug 185673: If the currently replaced item was selected, add it >+ * to the selection that is being restored. Only do this if its getData() is >+ * currently null >+ * >+ * @param selectedItems >+ * @param selection >+ * @param item >+ * @param element >+ * @return >+ */ >+ private TreeSelection adjustSelectionForReplace(Item[] selectedItems, >+ TreeSelection selection, GalleryItem item, Object element, Object parentElement) { >+ if (item.getData() != null || selectedItems.length == selection.size() >+ || parentElement == null) { >+ // Don't do anything - we are not seeing an instance of bug 185673 >+ return selection; >+ } >+ for (int i = 0; i < selectedItems.length; i++) { >+ if (item == selectedItems[i]) { >+ // The current item was selected, but its data is null. >+ // The data will be replaced by the given element, so to keep >+ // it selected, we have to add it to the selection. >+ TreePath[] originalPaths = selection.getPaths(); >+ int length = originalPaths.length; >+ TreePath[] paths = new TreePath[length + 1]; >+ System.arraycopy(originalPaths, 0, paths, 0, length); >+ // set the element temporarily so that we can call getTreePathFromItem >+ item.setData(element); >+ paths[length] = getTreePathFromItem(item); >+ item.setData(null); >+ return new TreeSelection(paths, selection.getElementComparer()); >+ } >+ } >+ // The item was not selected, return the given selection >+ return selection; >+ } >+ >+ public boolean isExpandable(Object element) { >+ if (contentProviderIsLazy) { >+ GalleryItem galleryItem = (GalleryItem) internalExpand(element, false); >+ if (galleryItem == null) { >+ return false; >+ } >+ virtualMaterializeItem(galleryItem); >+ return galleryItem.getItemCount() > 0; >+ } >+ return super.isExpandable(element); >+ } >+ >+ protected Object getParentElement(Object element) { >+ // TODO: determine why this variable is necessary and replace it with API >+// boolean oldBusy = busy; >+// busy = true; >+ try { >+ if (contentProviderIsLazy && !contentProviderIsTreeBased && !(element instanceof TreePath)) { >+ ILazyTreeContentProvider lazyTreeContentProvider = (ILazyTreeContentProvider) getContentProvider(); >+ return lazyTreeContentProvider.getParent(element); >+ } >+ if (contentProviderIsLazy && contentProviderIsTreeBased && !(element instanceof TreePath)) { >+ ILazyTreePathContentProvider lazyTreePathContentProvider = (ILazyTreePathContentProvider) getContentProvider(); >+ TreePath[] parents = lazyTreePathContentProvider >+ .getParents(element); >+ if (parents != null && parents.length > 0) { >+ return parents[0]; >+ } >+ } >+ return super.getParentElement(element); >+ } finally { >+ // TODO: determine why this variable is necessary and replace it with API >+// busy = oldBusy; >+ } >+ } >+ >+ protected void createChildren(Widget widget) { >+ if (contentProviderIsLazy) { >+ Object element = widget.getData(); >+ if (element == null && widget instanceof GalleryItem) { >+ // parent has not been materialized >+ virtualMaterializeItem((GalleryItem) widget); >+ // try getting the element now that updateElement was called >+ element = widget.getData(); >+ } >+ if (element == null) { >+ // give up because the parent is still not materialized >+ return; >+ } >+ Item[] children = getChildren(widget); >+ if (children.length == 1 && children[0].getData() == null) { >+ // found a dummy node >+ virtualLazyUpdateChildCount(widget, children.length); >+ children = getChildren(widget); >+ } >+ // touch all children to make sure they are materialized >+ for (int i = 0; i < children.length; i++) { >+ if (children[i].getData() == null) { >+ virtualLazyUpdateWidget(widget, i); >+ } >+ } >+ return; >+ } >+ super.createChildren(widget); >+ } >+ >+ protected void internalAdd(Widget widget, Object parentElement, >+ Object[] childElements) { >+ if (contentProviderIsLazy) { >+ if (widget instanceof GalleryItem) { >+ GalleryItem gi = (GalleryItem) widget; >+ int count = gi.getItemCount() + childElements.length; >+ gi.setItemCount(count); >+ gi.clearAll(false); >+ } else { >+ Gallery g = (Gallery) widget; >+ g.setItemCount(g.getItemCount() + childElements.length); >+ g.clearAll(false); >+ } >+ return; >+ } >+ super.internalAdd(widget, parentElement, childElements); >+ } > >+ private void virtualMaterializeItem(GalleryItem galleryItem) { >+ if (galleryItem.getData() != null) { >+ // already materialized >+ return; >+ } >+ if (!contentProviderIsLazy) { >+ return; >+ } >+ int index; >+ Widget parent = galleryItem.getParentItem(); >+ if (parent == null) { >+ parent = galleryItem.getParent(); >+ } >+ Object parentElement = parent.getData(); >+ if (parentElement != null) { >+ if (parent instanceof Gallery) { >+ index = ((Gallery) parent).indexOf(galleryItem); >+ } else { >+ index = ((GalleryItem) parent).indexOf(galleryItem); >+ } >+ virtualLazyUpdateWidget(parent, index); >+ } >+ } >+ >+ /** >+ * Refreshes the tree starting at the given widget. >+ * <p> >+ * EXPERIMENTAL. Not to be used except by JDT. This method was added to >+ * support JDT's explorations into grouping by working sets, which requires >+ * viewers to support multiple equal elements. See bug 76482 for more >+ * details. This support will likely be removed in Eclipse 3.2 in favor of >+ * proper support for multiple equal elements. >+ * </p> >+ * >+ * @param widget >+ * the widget >+ * @param element >+ * the element >+ * @param doStruct >+ * <code>true</code> if structural changes are to be picked up, >+ * and <code>false</code> if only label provider changes are of >+ * interest >+ * @param updateLabels >+ * <code>true</code> to update labels for existing elements, >+ * <code>false</code> to only update labels as needed, assuming >+ * that labels for existing elements are unchanged. >+ * @since 3.1 >+ */ >+ protected void internalRefresh(Widget widget, Object element, >+ boolean doStruct, boolean updateLabels) { >+ >+ if (widget instanceof Item) { >+ if (doStruct) { >+ updatePlus((Item) widget, element); >+ } >+ if (updateLabels || !equals(element, widget.getData())) { >+ doUpdateItem(widget, element, true); >+ } else { >+ associate(element, (Item) widget); >+ } >+ } >+ >+ if (doStruct) { >+ internalRefreshStruct(widget, element, updateLabels); >+ } else { >+ Item[] children = getChildren(widget); >+ if (children != null) { >+ for (int i = 0; i < children.length; i++) { >+ Widget item = children[i]; >+ Object data = item.getData(); >+ if (data != null) { >+ internalRefresh(item, data, doStruct, updateLabels); >+ } >+ } >+ } >+ } >+ } >+ >+ /* >+ * (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 (contentProviderIsLazy) { >+ // clear all starting with the given widget >+ if (widget instanceof Gallery) { >+ ((Gallery) widget).clearAll(true); >+ } else if (widget instanceof GalleryItem) { >+ ((GalleryItem) widget).clearAll(true); >+ } >+ int index = 0; >+ Widget parent = null; >+ if (widget instanceof GalleryItem) { >+ GalleryItem galleryItem = (GalleryItem) widget; >+ parent = galleryItem.getParentItem(); >+ if (parent == null) { >+ parent = galleryItem.getParent(); >+ } >+ if (parent instanceof Gallery) { >+ index = ((Gallery) parent).indexOf(galleryItem); >+ } else { >+ index = ((GalleryItem) parent).indexOf(galleryItem); >+ } >+ } >+ virtualRefreshExpandedItems(parent, widget, element, index); >+ return; >+ } >+ >+ // XXX: convert this method call to API >+// super.internalRefreshStruct(widget, element, updateLabels); >+ >+ // Simulate the call above, since it is not available >+ // Call deprecated version of this method, 'cause the one we want is package private >+// updateChildren(widget, element, null, updateLabels); >+ updateChildren(widget, element, null); >+ Item[] children = getChildren(widget); >+ if (children != null) { >+ for (int i = 0; i < children.length; i++) { >+ Widget item = children[i]; >+ Object data = item.getData(); >+ if (data != null) { >+ internalRefreshStruct(item, data, updateLabels); >+ } >+ } >+ } >+ } >+ >+ /** >+ * Traverses the visible (expanded) part of the tree and updates child >+ * counts. >+ * >+ * @param parent the parent of the widget, or <code>null</code> if the widget is the tree >+ * @param widget >+ * @param element >+ * @param index the index of the widget in the children array of its parent, or 0 if the widget is the tree >+ */ >+ private void virtualRefreshExpandedItems(Widget parent, Widget widget, Object element, int index) { >+ if (widget instanceof Gallery) { >+ if (element == null) { >+ ((Gallery) widget).setItemCount(0); >+ return; >+ } >+ virtualLazyUpdateChildCount(widget, getChildren(widget).length); >+ } else if (((GalleryItem) widget).isExpanded()) { >+ // prevent SetData callback >+ ((GalleryItem)widget).setText(" "); //$NON-NLS-1$ >+ virtualLazyUpdateWidget(parent, index); >+ } else { >+ return; >+ } >+ Item[] items = getChildren(widget); >+ for (int i = 0; i < items.length; i++) { >+ Item item = items[i]; >+ Object data = item.getData(); >+ virtualRefreshExpandedItems(widget, item, data, i); >+ } >+ } >+ >+ /* >+ * To unmap elements correctly, we need to register a dispose listener with >+ * the item if the tree is virtual. >+ */ >+ protected void mapElement(Object element, final Widget item) { >+ super.mapElement(element, item); >+ // make sure to unmap elements if the tree is virtual >+ if ((getGallery().getStyle() & SWT.VIRTUAL) != 0) { >+ // only add a dispose listener if item hasn't already on assigned >+ // because it is reused >+ if (item.getData(VIRTUAL_DISPOSE_KEY) == null) { >+ item.setData(VIRTUAL_DISPOSE_KEY, Boolean.TRUE); >+ item.addDisposeListener(new DisposeListener() { >+ public void widgetDisposed(DisposeEvent e) { >+ if (!galleryIsDisposed) { >+ Object data = item.getData(); >+ if (usingElementMap() && data != null) { >+ unmapElement(data, item); >+ } >+ } >+ } >+ }); >+ } >+ } >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.jface.viewers.AbstractTreeViewer#internalInitializeTree(org.eclipse.swt.widgets.Control) >+ */ >+ protected void internalInitializeTree(Control widget) { >+ if (contentProviderIsLazy) { >+ if (widget instanceof Gallery && widget.getData() != null) { >+ virtualLazyUpdateChildCount(widget, 0); >+ return; >+ } >+ } >+ super.internalInitializeTree(gallery); >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.jface.viewers.AbstractTreeViewer#updatePlus(org.eclipse.swt.widgets.Item, >+ * java.lang.Object) >+ */ >+ protected void updatePlus(Item item, Object element) { >+ if (contentProviderIsLazy) { >+ Object data = item.getData(); >+ int itemCount = 0; >+ if (data != null) { >+ // item is already materialized >+ itemCount = ((GalleryItem) item).getItemCount(); >+ } >+ virtualLazyUpdateHasChildren(item, itemCount); >+ } else { >+ super.updatePlus(item, element); >+ } >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.viewers.AbstractTreeViewer#handleTreeExpand(org.eclipse.swt.events.TreeEvent) >+ */ >+ protected void handleTreeExpand(TreeEvent event) { >+ if (contentProviderIsLazy) { >+ if (event.item.getData() != null) { >+ Item[] children = getChildren(event.item); >+ if (children.length == 1 && children[0].getData()==null) { >+ // we have a dummy child node, ask for an updated child >+ // count >+ virtualLazyUpdateChildCount(event.item, children.length); >+ } >+ fireTreeExpanded(new TreeExpansionEvent(this, event.item >+ .getData())); >+ } >+ return; >+ } >+ super.handleTreeExpand(event); >+ } >+ >+ /** >+ * For a TreeViewer with a tree with the VIRTUAL style bit set, inform the >+ * viewer about whether the given element or tree path has children. Avoid >+ * calling this method if the number of children has already been set. >+ * >+ * @param elementOrTreePath >+ * the element, or tree path >+ * @param hasChildren >+ * >+ * @since 3.3 >+ */ >+ public void setHasChildren(final Object elementOrTreePath, final boolean hasChildren) { >+ // TODO: determine why this method call is necessary and replace it with API >+// if (isBusy()) >+// return; >+ preservingSelection(new Runnable() { >+ public void run() { >+ if (internalIsInputOrEmptyPath(elementOrTreePath)) { >+ if (hasChildren) { >+ virtualLazyUpdateChildCount(getGallery(), >+ getChildren(getGallery()).length); >+ } else { >+ setChildCount(elementOrTreePath, 0); >+ } >+ return; >+ } >+ Widget[] items = internalFindItems(elementOrTreePath); >+ for (int i = 0; i < items.length; i++) { >+ GalleryItem item = (GalleryItem) items[i]; >+ if (!hasChildren) { >+ item.setItemCount(0); >+ } else { >+ if (!item.isExpanded()) { >+ item.setItemCount(1); >+ GalleryItem child = item.getItem(0); >+ if (child.getData() != null) { >+ disassociate(child); >+ } >+ // Simulate item.clear(0, true) >+ item.getItem(0).clearAll(true); >+ item.getItem(0).clear(); >+ } else { >+ virtualLazyUpdateChildCount(item, item.getItemCount()); >+ } >+ } >+ } >+ } >+ }); >+ } >+ >+ /** >+ * Update the widget at index. >+ * @param widget >+ * @param index >+ */ >+ private void virtualLazyUpdateWidget(Widget widget, int index) { >+ // TODO: determine why this variable is necessary and replace it with API >+// boolean oldBusy = busy; >+// busy = false; >+ try { >+ if (contentProviderIsTreeBased) { >+ TreePath treePath; >+ if (widget instanceof Item) { >+ if (widget.getData() == null) { >+ // we need to materialize the parent first >+ // see bug 167668 >+ // however, that would be too risky >+ // see bug 182782 and bug 182598 >+ // so we just ignore this call altogether >+ // and don't do this: virtualMaterializeItem((GalleryItem) widget); >+ return; >+ } >+ treePath = getTreePathFromItem((Item) widget); >+ } else { >+ treePath = TreePath.EMPTY; >+ } >+ ((ILazyTreePathContentProvider) getContentProvider()) >+ .updateElement(treePath, index); >+ } else { >+ ((ILazyTreeContentProvider) getContentProvider()).updateElement( >+ widget.getData(), index); >+ } >+ } finally { >+ // TODO: determine why this variable is necessary and replace it with API >+// busy = oldBusy; >+ } >+ } >+ >+ /** >+ * Update the child count >+ * @param widget >+ * @param currentChildCount >+ */ >+ private void virtualLazyUpdateChildCount(Widget widget, int currentChildCount) { >+ // TODO: determine why this variable is necessary and replace it with API >+// boolean oldBusy = busy; >+// busy = false; >+ try { >+ if (contentProviderIsTreeBased) { >+ TreePath treePath; >+ if (widget instanceof Item) { >+ treePath = getTreePathFromItem((Item) widget); >+ } else { >+ treePath = TreePath.EMPTY; >+ } >+ ((ILazyTreePathContentProvider) getContentProvider()) >+ .updateChildCount(treePath, currentChildCount); >+ } else { >+ ((ILazyTreeContentProvider) getContentProvider()).updateChildCount(widget.getData(), currentChildCount); >+ } >+ } finally { >+ // TODO: determine why this variable is necessary and replace it with API >+// busy = oldBusy; >+ } >+ } >+ >+ /** >+ * Update the item with the current child count. >+ * @param item >+ * @param currentChildCount >+ */ >+ private void virtualLazyUpdateHasChildren(Item item, int currentChildCount) { >+ // TODO: determine why this variable is necessary and replace it with API >+// boolean oldBusy = busy; >+// busy = false; >+ try { >+ if (contentProviderIsTreeBased) { >+ TreePath treePath; >+ treePath = getTreePathFromItem(item); >+ if (currentChildCount == 0) { >+ // item is not expanded (but may have a plus currently) >+ ((ILazyTreePathContentProvider) getContentProvider()) >+ .updateHasChildren(treePath); >+ } else { >+ ((ILazyTreePathContentProvider) getContentProvider()) >+ .updateChildCount(treePath, currentChildCount); >+ } >+ } else { >+ ((ILazyTreeContentProvider) getContentProvider()).updateChildCount(item.getData(), currentChildCount); >+ } >+ } finally { >+ // TODO: determine why this variable is necessary and replace it with API >+// busy = oldBusy; >+ } >+ } >+ >+ protected void disassociate(Item item) { >+ if (contentProviderIsLazy) { >+ // avoid causing a callback: >+ item.setText(" "); //$NON-NLS-1$ >+ } >+ super.disassociate(item); >+ } > }
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 Raw
Actions:
View
Attachments on
bug 224692
: 108725 |
108796
|
108797
|
108958