summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAbeer Bagul2013-01-16 23:50:32 (EST)
committer Pawel Piech2013-01-16 23:50:32 (EST)
commit195c46250c2a175e4a42eef2fd6bc3c03b2c5d4e (patch)
tree55f70ca13a4677028136f8202a3717d5887e7ca4
parent026cca5522660c2d4377f470479fd5ed386e3136 (diff)
downloadeclipse.platform.debug-195c46250c2a175e4a42eef2fd6bc3c03b2c5d4e.zip
eclipse.platform.debug-195c46250c2a175e4a42eef2fd6bc3c03b2c5d4e.tar.gz
eclipse.platform.debug-195c46250c2a175e4a42eef2fd6bc3c03b2c5d4e.tar.bz2
Bug 372181 - Working set support for Expressions View
Initial contribution.
-rw-r--r--org.eclipse.debug.ui/META-INF/MANIFEST.MF4
-rw-r--r--org.eclipse.debug.ui/icons/full/obj16/expression_workingset.gifbin0 -> 403 bytes
-rw-r--r--org.eclipse.debug.ui/plugin.properties8
-rw-r--r--org.eclipse.debug.ui/plugin.xml58
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIPlugin.java5
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/expressions/ActionMessages.java23
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/expressions/ActionMessages.properties11
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/expressions/AssignWorkingSetsAction.java268
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/expression/ExpressionFactory.java42
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/expression/ExpressionPersistableElementAdapter.java41
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/expression/ExpressionPersistableElementAdapterFactory.java40
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/expression/workingset/ExpressionLabelProvider.java48
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/expression/workingset/ExpressionWorkingSetElementAdapter.java57
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/expression/workingset/ExpressionWorkingSetFilter.java85
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/expression/workingset/ExpressionWorkingSetFilterManager.java405
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/expression/workingset/ExpressionWorkingSetMessages.java34
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/expression/workingset/ExpressionWorkingSetMessages.properties20
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/expression/workingset/ExpressionWorkingSetPage.java241
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/expression/workingset/ExpressionWorkingSetsAction.java72
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/expression/workingset/IExpressionWorkingSetConstants.java25
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/model/elements/ExpressionManagerContentProvider.java49
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/model/elements/IAddNewExpression.java20
22 files changed, 1552 insertions, 4 deletions
diff --git a/org.eclipse.debug.ui/META-INF/MANIFEST.MF b/org.eclipse.debug.ui/META-INF/MANIFEST.MF
index 83926ff..1e35b7d 100644
--- a/org.eclipse.debug.ui/META-INF/MANIFEST.MF
+++ b/org.eclipse.debug.ui/META-INF/MANIFEST.MF
@@ -70,7 +70,9 @@ Export-Package: org.eclipse.debug.internal.ui;
org.eclipse.debug.ui.console,
org.eclipse.debug.ui.contexts,
org.eclipse.debug.ui.memory,
- org.eclipse.debug.ui.sourcelookup
+ org.eclipse.debug.ui.sourcelookup,
+ org.eclipse.debug.internal.ui.expression;x-internal:=true,
+ org.eclipse.debug.internal.ui.expression.workingset;x-internal:=true
Require-Bundle: org.eclipse.core.expressions;bundle-version="[3.4.0,4.0.0)",
org.eclipse.core.variables;bundle-version="[3.2.0,4.0.0)",
org.eclipse.ui;bundle-version="[3.5.0,4.0.0)",
diff --git a/org.eclipse.debug.ui/icons/full/obj16/expression_workingset.gif b/org.eclipse.debug.ui/icons/full/obj16/expression_workingset.gif
new file mode 100644
index 0000000..a2fe681
--- /dev/null
+++ b/org.eclipse.debug.ui/icons/full/obj16/expression_workingset.gif
Binary files differ
diff --git a/org.eclipse.debug.ui/plugin.properties b/org.eclipse.debug.ui/plugin.properties
index 5b40f4e..2a491dd 100644
--- a/org.eclipse.debug.ui/plugin.properties
+++ b/org.eclipse.debug.ui/plugin.properties
@@ -393,4 +393,10 @@ console.out.label= Standard out
console.in.label= Standard in
console.err.label= Standard error
debug.ui.component.label = Platform Debug UI
-debug.core.component.label = Platform Debug Core \ No newline at end of file
+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
diff --git a/org.eclipse.debug.ui/plugin.xml b/org.eclipse.debug.ui/plugin.xml
index 8dfbcd9..ce52c69 100644
--- a/org.eclipse.debug.ui/plugin.xml
+++ b/org.eclipse.debug.ui/plugin.xml
@@ -11,6 +11,7 @@
IBM Corporation - initial API and implementation
Patrick Chuong (Texas Instruments) - Improve usability of the breakpoint view (Bug 238956)
Patrick Chuong (Texas Instruments) - Move debug toolbar actions to main window (Bug 332784)
+ Abeer Bagul (Tensilica) - Working set support for Expressions view (Bug 372181)
-->
<plugin>
@@ -1231,6 +1232,24 @@
</viewerContribution>
<viewerContribution
targetID="org.eclipse.debug.ui.ExpressionView"
+ id="org.eclipse.debug.ui.ExpressionViewPopupActions">
+ <visibility>
+ <and>
+ <objectClass name="org.eclipse.debug.core.model.IWatchExpression"/>
+ </and>
+ </visibility>
+ <action
+ label="%assignWatchExpressionToWorkingSet.label"
+ icon="icons/full/obj16/expression_workingset.gif"
+ helpContextId="assign_expression_to_working_set"
+ class="org.eclipse.debug.internal.ui.actions.expressions.AssignWorkingSetsAction"
+ tooltip="%assignWatchExpressionToWorkingSet.tooltip"
+ menubarPath="additions"
+ id="org.eclipse.debug.ui.watchExpressionActions.AssignWorkingSet">
+ </action>
+ </viewerContribution>
+ <viewerContribution
+ targetID="org.eclipse.debug.ui.ExpressionView"
id="org.eclipse.debug.ui.WatchExpressionActions">
<action
label="%editWatchExpressionAction.label"
@@ -3147,4 +3166,43 @@ M4 = Platform-specific fourth key
</component>
</extension>
+ <extension point="org.eclipse.ui.workingSets">
+ <workingSet
+ id="org.eclipse.debug.ui.expressionWorkingSet"
+ name="%ExpressionWorkingSet.name"
+ description="%ExpressionWorkingSet.description"
+ icon="icons/full/obj16/expression_workingset.gif"
+ pageClass="org.eclipse.debug.internal.ui.expression.workingset.ExpressionWorkingSetPage"
+ elementAdapterClass="org.eclipse.debug.internal.ui.expression.workingset.ExpressionWorkingSetElementAdapter"
+ />
+ </extension>
+
+ <extension
+ point="org.eclipse.ui.viewActions">
+ <viewContribution
+ targetID="org.eclipse.debug.ui.ExpressionView"
+ id="org.eclipse.debug.ui.expressionview.toolbar.workingset">
+ <action
+ class="org.eclipse.debug.internal.ui.expression.workingset.ExpressionWorkingSetsAction"
+ helpContextId="expression_working_sets_action_context"
+ id="org.eclipse.debug.ui.expressionView.toolbar.workingSets"
+ label="%ExpressionWorkingSet.manageAction.label"
+ menubarPath="additions"
+ style="push"
+ tooltip="%ExpressionWorkingSet.manageAction.tooltip"/>
+ </viewContribution>
+ </extension>
+
+ <extension point="org.eclipse.core.runtime.adapters">
+ <factory
+ class="org.eclipse.debug.internal.ui.expression.ExpressionPersistableElementAdapterFactory"
+ adaptableType="org.eclipse.debug.core.model.IExpression">
+ <adapter type="org.eclipse.ui.IPersistableElement"/>
+ </factory>
+ </extension>
+
+ <extension point="org.eclipse.ui.elementFactories">
+ <factory id="org.eclipse.debug.ui.elementfactory.expressions"
+ class="org.eclipse.debug.internal.ui.expression.ExpressionFactory" />
+ </extension>
</plugin>
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIPlugin.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIPlugin.java
index 963cd75..5893e5b 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIPlugin.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIPlugin.java
@@ -10,6 +10,7 @@
* Sascha Radike - bug 56642
* Martin Oberhuber (Wind River) - [327446] Avoid unnecessary wait-for-build dialog.
* Mohamed Hussein - bug 381175
+ * Abeer Bagul (Tensilica) - Working set support for Expressions view (Bug 372181)
*******************************************************************************/
package org.eclipse.debug.internal.ui;
@@ -60,6 +61,7 @@ import org.eclipse.debug.core.model.IDebugElement;
import org.eclipse.debug.core.model.IProcess;
import org.eclipse.debug.internal.core.IInternalDebugCoreConstants;
import org.eclipse.debug.internal.ui.contextlaunching.LaunchingResourceManager;
+import org.eclipse.debug.internal.ui.expression.workingset.ExpressionWorkingSetFilterManager;
import org.eclipse.debug.internal.ui.launchConfigurations.ClosedProjectFilter;
import org.eclipse.debug.internal.ui.launchConfigurations.DeletedProjectFilter;
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationEditDialog;
@@ -556,6 +558,9 @@ public class DebugUIPlugin extends AbstractUIPlugin implements ILaunchListener,
// start the breakpoint organizer manager
BreakpointOrganizerManager.getDefault();
+
+ //start the expression workingset manager
+ ExpressionWorkingSetFilterManager.getInstance().init();
getLaunchConfigurationManager().startup();
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/expressions/ActionMessages.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/expressions/ActionMessages.java
new file mode 100644
index 0000000..7c6c496
--- /dev/null
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/expressions/ActionMessages.java
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Tensilica Inc. 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:
+ * Abeer Bagul (Tensilica) - initial API and implementation (bug 372181)
+ *******************************************************************************/
+package org.eclipse.debug.internal.ui.actions.expressions;
+
+import org.eclipse.osgi.util.NLS;
+
+public class ActionMessages extends NLS {
+ private static final String BUNDLE_NAME = "org.eclipse.debug.internal.ui.actions.expressions.ActionMessages"; //$NON-NLS-1$
+
+ static {
+ NLS.initializeMessages(BUNDLE_NAME, ActionMessages.class);
+ }
+
+ public static String AssignWorkingSetsAction_0;
+}
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/expressions/ActionMessages.properties b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/expressions/ActionMessages.properties
new file mode 100644
index 0000000..c19069c
--- /dev/null
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/expressions/ActionMessages.properties
@@ -0,0 +1,11 @@
+###############################################################################
+# Copyright (c) 2012 Tensilica Inc. 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:
+# Abeer Bagul (Tensilica) - initial API and implementation (bug 372181)
+###############################################################################
+AssignWorkingSetsAction_0=Create working set... \ No newline at end of file
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/expressions/AssignWorkingSetsAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/expressions/AssignWorkingSetsAction.java
new file mode 100644
index 0000000..0902623
--- /dev/null
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/expressions/AssignWorkingSetsAction.java
@@ -0,0 +1,268 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Tensilica 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:
+ * Abeer Bagul (Tensilica) - initial API and implementation (bug 372181)
+ *******************************************************************************/
+package org.eclipse.debug.internal.ui.actions.expressions;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.debug.core.model.IWatchExpression;
+import org.eclipse.debug.internal.ui.expression.workingset.IExpressionWorkingSetConstants;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.ActionContributionItem;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IMenuCreator;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.window.Window;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.MenuEvent;
+import org.eclipse.swt.events.MenuListener;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.ui.IWorkingSet;
+import org.eclipse.ui.IWorkingSetManager;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.dialogs.IWorkingSetNewWizard;
+
+/**
+ * Shows a submenu which lists all expression working sets.
+ * User can select any of the working sets in the submenu to assign
+ * selected expressions to this working set.
+ * <p>
+ * The submenu also contains a menuitem "Create working set..."
+ * which opens the Add New Expression Working Set dialog.
+ */
+public class AssignWorkingSetsAction extends WatchExpressionAction {
+
+ /*
+ * Represents a checkable expression workingset menuitem
+ *
+ * When user checks this menuitem, expressions selected in the view
+ * will be added to this working set.
+ */
+ private class SelectWorkingSetAction extends Action {
+
+ private IWorkingSet workingSet;
+
+ SelectWorkingSetAction(IWorkingSet workingSet) {
+ super(workingSet.getName(), AS_CHECK_BOX);
+ this.workingSet = workingSet;
+ }
+
+ public void run() {
+ IWatchExpression[] selectedExpressions = getSelectedExpressions();
+ if (isChecked()) {
+ //add all selected expressions to the workingset
+ //ignore if any selected expression is already in the working set
+ List newExpressions = new ArrayList();
+ newExpressions.addAll(Arrays.asList(workingSet.getElements()));
+
+ IAdaptable[] existingExpressions = workingSet.getElements();
+
+ for (int i=0; i<selectedExpressions.length; i++) {
+ IWatchExpression expressionToAdd = selectedExpressions[i];
+ int j = 0;
+ for (; j<existingExpressions.length; j++) {
+ IAdaptable existingAdaptable = existingExpressions[j];
+ IWatchExpression existingExpression = (IWatchExpression) existingAdaptable.getAdapter(IWatchExpression.class);
+ if (existingExpression != null
+ && existingExpression.equals(expressionToAdd))
+ break;
+ }
+ if (j == existingExpressions.length)
+ newExpressions.add(expressionToAdd);
+ }
+
+ IAdaptable[] newElements = new IAdaptable[newExpressions.size()];
+ for (int i=0, size=newExpressions.size(); i<size; i++)
+ newElements[i] = (IAdaptable) newExpressions.get(i);
+ workingSet.setElements(newElements);
+ }
+ else {
+ //remove selected expressions from this workingset
+ List newExpressions = new ArrayList();
+ newExpressions.addAll(Arrays.asList(workingSet.getElements()));
+
+ for (int i=0; i<selectedExpressions.length; i++) {
+ IWatchExpression expressionToRemove = selectedExpressions[i];
+
+ for (int j=0, size=newExpressions.size(); j<size; j++) {
+ IAdaptable existingAdaptable = (IAdaptable) newExpressions.get(j);
+ IWatchExpression existingExpression = (IWatchExpression) existingAdaptable.getAdapter(IWatchExpression.class);
+ if (existingExpression != null
+ && existingExpression.equals(expressionToRemove)) {
+ newExpressions.remove(j--);
+ break;
+ }
+ }
+ }
+
+ IAdaptable[] newElements = new IAdaptable[newExpressions.size()];
+ for (int i=0, size=newExpressions.size(); i<size; i++)
+ newElements[i] = (IAdaptable) newExpressions.get(i);
+ workingSet.setElements(newElements);
+ }
+ }
+ }
+
+ /*
+ * Click this menuitem to open the "New Expression Working Set" page.
+ * Expressions selected in the view are pre-checked in the page,
+ * user just has to type a working set name and click OK.
+ */
+ private class CreateWorkingSetAction extends Action {
+
+ CreateWorkingSetAction() {
+ super(ActionMessages.AssignWorkingSetsAction_0, SWT.PUSH);
+ }
+
+ public void run() {
+ IWorkingSetManager manager = PlatformUI.getWorkbench().getWorkingSetManager();
+ IWorkingSetNewWizard wizard = manager.createWorkingSetNewWizard(
+ new String[] {IExpressionWorkingSetConstants.EXPRESSION_WORKINGSET_ID});
+ if (wizard != null)
+ {
+ WizardDialog dialog = new WizardDialog(
+ PlatformUI.getWorkbench().getDisplay().getActiveShell(),
+ wizard);
+
+ dialog.create();
+
+ if (dialog.open() == Window.OK) {
+ IWorkingSet workingSet = wizard.getSelection();
+ manager.addWorkingSet(workingSet);
+ }
+ }
+ }
+ }
+
+ public void run(IAction action) {
+ //noop, we have a submenu
+ }
+
+ public void selectionChanged(IAction action, ISelection selection) {
+ super.selectionChanged(action, selection);
+
+ //assign a submenu to this action
+ action.setMenuCreator(new IMenuCreator() {
+
+ private Menu workingSetsSubMenu;
+
+ /*
+ * Create a submenu.
+ * For each expression workingset defined in the workspace,
+ * add a checkbox menuitem to the submenu.
+ * If the selected expressions are already assigned
+ * to any workingset, pre-check the menuitem
+ * representing that workingset.
+ * When user checks a workingset, assign
+ * expressions selected in the view to this workingset.
+ * When user unchecks a workingset, remove
+ * expressions selected in the view from this workingset.
+ * Pre-check only those workingsets
+ * which contain all selected expressions.
+ */
+ public Menu getMenu(Menu parent) {
+ if (workingSetsSubMenu == null) {
+ workingSetsSubMenu = new Menu(parent);
+ createMenuItems();
+ workingSetsSubMenu.addMenuListener(new MenuListener() {
+
+ public void menuShown(MenuEvent e) {
+ //noop
+
+ }
+
+ public void menuHidden(MenuEvent e) {
+ //noop
+
+ }
+ });
+ }
+
+ return workingSetsSubMenu;
+ }
+
+ public Menu getMenu(Control parent) {
+ //noop - we are creating a submenu for a menuitem
+ return null;
+ }
+
+ public void dispose() {
+ //dispose the submenu
+ if (workingSetsSubMenu != null) {
+ if (!workingSetsSubMenu.isDisposed())
+ workingSetsSubMenu.dispose();
+ workingSetsSubMenu = null;
+ }
+ }
+
+ private void createMenuItems() {
+ //get all expression working sets
+ IWorkingSet[] allWorkingSets = PlatformUI.getWorkbench().getWorkingSetManager().getWorkingSets();
+ List expressionWorkingSets = new ArrayList();
+ for (int i=0; i<allWorkingSets.length; i++)
+ {
+ IWorkingSet workingSet = allWorkingSets[i];
+ if (IExpressionWorkingSetConstants.EXPRESSION_WORKINGSET_ID.equals(workingSet.getId()))
+ expressionWorkingSets.add(workingSet);
+ }
+
+ int i = 0;
+ //for each expression working set, create a menuitem
+ for (int size=expressionWorkingSets.size(); i<size; i++)
+ {
+ IWorkingSet expressionWorkingSet = (IWorkingSet) expressionWorkingSets.get(i);
+ SelectWorkingSetAction selectAction = new SelectWorkingSetAction(expressionWorkingSet);
+ ActionContributionItem selectItem = new ActionContributionItem(selectAction);
+ selectItem.fill(workingSetsSubMenu, i);
+
+ //if all selected expressions are included in this working set,
+ //check it
+ IWatchExpression[] selectedExpressions = getSelectedExpressions();
+ int j = 0;
+ for (; j<selectedExpressions.length; j++)
+ {
+ IAdaptable[] existingExpressions = expressionWorkingSet.getElements();
+
+ int k = 0;
+ for (; k<existingExpressions.length; k++)
+ {
+ IAdaptable existingAdaptable = existingExpressions[k];
+ IWatchExpression existingExpression = (IWatchExpression) existingAdaptable.getAdapter(IWatchExpression.class);
+
+ if (existingExpression != null
+ && (existingExpression.equals(selectedExpressions[j])))
+ break;
+ }
+
+ if (k == existingExpressions.length)
+ break;
+ }
+
+ selectAction.setChecked(j != 0 && j == selectedExpressions.length);
+ }
+
+ Separator separator = new Separator();
+ separator.fill(workingSetsSubMenu, i);
+ i++;
+
+ //create a menuitem to open the "Add new expression working set" page
+ CreateWorkingSetAction createAction = new CreateWorkingSetAction();
+ ActionContributionItem createItem = new ActionContributionItem(createAction);
+ createItem.fill(workingSetsSubMenu, i);
+ }
+ });
+ }
+}
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/expression/ExpressionFactory.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/expression/ExpressionFactory.java
new file mode 100644
index 0000000..708d108
--- /dev/null
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/expression/ExpressionFactory.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Tensilica Inc 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:
+ * Abeer Bagul (Tensilica Inc) - initial API and implementation (Bug 372181)
+ *******************************************************************************/
+package org.eclipse.debug.internal.ui.expression;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.model.IExpression;
+import org.eclipse.ui.IElementFactory;
+import org.eclipse.ui.IMemento;
+
+/**
+ * Factory to restore an expression from a memento.
+ * @since 3.9
+ */
+public class ExpressionFactory implements IElementFactory {
+
+ public static final String ID = "org.eclipse.debug.ui.elementfactory.expressions"; //$NON-NLS-1$
+
+ public IAdaptable createElement(IMemento memento) {
+ String expressionText = memento.getString(ExpressionPersistableElementAdapter.TAG_EXPRESSION_TEXT);
+ if (expressionText != null)
+ {
+ IExpression[] expressions = DebugPlugin.getDefault().getExpressionManager().getExpressions();
+ for (int i=0; i<expressions.length; i++) {
+ IExpression expr = expressions[i];
+ if (expr.getExpressionText().equals(expressionText))
+ return expr;
+ }
+ }
+
+ return null;
+ }
+
+}
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/expression/ExpressionPersistableElementAdapter.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/expression/ExpressionPersistableElementAdapter.java
new file mode 100644
index 0000000..0705774
--- /dev/null
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/expression/ExpressionPersistableElementAdapter.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Tensilica Inc 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:
+ * Abeer Bagul (Tensilica Inc) - initial API and implementation (Bug 372181)
+ *******************************************************************************/
+package org.eclipse.debug.internal.ui.expression;
+
+import org.eclipse.debug.core.model.IExpression;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.IPersistableElement;
+
+/**
+ * This adapter saves an expression to a memento.
+ * It also returns ID of ExpressionFactory which is used to create a factory object,
+ * which in turn will restore the expression from the memento
+ * @since 3.9
+ */
+public class ExpressionPersistableElementAdapter implements IPersistableElement {
+
+ public static final String TAG_EXPRESSION_TEXT = "TAG_EXPRESSION_TEXT"; //$NON-NLS-1$
+
+ private IExpression fExpression;
+
+ public ExpressionPersistableElementAdapter(IExpression expression) {
+ this.fExpression = expression;
+ }
+
+ public void saveState(IMemento memento) {
+ memento.putString(TAG_EXPRESSION_TEXT, fExpression.getExpressionText());
+ }
+
+ public String getFactoryId() {
+ return ExpressionFactory.ID;
+ }
+
+}
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/expression/ExpressionPersistableElementAdapterFactory.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/expression/ExpressionPersistableElementAdapterFactory.java
new file mode 100644
index 0000000..d374910
--- /dev/null
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/expression/ExpressionPersistableElementAdapterFactory.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Tensilica Inc 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:
+ * Abeer Bagul (Tensilica Inc) - initial API and implementation (Bug 372181)
+ *******************************************************************************/
+package org.eclipse.debug.internal.ui.expression;
+
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.eclipse.debug.core.model.IExpression;
+import org.eclipse.ui.IPersistableElement;
+
+/**
+ * Adapts an expression to IPersistableElement.
+ * The adapter will save the expression to a memento.
+ *
+ * @see ExpressionPersistableElementAdapter
+ * @see ExpressionFactory
+ * @since 3.9
+ */
+public class ExpressionPersistableElementAdapterFactory implements
+ IAdapterFactory {
+
+ public Object getAdapter(Object adaptableObject, Class adapterType) {
+ if (adapterType == IPersistableElement.class)
+ if (adaptableObject instanceof IExpression)
+ return new ExpressionPersistableElementAdapter((IExpression) adaptableObject);
+
+ return null;
+ }
+
+ public Class[] getAdapterList() {
+ return new Class[] {IPersistableElement.class};
+ }
+
+}
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/expression/workingset/ExpressionLabelProvider.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/expression/workingset/ExpressionLabelProvider.java
new file mode 100644
index 0000000..01c3f98
--- /dev/null
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/expression/workingset/ExpressionLabelProvider.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Tensilica Inc 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:
+ * Abeer Bagul (Tensilica Inc) - initial API and implementation (Bug 372181)
+ *******************************************************************************/
+package org.eclipse.debug.internal.ui.expression.workingset;
+
+import org.eclipse.debug.core.model.IExpression;
+import org.eclipse.debug.ui.DebugUITools;
+import org.eclipse.debug.ui.IDebugUIConstants;
+import org.eclipse.jface.viewers.BaseLabelProvider;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * Label provider for the Expression Working Set Page,
+ * used while creating a new working set.
+ * <p>
+ * Returns the text of an expression to display in the checklist.
+ *
+ * @since 3.9
+ */
+public class ExpressionLabelProvider extends BaseLabelProvider implements ITableLabelProvider {
+
+ public Image getColumnImage(Object element, int columnIndex) {
+ if (element instanceof IExpression)
+ {
+ if (columnIndex == 0)
+ return DebugUITools.getImage(IDebugUIConstants.IMG_OBJS_EXPRESSION);
+ }
+ return null;
+ }
+
+ public String getColumnText(Object element, int columnIndex) {
+ if (element instanceof IExpression)
+ {
+ if (columnIndex == 0)
+ return ((IExpression) element).getExpressionText();
+ }
+ return null;
+ }
+
+}
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/expression/workingset/ExpressionWorkingSetElementAdapter.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/expression/workingset/ExpressionWorkingSetElementAdapter.java
new file mode 100644
index 0000000..5a99063
--- /dev/null
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/expression/workingset/ExpressionWorkingSetElementAdapter.java
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Tensilica Inc 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:
+ * Abeer Bagul (Tensilica Inc) - initial API and implementation (Bug 372181)
+ *******************************************************************************/
+package org.eclipse.debug.internal.ui.expression.workingset;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.model.IExpression;
+import org.eclipse.ui.IWorkingSet;
+import org.eclipse.ui.IWorkingSetElementAdapter;
+
+/**
+ * Consulted by workbench pull down actions that add/remove selected elements to/from
+ * working sets. Allows expression working sets to select which elements are applicable
+ * for adding/removing.
+ *
+ * @since 3.9
+ */
+public class ExpressionWorkingSetElementAdapter implements
+ IWorkingSetElementAdapter {
+
+ public IAdaptable[] adaptElements(IWorkingSet ws, IAdaptable[] elements) {
+ for (int i = 0; i < elements.length; i++) {
+ IExpression expression = (IExpression)DebugPlugin.getAdapter(elements[i], IExpression.class);
+ if (expression != null) {
+ return selectExpressions(elements);
+ }
+ }
+ return elements;
+ }
+
+ private IAdaptable[] selectExpressions(IAdaptable[] elements) {
+ List expressions = new ArrayList(elements.length);
+ for (int i = 0; i < elements.length; i++) {
+ IExpression expression = (IExpression)DebugPlugin.getAdapter(elements[i], IExpression.class);
+ if (expression != null) {
+ expressions.add(expression);
+ }
+ }
+ return (IAdaptable[]) expressions.toArray(new IAdaptable[expressions.size()]);
+ }
+
+ public void dispose() {
+
+ }
+
+}
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/expression/workingset/ExpressionWorkingSetFilter.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/expression/workingset/ExpressionWorkingSetFilter.java
new file mode 100644
index 0000000..d169b63
--- /dev/null
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/expression/workingset/ExpressionWorkingSetFilter.java
@@ -0,0 +1,85 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Tensilica Inc 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:
+ * Abeer Bagul (Tensilica Inc) - initial API and implementation (Bug 372181)
+ *******************************************************************************/
+package org.eclipse.debug.internal.ui.expression.workingset;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.debug.core.model.IExpression;
+import org.eclipse.debug.internal.ui.model.elements.IAddNewExpression;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.ITreeModelViewer;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.TreeModelViewerFilter;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.ui.IWorkingSet;
+
+/**
+ * Holds a list of working sets selected for an instance of Expression view,
+ * and filters in only those expressions which are part of the selected working sets.
+ * If no working sets are selected for a view, it filters in all expressions.
+ *
+ * This filter always allows the "Add new expression" node.
+ * @since 3.9
+ */
+public class ExpressionWorkingSetFilter extends TreeModelViewerFilter {
+
+ private IWorkingSet[] selectedWorkingSets;
+
+ public IWorkingSet[] getSelectedWorkingSets() {
+ return selectedWorkingSets;
+ }
+
+ public void setSelectedWorkingSets(IWorkingSet[] selectedWorkingSets) {
+ this.selectedWorkingSets = selectedWorkingSets;
+ }
+
+ public boolean select(Viewer viewer, Object parentElement, Object element) {
+
+ if (selectedWorkingSets == null)
+ return true;
+
+ if (selectedWorkingSets.length == 0)
+ return true;
+
+ if (element instanceof IAddNewExpression)
+ return true;
+
+ if (element instanceof IAdaptable)
+ {
+ IExpression expressionToFilter = (IExpression) ((IAdaptable) element).getAdapter(IExpression.class);
+ if (expressionToFilter != null)
+ {
+ return isInWorkingSet(expressionToFilter);
+ }
+ }
+
+ return false;
+ }
+
+ private boolean isInWorkingSet(IExpression expression)
+ {
+ for (int i=0; i<selectedWorkingSets.length; i++)
+ {
+ IWorkingSet exprWorkingSet = selectedWorkingSets[i];
+ IAdaptable[] workingSetElements = exprWorkingSet.getElements();
+ for (int j=0; j<workingSetElements.length; j++)
+ {
+ IAdaptable workingSetElement = workingSetElements[j];
+ IExpression workingSetExpression = (IExpression) workingSetElement.getAdapter(IExpression.class);
+ if (expression.getExpressionText().equals(workingSetExpression.getExpressionText()))
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public boolean isApplicable(ITreeModelViewer viewer, Object parentElement) {
+ return true;
+ }
+}
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/expression/workingset/ExpressionWorkingSetFilterManager.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/expression/workingset/ExpressionWorkingSetFilterManager.java
new file mode 100644
index 0000000..bcaee16
--- /dev/null
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/expression/workingset/ExpressionWorkingSetFilterManager.java
@@ -0,0 +1,405 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Tensilica Inc 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:
+ * Abeer Bagul (Tensilica Inc) - initial API and implementation (Bug 372181)
+ *******************************************************************************/
+package org.eclipse.debug.internal.ui.expression.workingset;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.debug.internal.ui.DebugUIPlugin;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.TreeModelViewer;
+import org.eclipse.debug.internal.ui.views.expression.ExpressionView;
+import org.eclipse.debug.ui.IDebugUIConstants;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.jface.viewers.ViewerFilter;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.IPartListener2;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IViewReference;
+import org.eclipse.ui.IWindowListener;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPartReference;
+import org.eclipse.ui.IWorkbenchWindow;
+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.progress.WorkbenchJob;
+
+/**
+ * Manages expression working set filters for all expression views in the workbench.
+ * <p>
+ * It saves info about which working sets are applied to each expression view,
+ * and restores the info and filter when an expression view is opened.
+ *
+ * @since 3.9
+ */
+public class ExpressionWorkingSetFilterManager implements IPropertyChangeListener
+{
+
+ private static final String PREF_WORKINGSETS = "expressionWorkingSets"; //$NON-NLS-1$
+ private static final String ELEMENT_WORKINGSETS = "expressionWorkingsets"; //$NON-NLS-1$
+ private static final String ELEMENT_EXPRESSIONVIEW = "expressionView"; //$NON-NLS-1$
+ private static final String ELEMENT_WORKINGSET = "workingSet"; //$NON-NLS-1$
+
+ private static ExpressionWorkingSetFilterManager INSTANCE;
+
+ private static boolean fInitialized = false;
+
+ private ExpressionWorkingSetFilterManager()
+ {
+
+ }
+
+ synchronized public static ExpressionWorkingSetFilterManager getInstance() {
+ if (INSTANCE == null) {
+ INSTANCE = new ExpressionWorkingSetFilterManager();
+ }
+ return INSTANCE;
+ }
+
+ synchronized public void init() {
+ if (fInitialized) return;
+ fInitialized = true;
+
+ initListeners();
+
+ final XMLMemento fworkingSetsMemento = getMemento();
+
+ new WorkbenchJob("Initializing expression view working sets") { //$NON-NLS-1$
+ { setSystem(true); }
+ public IStatus runInUIThread(IProgressMonitor monitor) {
+ IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
+ for (int i=0; i<windows.length; i++) {
+ IWorkbenchWindow window = windows[i];
+ IViewReference[] viewRefs = window.getActivePage().getViewReferences();
+ for (int j=0; j<viewRefs.length; j++) {
+ IViewReference viewRef = viewRefs[j];
+ try {
+ if (IDebugUIConstants.ID_EXPRESSION_VIEW.equals(viewRef.getId()))
+ {
+ IViewPart expressionView = viewRef.getView(false);
+ if (expressionView != null)
+ applyFilter(expressionView, fworkingSetsMemento);
+ }
+ }
+ finally {
+
+ }
+ }
+ }
+ return Status.OK_STATUS;
+ }
+ }.schedule();
+ }
+
+ private void applyFilter(IViewPart expressionView, XMLMemento workingSetsMemento)
+ {
+ String mementoID = expressionView.getViewSite().getId() +
+ expressionView.getViewSite().getSecondaryId();
+
+ List workingSets = new ArrayList();
+
+ if (workingSetsMemento != null)
+ {
+ IMemento[] viewMementos = workingSetsMemento.getChildren(ELEMENT_EXPRESSIONVIEW);
+ for (int i=0; i<viewMementos.length; i++) {
+ IMemento viewMemento = viewMementos[i];
+ if (mementoID.equals(viewMemento.getID())) {
+ IMemento[] workingsetMementos = viewMemento.getChildren(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)
+ workingSets.add(workingSet);
+ }
+
+ break;
+ }
+ }
+ }
+
+ applyWorkingSets((ExpressionView) expressionView, (IWorkingSet[]) workingSets.toArray(new IWorkingSet[0]));
+ }
+
+ private void initListeners() {
+ IWorkbench wb = PlatformUI.getWorkbench();
+
+ final IPartListener2 partListener = new IPartListener2() {
+
+ public void partVisible(IWorkbenchPartReference partRef) {}
+
+ public void partInputChanged(IWorkbenchPartReference partRef) {}
+
+ public void partHidden(IWorkbenchPartReference partRef) {}
+
+ public void partDeactivated(IWorkbenchPartReference partRef) {}
+
+ public void partBroughtToTop(IWorkbenchPartReference partRef) {}
+
+ public void partActivated(IWorkbenchPartReference partRef) {}
+
+ public void partOpened(IWorkbenchPartReference partRef) {
+ if (partRef instanceof IViewReference) {
+ if (! partRef.getId().equals(IDebugUIConstants.ID_EXPRESSION_VIEW))
+ return;
+ IViewPart part = ((IViewReference) partRef).getView(false);
+ if (part != null)
+ {
+ applyFilter(part, getMemento());
+ }
+ }
+ }
+
+ public void partClosed(IWorkbenchPartReference partRef) {}
+ };
+ // subscribe to existing workbench window listener
+ IWorkbenchWindow[] windows = wb.getWorkbenchWindows();
+ for (int i=0; i<windows.length; i++) {
+ IWorkbenchWindow ww = windows[i];
+ ww.getPartService().addPartListener(partListener);
+ }
+
+ // subscribe to new workbench window listener
+ wb.addWindowListener(new IWindowListener() {
+
+ public void windowDeactivated(IWorkbenchWindow window) {}
+
+ public void windowActivated(IWorkbenchWindow window) {}
+
+ public void windowClosed(IWorkbenchWindow window) {}
+
+ public void windowOpened(IWorkbenchWindow window) {
+ window.getPartService().addPartListener(partListener);
+ }
+ });
+
+ PlatformUI.getWorkbench().getWorkingSetManager().addPropertyChangeListener(this);
+ }
+
+ private static XMLMemento getMemento()
+ {
+ IPreferenceStore prefStore = DebugUIPlugin.getDefault().getPreferenceStore();
+ String workingSetsMementoRaw = prefStore.getString(PREF_WORKINGSETS);
+ workingSetsMementoRaw = workingSetsMementoRaw.trim();
+ if (workingSetsMementoRaw.length() == 0)
+ return null;
+ XMLMemento workingSetsMemento = null;
+ try {
+ workingSetsMemento = XMLMemento.createReadRoot(new StringReader(workingSetsMementoRaw));
+ } catch (WorkbenchException e) {
+ DebugUIPlugin.log(e);
+ }
+ return workingSetsMemento;
+ }
+
+ public static void applyWorkingSets(ExpressionView exprView, IWorkingSet[] selectedWorkingSets)
+ {
+ ExpressionWorkingSetFilter workingSetFilter = getFilter(exprView);
+
+ workingSetFilter.setSelectedWorkingSets(selectedWorkingSets);
+
+ exprView.getViewer().refresh();
+
+ saveWorkingSets(exprView, selectedWorkingSets);
+ }
+
+ private static ExpressionWorkingSetFilter getFilter(ExpressionView exprView)
+ {
+ ExpressionWorkingSetFilter workingSetFilter = null;
+
+ ViewerFilter[] existingFilters = ((TreeModelViewer) exprView.getViewer()).getFilters();
+ for (int i=0; i<existingFilters.length; i++) {
+ ViewerFilter existingFilter = existingFilters[i];
+ if (existingFilter instanceof ExpressionWorkingSetFilter)
+ {
+ workingSetFilter = (ExpressionWorkingSetFilter) existingFilter;
+ break;
+ }
+ }
+
+ if (workingSetFilter == null)
+ {
+ workingSetFilter = new ExpressionWorkingSetFilter();
+ ((TreeModelViewer) exprView.getViewer()).addFilter(workingSetFilter);
+ }
+
+ return workingSetFilter;
+ }
+
+ private static ExpressionView[] getExpressionViews()
+ {
+ List expressionViews = new ArrayList();
+
+ IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
+ for (int i=0; i<windows.length; i++) {
+ IWorkbenchWindow window = windows[i];
+ IViewReference[] viewRefs = window.getActivePage().getViewReferences();
+ for (int j=0; j<viewRefs.length; j++) {
+ IViewReference viewRef = viewRefs[j];
+ if (IDebugUIConstants.ID_EXPRESSION_VIEW.equals(viewRef.getId())) {
+ IViewPart expressionView = viewRef.getView(false);
+ if (expressionView != null)
+ expressionViews.add(expressionView);
+ }
+ }
+ }
+
+ return (ExpressionView[]) expressionViews.toArray(new ExpressionView[0]);
+ }
+
+ public static IWorkingSet[] getWorkingSets(ExpressionView exprView)
+ {
+ ExpressionWorkingSetFilter workingSetFilter = getFilter(exprView);
+ if (workingSetFilter == null)
+ return null;
+
+ return workingSetFilter.getSelectedWorkingSets();
+ }
+
+ private static void saveWorkingSets(ExpressionView exprView, IWorkingSet[] selectedWorkingSets)
+ {
+ String mementoID = exprView.getViewSite().getId() +
+ exprView.getViewSite().getSecondaryId();
+
+ XMLMemento rootMemento = XMLMemento.createWriteRoot(ELEMENT_WORKINGSETS);
+
+ XMLMemento savedMemento = getMemento();
+
+ if (savedMemento != null) {
+ IMemento[] viewMementos = savedMemento.getChildren(ELEMENT_EXPRESSIONVIEW);
+ for (int i=0; i<viewMementos.length; i++) {
+ IMemento savedViewMemento = viewMementos[i];
+ if (!mementoID.equals(savedViewMemento.getID()))
+ {
+ IMemento newViewMemento = rootMemento.createChild(ELEMENT_EXPRESSIONVIEW, savedViewMemento.getID());
+
+ IMemento[] savedWorkingSetMementos = savedViewMemento.getChildren(ELEMENT_WORKINGSET);
+ for (int j=0; j<savedWorkingSetMementos.length; j++) {
+ IMemento savedWorkingSetMemento = savedWorkingSetMementos[j];
+ newViewMemento.createChild(ELEMENT_WORKINGSET, savedWorkingSetMemento.getID());
+ }
+ }
+ }
+ }
+
+ IMemento viewMemento = rootMemento.createChild(ELEMENT_EXPRESSIONVIEW, mementoID);
+
+ for (int i=0; i<selectedWorkingSets.length; i++) {
+ IWorkingSet workingSet = selectedWorkingSets[i];
+ viewMemento.createChild(ELEMENT_WORKINGSET, workingSet.getName());
+ }
+
+ ByteArrayOutputStream mementoOutputStream = new ByteArrayOutputStream();
+ try {
+ rootMemento.save(new OutputStreamWriter(mementoOutputStream));
+ } catch (IOException e) {
+ DebugUIPlugin.log(e);
+ }
+
+ String workingSetsMementoRaw = mementoOutputStream.toString();
+
+ IPreferenceStore prefStore = DebugUIPlugin.getDefault().getPreferenceStore();
+ prefStore.setValue(PREF_WORKINGSETS, workingSetsMementoRaw);
+ }
+
+// private static IWorkingSet[] getExpressionWorkingSets()
+// {
+// List expressionWorkingSets = new ArrayList();
+//
+// IWorkingSetManager workingSetManager = PlatformUI.getWorkbench().getWorkingSetManager();
+// IWorkingSet[] workingSets = workingSetManager.getWorkingSets();
+// for (int i=0; i<workingSets.length; i++) {
+// IWorkingSet workingSet = workingSets[i];
+// if (workingSet.getId().equals(IExpressionWorkingSetConstants.EXPRESSION_WORKINGSET_ID))
+// {
+// expressionWorkingSets.add(workingSet);
+// }
+// }
+//
+// return (IWorkingSet[]) expressionWorkingSets.toArray(new IWorkingSet[0]);
+// }
+
+ public void propertyChange(PropertyChangeEvent event) {
+ if (IWorkingSetManager.CHANGE_WORKING_SET_REMOVE.equals(event.getProperty()))
+ {
+ IWorkingSet removedWorkingSet = (IWorkingSet) event.getOldValue();
+
+ ExpressionView[] views = getExpressionViews();
+ for (int i=0; i<views.length; i++) {
+ ExpressionView expressionView = views[i];
+ IWorkingSet[] appliedWorkingSets = getWorkingSets(expressionView);
+ if (appliedWorkingSets == null)
+ continue;
+ if (appliedWorkingSets.length == 0)
+ continue;
+
+ List remainingWorkingSets = new ArrayList();
+
+ boolean isRemoved = false;
+ for (int j=0; j<appliedWorkingSets.length; j++) {
+ IWorkingSet appliedWorkingSet = appliedWorkingSets[j];
+ if (removedWorkingSet.getName().equals(appliedWorkingSet.getName()))
+ {
+ isRemoved = true;
+ continue;
+ }
+ remainingWorkingSets.add(appliedWorkingSet);
+ }
+
+ if (isRemoved)
+ applyWorkingSets(expressionView, (IWorkingSet[]) remainingWorkingSets.toArray(new IWorkingSet[0]));
+ }
+ }
+ else if (IWorkingSetManager.CHANGE_WORKING_SET_CONTENT_CHANGE.equals(event.getProperty()))
+ {
+ IWorkingSet changedWorkingSet = (IWorkingSet) event.getNewValue();
+
+ ExpressionView[] views = getExpressionViews();
+ for (int i=0; i<views.length; i++) {
+ ExpressionView expressionView = views[i];
+ IWorkingSet[] appliedWorkingSets = getWorkingSets(expressionView);
+ if (appliedWorkingSets == null)
+ continue;
+ if (appliedWorkingSets.length == 0)
+ continue;
+
+ List remainingWorkingSets = new ArrayList();
+
+ boolean isChanged = false;
+ for (int j=0; j<appliedWorkingSets.length; j++) {
+ IWorkingSet appliedWorkingSet = appliedWorkingSets[j];
+ if (changedWorkingSet.getName().equals(appliedWorkingSet.getName()))
+ {
+ isChanged = true;
+ }
+ remainingWorkingSets.add(appliedWorkingSet);
+ }
+
+ if (isChanged)
+ applyWorkingSets(expressionView, (IWorkingSet[]) remainingWorkingSets.toArray(new IWorkingSet[0]));
+ }
+ }
+
+ }
+
+
+}
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/expression/workingset/ExpressionWorkingSetMessages.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/expression/workingset/ExpressionWorkingSetMessages.java
new file mode 100644
index 0000000..efd40b1
--- /dev/null
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/expression/workingset/ExpressionWorkingSetMessages.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Tensilica Inc 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:
+ * Abeer Bagul (Tensilica Inc) - initial API and implementation (Bug 372181)
+ *******************************************************************************/
+package org.eclipse.debug.internal.ui.expression.workingset;
+
+import org.eclipse.osgi.util.NLS;
+
+public class ExpressionWorkingSetMessages extends NLS
+{
+ static
+ {
+ initializeMessages("org.eclipse.debug.internal.ui.expression.workingset.ExpressionWorkingSetMessages", //$NON-NLS-1$
+ ExpressionWorkingSetMessages.class);
+ }
+
+ public static String Page_Title;
+ public static String Page_Description;
+
+ public static String WorkingSetName_label;
+ public static String Expressions_label;
+ public static String SelectAll;
+ public static String DeselectAll;
+
+ public static String Error_whitespace;
+ public static String Error_emptyName;
+ public static String Error_nameExists;
+}
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/expression/workingset/ExpressionWorkingSetMessages.properties b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/expression/workingset/ExpressionWorkingSetMessages.properties
new file mode 100644
index 0000000..c721e6c
--- /dev/null
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/expression/workingset/ExpressionWorkingSetMessages.properties
@@ -0,0 +1,20 @@
+###############################################################################
+# Copyright (c) 2012 Tensilica Inc 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:
+# Abeer Bagul (Tensilica Inc) - initial API and implementation (Bug 372181)
+###############################################################################
+
+Page_Title=Expression Working Set
+Page_Description=Enter a working set name and select expressions.
+WorkingSetName_label=&Working set name:
+Expressions_label=&Expressions:
+SelectAll=Select &All
+DeselectAll=&Deselect All
+Error_whitespace=Working set name must not have leading or trailing whitespace
+Error_emptyName=Enter working set name
+Error_nameExists=A working set with that name already exists \ No newline at end of file
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/expression/workingset/ExpressionWorkingSetPage.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/expression/workingset/ExpressionWorkingSetPage.java
new file mode 100644
index 0000000..c7cfc9a
--- /dev/null
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/expression/workingset/ExpressionWorkingSetPage.java
@@ -0,0 +1,241 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Tensilica Inc 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:
+ * Abeer Bagul (Tensilica Inc) - initial API and implementation (Bug 372181)
+ *******************************************************************************/
+package org.eclipse.debug.internal.ui.expression.workingset;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.model.IExpression;
+import org.eclipse.debug.ui.IDebugUIConstants;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.CheckboxTableViewer;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IWorkingSet;
+import org.eclipse.ui.IWorkingSetManager;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.dialogs.IWorkingSetPage;
+
+/**
+ * The Expression working set page allows the user to create
+ * and edit an expression working set.
+ *
+ * @since 3.9
+ */
+public class ExpressionWorkingSetPage extends WizardPage implements
+ IWorkingSetPage {
+
+ private static final String PAGE_NAME = "expressionWorkingSetPage"; //$NON-NLS-1$
+
+ private Text txtWorkingSetName;
+ private CheckboxTableViewer expressionsViewer;
+
+ private boolean isFirstCheck;
+ private IWorkingSet workingSet;
+
+ public ExpressionWorkingSetPage()
+ {
+ super(PAGE_NAME,
+ ExpressionWorkingSetMessages.Page_Title,
+ null);
+ setDescription(ExpressionWorkingSetMessages.Page_Description);
+ isFirstCheck = true;
+ }
+
+ public void createControl(Composite parent)
+ {
+ initializeDialogUnits(parent);
+
+ Composite composite= new Composite(parent, SWT.NONE);
+ composite.setLayout(new GridLayout());
+ composite.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
+ setControl(composite);
+
+ Label label= new Label(composite, SWT.WRAP);
+ label.setText(ExpressionWorkingSetMessages.WorkingSetName_label);
+ GridData gd= new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_CENTER);
+ label.setLayoutData(gd);
+
+ txtWorkingSetName= new Text(composite, SWT.SINGLE | SWT.BORDER);
+ txtWorkingSetName.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
+ txtWorkingSetName.addModifyListener(
+ new ModifyListener() {
+
+ public void modifyText(ModifyEvent e) {
+ validateInput();
+ }
+ }
+ );
+ txtWorkingSetName.setFocus();
+
+ label= new Label(composite, SWT.WRAP);
+ label.setText(ExpressionWorkingSetMessages.Expressions_label);
+ gd = new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_CENTER);
+ label.setLayoutData(gd);
+
+ expressionsViewer = CheckboxTableViewer.newCheckList(composite, SWT.BORDER);
+ expressionsViewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ expressionsViewer.setContentProvider(new ArrayContentProvider());
+ expressionsViewer.setLabelProvider(new ExpressionLabelProvider());
+
+ // Add select / deselect all buttons
+ Composite buttonComposite = new Composite(composite, SWT.NONE);
+ buttonComposite.setLayout(new GridLayout(2, false));
+ buttonComposite.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
+
+ Button selectAllButton = new Button(buttonComposite, SWT.PUSH);
+ selectAllButton.setText(ExpressionWorkingSetMessages.SelectAll);
+ selectAllButton.addSelectionListener(new SelectionAdapter() {
+
+ public void widgetSelected(SelectionEvent selectionEvent) {
+ expressionsViewer.getTable().selectAll();
+ expressionsViewer.setCheckedElements(
+ ((IStructuredSelection) expressionsViewer.getSelection()).toArray());
+ expressionsViewer.setGrayedElements(new Object[] {});
+ expressionsViewer.getTable().deselectAll();
+ validateInput();
+ }
+ });
+ Button deselectAllButton = new Button(buttonComposite, SWT.PUSH);
+ deselectAllButton.setText(ExpressionWorkingSetMessages.DeselectAll);
+ deselectAllButton.addSelectionListener(new SelectionAdapter() {
+
+ public void widgetSelected(SelectionEvent selectionEvent) {
+ expressionsViewer.setCheckedElements(new Object[] {});
+ validateInput();
+ }
+ });
+
+ Dialog.applyDialogFont(composite);
+
+ populateData();
+ }
+
+ private void populateData()
+ {
+ //get all expressions defined in the workspace
+ IExpression[] allExpressions = DebugPlugin.getDefault().getExpressionManager().getExpressions();
+ expressionsViewer.setInput(allExpressions);
+
+ IViewPart expressionView = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
+ .findView(IDebugUIConstants.ID_EXPRESSION_VIEW);
+
+ if (workingSet != null)
+ {
+ IAdaptable[] checkedExpressions = workingSet.getElements();
+ expressionsViewer.setCheckedElements(checkedExpressions);
+ }
+ else
+ {
+ IStructuredSelection selection;
+ if (expressionView == null) {
+ selection = new StructuredSelection();
+ } else {
+ selection = (IStructuredSelection)expressionView.getViewSite().getSelectionProvider().getSelection();
+ }
+ List checkedExpressions = new ArrayList();
+ Iterator it1 = selection.iterator();
+ while (it1.hasNext())
+ {
+ IExpression checkedExpr = (IExpression) DebugPlugin.getAdapter(it1.next(), IExpression.class);
+ if (checkedExpr != null)
+ checkedExpressions.add(checkedExpr);
+ }
+
+ expressionsViewer.setCheckedElements(checkedExpressions.toArray());
+ }
+
+ if (workingSet != null)
+ txtWorkingSetName.setText(workingSet.getName());
+ validateInput();
+
+ }
+
+ public void finish() {
+ String workingSetName = txtWorkingSetName.getText();
+ Object[] checkedElements = expressionsViewer.getCheckedElements();
+ IExpression[] checkedExpressions = new IExpression[checkedElements.length];
+ for (int i=0; i<checkedElements.length; i++) {
+ Object checkedElement = checkedElements[i];
+ checkedExpressions[i] = (IExpression) checkedElement;
+ }
+
+ if (workingSet == null) {
+ IWorkingSetManager workingSetManager= PlatformUI.getWorkbench().getWorkingSetManager();
+ workingSet = workingSetManager.createWorkingSet(workingSetName, checkedExpressions);
+ } else {
+ workingSet.setName(workingSetName);
+ workingSet.setElements(checkedExpressions);
+ }
+ }
+
+ public IWorkingSet getSelection() {
+ return workingSet;
+ }
+
+ public void setSelection(IWorkingSet workingSet) {
+ Assert.isNotNull(workingSet, "Working set must not be null"); //$NON-NLS-1$
+ this.workingSet = workingSet;
+ if (getContainer() != null && getShell() != null && txtWorkingSetName != null) {
+ isFirstCheck= false;
+ txtWorkingSetName.setText(workingSet.getName());
+ validateInput();
+ }
+ }
+
+ /**
+ * validates the current input of the page to determine if the finish button can be enabled
+ */
+ private void validateInput() {
+ String errorMessage= null;
+ String newText= txtWorkingSetName.getText();
+
+ if (! newText.equals(newText.trim()))
+ errorMessage = ExpressionWorkingSetMessages.Error_whitespace;
+ if (newText.equals("")) { //$NON-NLS-1$
+ if (isFirstCheck) {
+ setPageComplete(false);
+ isFirstCheck= false;
+ return;
+ }
+ errorMessage = ExpressionWorkingSetMessages.Error_emptyName;
+ }
+ isFirstCheck = false;
+ if (errorMessage == null && (workingSet == null || newText.equals(workingSet.getName()) == false)) {
+ IWorkingSet[] workingSets= PlatformUI.getWorkbench().getWorkingSetManager().getWorkingSets();
+ for (int i= 0; i < workingSets.length; i++) {
+ if (newText.equals(workingSets[i].getName())) {
+ errorMessage = ExpressionWorkingSetMessages.Error_nameExists;
+ }
+ }
+ }
+ setErrorMessage(errorMessage);
+ setPageComplete(errorMessage == null);
+ }
+}
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/expression/workingset/ExpressionWorkingSetsAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/expression/workingset/ExpressionWorkingSetsAction.java
new file mode 100644
index 0000000..646ffd7
--- /dev/null
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/expression/workingset/ExpressionWorkingSetsAction.java
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Tensilica Inc 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:
+ * Abeer Bagul (Tensilica Inc) - initial API and implementation (Bug 372181)
+ *******************************************************************************/
+package org.eclipse.debug.internal.ui.expression.workingset;
+
+import org.eclipse.debug.internal.ui.views.expression.ExpressionView;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.ui.IActionDelegate2;
+import org.eclipse.ui.IViewActionDelegate;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IWorkingSet;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.dialogs.IWorkingSetSelectionDialog;
+
+/**
+ * Opens the Working set wizard where user can define expression working sets.
+ * @since 3.9
+ */
+public class ExpressionWorkingSetsAction implements IViewActionDelegate,
+ IActionDelegate2 {
+
+ private ExpressionView fView;
+
+ public void run(IAction action) {
+ IWorkingSetSelectionDialog selectionDialog = PlatformUI.getWorkbench().getWorkingSetManager().createWorkingSetSelectionDialog(
+ PlatformUI.getWorkbench().getDisplay().getActiveShell(),
+ true,
+ new String[] {IExpressionWorkingSetConstants.EXPRESSION_WORKINGSET_ID});
+
+ selectionDialog.setSelection(ExpressionWorkingSetFilterManager.getWorkingSets(fView));
+
+ if (selectionDialog.open() != Window.OK)
+ return;
+
+ IWorkingSet[] selectedWorkingSets = selectionDialog.getSelection();
+ if (selectedWorkingSets == null)
+ return;
+
+ ExpressionWorkingSetFilterManager.applyWorkingSets(fView, selectedWorkingSets);
+ }
+
+ public void selectionChanged(IAction action, ISelection selection) {
+
+ }
+
+ public void init(IAction action) {
+
+ }
+
+ public void dispose() {
+ fView = null;
+ }
+
+ public void runWithEvent(IAction action, Event event) {
+ run(action);
+ }
+
+ public void init(IViewPart view) {
+ fView = (ExpressionView) view;
+ }
+
+}
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/expression/workingset/IExpressionWorkingSetConstants.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/expression/workingset/IExpressionWorkingSetConstants.java
new file mode 100644
index 0000000..b1146d8
--- /dev/null
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/expression/workingset/IExpressionWorkingSetConstants.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Tensilica Inc 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:
+ * Abeer Bagul (Tensilica Inc) - initial API and implementation (Bug 372181)
+ *******************************************************************************/
+package org.eclipse.debug.internal.ui.expression.workingset;
+
+/**
+ * @since 3.9
+ */
+public interface IExpressionWorkingSetConstants
+{
+ /**
+ * Identifier for expression working set type.
+ * <br>
+ * Value is: <code>org.eclipse.cdt.dsf.ui.expressionWorkingSet</code>
+ *
+ */
+ public static final String EXPRESSION_WORKINGSET_ID = "org.eclipse.debug.ui.expressionWorkingSet"; //$NON-NLS-1$
+}
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 ea88465..227b6fe 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
@@ -8,6 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
* Wind Rvier Systems - added support for columns (bug 235646)
+ * Abeer Bagul (Tensilica) - Working set support for Expressions view (bug 372181)
*******************************************************************************/
package org.eclipse.debug.internal.ui.model.elements;
@@ -22,11 +23,13 @@ import org.eclipse.debug.internal.core.IInternalDebugCoreConstants;
import org.eclipse.debug.internal.ui.DebugUIMessages;
import org.eclipse.debug.internal.ui.DefaultLabelProvider;
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
+import org.eclipse.debug.internal.ui.expression.workingset.ExpressionWorkingSetFilterManager;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementEditor;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementLabelProvider;
import org.eclipse.debug.internal.ui.viewers.model.provisional.ILabelUpdate;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerUpdate;
+import org.eclipse.debug.internal.ui.views.expression.ExpressionView;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.debug.ui.IDebugUIConstants;
import org.eclipse.jface.resource.JFaceResources;
@@ -36,6 +39,9 @@ import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkingSet;
+import org.eclipse.ui.PlatformUI;
/**
* Default content provider for the expression manager.
@@ -48,10 +54,33 @@ public class ExpressionManagerContentProvider extends ElementContentProvider {
*
* @since 3.6
*/
- private static class AddNewExpressionElement implements IElementLabelProvider, IElementEditor, ICellModifier {
+ private static class AddNewExpressionElement implements IElementLabelProvider, IElementEditor, ICellModifier, IAddNewExpression {
+ /* Record the working sets applied to this view (none if null).
+ * When a new expression is created, add it to applied working sets.
+ */
+ private String[] workingSetNames = null;
+
public void update(ILabelUpdate[] updates) {
+
+ workingSetNames = null;
+
for (int i = 0; i < updates.length; i++) {
+
+ if (i == 0)
+ {
+ //from the presentation context, find out the list of
+ //working sets applied to this view.
+ IWorkbenchPart expressionView = updates[i].getPresentationContext().getPart();
+ IWorkingSet[] workingSets = ExpressionWorkingSetFilterManager.getWorkingSets((ExpressionView) expressionView);
+ if (workingSets.length > 0)
+ workingSetNames = new String[workingSets.length];
+ for (int j=0; j<workingSets.length; j++)
+ {
+ workingSetNames[j] = workingSets[j].getName();
+ }
+ }
+
String[] columnIds = updates[i].getColumnIds();
if (columnIds == null) {
updateLabel(updates[i], 0);
@@ -107,6 +136,23 @@ public class ExpressionManagerContentProvider extends ElementContentProvider {
DebugPlugin.getDefault().getExpressionManager().newWatchExpression(expressionText);
DebugPlugin.getDefault().getExpressionManager().addExpression(newExpression);
newExpression.setExpressionContext(getContext());
+
+ //if any working sets are applied to this view,
+ //add this expression to all applied working sets,
+ //otherwise it will be filtered out from the view.
+ if (workingSetNames != null)
+ {
+ for (int i=0; i<workingSetNames.length; i++)
+ {
+ String workingSetName = workingSetNames[i];
+ IWorkingSet workingSet = PlatformUI.getWorkbench().getWorkingSetManager().getWorkingSet(workingSetName);
+ IAdaptable[] existingElements = workingSet.getElements();
+ IAdaptable[] newElements = new IAdaptable[existingElements.length + 1];
+ System.arraycopy(existingElements, 0, newElements, 0, existingElements.length);
+ newElements[newElements.length - 1] = newExpression;
+ workingSet.setElements(newElements);
+ }
+ }
}
}
@@ -120,7 +166,6 @@ public class ExpressionManagerContentProvider extends ElementContentProvider {
}
return context;
}
-
}
private static final AddNewExpressionElement ADD_NEW_EXPRESSION_ELEMENT = new AddNewExpressionElement();
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/model/elements/IAddNewExpression.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/model/elements/IAddNewExpression.java
new file mode 100644
index 0000000..77aeebd
--- /dev/null
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/model/elements/IAddNewExpression.java
@@ -0,0 +1,20 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Tensilica Inc 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:
+ * Abeer Bagul (Tensilica Inc) - initial API and implementation (Bug 372181)
+ *******************************************************************************/
+package org.eclipse.debug.internal.ui.model.elements;
+
+/**
+ * A marker interface to be implemented by objects which represent the "Add new expression" node in Expressions view.
+ * An object which implements this interface will always be visible in the view,
+ * even if user has selected working sets to filter expressions visible in the view.
+ */
+public interface IAddNewExpression {
+
+}