diff options
Diffstat (limited to 'org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/LaunchViewer.java')
-rw-r--r-- | org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/LaunchViewer.java | 323 |
1 files changed, 4 insertions, 319 deletions
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 |