diff options
author | Pawel Piech | 2013-02-06 21:00:54 +0000 |
---|---|---|
committer | Pawel Piech | 2013-02-27 18:36:26 +0000 |
commit | faf798e1240cdf437166b53f7dd3fcb5cc7e84ef (patch) | |
tree | df6f10ad2bd1b2f1c8506425de44ec95339218be /org.eclipse.debug.ui | |
parent | eca4380528c0d428b566d5f5e58e7026e18489a1 (diff) | |
download | eclipse.platform.debug-faf798e1240cdf437166b53f7dd3fcb5cc7e84ef.tar.gz eclipse.platform.debug-faf798e1240cdf437166b53f7dd3fcb5cc7e84ef.tar.xz eclipse.platform.debug-faf798e1240cdf437166b53f7dd3fcb5cc7e84ef.zip |
Bug 372181 - Working set support for Expressions View
- Added serializing of selected expression sets based on stack frame.
Diffstat (limited to 'org.eclipse.debug.ui')
6 files changed, 203 insertions, 158 deletions
diff --git a/org.eclipse.debug.ui/plugin.properties b/org.eclipse.debug.ui/plugin.properties index 6f83288f9..ce197ff4e 100644 --- a/org.eclipse.debug.ui/plugin.properties +++ b/org.eclipse.debug.ui/plugin.properties @@ -399,7 +399,9 @@ debug.ui.component.label = Platform Debug UI debug.core.component.label = Platform Debug Core # Expression working set -ExpressionWorkingSet.name=Expression -ExpressionWorkingSet.description=A working set that contains expressions -ExpressionWorkingSet.manageAction.label=&Working Sets... -ExpressionWorkingSet.manageAction.tooltip=Manage Working Sets
\ No newline at end of file +expressionWorkingSet.name=Expression +expressionWorkingSet.description=A working set that contains expressions +expressionWorkingSet.manageAction.label=&Working Sets... +expressionWorkingSet.manageAction.tooltip=Manage Working Sets +expressionWorkingSet.autoSelectAction.label=&Auto Select Working Sets +expressionWorkingSet.autoSelectAction.tooltip=Automatically select Working Sets based on view input
\ No newline at end of file diff --git a/org.eclipse.debug.ui/plugin.xml b/org.eclipse.debug.ui/plugin.xml index 15a24ea3b..7ba2988ae 100644 --- a/org.eclipse.debug.ui/plugin.xml +++ b/org.eclipse.debug.ui/plugin.xml @@ -3169,8 +3169,8 @@ M4 = Platform-specific fourth key <extension point="org.eclipse.ui.workingSets"> <workingSet id="org.eclipse.debug.ui.expressionWorkingSet" - name="%ExpressionWorkingSet.name" - description="%ExpressionWorkingSet.description" + name="%expressionWorkingSet.name" + description="%expressionWorkingSet.description" icon="icons/full/obj16/expression_workingset.gif" pageClass="org.eclipse.debug.internal.ui.views.expression.ExpressionWorkingSetPage" elementAdapterClass="org.eclipse.debug.internal.ui.views.expression.ExpressionWorkingSetElementAdapter" @@ -3183,13 +3183,21 @@ M4 = Platform-specific fourth key targetID="org.eclipse.debug.ui.ExpressionView" id="org.eclipse.debug.ui.expressionview.toolbar.workingset"> <action + class="org.eclipse.debug.internal.ui.actions.expressions.AutoSelectWorkingSetsAction" + helpContextId="expression_auto_select_working_sets_action_context" + id="org.eclipse.debug.ui.expressionView.toolbar.autoSelectWorkingSets" + label="%expressionWorkingSet.autoSelectAction.label" + menubarPath="additions" + style="toggle" + tooltip="%expressionWorkingSet.autoSelectAction.tooltip"/> + <action class="org.eclipse.debug.internal.ui.actions.expressions.ExpressionWorkingSetsAction" helpContextId="expression_working_sets_action_context" id="org.eclipse.debug.ui.expressionView.toolbar.workingSets" - label="%ExpressionWorkingSet.manageAction.label" + label="%expressionWorkingSet.manageAction.label" menubarPath="additions" style="push" - tooltip="%ExpressionWorkingSet.manageAction.tooltip"/> + tooltip="%expressionWorkingSet.manageAction.tooltip"/> </viewContribution> </extension> diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/expressions/AutoSelectWorkingSetsAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/expressions/AutoSelectWorkingSetsAction.java new file mode 100644 index 000000000..393dad206 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/expressions/AutoSelectWorkingSetsAction.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2000, 2007 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.actions.expressions; + + +import org.eclipse.debug.internal.ui.views.expression.ExpressionView; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.IViewActionDelegate; +import org.eclipse.ui.IViewPart; + +/** + * Open a watch expression dialog and add the created watch expression to the + * expression view. + */ +public class AutoSelectWorkingSetsAction extends WatchExpressionAction implements IViewActionDelegate { + + IViewPart fView; + + /** + * @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart) + */ + public void init(IViewPart view) { + fView = view; + super.init(view); + } + + /** + * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) + */ + public void run(IAction action) { + if (fView instanceof ExpressionView) { + ((ExpressionView)fView).setAutoSelectWoringSets(action.isChecked()); + } + } + + /** + * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection) + */ + public void selectionChanged(IAction action, ISelection selection) { + if (fView instanceof ExpressionView) { + boolean autoSelect = ((ExpressionView)fView).isAutoSelectWorkingSets(); + if (!action.isChecked() == autoSelect) { + action.setChecked(autoSelect); + } + } + } + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/model/elements/ExpressionManagerContentProvider.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/model/elements/ExpressionManagerContentProvider.java index 6d9fa0336..72ab37aab 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/model/elements/ExpressionManagerContentProvider.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/model/elements/ExpressionManagerContentProvider.java @@ -117,7 +117,6 @@ public class ExpressionManagerContentProvider extends ElementContentProvider { String expressionText = DefaultLabelProvider.encodeEsacpedChars((String)value); IWatchExpression newExpression= DebugPlugin.getDefault().getExpressionManager().newWatchExpression(expressionText); - DebugPlugin.getDefault().getExpressionManager().addExpression(newExpression); newExpression.setExpressionContext(getContext()); //if any working sets are applied to this view, @@ -138,6 +137,10 @@ public class ExpressionManagerContentProvider extends ElementContentProvider { workingSet.setElements(newElements); } } + // Add the new expression to the expression manager only after + // working sets are updated. Otherwise, the viewer may filter + // out the new expression. + DebugPlugin.getDefault().getExpressionManager().addExpression(newExpression); } } 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 deleted file mode 100644 index dec5c1af7..000000000 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/expression/ExpressionMementoService.java +++ /dev/null @@ -1,116 +0,0 @@ -/******************************************************************************* - * 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 e6228b0c5..4185c798e 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 @@ -13,6 +13,11 @@ package org.eclipse.debug.internal.ui.views.expression; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; @@ -72,6 +77,7 @@ import org.eclipse.ui.IWorkbenchCommandConstants; import org.eclipse.ui.IWorkingSet; import org.eclipse.ui.IWorkingSetManager; import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.WorkbenchException; import org.eclipse.ui.XMLMemento; import org.eclipse.ui.actions.ActionFactory; @@ -80,13 +86,16 @@ import org.eclipse.ui.actions.ActionFactory; * pane. */ public class ExpressionView extends VariablesView { - - /** - * the preference name for the view part of the sash form - * @since 3.9 - */ + + // The preference name for autoselect working sets toggle + private static final String PREF_WORKINGSETS_AUTOSELECT = DebugUIPlugin.getUniqueIdentifier() + ".workingSetAutoselect"; //$NON-NLS-1$ + + // The preference name for saving fWorkingSets private static final String PREF_ELEMENT_WORKINGSET = DebugUIPlugin.getUniqueIdentifier() + ".workingSet"; //$NON-NLS-1$ + // The preference name for saving fWorkingSetMementos. + private static final String PREF_ELEMENT_WORKINGSET_MEMENTOS = DebugUIPlugin.getUniqueIdentifier() + ".workingSetMementos"; //$NON-NLS-1$ + private static final IWorkingSet[] EMPTY_WORKING_SETS = new IWorkingSet[0]; private PasteWatchExpressionsAction fPasteAction; @@ -94,7 +103,7 @@ public class ExpressionView extends VariablesView { private IWorkingSet[] fWorkingSets; - private boolean fAutoSelectWorkingSets = true; + private boolean fAutoSelectnWorkingSets = true; private Map fWorkingSetMementos = new LinkedHashMap(); @@ -153,7 +162,7 @@ public class ExpressionView extends VariablesView { super.contextActivated(new StructuredSelection(DebugPlugin.getDefault().getExpressionManager())); } else { super.contextActivated(selection); - if (fAutoSelectWorkingSets) { + if (fAutoSelectnWorkingSets) { Object element = ((IStructuredSelection)selection).getFirstElement(); compareElementMementos(element); } @@ -176,6 +185,16 @@ public class ExpressionView extends VariablesView { updateAction(FIND_ACTION); } + public void setAutoSelectWoringSets(boolean autoSelect) { + if (fAutoSelectnWorkingSets != autoSelect) { + fAutoSelectnWorkingSets = autoSelect; + } + } + + public boolean isAutoSelectWorkingSets() { + return fAutoSelectnWorkingSets; + } + public void elementCompareComplete(String[] workingSetNames) { IWorkingSetManager mgr = PlatformUI.getWorkbench().getWorkingSetManager(); List workingSetList = new ArrayList(); @@ -314,39 +333,109 @@ public class ExpressionView extends VariablesView { public Viewer createViewer(Composite parent) { TreeModelViewer viewer = (TreeModelViewer)super.createViewer(parent); - - IMemento[] workingsetMementos = getMemento().getChildren(PREF_ELEMENT_WORKINGSET); - if (workingsetMementos != null) { + + initWorkingSets(); + initWorkingSetMementos(); + getWorkingSetFilter(viewer).setSelectedWorkingSets(fWorkingSets); + updateWorkingSetsProperty(viewer.getPresentationContext()); + + return viewer; + } + + private String[] loadWorkingSetNames(IMemento memento) { + IMemento[] workingsets = memento.getChildren(PREF_ELEMENT_WORKINGSET); + if (workingsets != 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); + for (int j=0; j<workingsets.length; j++) { + list.add(workingsets[j].getID()); + } + return (String[])list.toArray(new String[list.size()]); + } + return new String[0]; + } + + private void initWorkingSets() { + String[] workingSetNames = loadWorkingSetNames(getMemento()); + List list = new ArrayList(); + for (int j = 0; j < workingSetNames.length; j++) { + IWorkingSet workingsetObject = PlatformUI.getWorkbench().getWorkingSetManager().getWorkingSet(workingSetNames[j]); + if (workingsetObject != null) { + list.add(workingsetObject); } - fWorkingSets = (IWorkingSet[]) list.toArray(new IWorkingSet[list.size()]); - } else { - fWorkingSets = EMPTY_WORKING_SETS; } - getWorkingSetFilter(viewer).setSelectedWorkingSets(fWorkingSets); - updateWorkingSetsProperty(viewer.getPresentationContext()); + fWorkingSets = (IWorkingSet[]) list.toArray(new IWorkingSet[list.size()]); + } - return viewer; + private void initWorkingSetMementos() { + IMemento[] workingsetMementos = getMemento().getChildren(PREF_ELEMENT_WORKINGSET_MEMENTOS); + if (workingsetMementos != null) { + for (int j=0; j<workingsetMementos.length; j++) { + String[] workingSetNames = loadWorkingSetNames(workingsetMementos[j]); + String string = workingsetMementos[j].getID(); + if(string.length() > 0 && workingSetNames != null) { + ByteArrayInputStream bin = new ByteArrayInputStream(string.getBytes()); + InputStreamReader reader = new InputStreamReader(bin); + try { + XMLMemento workingSetsKey = XMLMemento.createReadRoot(reader); + fWorkingSetMementos.put(workingSetsKey, workingSetNames); + } catch (WorkbenchException e) { + } finally { + try { + reader.close(); + bin.close(); + } catch (IOException e){} + } + } + } + } } - + public void saveViewerState(IMemento memento) { super.saveViewerState(memento); - - - for (int i=0; i<fWorkingSets.length; i++) { - memento.createChild(PREF_ELEMENT_WORKINGSET, fWorkingSets[i].getName()); - } + + memento.putBoolean(PREF_WORKINGSETS_AUTOSELECT, fAutoSelectnWorkingSets); + if (!fAutoSelectnWorkingSets) { + saveWorkingSets(memento, getWorkingSetNames()); + } + saveWorkingSetMementos(memento); } + private void saveWorkingSets(IMemento memento, String[] workingSetNames) { + for (int i=0; i<workingSetNames.length; i++) { + memento.createChild(PREF_ELEMENT_WORKINGSET, workingSetNames[i]); + } + } + + private void saveWorkingSetMementos(IMemento memento) { + for (Iterator itr = fWorkingSetMementos.entrySet().iterator(); itr.hasNext();) { + Map.Entry entry = (Map.Entry)itr.next(); + String keyMementoString = getMenentoString((XMLMemento)entry.getKey()); + IMemento workingSetsForElementMemento = memento.createChild(PREF_ELEMENT_WORKINGSET_MEMENTOS, keyMementoString); + saveWorkingSets(workingSetsForElementMemento, (String[])entry.getValue()); + } + } + + private String getMenentoString(XMLMemento memento) { + ByteArrayOutputStream bout = new ByteArrayOutputStream(); + OutputStreamWriter writer = new OutputStreamWriter(bout); + + try { + memento.save(writer); + return bout.toString(); + } catch (IOException e) { + } finally { + try { + writer.close(); + bout.close(); + } catch (IOException e) { + } + } + return null; + } + public void applyWorkingSets(IWorkingSet[] selectedWorkingSets) { doApplyWorkingSets(selectedWorkingSets); - saveWorkingSetsMemento(); + saveWorkingSetsForInput(); } private void doApplyWorkingSets(IWorkingSet[] selectedWorkingSets) { @@ -357,7 +446,7 @@ public class ExpressionView extends VariablesView { getViewer().refresh(); } - private void saveWorkingSetsMemento() { + private void saveWorkingSetsForInput() { if (fPendingMementoRequest != null) { fPendingMementoRequest.cancel(); } @@ -435,9 +524,11 @@ public class ExpressionView extends VariablesView { // cancel any pending update cancelPendingCompareRequests(); - fPendingCompareRequests = requests; - provdier.compareElements((IElementCompareRequest[]) - fPendingCompareRequests.toArray(new IElementCompareRequest[fPendingCompareRequests.size()]) ); + if (!requests.isEmpty()) { + fPendingCompareRequests = requests; + provdier.compareElements((IElementCompareRequest[]) + fPendingCompareRequests.toArray(new IElementCompareRequest[fPendingCompareRequests.size()]) ); + } } else { doApplyWorkingSets(EMPTY_WORKING_SETS); } |