Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDarin Wright2004-11-22 22:33:32 +0000
committerDarin Wright2004-11-22 22:33:32 +0000
commit6d32e2a5ac06538581a7213203b6adc5ff7a440c (patch)
treee033b1529047bb0140a89a3435b3fb3179b6a55a
parentaff7e375b5b722c287b0c3185688983ab6c66c95 (diff)
downloadeclipse.platform.debug-6d32e2a5ac06538581a7213203b6adc5ff7a440c.tar.gz
eclipse.platform.debug-6d32e2a5ac06538581a7213203b6adc5ff7a440c.tar.xz
eclipse.platform.debug-6d32e2a5ac06538581a7213203b6adc5ff7a440c.zip
Bug 44724 - background content in debug views
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/RemoteTreeContentManager.java (renamed from org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/IncrementalDeferredTreeContentManager.java)41
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/RemoteTreeViewer.java362
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/DebugViewContentProvider.java3
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/LaunchView.java3
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/LaunchViewer.java323
5 files changed, 385 insertions, 347 deletions
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/IncrementalDeferredTreeContentManager.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/RemoteTreeContentManager.java
index 0172a117f..efc1e578a 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/IncrementalDeferredTreeContentManager.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/RemoteTreeContentManager.java
@@ -7,24 +7,14 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
-package org.eclipse.debug.internal.ui.views.launch;
+package org.eclipse.debug.internal.ui.views;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.debug.internal.ui.views.DebugUIViewsMessages; import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.ui.IWorkbenchPartSite;
-import org.eclipse.ui.internal.progress.PendingUpdateAdapter;
-import org.eclipse.ui.progress.DeferredTreeContentManager;
-import org.eclipse.ui.progress.IDeferredWorkbenchAdapter;
-import org.eclipse.ui.progress.IElementCollector;
-import org.eclipse.ui.progress.WorkbenchJob;
-/**
- * A deferred content manager that merges content into a tree rather then replacing * it children with a "pending" node, and then the real children. This avoids * collapsing the viewer when a refresh is performed. This implementation is * currently tied to the LaunchViewer. * * @since 3.1
+import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.ui.IWorkbenchPartSite; import org.eclipse.ui.internal.progress.PendingUpdateAdapter; import org.eclipse.ui.progress.DeferredTreeContentManager; import org.eclipse.ui.progress.IDeferredWorkbenchAdapter; import org.eclipse.ui.progress.IElementCollector; import org.eclipse.ui.progress.WorkbenchJob; /**
+ * A remote content manager that merges content into a tree rather then replacing * its children with a "pending" node, and then the real children when they are available. * This avoids collapsing the viewer when a refresh is performed. This implementation is * currently tied to the <code>RemoteTreeViewer</code>. * * @since 3.1
*/
-public class IncrementalDeferredTreeContentManager extends DeferredTreeContentManager {
+public class RemoteTreeContentManager extends DeferredTreeContentManager {
- private LaunchViewer fViewer;
+ private RemoteTreeViewer fViewer;
/**
* Contructs a new content manager.
*
@@ -32,7 +22,7 @@ public class IncrementalDeferredTreeContentManager extends DeferredTreeContentMa
* @param viewer viewer
* @param site part site
*/
- public IncrementalDeferredTreeContentManager(ITreeContentProvider provider, LaunchViewer viewer, IWorkbenchPartSite site) {
+ public RemoteTreeContentManager(ITreeContentProvider provider, RemoteTreeViewer viewer, IWorkbenchPartSite site) {
super(provider, viewer, site);
fViewer = viewer;
}
@@ -43,7 +33,7 @@ public class IncrementalDeferredTreeContentManager extends DeferredTreeContentMa
* The parent object being filled in,
* @param placeholder
* The adapter that will be used to indicate that results are
- * pending.
+ * pending, possibly <code>null</code>
* @return IElementCollector
*/
protected IElementCollector createElementCollector(final Object parent, final PendingUpdateAdapter placeholder) {
@@ -109,10 +99,10 @@ public class IncrementalDeferredTreeContentManager extends DeferredTreeContentMa
/**
* Create a UIJob to replace the children of the parent in the tree viewer.
*
- * @param parent
- * @param children
- * @param offset
- * @param monitor
+ * @param parent the parent for which children are to be replaced
+ * @param children the replacement children
+ * @param offset the offset at which to start replacing children
+ * @param monitor progress monitor
*/
protected void replaceChildren(final Object parent, final Object[] children, final int offset, IProgressMonitor monitor) {
WorkbenchJob updateJob = new WorkbenchJob(DebugUIViewsMessages.getString("IncrementalDeferredTreeContentManager.0")) { //$NON-NLS-1$
@@ -137,11 +127,10 @@ public class IncrementalDeferredTreeContentManager extends DeferredTreeContentMa
}
/**
- * Create a UIJob to replace the children of the parent in the tree viewer.
+ * Create a UIJob to prune the children of the parent in the tree viewer, starting * at the given offset.
*
- * @param parent
- * @param children
- * @param offset
+ * @param parent the parent for which children should be pruned
+ * @param offset the offset at which children should be pruned. All children at and after * this index will be removed from the tree.
* @param monitor
*/
protected void prune(final Object parent, final int offset) {
@@ -164,4 +153,4 @@ public class IncrementalDeferredTreeContentManager extends DeferredTreeContentMa
};
updateJob.setSystem(true);
updateJob.schedule();
- } /* (non-Javadoc) * @see org.eclipse.ui.progress.DeferredTreeContentManager#runClearPlaceholderJob(org.eclipse.ui.internal.progress.PendingUpdateAdapter) */ protected void runClearPlaceholderJob(PendingUpdateAdapter placeholder) { if (placeholder != null) { super.runClearPlaceholderJob(placeholder); } } }
+ } /* (non-Javadoc) * @see org.eclipse.ui.progress.DeferredTreeContentManager#runClearPlaceholderJob(org.eclipse.ui.internal.progress.PendingUpdateAdapter) */ protected void runClearPlaceholderJob(PendingUpdateAdapter placeholder) { // the placeholder is not used when there were already children in the tree (null) if (placeholder != null) { super.runClearPlaceholderJob(placeholder); } } }
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/RemoteTreeViewer.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/RemoteTreeViewer.java
new file mode 100644
index 000000000..7996c8470
--- /dev/null
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/RemoteTreeViewer.java
@@ -0,0 +1,362 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.debug.internal.ui.views;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Item;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeItem;
+import org.eclipse.swt.widgets.Widget;
+import org.eclipse.ui.model.IWorkbenchAdapter;
+import org.eclipse.ui.progress.UIJob;
+
+/**
+ * A tree viewer that displays remote content. Content is retrieved in a background
+ * job, and the viewer is updated incrementally on a refresh.
+ *
+ * @since 3.1
+ */
+public class RemoteTreeViewer extends TreeViewer {
+
+ private ExpansionJob fExpansionJob = null;
+ private SelectionJob fSelectionJob = null;
+
+ class ExpansionJob extends UIJob {
+
+ private Object element;
+ private List parents; // top down
+ private Object lock;
+
+ /**
+ * Constucts a job to expand the given element.
+ *
+ * @param target the element to expand
+ */
+ public ExpansionJob(Object target, Object lock) {
+ super(DebugUIViewsMessages.getString("LaunchViewer.1")); //$NON-NLS-1$
+ element = target;
+ parents = new ArrayList();
+ this.lock = lock;
+ addAllParents(parents, element);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.progress.UIJob#runInUIThread(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public IStatus runInUIThread(IProgressMonitor monitor) {
+ if (getControl().isDisposed()) {
+ return Status.OK_STATUS;
+ }
+ synchronized (lock) {
+ boolean allParentsExpanded = true;
+ Iterator iterator = parents.iterator();
+ while (iterator.hasNext() && !monitor.isCanceled()) {
+ Object parent = iterator.next();
+ TreeItem item = (TreeItem) findItem(parent);
+ if (item != null) {
+ expandToLevel(parent, 1);
+ } else {
+ allParentsExpanded = false;
+ break;
+ }
+ }
+ if (allParentsExpanded) {
+ TreeItem item = (TreeItem) findItem(element);
+ if (item != null) {
+ if (isExpandable(element)) {
+ expandToLevel(element, 1);
+ }
+ fExpansionJob = null;
+ return Status.OK_STATUS;
+ }
+ }
+ return Status.OK_STATUS;
+ }
+ }
+
+ }
+
+ class SelectionJob extends UIJob {
+
+ private Object element;
+ private List parents; // top down
+ private Object lock;
+
+ /**
+ * Constucts a job to select the given element.
+ *
+ * @param target the element to select
+ */
+ public SelectionJob(Object target, Object lock) {
+ super(DebugUIViewsMessages.getString("LaunchViewer.0")); //$NON-NLS-1$
+ element = target;
+ parents = new ArrayList();
+ this.lock = lock;
+ addAllParents(parents, element);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.progress.UIJob#runInUIThread(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public IStatus runInUIThread(IProgressMonitor monitor) {
+ if (getControl().isDisposed()) {
+ return Status.OK_STATUS;
+ }
+ synchronized (lock) {
+ boolean allParentsExpanded = true;
+ Iterator iterator = parents.iterator();
+ while (iterator.hasNext() && !monitor.isCanceled()) {
+ Object parent = iterator.next();
+ TreeItem item = (TreeItem) findItem(parent);
+ if (item != null) {
+ expandToLevel(parent, 1);
+ } else {
+ allParentsExpanded = false;
+ break;
+ }
+ }
+ if (allParentsExpanded) {
+ if (findItem(element) != null) {
+ setSelection(new StructuredSelection(element), true);
+ fSelectionJob = null;
+ return Status.OK_STATUS;
+ }
+ }
+ return Status.OK_STATUS;
+ }
+ }
+
+ }
+
+ /**
+ * Constructs a remote tree viewer parented by the given composite.
+ *
+ * @param parent parent composite
+ */
+ public RemoteTreeViewer(Composite parent) {
+ super(parent);
+ }
+
+
+
+ protected void runDeferredUpdates() {
+ if (fExpansionJob != null) {
+ fExpansionJob.schedule();
+ }
+ if (fSelectionJob != null) {
+ fSelectionJob.schedule();
+ }
+ }
+
+ /**
+ * Constructs a remote tree viewer parented by the given composite
+ * with the given style.
+ *
+ * @param parent parent composite
+ * @param style style bits
+ */
+ public RemoteTreeViewer(Composite parent, int style) {
+ super(parent, style);
+ }
+
+ /**
+ * Constructs a remote tree viewer with the given tree.
+ *
+ * @param tree tree widget
+ */
+ public RemoteTreeViewer(Tree tree) {
+ super(tree);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.AbstractTreeViewer#add(java.lang.Object, java.lang.Object)
+ */
+ public synchronized void add(Object parentElement, Object childElement) {
+ super.add(parentElement, childElement);
+ runDeferredUpdates();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.AbstractTreeViewer#add(java.lang.Object, java.lang.Object[])
+ */
+ public synchronized void add(Object parentElement, Object[] childElements) {
+ super.add(parentElement, childElements);
+ runDeferredUpdates();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.AbstractTreeViewer#remove(java.lang.Object)
+ */
+ public synchronized void remove(Object element) {
+ super.remove(element);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.AbstractTreeViewer#remove(java.lang.Object[])
+ */
+ public synchronized void remove(Object[] elements) {
+ super.remove(elements);
+ }
+
+ /**
+ * Cancels any deferred updates currently scheduled/running.
+ */
+ public void cancelJobs() {
+ cancel(fSelectionJob);
+ cancel(fExpansionJob);
+ }
+
+ public synchronized void deferExpansion(Object element) {
+ TreeItem treeItem = (TreeItem) findItem(element);
+ if (treeItem == null) {
+ if (fExpansionJob != null) {
+ fExpansionJob.cancel();
+ }
+ fExpansionJob = new ExpansionJob(element, this);
+ fExpansionJob.schedule();
+ } else {
+ if (!getExpanded(treeItem)) {
+ expandToLevel(element, 1);
+ }
+ }
+ }
+
+ public synchronized void setDeferredSelection(Object element) {
+ if (findItem(element) == null) {
+ if (fSelectionJob != null) {
+ fSelectionJob.cancel();
+ }
+ fSelectionJob = new SelectionJob(element, this);
+ fSelectionJob.schedule();
+ } else {
+ setSelection(new StructuredSelection(element), true);
+ }
+ }
+
+ private void cancel(Job job) {
+ if (job != null) {
+ job.cancel();
+ }
+ }
+
+ private void addAllParents(List list, Object element) {
+ if (element instanceof IAdaptable) {
+ IAdaptable adaptable = (IAdaptable) element;
+ IWorkbenchAdapter adapter = (IWorkbenchAdapter) adaptable.getAdapter(IWorkbenchAdapter.class);
+ if (adapter != null) {
+ Object parent = adapter.getParent(element);
+ if (parent != null) {
+ list.add(0, parent);
+ if (!(parent instanceof ILaunch))
+ addAllParents(list, parent);
+ }
+ }
+ }
+ }
+
+
+
+ public Object[] filter(Object[] elements) {
+ return super.filter(elements);
+ }
+
+
+
+ public Object[] getCurrentChildren(Object parent) {
+ Widget widget = findItem(parent);
+ if (widget != null) {
+ Item[] items = getChildren(widget);
+ Object[] children = new Object[items.length];
+ for (int i = 0; i < children.length; i++) {
+ Object data = items[i].getData();
+ if (data == null) {
+ data = new Object();
+ }
+ children[i] = data;
+ }
+ return children;
+ }
+ return null;
+ }
+
+
+
+ public synchronized void prune(Object parent, int offset) {
+ Widget widget = findItem(parent);
+ if (widget != null) {
+ Item[] currentChildren = getChildren(widget);
+ if (offset < currentChildren.length) {
+ Object[] pruned = new Object[currentChildren.length - offset];
+ System.arraycopy(currentChildren, offset, pruned, 0, pruned.length);
+ remove(pruned);
+ }
+ }
+ }
+
+
+
+ public synchronized void replace(Object parent, Object[] children, int offset) {
+ Widget widget = findItem(parent);
+ if (widget == null) {
+ add(parent, children);
+ return;
+ }
+ Item[] currentChildren = getChildren(widget);
+ if (offset >= currentChildren.length) {
+ // append
+ add(parent, children);
+ } else {
+ // replace
+ for (int i = 0; i < children.length; i++) {
+ Object child = children[i];
+ if (offset < currentChildren.length) {
+ // replace
+ Item item = currentChildren[offset];
+ Object data = item.getData();
+ if (!child.equals(data)) {
+ associate(child, item);
+ internalRefresh(item, child, true, true);
+ } else {
+ internalRefresh(item, child, false, true);
+ }
+ } else {
+ // add
+ int numLeft = children.length - i;
+ if (numLeft > 1) {
+ Object[] others = new Object[numLeft];
+ System.arraycopy(children, i, others, 0, numLeft);
+ add(parent, others);
+ } else {
+ add(parent, child);
+ }
+ return;
+ }
+ offset++;
+ }
+ }
+ runDeferredUpdates();
+ }
+
+}
+
+
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/DebugViewContentProvider.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/DebugViewContentProvider.java
index 386e13678..acb2a287f 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/DebugViewContentProvider.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/DebugViewContentProvider.java
@@ -19,6 +19,7 @@ import org.eclipse.debug.core.model.IDebugTarget;
import org.eclipse.debug.core.model.IProcess;
import org.eclipse.debug.core.model.IStackFrame;
import org.eclipse.debug.core.model.IThread;
+import org.eclipse.debug.internal.ui.views.RemoteTreeContentManager;
import org.eclipse.ui.IWorkbenchPartSite;
import org.eclipse.ui.model.BaseWorkbenchContentProvider;
import org.eclipse.ui.progress.DeferredTreeContentManager;
@@ -33,7 +34,7 @@ public class DebugViewContentProvider extends BaseWorkbenchContentProvider {
private DeferredTreeContentManager fManager;
public DebugViewContentProvider(LaunchViewer tree, IWorkbenchPartSite site) {
- fManager = new IncrementalDeferredTreeContentManager(this, tree, site);
+ fManager = new RemoteTreeContentManager(this, tree, site);
}
/* (non-Javadoc)
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/LaunchView.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/LaunchView.java
index 92f3f24d9..06fa6c7c1 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/LaunchView.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/LaunchView.java
@@ -51,6 +51,7 @@ import org.eclipse.debug.internal.ui.views.DebugUIViewsMessages;
import org.eclipse.debug.internal.ui.views.DebugViewDecoratingLabelProvider;
import org.eclipse.debug.internal.ui.views.DebugViewInterimLabelProvider;
import org.eclipse.debug.internal.ui.views.DebugViewLabelDecorator;
+import org.eclipse.debug.internal.ui.views.RemoteTreeViewer;
import org.eclipse.debug.ui.IDebugEditorPresentation;
import org.eclipse.debug.ui.IDebugModelPresentation;
import org.eclipse.debug.ui.IDebugUIConstants;
@@ -425,7 +426,7 @@ public class LaunchView extends AbstractDebugEventHandlerView implements ISelect
* @see org.eclipse.ui.IWorkbenchPart#dispose()
*/
public void dispose() {
- LaunchViewer viewer = (LaunchViewer) getViewer();
+ RemoteTreeViewer viewer = (RemoteTreeViewer) getViewer();
if (viewer != null) {
viewer.removeSelectionChangedListener(this);
viewer.cancelJobs();
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/LaunchViewer.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/LaunchViewer.java
index a4c7624dc..8186de4fe 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/LaunchViewer.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/LaunchViewer.java
@@ -11,23 +11,11 @@
package org.eclipse.debug.internal.ui.views.launch;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.model.IThread;
-import org.eclipse.debug.internal.ui.views.DebugUIViewsMessages;
import org.eclipse.debug.internal.ui.views.DebugViewInterimLabelProvider;
+import org.eclipse.debug.internal.ui.views.RemoteTreeViewer;
import org.eclipse.jface.viewers.IColorProvider;
import org.eclipse.jface.viewers.ILabelProvider;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
@@ -35,124 +23,12 @@ import org.eclipse.swt.widgets.Item;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.swt.widgets.Widget;
-import org.eclipse.ui.model.IWorkbenchAdapter;
-import org.eclipse.ui.progress.UIJob;
/**
* The launch viewer displays a tree of launches.
*/
-public class LaunchViewer extends TreeViewer {
- private SelectionJob fSelectionJob = null;
- private ExpansionJob fExpansionJob = null;
-
- class SelectionJob extends UIJob {
-
- private Object element;
- private List parents; // top down
- private Object lock;
-
- /**
- * Constucts a job to select the given element.
- *
- * @param target the element to select
- */
- public SelectionJob(Object target, Object lock) {
- super(DebugUIViewsMessages.getString("LaunchViewer.0")); //$NON-NLS-1$
- element = target;
- parents = new ArrayList();
- this.lock = lock;
- addAllParents(parents, element);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.progress.UIJob#runInUIThread(org.eclipse.core.runtime.IProgressMonitor)
- */
- public IStatus runInUIThread(IProgressMonitor monitor) {
- if (getControl().isDisposed()) {
- return Status.OK_STATUS;
- }
- synchronized (lock) {
- boolean allParentsExpanded = true;
- Iterator iterator = parents.iterator();
- while (iterator.hasNext() && !monitor.isCanceled()) {
- Object parent = iterator.next();
- TreeItem item = (TreeItem) findItem(parent);
- if (item != null) {
- expandToLevel(parent, 1);
- } else {
- allParentsExpanded = false;
- break;
- }
- }
- if (allParentsExpanded) {
- if (findItem(element) != null) {
- setSelection(new StructuredSelection(element), true);
- fSelectionJob = null;
- return Status.OK_STATUS;
- }
- }
- return Status.OK_STATUS;
- }
- }
-
- }
-
- class ExpansionJob extends UIJob {
-
- private Object element;
- private List parents; // top down
- private Object lock;
-
- /**
- * Constucts a job to expand the given element.
- *
- * @param target the element to expand
- */
- public ExpansionJob(Object target, Object lock) {
- super(DebugUIViewsMessages.getString("LaunchViewer.1")); //$NON-NLS-1$
- element = target;
- parents = new ArrayList();
- this.lock = lock;
- addAllParents(parents, element);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.progress.UIJob#runInUIThread(org.eclipse.core.runtime.IProgressMonitor)
- */
- public IStatus runInUIThread(IProgressMonitor monitor) {
- if (getControl().isDisposed()) {
- return Status.OK_STATUS;
- }
- synchronized (lock) {
- boolean allParentsExpanded = true;
- Iterator iterator = parents.iterator();
- while (iterator.hasNext() && !monitor.isCanceled()) {
- Object parent = iterator.next();
- TreeItem item = (TreeItem) findItem(parent);
- if (item != null) {
- expandToLevel(parent, 1);
- } else {
- allParentsExpanded = false;
- break;
- }
- }
- if (allParentsExpanded) {
- TreeItem item = (TreeItem) findItem(element);
- if (item != null) {
- if (isExpandable(element)) {
- expandToLevel(element, 1);
- }
- fExpansionJob = null;
- return Status.OK_STATUS;
- }
- }
- return Status.OK_STATUS;
- }
- }
-
- }
-
- /**
+public class LaunchViewer extends RemoteTreeViewer {
+ /**
* Overridden to fix bug 39709 - duplicate items in launch viewer. The
* workaround is required since debug creation events (which result in
* additions to the tree) are processed asynchrnously with the expanding
@@ -163,42 +39,10 @@ public class LaunchViewer extends TreeViewer {
public synchronized void add(Object parentElement, Object childElement) {
if (findItem(childElement) == null) {
super.add(parentElement, childElement);
- runDeferredUpdates();
}
}
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.AbstractTreeViewer#add(java.lang.Object, java.lang.Object[])
- */
- public synchronized void add(Object parentElement, Object[] childElements) {
- super.add(parentElement, childElements);
- runDeferredUpdates();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.AbstractTreeViewer#remove(java.lang.Object)
- */
- public synchronized void remove(Object element) {
- super.remove(element);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.AbstractTreeViewer#remove(java.lang.Object[])
- */
- public synchronized void remove(Object[] elements) {
- super.remove(elements);
- }
- private void runDeferredUpdates() {
- if (fExpansionJob != null) {
- fExpansionJob.schedule();
- }
- if (fSelectionJob != null) {
- fSelectionJob.schedule();
- }
- }
-
- public LaunchViewer(Composite parent) {
+ public LaunchViewer(Composite parent) {
super(new Tree(parent, SWT.MULTI));
setUseHashlookup(true);
}
@@ -266,163 +110,4 @@ public class LaunchViewer extends TreeViewer {
getControl().setRedraw(true);
}
- /**
- * If the element is in the tree, reveal and select if. Otherwise, reveal
- * and select the item when it is added. Calling this method overrides
- * any previous deferred selection.
- *
- * @param element element to be selected if present or when added to the tree
- */
- public synchronized void setDeferredSelection(Object element) {
- if (findItem(element) == null) {
- if (fSelectionJob != null) {
- fSelectionJob.cancel();
- }
- fSelectionJob = new SelectionJob(element, this);
- fSelectionJob.schedule();
- } else {
- setSelection(new StructuredSelection(element), true);
- }
- }
-
- public synchronized void deferExpansion(Object element) {
- TreeItem treeItem = (TreeItem) findItem(element);
- if (treeItem == null) {
- if (fExpansionJob != null) {
- fExpansionJob.cancel();
- }
- fExpansionJob = new ExpansionJob(element, this);
- fExpansionJob.schedule();
- } else {
- if (!getExpanded(treeItem)) {
- expandToLevel(element, 1);
- }
- }
- }
-
- private void addAllParents(List list, Object element) {
- if (element instanceof IAdaptable) {
- IAdaptable adaptable = (IAdaptable) element;
- IWorkbenchAdapter adapter = (IWorkbenchAdapter) adaptable.getAdapter(IWorkbenchAdapter.class);
- if (adapter != null) {
- Object parent = adapter.getParent(element);
- if (parent != null) {
- list.add(0, parent);
- if (!(parent instanceof ILaunch))
- addAllParents(list, parent);
- }
- }
- }
- }
-
- protected void cancelJobs() {
- cancel(fSelectionJob);
- cancel(fExpansionJob);
- }
-
- private void cancel(Job job) {
- if (job != null) {
- job.cancel();
- }
- }
-
- /**
- * Replaces the given parent's current children with the specified children
- * starting at the specified offset in the parent's current children.
- *
- * @param parent parent of children to replace
- * @param children replacement children
- * @param offset the offset at which to start replacing the children
- */
- protected synchronized void replace(Object parent, Object[] children, int offset) {
- Widget widget = findItem(parent);
- if (widget == null) {
- add(parent, children);
- return;
- }
- Item[] currentChildren = getChildren(widget);
- if (offset >= currentChildren.length) {
- // append
- add(parent, children);
- } else {
- // replace
- for (int i = 0; i < children.length; i++) {
- Object child = children[i];
- if (offset < currentChildren.length) {
- // replace
- Item item = currentChildren[offset];
- Object data = item.getData();
- if (!child.equals(data)) {
- associate(child, item);
- internalRefresh(item, child, true, true);
- } else {
- internalRefresh(item, child, false, true);
- }
- } else {
- // add
- int numLeft = children.length - i;
- if (numLeft > 1) {
- Object[] others = new Object[numLeft];
- System.arraycopy(children, i, others, 0, numLeft);
- add(parent, others);
- } else {
- add(parent, child);
- }
- return;
- }
- offset++;
- }
- }
- runDeferredUpdates();
- }
-
- /**
- * Prunes the given parent's children at the given offset. All children
- * at and after the given offset are removed from the tree.
- *
- * @param parent parent to prune children from
- * @param offset offset of first child to prune
- */
- protected synchronized void prune(Object parent, int offset) {
- Widget widget = findItem(parent);
- if (widget != null) {
- Item[] currentChildren = getChildren(widget);
- if (offset < currentChildren.length) {
- Object[] pruned = new Object[currentChildren.length - offset];
- System.arraycopy(currentChildren, offset, pruned, 0, pruned.length);
- remove(pruned);
- }
- }
- }
-
- /**
- * Returns the current children of the given parent element.
- *
- * @param parent parent
- * @return the current children of the given parent element, possibly <code>null</code>
- */
- public Object[] getCurrentChildren(Object parent) {
- Widget widget = findItem(parent);
- if (widget != null) {
- Item[] items = getChildren(widget);
- Object[] children = new Object[items.length];
- for (int i = 0; i < children.length; i++) {
- Object data = items[i].getData();
- if (data == null) {
- data = new Object();
- }
- children[i] = data;
- }
- return children;
- }
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.StructuredViewer#filter(java.lang.Object[])
- */
- public Object[] filter(Object[] elements) {
- return super.filter(elements);
- }
-
} \ No newline at end of file

Back to the top