Bug 153500 Asynchronous model viewer [batch updates]
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/model/elements/ElementContentProvider.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/model/elements/ElementContentProvider.java index 08a943b..8747709 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/model/elements/ElementContentProvider.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/model/elements/ElementContentProvider.java
@@ -32,13 +32,16 @@ /* (non-Javadoc) * @see org.eclipse.debug.internal.ui.viewers.model.provisional.IElementContentProvider#updateChildren(java.lang.Object, int, int, org.eclipse.debug.internal.ui.viewers.provisional.IPresentationContext, org.eclipse.debug.internal.ui.viewers.model.provisional.IElementRequestMonitor) */ - public void update(final IChildrenUpdate update) { + public void update(final IChildrenUpdate[] updates) { Job job = new Job("children update") { //$NON-NLS-1$ protected IStatus run(IProgressMonitor monitor) { - if (!update.isCanceled()) { - retrieveChildren(update); + for (int i = 0; i < updates.length; i++) { + IChildrenUpdate update = updates[i]; + if (!update.isCanceled()) { + retrieveChildren(update); + } + update.done(); } - update.done(); return Status.OK_STATUS; } }; @@ -50,13 +53,16 @@ /* (non-Javadoc) * @see org.eclipse.debug.internal.ui.viewers.model.provisional.IElementContentProvider#update(org.eclipse.debug.internal.ui.viewers.model.provisional.IChildrenCountUpdate) */ - public void update(final IChildrenCountUpdate update) { + public void update(final IChildrenCountUpdate[] updates) { Job job = new Job("child count update") { //$NON-NLS-1$ protected IStatus run(IProgressMonitor monitor) { - if (!update.isCanceled()) { - retrieveChildCount(update); + for (int i = 0; i < updates.length; i++) { + IChildrenCountUpdate update = updates[i]; + if (!update.isCanceled()) { + retrieveChildCount(update); + } + update.done(); } - update.done(); return Status.OK_STATUS; } }; @@ -77,7 +83,7 @@ IPresentationContext context = update.getPresentationContext(); if (supportsContext(context)) { int offset = update.getOffset(); - Object parent = update.getElement(update.getParent()); + Object parent = update.getElement(update.getElementPath()); if (parent == null) { update.setCanceled(true); } else { @@ -108,26 +114,20 @@ IStatus status = Status.OK_STATUS; try { IPresentationContext context = update.getPresentationContext(); - TreePath[] parents = update.getParents(); + TreePath elementPath = update.getElementPath(); if (supportsContext(context)) { - for (int i = 0; i < parents.length; i++) { - Object parent = update.getElement(parents[i]); - if (parent == null) { - // viewer input changed to null - update.setCanceled(true); - break; - } - int childCount = getChildCount(parent, context, update); - if (update.isCanceled()) { - break; - } else { - update.setChildCount(parents[i], childCount); + Object element = update.getElement(elementPath); + if (element == null) { + // viewer input changed to null + update.setCanceled(true); + } else { + int childCount = getChildCount(element, context, update); + if (!update.isCanceled()) { + update.setChildCount(childCount); } } } else { - for (int i = 0; i < parents.length; i++) { - update.setChildCount(parents[i], 0); - } + update.setChildCount(0); } } catch (CoreException e) { status = e.getStatus(); @@ -152,7 +152,7 @@ /** * Returns the number of children for the given element. * - * @param element element that may have children + * @param elementPath element that may have children * @param context context element will be presented in * @return number of children * @throws CoreException if an exception occurs determining child count @@ -197,13 +197,16 @@ return null; } - public void update(final IHasChildrenUpdate update) { + public void update(final IHasChildrenUpdate[] updates) { Job job = new Job("has children update") { //$NON-NLS-1$ protected IStatus run(IProgressMonitor monitor) { - if (!monitor.isCanceled()) { - updateHasChildren(update); + for (int i = 0; i < updates.length; i++) { + IHasChildrenUpdate update = updates[i]; + if (!update.isCanceled()) { + updateHasChildren(update); + } + update.done(); } - update.done(); return Status.OK_STATUS; } }; @@ -222,23 +225,20 @@ IStatus status = Status.OK_STATUS; try { IPresentationContext context = update.getPresentationContext(); - TreePath[] elements = update.getElements(); + TreePath elementPath = update.getElementPath(); if (supportsContext(context)) { - for (int i = 0; i < elements.length; i++) { - Object element = update.getElement(elements[i]); - if (element == null) { - update.setCanceled(true); - } else { - boolean hasChildren = hasChildren(element, context, update); - if (!update.isCanceled()) { - update.setHasChilren(elements[i], hasChildren); - } + Object element = update.getElement(elementPath); + if (element == null) { + // viewer input changed to null + update.setCanceled(true); + } else { + boolean hasChildren = hasChildren(element, context, update); + if (!update.isCanceled()) { + update.setHasChilren(hasChildren); } } } else { - for (int i = 0; i < elements.length; i++) { - update.setHasChilren(elements[i], false); - } + update.setHasChilren(false); } } catch (CoreException e) { status = e.getStatus();
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/model/elements/ElementLabelProvider.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/model/elements/ElementLabelProvider.java index b56714a..d985dae 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/model/elements/ElementLabelProvider.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/model/elements/ElementLabelProvider.java
@@ -167,7 +167,7 @@ protected void retrieveLabel(ILabelUpdate update) throws CoreException { String[] columnIds = update.getColumnIds(); IPresentationContext presentationContext = update.getPresentationContext(); - TreePath elementPath = update.getElement(); + TreePath elementPath = update.getElementPath(); int numColumns = 1; if (columnIds != null) { numColumns = columnIds.length;
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/BatchUpdate.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/BatchUpdate.java new file mode 100644 index 0000000..b5ae4d3 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/BatchUpdate.java
@@ -0,0 +1,95 @@ +/******************************************************************************* + * 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.debug.internal.ui.viewers.model; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.ui.progress.WorkbenchJob; + +/** + * A group of viewer updates to batch together into one UI update job. + * + * @since 3.3 + */ +class BatchUpdate { + + /** + * Pending batched updates + */ + private Set fPending = new HashSet(); + + /** + * List of updates needing to run a UI job + */ + private List fComplete = null; + + protected WorkbenchJob fViewerUpdateJob = new WorkbenchJob("Asynchronous viewer update") { //$NON-NLS-1$ + public IStatus runInUIThread(IProgressMonitor monitor) { + // necessary to check if viewer is disposed + Iterator updates = fComplete.iterator(); + while (updates.hasNext()) { + ViewerUpdateMonitor update = (ViewerUpdateMonitor) updates.next(); + try { + if (!update.isCanceled() && !update.getContentProvider().isDisposed()) { + IStatus status = update.getStatus(); + if (status == null || status.isOK()) { + update.performUpdate(); + } + } + } finally { + update.getContentProvider().updateComplete(update); + } + } + return Status.OK_STATUS; + } + }; + + /** + * Batch the given update with this group. + * + * @param update update to batch + */ + public synchronized void batch(ViewerUpdateMonitor update) { + fPending.add(update); + } + + /** + * Notification the given update is done. + * + * @param update update completed + */ + public void done(ViewerUpdateMonitor update) { + boolean allDone = false; + synchronized (this) { + fPending.remove(update); + allDone = fPending.isEmpty(); + if (!update.isCanceled()) { + if (fComplete == null) { + fComplete = new ArrayList(fPending.size() + 1); + } + fComplete.add(update); + } + } + if (update.isCanceled()) { + update.getContentProvider().updateComplete(update); + } else if (allDone) { + fViewerUpdateJob.schedule(); + } + } + +}
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/ChildrenCountUpdate.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/ChildrenCountUpdate.java index e147153..4ca3c69 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/ChildrenCountUpdate.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/ChildrenCountUpdate.java
@@ -10,15 +10,7 @@ *******************************************************************************/ package org.eclipse.debug.internal.ui.viewers.model; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; -import java.util.Map.Entry; - import org.eclipse.debug.internal.ui.viewers.model.provisional.IChildrenCountUpdate; -import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementContentProvider; import org.eclipse.jface.viewers.TreePath; import org.eclipse.jface.viewers.TreeViewer; @@ -27,90 +19,46 @@ */ class ChildrenCountUpdate extends ViewerUpdateMonitor implements IChildrenCountUpdate { - /** - * Map of <code>TreePath</code>s to <code>Integer</code>s. - */ - private Map fCounts = new HashMap(); - - /** - * Set of <code>TreePath</code>s. - */ - private Set fParents = new HashSet(); - - private boolean fStarted = false; - private IElementContentProvider fContentProvider; + private TreePath fElementPath; + private int fCount = 0; /** * @param contentProvider */ - public ChildrenCountUpdate(ModelContentProvider contentProvider, IElementContentProvider elementContentProvider) { + public ChildrenCountUpdate(ModelContentProvider contentProvider, TreePath elementPath) { super(contentProvider); - fContentProvider = elementContentProvider; + fElementPath = elementPath; } /* (non-Javadoc) * @see org.eclipse.debug.internal.ui.viewers.model.provisional.viewers.ViewerUpdateMonitor#performUpdate() */ protected void performUpdate() { - Iterator iterator = fCounts.entrySet().iterator(); - while (iterator.hasNext()) { - Entry entry = (Entry) iterator.next(); - int count = ((Integer)(entry.getValue())).intValue(); - TreePath parentPath = (TreePath) entry.getKey(); - int viewCount = count; - if (count == 0) { - getContentProvider().clearFilters(parentPath); - } else { - viewCount = getContentProvider().modelToViewChildCount(parentPath, count); - } - if (ModelContentProvider.DEBUG_CONTENT_PROVIDER) { - System.out.println("setChildCount(" + getElement(parentPath) + ", modelCount: " + count + " viewCount: " + viewCount + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - } - ((TreeViewer)(getContentProvider().getViewer())).setChildCount(parentPath, viewCount); - } - } - - public void setChildCount(TreePath parentPath, int numChildren) { - fCounts.put(parentPath, new Integer(numChildren)); - } - - /** - * @param element - * @return - */ - protected boolean coalesce(TreePath treePath) { - fParents.add(treePath); - return true; - } - - /** - * - */ - protected void start() { - synchronized (this) { - if (fStarted) { - return; - } - fStarted = true; - } - TreeModelContentProvider contentProvider = (TreeModelContentProvider)getContentProvider(); - contentProvider.countRequestStarted(fContentProvider); - if (!isCanceled()) { - fContentProvider.update(this); + int viewCount = fCount; + if (viewCount == 0) { + getContentProvider().clearFilters(fElementPath); } else { - done(); + viewCount = getContentProvider().modelToViewChildCount(fElementPath, fCount); } + if (ModelContentProvider.DEBUG_CONTENT_PROVIDER) { + System.out.println("setChildCount(" + getElement(fElementPath) + ", modelCount: " + fCount + " viewCount: " + viewCount + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + } + ((TreeViewer)(getContentProvider().getViewer())).setChildCount(fElementPath, viewCount); } - public TreePath[] getParents() { - return (TreePath[]) fParents.toArray(new TreePath[fParents.size()]); + public void setChildCount(int numChildren) { + fCount = numChildren; + } + + public TreePath getElementPath() { + return fElementPath; } /* (non-Javadoc) * @see org.eclipse.debug.internal.ui.viewers.model.ViewerUpdateMonitor#isContained(org.eclipse.jface.viewers.TreePath) */ boolean isContained(TreePath path) { - return ((TreePath)fParents.iterator().next()).startsWith(path, null); + return fElementPath.startsWith(path, null); } }
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/ChildrenUpdate.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/ChildrenUpdate.java index 8ee031c..acec06f 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/ChildrenUpdate.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/ChildrenUpdate.java
@@ -121,7 +121,7 @@ TreeModelContentProvider contentProvider = (TreeModelContentProvider)getContentProvider(); contentProvider.childRequestStarted(this); if (!isCanceled()) { - fContentProvider.update(this); + fContentProvider.update(new IChildrenUpdate[]{this}); } else { done(); } @@ -141,7 +141,7 @@ return fIndex; } - public TreePath getParent() { + public TreePath getElementPath() { return fParentPath; }
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/HasChildrenUpdate.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/HasChildrenUpdate.java index e8103c9..a48fc21 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/HasChildrenUpdate.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/HasChildrenUpdate.java
@@ -10,14 +10,6 @@ *******************************************************************************/ package org.eclipse.debug.internal.ui.viewers.model; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; -import java.util.Map.Entry; - -import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementContentProvider; import org.eclipse.debug.internal.ui.viewers.model.provisional.IHasChildrenUpdate; import org.eclipse.jface.viewers.TreePath; import org.eclipse.jface.viewers.TreeViewer; @@ -27,92 +19,47 @@ */ class HasChildrenUpdate extends ViewerUpdateMonitor implements IHasChildrenUpdate { - /** - * Map of <code>TreePath</code>s to <code>Boolean</code>s. - */ - private Map fBooleans = new HashMap(); - - /** - * Set of <code>TreePath</code>s. - */ - private Set fElements = new HashSet(); - - private boolean fStarted = false; - private IElementContentProvider fContentProvider; + private TreePath fElementPath; + private boolean fHasChildren = false; /** * @param contentProvider */ - public HasChildrenUpdate(ModelContentProvider contentProvider, IElementContentProvider elementContentProvider) { + public HasChildrenUpdate(ModelContentProvider contentProvider, TreePath elementPath) { super(contentProvider); - fContentProvider = elementContentProvider; + fElementPath = elementPath; } /* (non-Javadoc) * @see org.eclipse.debug.internal.ui.viewers.model.provisional.viewers.ViewerUpdateMonitor#performUpdate() */ protected void performUpdate() { - Iterator iterator = fBooleans.entrySet().iterator(); - while (iterator.hasNext()) { - Entry entry = (Entry) iterator.next(); - boolean hasChildren = ((Boolean)(entry.getValue())).booleanValue(); - TreePath elementPath = (TreePath) entry.getKey(); - ModelContentProvider contentProvider = getContentProvider(); - if (!hasChildren) { - contentProvider.clearFilters(elementPath); - } - if (ModelContentProvider.DEBUG_CONTENT_PROVIDER) { - System.out.println("setHasChildren(" + getElement(elementPath) + " >> " + hasChildren); //$NON-NLS-1$ //$NON-NLS-2$ - } - ((TreeViewer)(contentProvider.getViewer())).setHasChildren(elementPath, hasChildren); - if (elementPath.getSegmentCount() > 0) { - contentProvider.doRestore(elementPath); - } + ModelContentProvider contentProvider = getContentProvider(); + if (!fHasChildren) { + contentProvider.clearFilters(fElementPath); + } + if (ModelContentProvider.DEBUG_CONTENT_PROVIDER) { + System.out.println("setHasChildren(" + getElement(fElementPath) + " >> " + fHasChildren); //$NON-NLS-1$ //$NON-NLS-2$ + } + ((TreeViewer)(contentProvider.getViewer())).setHasChildren(fElementPath, fHasChildren); + if (fElementPath.getSegmentCount() > 0) { + contentProvider.doRestore(fElementPath); } } - /** - * @param element - * @return - */ - protected boolean coalesce(TreePath treePath) { - fElements.add(treePath); - return true; + public TreePath getElementPath() { + return fElementPath; } - /** - * - */ - protected void start() { - synchronized (this) { - if (fStarted) { - return; - } - fStarted = true; - } - TreeModelContentProvider contentProvider = (TreeModelContentProvider)getContentProvider(); - contentProvider.hasChildrenRequestStarted(fContentProvider); - if (!isCanceled()) { - fContentProvider.update(this); - } else { - done(); - } - } - - public TreePath[] getElements() { - return (TreePath[]) fElements.toArray(new TreePath[fElements.size()]); - } - - public void setHasChilren(TreePath element, boolean hasChildren) { - fBooleans.put(element, Boolean.valueOf(hasChildren)); - + public void setHasChilren(boolean hasChildren) { + fHasChildren = hasChildren; } /* (non-Javadoc) * @see org.eclipse.debug.internal.ui.viewers.model.ViewerUpdateMonitor#isContained(org.eclipse.jface.viewers.TreePath) */ boolean isContained(TreePath path) { - return ((TreePath)fElements.iterator().next()).startsWith(path, null); + return fElementPath.startsWith(path, null); } }
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/LabelUpdate.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/LabelUpdate.java index 4a23cd9..8801ebc 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/LabelUpdate.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/LabelUpdate.java
@@ -73,7 +73,7 @@ /* (non-Javadoc) * @see org.eclipse.debug.internal.ui.viewers.model.provisional.ILabelUpdate#getElement() */ - public TreePath getElement() { + public TreePath getElementPath() { return fElementPath; }
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/TreeModelContentProvider.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/TreeModelContentProvider.java index 34768a9..66284ec 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/TreeModelContentProvider.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/TreeModelContentProvider.java
@@ -10,8 +10,10 @@ *******************************************************************************/ package org.eclipse.debug.internal.ui.viewers.model; +import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.Timer; @@ -22,6 +24,7 @@ import org.eclipse.core.runtime.Status; import org.eclipse.debug.internal.ui.viewers.model.provisional.IChildrenUpdate; import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementContentProvider; +import org.eclipse.debug.internal.ui.viewers.model.provisional.IHasChildrenUpdate; import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelDelta; import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext; import org.eclipse.debug.internal.ui.viewers.model.provisional.ModelDelta; @@ -82,20 +85,25 @@ Object element = getElement(path); IElementContentProvider contentAdapter = getContentAdapter(element); if (contentAdapter != null) { - ChildrenCountUpdate request = (ChildrenCountUpdate) fPendingCountRequests.get(contentAdapter); - if (request != null) { - if (request.coalesce(path)) { - return; - } else { - request.start(); - } + ChildrenCountUpdate request = new ChildrenCountUpdate(this, path); + List requests = (List) fPendingCountRequests.get(contentAdapter); + if (requests != null) { + requests.add(request); + return; } - final ChildrenCountUpdate newRequest = new ChildrenCountUpdate(this, contentAdapter); - newRequest.coalesce(path); - fPendingCountRequests.put(contentAdapter, newRequest); + requests = new ArrayList(); + requests.add(request); + fPendingCountRequests.put(contentAdapter, requests); + final IElementContentProvider adapter = contentAdapter; fTimer.schedule(new TimerTask() { public void run() { - newRequest.start(); + List updates = null; + synchronized (TreeModelContentProvider.this) { + updates = (List) fPendingCountRequests.remove(adapter); + } + ChildrenCountUpdate[] array = (ChildrenCountUpdate[]) updates.toArray(new ChildrenCountUpdate[updates.size()]); + batch(array); + adapter.update(array); } }, 10L); } @@ -127,37 +135,44 @@ Object element = getElement(path); IElementContentProvider contentAdapter = getContentAdapter(element); if (contentAdapter != null) { - HasChildrenUpdate request = (HasChildrenUpdate) fPendingHasChildrenRequests.get(contentAdapter); - if (request != null) { - if (request.coalesce(path)) { - return; - } else { - request.start(); - } + HasChildrenUpdate request = new HasChildrenUpdate(this, path); + List requests = (List) fPendingHasChildrenRequests.get(contentAdapter); + if (requests != null) { + requests.add(request); + return; } - final HasChildrenUpdate newRequest = new HasChildrenUpdate(this, contentAdapter); - newRequest.coalesce(path); - fPendingHasChildrenRequests.put(contentAdapter, newRequest); + requests = new ArrayList(); + requests.add(request); + fPendingHasChildrenRequests.put(contentAdapter, requests); + final IElementContentProvider adapter = contentAdapter; fTimer.schedule(new TimerTask() { public void run() { - newRequest.start(); + List list = null; + synchronized (TreeModelContentProvider.this) { + list = (List) fPendingHasChildrenRequests.remove(adapter); + } + adapter.update((IHasChildrenUpdate[]) list.toArray(new IHasChildrenUpdate[list.size()])); } }, 10L); } } + /** + * Batches the given update requests into one UI job on completion + * + * @param updates updates to batch + */ + protected void batch(ViewerUpdateMonitor[] updates) { + BatchUpdate batch = new BatchUpdate(); + for (int i = 0; i < updates.length; i++) { + updates[i].setBatchUpdate(batch); + } + } + protected synchronized void childRequestStarted(IChildrenUpdate update) { - fPendingChildRequests.remove(update.getParent()); + fPendingChildRequests.remove(update.getElementPath()); } - protected synchronized void countRequestStarted(Object key) { - fPendingCountRequests.remove(key); - } - - protected synchronized void hasChildrenRequestStarted(Object key) { - fPendingHasChildrenRequests.remove(key); - } - /* (non-Javadoc) * @see org.eclipse.debug.internal.ui.viewers.model.provisional.viewers.ModelContentProvider#getPresentationContext() */
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/ViewerUpdateMonitor.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/ViewerUpdateMonitor.java index 8014e05..32827aa 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/ViewerUpdateMonitor.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/ViewerUpdateMonitor.java
@@ -33,6 +33,11 @@ */ private boolean fDone = false; + /** + * Associated batch operation, or <code>null</code> + */ + private BatchUpdate fBatchUpdate = null; + protected WorkbenchJob fViewerUpdateJob = new WorkbenchJob("Asynchronous viewer update") { //$NON-NLS-1$ public IStatus runInUIThread(IProgressMonitor monitor) { // necessary to check if viewer is disposed @@ -86,9 +91,16 @@ */ public final void done() { synchronized (this) { + if (isDone()) { + return; + } fDone = true; } - scheduleViewerUpdate(0L); + if (fBatchUpdate != null) { + fBatchUpdate.done(this); + } else { + scheduleViewerUpdate(); + } } /** @@ -100,9 +112,9 @@ return fDone; } - protected void scheduleViewerUpdate(long ms) { + protected void scheduleViewerUpdate() { if(!isCanceled()) { - fViewerUpdateJob.schedule(ms); + fViewerUpdateJob.schedule(); } else { getContentProvider().updateComplete(this); } @@ -133,4 +145,9 @@ */ abstract boolean isContained(TreePath path); + synchronized void setBatchUpdate(BatchUpdate batchUpdate) { + fBatchUpdate = batchUpdate; + batchUpdate.batch(this); + } + }
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/provisional/IChildrenCountUpdate.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/provisional/IChildrenCountUpdate.java index 9ea4246..67c271c 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/provisional/IChildrenCountUpdate.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/provisional/IChildrenCountUpdate.java
@@ -21,18 +21,17 @@ public interface IChildrenCountUpdate extends IViewerUpdate { /** - * Returns the parent elements that children counts have been requested for - * as tree paths. An empty path identifies the root element. + * Returns the element that a child count has been requested for + * as a tree path. An empty path identifies the root element. * - * @return parent elements as tree paths + * @return element as a tree path */ - public TreePath[] getParents(); + public TreePath getElementPath(); /** - * Sets the number of children for the given parent. + * Sets the number of children for this update. * - * @param parent parent element or empty path for root element * @param numChildren number of children */ - public void setChildCount(TreePath parentPath, int numChildren); + public void setChildCount(int numChildren); }
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/provisional/IChildrenUpdate.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/provisional/IChildrenUpdate.java index d477a2c..113c4b9 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/provisional/IChildrenUpdate.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/provisional/IChildrenUpdate.java
@@ -21,12 +21,12 @@ public interface IChildrenUpdate extends IViewerUpdate { /** - * Returns the parent element that children are being requested for + * Returns the element that children are being requested for * as a tree path. An empty path identifies the root element. * - * @return parent element as a tree path + * @return element as a tree path */ - public TreePath getParent(); + public TreePath getElementPath(); /** * Returns the offset at which children have been requested for. This is
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/provisional/IElementContentProvider.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/provisional/IElementContentProvider.java index 19ee90d..0490995 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/provisional/IElementContentProvider.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/provisional/IElementContentProvider.java
@@ -20,24 +20,26 @@ /** * Updates the number of children for the given parent elements in the - * specified request. + * specified requests. * - * @param update specifies counts to update and stores result + * @param updates each update specifies an element to update and provides + * a store for the result */ - public void update(IChildrenCountUpdate update); + public void update(IChildrenCountUpdate[] updates); /** - * Updates children as requested by the update. + * Updates children as requested by the given updates. * - * @param update specifies children to update and stores result + * @param updates each update specifies children to update and stores results */ - public void update(IChildrenUpdate update); + public void update(IChildrenUpdate[] updates); /** * Updates whether elements have children. * - * @param update specifies elements to update and stores result + * @param updates each update specifies an element to update and provides + * a store for the result */ - public void update(IHasChildrenUpdate update); + public void update(IHasChildrenUpdate[] updates); }
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/provisional/IHasChildrenUpdate.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/provisional/IHasChildrenUpdate.java index 9dc6021..cd6db7d 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/provisional/IHasChildrenUpdate.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/provisional/IHasChildrenUpdate.java
@@ -13,25 +13,24 @@ import org.eclipse.jface.viewers.TreePath; /** - * Context sensitive update request for whether elements have children. + * Context sensitive update request for whether an element has children. * * @since 3.3 */ public interface IHasChildrenUpdate extends IViewerUpdate { /** - * The elements this request is for specified as tree paths. + * The element this request is for specified as a tree path. * An empty path identifies the root element. * - * @return elements as tree paths + * @return element as a tree path */ - public TreePath[] getElements(); + public TreePath getElementPath(); /** - * Sets whether the given element has children. + * Sets whether there are children for this update. * - * @param element tree path to element, or empty for root element - * @param hasChildren whether it has children + * @param hasChildren whether there are children */ - public void setHasChilren(TreePath element, boolean hasChildren); + public void setHasChilren(boolean hasChildren); }
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/provisional/ILabelUpdate.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/provisional/ILabelUpdate.java index d628f47..63e45e4 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/provisional/ILabelUpdate.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/provisional/ILabelUpdate.java
@@ -27,7 +27,7 @@ * * @return associated element tree path */ - public TreePath getElement(); + public TreePath getElementPath(); /** * Returns the id's of the visible columns in presentation order,