summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPawel Piech2013-01-18 12:04:03 (EST)
committer Pawel Piech2013-02-27 13:36:26 (EST)
commiteca4380528c0d428b566d5f5e58e7026e18489a1 (patch)
tree1656e15725bd32830de7dfd27a65559dbfb0e078
parent629fdb37570540d6c8be0f734770177e30c204e2 (diff)
downloadeclipse.platform.debug-eca4380528c0d428b566d5f5e58e7026e18489a1.zip
eclipse.platform.debug-eca4380528c0d428b566d5f5e58e7026e18489a1.tar.gz
eclipse.platform.debug-eca4380528c0d428b566d5f5e58e7026e18489a1.tar.bz2
Bug 372181 - Working set support for Expressions View
Added using mementos to select working sets.
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/expression/ExpressionElementCompareRequest.java46
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/expression/ExpressionElementMementoRequest.java89
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/expression/ExpressionMementoService.java116
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/expression/ExpressionView.java142
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/expression/IElementCompareRequestor.java18
5 files changed, 402 insertions, 9 deletions
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/expression/ExpressionElementCompareRequest.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/expression/ExpressionElementCompareRequest.java
new file mode 100644
index 0000000..09a6996
--- /dev/null
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/expression/ExpressionElementCompareRequest.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2011 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
+ * Wind River Systems - Fix for viewer state save/restore [188704]
+ *******************************************************************************/
+package org.eclipse.debug.internal.ui.views.expression;
+
+import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementCompareRequest;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
+import org.eclipse.ui.IMemento;
+
+/**
+ * @since 3.3
+ */
+public class ExpressionElementCompareRequest extends ExpressionElementMementoRequest implements IElementCompareRequest {
+
+ private boolean fEqual;
+
+ public ExpressionElementCompareRequest(ExpressionView view, IPresentationContext context, Object element, IMemento memento, String[] workingSets) {
+ super(view, context, element, memento, workingSets);
+ }
+ public void setEqual(boolean equal) {
+ fEqual = equal;
+ }
+
+ public boolean isEqual() {
+ return fEqual;
+ }
+
+ protected void performFinished() {
+ fView.compareRequestFinished(ExpressionElementCompareRequest.this);
+ }
+
+ public String toString() {
+ StringBuffer buf = new StringBuffer();
+ buf.append("IElementCompareRequest: "); //$NON-NLS-1$
+ buf.append(getElement());
+ return buf.toString();
+ }
+}
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/expression/ExpressionElementMementoRequest.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/expression/ExpressionElementMementoRequest.java
new file mode 100644
index 0000000..6462771
--- /dev/null
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/expression/ExpressionElementMementoRequest.java
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2011 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
+ * Wind River Systems - Fix for viewer state save/restore [188704]
+ *******************************************************************************/
+package org.eclipse.debug.internal.ui.views.expression;
+
+import org.eclipse.debug.internal.core.commands.Request;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementMementoRequest;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
+import org.eclipse.jface.viewers.TreePath;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IMemento;
+
+/**
+ * @since 3.3
+ */
+public class ExpressionElementMementoRequest extends Request implements IElementMementoRequest {
+
+ final ExpressionView fView;
+ final IPresentationContext fContext;
+ final Object fElement;
+ IMemento fMemento;
+ final String[] fWorkingSets;
+
+ public ExpressionElementMementoRequest(ExpressionView view, IPresentationContext context, Object element, IMemento memento, String[] workingSets) {
+ fView = view;
+ fContext = context;
+ fElement = element;
+ fWorkingSets = workingSets;
+ fMemento = memento;
+ }
+
+ public Object getElement() {
+ return fElement;
+ }
+
+ public TreePath getElementPath() {
+ return TreePath.EMPTY;
+ }
+
+ public IMemento getMemento() {
+ return fMemento;
+ }
+
+ public Object getViewerInput() {
+ return fElement;
+ }
+
+ public void done() {
+ Display display = fView.getSite().getShell().getDisplay();
+ if (display == null || display.isDisposed()) return;
+
+ if (display.getThread() != Thread.currentThread()) {
+ display.asyncExec(new Runnable() {
+ public void run() {
+ performFinished();
+ }
+ });
+ } else {
+ performFinished();
+ }
+ }
+
+ protected void performFinished() {
+ fView.mementoRequestFinished(this);
+ }
+
+ public String toString() {
+ StringBuffer buf = new StringBuffer();
+ buf.append("IElementCompareRequest: "); //$NON-NLS-1$
+ buf.append(getElement());
+ return buf.toString();
+ }
+
+ public IPresentationContext getPresentationContext() {
+ return fContext;
+ }
+
+ public String[] getWorkingSets() {
+ return fWorkingSets;
+ }
+}
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/expression/ExpressionMementoService.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/expression/ExpressionMementoService.java
new file mode 100644
index 0000000..dec5c1a
--- /dev/null
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/expression/ExpressionMementoService.java
@@ -0,0 +1,116 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2011 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
+ * Wind River - Pawel Piech - NPE when closing the Variables view (Bug 213719)
+ *******************************************************************************/
+package org.eclipse.debug.internal.ui.views.expression;
+
+import org.eclipse.debug.internal.ui.viewers.model.ViewerAdapterService;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementCompareRequest;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementMementoProvider;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.ITreeModelViewer;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerInputProvider;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerInputUpdate;
+
+/**
+ */
+public class ExpressionMementoService {
+
+ /**
+ * An input object which will yield a null input element.
+ *
+ * @since 3.6
+ */
+ public final static Object NULL_INPUT = new IViewerInputProvider() {
+ public void update(IViewerInputUpdate update) {
+ update.setInputElement(null);
+ update.done();
+ }
+ };
+
+ // previous update request, cancelled when a new request comes in
+ private ExpressionElementCompareRequest[] fPendingRequests = null;
+
+ private int fOutstandingRequestCount = 0;
+
+ private IElementCompareRequestor fRequestor = null;
+
+ private ITreeModelViewer fViewer;
+
+ /**
+ * Constructs a viewer input service for the given requester and presentation context.
+ *
+ * @param viewer for which inputs are required
+ * @param requestor client requesting viewer inputs
+ */
+ public ExpressionMementoService(ITreeModelViewer viewer, IElementCompareRequestor requestor) {
+ fRequestor = requestor;
+ fViewer = viewer;
+ }
+
+ /**
+ * Resolves a viewer input derived from the given source object.
+ * Reports the result to the given this service's requester. A requester may be called back
+ * in the same or thread, or asynchronously in a different thread. Cancels any previous
+ * incomplete request from this service's requester.
+ *
+ * @param source source from which to derive a viewer input
+ */
+ public void compareInputMementos(Object source, IElementCompareRequest[] requests) {
+ IElementMementoProvider provdier = ViewerAdapterService.getMementoProvider(source);
+ synchronized (this) {
+ // cancel any pending update
+ //cancelPendingUpdates();
+ fOutstandingRequestCount = requests.length;
+ fPendingRequests = new ExpressionElementCompareRequest[requests.length];
+ for (int i = 0; i < requests.length; i++) {
+ fPendingRequests[i] = new ExpressionElementCompareRequest(
+ fViewer.getPresentationContext(), requests[i].getElement(), requests[i].getMemento(), null)
+ {
+ public void done() {
+ if (!isCanceled()) {
+ synchronized(ExpressionMementoService.this) {
+ fOutstandingRequestCount--;
+ if (fOutstandingRequestCount == 0) {
+ fRequestor.elementCompareComplete(fPendingRequests);
+ fPendingRequests = null;
+ }
+ }
+ }
+ }
+
+ };
+ }
+ }
+ if (provdier == null) {
+ for (int i = 0; i < requests.length; i++) {
+ fPendingRequests[i].setEqual(false);
+ fPendingRequests[i].done();
+ }
+ } else {
+ provdier.compareElements(fPendingRequests);
+ }
+ }
+
+ private synchronized void cancelPendingUpdates() {
+ if (fPendingRequests != null) {
+ for (int i = 0; i < fPendingRequests.length; i++) {
+ fPendingRequests[i].cancel();
+ }
+ }
+ fPendingRequests = null;
+ }
+
+ /**
+ * Disposes this viewer input service, canceling any pending jobs.
+ */
+ public synchronized void dispose() {
+ cancelPendingUpdates();
+ }
+}
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/expression/ExpressionView.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/expression/ExpressionView.java
index 8a9cbc0..e6228b0 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/expression/ExpressionView.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/expression/ExpressionView.java
@@ -14,7 +14,12 @@ package org.eclipse.debug.internal.ui.views.expression;
import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Map;
+import java.util.Set;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IStatus;
@@ -29,6 +34,10 @@ import org.eclipse.debug.internal.ui.actions.expressions.EditWatchExpressinInPla
import org.eclipse.debug.internal.ui.actions.expressions.PasteWatchExpressionsAction;
import org.eclipse.debug.internal.ui.actions.variables.ChangeVariableValueAction;
import org.eclipse.debug.internal.ui.preferences.IDebugPreferenceConstants;
+import org.eclipse.debug.internal.ui.viewers.model.ViewerAdapterService;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementCompareRequest;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementMementoProvider;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementMementoRequest;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
import org.eclipse.debug.internal.ui.viewers.model.provisional.ITreeModelViewer;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerInputUpdate;
@@ -46,6 +55,7 @@ import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.util.LocalSelectionTransfer;
import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
@@ -60,7 +70,9 @@ import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.IWorkbenchCommandConstants;
import org.eclipse.ui.IWorkingSet;
+import org.eclipse.ui.IWorkingSetManager;
import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.XMLMemento;
import org.eclipse.ui.actions.ActionFactory;
/**
@@ -75,12 +87,21 @@ public class ExpressionView extends VariablesView {
*/
private static final String PREF_ELEMENT_WORKINGSET = DebugUIPlugin.getUniqueIdentifier() + ".workingSet"; //$NON-NLS-1$
+ private static final IWorkingSet[] EMPTY_WORKING_SETS = new IWorkingSet[0];
private PasteWatchExpressionsAction fPasteAction;
private EditWatchExpressinInPlaceAction fEditInPlaceAction;
private IWorkingSet[] fWorkingSets;
+ private boolean fAutoSelectWorkingSets = true;
+
+ private Map fWorkingSetMementos = new LinkedHashMap();
+
+ private Set fPendingCompareRequests;
+
+ private ExpressionElementMementoRequest fPendingMementoRequest;
+
/* (non-Javadoc)
* @see org.eclipse.debug.internal.ui.views.variables.VariablesView#getHelpContextId()
*/
@@ -132,6 +153,10 @@ public class ExpressionView extends VariablesView {
super.contextActivated(new StructuredSelection(DebugPlugin.getDefault().getExpressionManager()));
} else {
super.contextActivated(selection);
+ if (fAutoSelectWorkingSets) {
+ Object element = ((IStructuredSelection)selection).getFirstElement();
+ compareElementMementos(element);
+ }
}
if (isAvailable() && isVisible()) {
updateAction("ContentAssist"); //$NON-NLS-1$
@@ -151,6 +176,18 @@ public class ExpressionView extends VariablesView {
updateAction(FIND_ACTION);
}
+ public void elementCompareComplete(String[] workingSetNames) {
+ IWorkingSetManager mgr = PlatformUI.getWorkbench().getWorkingSetManager();
+ List workingSetList = new ArrayList();
+ for (int j = 0; j < workingSetNames.length; j++) {
+ IWorkingSet workingSet = mgr.getWorkingSet(workingSetNames[j]);
+ if (workingSet != null) {
+ workingSetList.add(workingSet);
+ }
+ }
+ doApplyWorkingSets((IWorkingSet[])workingSetList.toArray(new IWorkingSet[workingSetList.size()]));
+ }
+
/* (non-Javadoc)
* @see org.eclipse.debug.internal.ui.views.variables.VariablesView#getDetailPanePreferenceKey()
*/
@@ -193,6 +230,8 @@ public class ExpressionView extends VariablesView {
public void dispose() {
fEditInPlaceAction.dispose();
+ cancelPendingCompareRequests();
+ if (fPendingMementoRequest != null) fPendingMementoRequest.cancel();
super.dispose();
}
@@ -276,16 +315,20 @@ public class ExpressionView extends VariablesView {
public Viewer createViewer(Composite parent) {
TreeModelViewer viewer = (TreeModelViewer)super.createViewer(parent);
- List list = new ArrayList();
IMemento[] workingsetMementos = getMemento().getChildren(PREF_ELEMENT_WORKINGSET);
- for (int j=0; j<workingsetMementos.length; j++) {
- IMemento workingSetMemento = workingsetMementos[j];
- String workingSetName = workingSetMemento.getID();
- IWorkingSet workingSet = PlatformUI.getWorkbench().getWorkingSetManager().getWorkingSet(workingSetName);
- if (workingSet != null)
- list.add(workingSet);
+ if (workingsetMementos != null) {
+ List list = new ArrayList();
+ for (int j=0; j<workingsetMementos.length; j++) {
+ IMemento workingSetMemento = workingsetMementos[j];
+ String workingSetName = workingSetMemento.getID();
+ IWorkingSet workingSet = PlatformUI.getWorkbench().getWorkingSetManager().getWorkingSet(workingSetName);
+ if (workingSet != null)
+ list.add(workingSet);
+ }
+ fWorkingSets = (IWorkingSet[]) list.toArray(new IWorkingSet[list.size()]);
+ } else {
+ fWorkingSets = EMPTY_WORKING_SETS;
}
- fWorkingSets = (IWorkingSet[]) list.toArray(new IWorkingSet[list.size()]);
getWorkingSetFilter(viewer).setSelectedWorkingSets(fWorkingSets);
updateWorkingSetsProperty(viewer.getPresentationContext());
@@ -302,11 +345,52 @@ public class ExpressionView extends VariablesView {
}
public void applyWorkingSets(IWorkingSet[] selectedWorkingSets) {
+ doApplyWorkingSets(selectedWorkingSets);
+ saveWorkingSetsMemento();
+ }
+
+ private void doApplyWorkingSets(IWorkingSet[] selectedWorkingSets) {
fWorkingSets = selectedWorkingSets;
TreeModelViewer viewer = (TreeModelViewer)getViewer();
getWorkingSetFilter(viewer).setSelectedWorkingSets(fWorkingSets);
updateWorkingSetsProperty(viewer.getPresentationContext());
- getViewer().refresh();
+ getViewer().refresh();
+ }
+
+ private void saveWorkingSetsMemento() {
+ if (fPendingMementoRequest != null) {
+ fPendingMementoRequest.cancel();
+ }
+ Object element = getDebugContextElement();
+ IElementMementoProvider provider = ViewerAdapterService.getMementoProvider(element);
+ if (provider == null) return;
+
+ XMLMemento expressionMemento = XMLMemento.createWriteRoot("EXPRESSION_WORKING_SETS_MEMENTO"); //$NON-NLS-1$
+ fPendingMementoRequest = new ExpressionElementMementoRequest(
+ this, getPresentationContext(), getDebugContextElement(), expressionMemento, getWorkingSetNames());
+ provider.encodeElements(new IElementMementoRequest[] { fPendingMementoRequest });
+ }
+
+ void mementoRequestFinished(ExpressionElementMementoRequest request) {
+ if (!request.isCanceled()) {
+ fWorkingSetMementos.put(request.getMemento(), request.getWorkingSets());
+ }
+ }
+
+ private String[] getWorkingSetNames() {
+ String[] names = new String[fWorkingSets.length];
+ for (int i = 0; i < fWorkingSets.length; i++) {
+ names[i] = fWorkingSets[i].getName();
+ }
+ return names;
+ }
+
+ private Object getDebugContextElement() {
+ ISelection selection = getDebugContext();
+ if (selection == null || selection.isEmpty() || !(selection instanceof IStructuredSelection)) {
+ return DebugPlugin.getDefault().getExpressionManager();
+ }
+ return ((IStructuredSelection)selection).getFirstElement();
}
private void updateWorkingSetsProperty(IPresentationContext presentationContext) {
@@ -339,4 +423,44 @@ public class ExpressionView extends VariablesView {
return workingSetFilter;
}
+ private void compareElementMementos(Object source) {
+ IElementMementoProvider provdier = ViewerAdapterService.getMementoProvider(source);
+ if (provdier != null) {
+ Set requests = new HashSet(fWorkingSetMementos.size() * 4/3);
+ for (Iterator itr = fWorkingSetMementos.entrySet().iterator(); itr.hasNext();) {
+ Map.Entry entry = (Map.Entry)itr.next();
+ requests.add( new ExpressionElementCompareRequest(
+ this, getPresentationContext(), source, (IMemento)entry.getKey(), (String[])entry.getValue()) );
+ }
+
+ // cancel any pending update
+ cancelPendingCompareRequests();
+ fPendingCompareRequests = requests;
+ provdier.compareElements((IElementCompareRequest[])
+ fPendingCompareRequests.toArray(new IElementCompareRequest[fPendingCompareRequests.size()]) );
+ } else {
+ doApplyWorkingSets(EMPTY_WORKING_SETS);
+ }
+ }
+
+ void compareRequestFinished(final ExpressionElementCompareRequest request) {
+ if (fPendingCompareRequests != null && fPendingCompareRequests.remove(request)) {
+ if (!request.isCanceled() && request.isEqual()) {
+ elementCompareComplete(request.getWorkingSets());
+ cancelPendingCompareRequests();
+ } else if (fPendingCompareRequests.isEmpty()) {
+ elementCompareComplete(new String[0]);
+ fPendingCompareRequests = null;
+ }
+ }
+ }
+
+ private void cancelPendingCompareRequests() {
+ if (fPendingCompareRequests == null) return;
+ for (Iterator itr = fPendingCompareRequests.iterator(); itr.hasNext();) {
+ ((IElementCompareRequest)itr.next()).cancel();
+ }
+ fPendingCompareRequests = null;
+ }
+
}
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/expression/IElementCompareRequestor.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/expression/IElementCompareRequestor.java
new file mode 100644
index 0000000..1939b43
--- /dev/null
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/expression/IElementCompareRequestor.java
@@ -0,0 +1,18 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2008 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.views.expression;
+
+
+/**
+ */
+public interface IElementCompareRequestor {
+ public void elementCompareComplete(final ExpressionElementCompareRequest[] requests);
+}