From 435afec99439c7c3a13e4ae90d494e9a14e45dde Mon Sep 17 00:00:00 2001 From: Pawel Piech Date: Thu, 8 Mar 2012 11:30:14 -0800 Subject: [PATCH] Bug 344023 - [var] Need a way to override Find action of Variables view and its derived classes --- org.eclipse.debug.examples.ui/plugin.xml | 9 +- .../examples/ui/pda/adapters/AdapterFactory.java | 10 +- .../ui/pda/adapters/PDAVirtualFindAction.java | 317 ++++++++++++++++++++ .../ui/pda/adapters/ViewActionProvider.java | 59 ++++ .../model/provisional/IViewActionProvider.java | 34 ++ .../ui/views/breakpoints/BreakpointsView.java | 12 +- .../ui/views/expression/ExpressionView.java | 6 +- .../internal/ui/views/modules/ModulesView.java | 2 +- .../internal/ui/views/variables/VariablesView.java | 136 ++++++--- .../ui/org/eclipse/debug/ui/AbstractDebugView.java | 1 + 10 files changed, 526 insertions(+), 60 deletions(-) create mode 100644 org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/adapters/PDAVirtualFindAction.java create mode 100644 org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/adapters/ViewActionProvider.java create mode 100644 org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/provisional/IViewActionProvider.java diff --git a/org.eclipse.debug.examples.ui/plugin.xml b/org.eclipse.debug.examples.ui/plugin.xml index f773254..5b1382d 100644 --- a/org.eclipse.debug.examples.ui/plugin.xml +++ b/org.eclipse.debug.examples.ui/plugin.xml @@ -229,7 +229,6 @@ --> - + + + + 0 ); + } + +} diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/adapters/ViewActionProvider.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/adapters/ViewActionProvider.java new file mode 100644 index 0000000..61ff466 --- /dev/null +++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/adapters/ViewActionProvider.java @@ -0,0 +1,59 @@ +/** + * + */ +package org.eclipse.debug.examples.ui.pda.adapters; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.debug.internal.ui.viewers.model.VirtualFindAction; +import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext; +import org.eclipse.debug.internal.ui.viewers.model.provisional.IViewActionProvider; +import org.eclipse.debug.internal.ui.viewers.model.provisional.TreeModelViewer; +import org.eclipse.debug.internal.ui.viewers.model.provisional.VirtualTreeModelViewer; +import org.eclipse.debug.ui.IDebugUIConstants; +import org.eclipse.debug.ui.IDebugView; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IAction; +import org.eclipse.swt.SWT; +import org.eclipse.ui.texteditor.IUpdate; + +/** + * @author pawel + * + */ +public class ViewActionProvider implements IViewActionProvider { + + Map fActions = new HashMap(); + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.ui.viewers.model.provisional.IViewActionProvider#getAction(org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext, java.lang.String) + */ + public IAction getAction(IPresentationContext presentationContext, String actionID) { + if (presentationContext.getId().equals(IDebugUIConstants.ID_VARIABLE_VIEW) && + IDebugView.FIND_ACTION.equals(actionID) ) + { + Action action = (Action)fActions.get(presentationContext); + if (action == null) { + action = new PDAVirtualFindAction(presentationContext); + fActions.put(presentationContext, action); + } + return action; + } + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.ui.viewers.model.provisional.IViewActionProvider#getUpdatables(org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext) + */ + public IUpdate[] getUpdatables(IPresentationContext presentationContext) { + IUpdate action = (IUpdate)fActions.get(presentationContext); + if (action != null) { + action = new PDAVirtualFindAction(presentationContext); + fActions.put(presentationContext, action); + return new IUpdate[] {action}; + } + return new IUpdate[0]; + } + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/provisional/IViewActionProvider.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/provisional/IViewActionProvider.java new file mode 100644 index 0000000..eef1c1b --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/provisional/IViewActionProvider.java @@ -0,0 +1,34 @@ +/***************************************************************** + * Copyright (c) 2012 Texas Instruments 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: + * Texas Instruments - View action override (Bug 344023) + *****************************************************************/ +package org.eclipse.debug.internal.ui.viewers.model.provisional; + +import org.eclipse.jface.action.IAction; + + +/** + * Action provider allows a debug model to override the standard actions in the + * variables view. The client should return this provider as an adapter to the + * input element of the variables view. + * + * @since 3.8 + */ +public interface IViewActionProvider { + /** + * Get action for a given presentation context and action id. Implementation + * should return an action implementation appropriate for given view and action ID. + * The implementation may registerter itself as listener to presentation context + * to determine when to dispose the returned action. + * @param presentationContext presentation context + * @param actionID action id + * @return action or null + */ + public IAction getAction(IPresentationContext presentationContext, String actionID); +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/breakpoints/BreakpointsView.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/breakpoints/BreakpointsView.java index 10e6855..a7d12ef 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/breakpoints/BreakpointsView.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/breakpoints/BreakpointsView.java @@ -69,6 +69,7 @@ import org.eclipse.debug.internal.ui.breakpoints.provisional.IBreakpointOrganize import org.eclipse.debug.internal.ui.breakpoints.provisional.IBreakpointUIConstants; import org.eclipse.debug.internal.ui.elements.adapters.DefaultBreakpointsViewInput; import org.eclipse.debug.internal.ui.preferences.IDebugPreferenceConstants; +import org.eclipse.debug.internal.ui.viewers.model.VirtualFindAction; import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelDelta; import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext; import org.eclipse.debug.internal.ui.viewers.model.provisional.ITreeModelViewer; @@ -250,7 +251,8 @@ public class BreakpointsView extends VariablesView implements IBreakpointManager PasteBreakpointsAction paste = new PasteBreakpointsAction(this); setAction(PASTE_ACTION, paste); paste.setActionDefinitionId(ActionFactory.PASTE.getCommandId()); - actionBars.setGlobalActionHandler(ActionFactory.PASTE.getId(), paste); + //actionBars.setGlobalActionHandler(ActionFactory.PASTE.getId(), paste); + setGlobalAction(ActionFactory.PASTE.getId(), paste); getViewer().addSelectionChangedListener(paste); paste.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_PASTE)); @@ -263,9 +265,11 @@ public class BreakpointsView extends VariablesView implements IBreakpointManager fUndoAction.setActionDefinitionId(IWorkbenchCommandConstants.EDIT_UNDO); fRedoAction= new RedoActionHandler(getSite(), undoContext); fRedoAction.setActionDefinitionId(IWorkbenchCommandConstants.EDIT_REDO); - actionBars.setGlobalActionHandler(ActionFactory.UNDO.getId(), fUndoAction); - actionBars.setGlobalActionHandler(ActionFactory.REDO.getId(), fRedoAction); - + //actionBars.setGlobalActionHandler(ActionFactory.UNDO.getId(), fUndoAction); + //actionBars.setGlobalActionHandler(ActionFactory.REDO.getId(), fRedoAction); + setGlobalAction(ActionFactory.UNDO.getId(), fUndoAction); + setGlobalAction(ActionFactory.REDO.getId(), fRedoAction); + setGlobalAction(FIND_ACTION, new VirtualFindAction(getVariablesViewer())); } /* 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 5cc4ef9..c92b88c 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 @@ -83,7 +83,7 @@ public class ExpressionView extends VariablesView { protected void fillContextMenu(IMenuManager menu) { menu.add(new Separator(IDebugUIConstants.EMPTY_EXPRESSION_GROUP)); menu.add(new Separator(IDebugUIConstants.EXPRESSION_GROUP)); - menu.add(getAction(VARIABLES_FIND_ELEMENT_ACTION)); + menu.add(getAction(FIND_ACTION)); ChangeVariableValueAction changeValueAction = (ChangeVariableValueAction)getAction("ChangeVariableValue"); //$NON-NLS-1$ if (changeValueAction.isApplicable()) { menu.add(changeValueAction); @@ -128,7 +128,6 @@ public class ExpressionView extends VariablesView { } else { setViewerInput(DebugPlugin.getDefault().getExpressionManager()); } - updateAction(VARIABLES_FIND_ELEMENT_ACTION); updateAction(FIND_ACTION); } @@ -170,7 +169,6 @@ public class ExpressionView extends VariablesView { configure(fPasteAction, IWorkbenchCommandConstants.EDIT_PASTE, PASTE_ACTION, ISharedImages.IMG_TOOL_PASTE); fEditInPlaceAction = new EditWatchExpressinInPlaceAction(this); configure(fEditInPlaceAction, IWorkbenchCommandConstants.FILE_RENAME, ActionFactory.RENAME.getId(), null); - } public void dispose() { @@ -195,7 +193,7 @@ public class ExpressionView extends VariablesView { String imgId) { setAction(defId, action); action.setActionDefinitionId(defId); - getViewSite().getActionBars().setGlobalActionHandler(globalId, action); + setGlobalAction(globalId, action); if (imgId != null) { action.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(imgId)); } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/modules/ModulesView.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/modules/ModulesView.java index 2a98515..dfe0b55 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/modules/ModulesView.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/modules/ModulesView.java @@ -60,7 +60,7 @@ public class ModulesView extends VariablesView { protected void fillContextMenu( IMenuManager menu ) { menu.add( new Separator( IDebugUIConstants.EMPTY_MODULES_GROUP ) ); menu.add( new Separator( IDebugUIConstants.MODULES_GROUP ) ); - menu.add(getAction(VARIABLES_FIND_ELEMENT_ACTION)); + menu.add(getAction(FIND_ACTION)); menu.add(new Separator()); IAction action = new AvailableDetailPanesAction(this); if (isDetailPaneVisible() && action.isEnabled()) { diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/VariablesView.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/VariablesView.java index 4f4b4a4..a204c41 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/VariablesView.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/VariablesView.java @@ -24,6 +24,9 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; @@ -31,6 +34,7 @@ import org.eclipse.core.runtime.ListenerList; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.debug.core.DebugException; +import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.internal.ui.DebugUIPlugin; import org.eclipse.debug.internal.ui.DelegatingModelPresentation; import org.eclipse.debug.internal.ui.IDebugHelpContextIds; @@ -49,6 +53,7 @@ import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelDelta; import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelDeltaVisitor; import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelProxy; import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext; +import org.eclipse.debug.internal.ui.viewers.model.provisional.IViewActionProvider; import org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerInputRequestor; import org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerInputUpdate; import org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerUpdate; @@ -284,6 +289,8 @@ public class VariablesView extends AbstractDebugView implements IDebugContextLis */ private ViewerInputService fInputService; + private Map fGlobalActionMap = new HashMap(); + /** * Viewer input requester used to update the viewer once the viewer input has been * resolved. @@ -333,27 +340,7 @@ public class VariablesView extends AbstractDebugView implements IDebugContextLis * Sash weights for a specific detail pane type */ protected static final String DETAIL_PANE_TYPE = "DETAIL_PANE_TYPE"; //$NON-NLS-1$ - - /** - * Key for "Find..." action. - */ - protected static final String VARIABLES_FIND_ELEMENT_ACTION = FIND_ACTION + ".Variables"; //$NON-NLS-1$ - - /** - * Key for "Select All" action. - */ - protected static final String VARIABLES_SELECT_ALL_ACTION = SELECT_ALL_ACTION + ".Variables"; //$NON-NLS-1$ - - /** - * Key for "Copy" action. - */ - protected static final String VARIABLES_COPY_ACTION = COPY_ACTION + ".Variables"; //$NON-NLS-1$ - - /** - * Key for "Paste" action. - */ - protected static final String VARIABLES_PASTE_ACTION = PASTE_ACTION + ".Variables"; //$NON-NLS-1$ - + /** * Visits deltas to determine if details should be displayed */ @@ -449,7 +436,6 @@ public class VariablesView extends AbstractDebugView implements IDebugContextLis */ protected void viewerInputUpdateComplete(IViewerInputUpdate update) { setViewerInput(update.getInputElement()); - updateAction(VARIABLES_FIND_ELEMENT_ACTION); updateAction(FIND_ACTION); } @@ -657,7 +643,7 @@ public class VariablesView extends AbstractDebugView implements IDebugContextLis protected String getDetailPanePreferenceKey() { return IDebugPreferenceConstants.VARIABLES_DETAIL_PANE_ORIENTATION; } - + /** * Create and return the main tree viewer that displays variable. */ @@ -671,11 +657,7 @@ public class VariablesView extends AbstractDebugView implements IDebugContextLis public void focusGained(FocusEvent e) { fTreeHasFocus = true; fSelectionProvider.setActiveProvider(variablesViewer); - setAction(SELECT_ALL_ACTION, getAction(VARIABLES_SELECT_ALL_ACTION)); - setAction(COPY_ACTION, getAction(VARIABLES_COPY_ACTION)); - setAction(PASTE_ACTION, getAction(VARIABLES_PASTE_ACTION)); - setAction(FIND_ACTION, getAction(VARIABLES_FIND_ELEMENT_ACTION)); - getViewSite().getActionBars().updateActionBars(); + setGlobalActions(); } public void focusLost(FocusEvent e){ @@ -683,10 +665,7 @@ public class VariablesView extends AbstractDebugView implements IDebugContextLis // This should allow toolbar actions to remain active when the view // is de-activated but still visible. // Bug 316850. - setAction(SELECT_ALL_ACTION, null); - setAction(COPY_ACTION,null); - setAction(FIND_ACTION, null); - setAction(PASTE_ACTION, null); + clearGlobalActions(); getViewSite().getActionBars().updateActionBars(); } }); @@ -708,8 +687,29 @@ public class VariablesView extends AbstractDebugView implements IDebugContextLis return variablesViewer; } - - + private void setGlobalActions() { + for (Iterator entryItr = fGlobalActionMap.entrySet().iterator(); entryItr.hasNext();) { + Map.Entry entry = (Map.Entry)entryItr.next(); + String actionID = (String)entry.getKey(); + IAction action = getOverrideAction(actionID); + if (action == null) { + action = (IAction)entry.getValue(); + } + setAction(actionID, action); + } + getViewSite().getActionBars().updateActionBars(); + System.out.println("set " + getSite().getId()); + } + + private void clearGlobalActions() { + for (Iterator keyItr = fGlobalActionMap.keySet().iterator(); keyItr.hasNext();) { + String id = (String)keyItr.next(); + setAction(id, null); + } + getViewSite().getActionBars().updateActionBars(); + System.out.println("cleared " + getSite().getId()); + } + /** * Returns the active debug context for this view based on the view's * site IDs. @@ -929,21 +929,59 @@ public class VariablesView extends AbstractDebugView implements IDebugContextLis setAction("ChangeVariableValue", action); //$NON-NLS-1$ action= new VirtualFindAction(getVariablesViewer()); - setAction(VARIABLES_FIND_ELEMENT_ACTION, action); + setGlobalAction(FIND_ACTION, action); } - - /* (non-Javadoc) + + /** + * Adds the given action to the set of global actions managed by this + * variables view. Global actions are cleard and reset whenever the detail + * pane is activated to allow the detail pane to set the actions as + * well. * - * Save the copy action so we can restore it on focus lost/gain + * @param actionID Action ID that the given action implements. + * @param action Action implementation. * - * @see org.eclipse.debug.ui.AbstractDebugView#createContextMenu(org.eclipse.swt.widgets.Control) + * @since 3.8 */ - protected void createContextMenu(Control menuControl) { - super.createContextMenu(menuControl); - setAction(VARIABLES_COPY_ACTION, getAction(COPY_ACTION)); - setAction(VARIABLES_PASTE_ACTION, getAction(PASTE_ACTION)); + protected void setGlobalAction(String actionID, IAction action) { + fGlobalActionMap.put(actionID, action); } - + + public IAction getAction(String actionID) { + // Check if model overrides the action. Global action overrides are + // checked in setGlobalActions() so skip them here. + if (!fGlobalActionMap.containsKey(actionID)) { + IAction overrideAction = getOverrideAction(actionID); + if (overrideAction != null) { + return overrideAction; + } + } + return super.getAction(actionID); + } + + private IAction getOverrideAction(String actionID) { + Viewer viewer = getViewer(); + if (viewer != null) { + IViewActionProvider actionProvider = (IViewActionProvider) DebugPlugin.getAdapter( + viewer.getInput(), IViewActionProvider.class); + if (actionProvider != null) { + IAction action = actionProvider.getAction(getPresentationContext(), actionID); + if (action != null) { + return action; + } + } + } + return null; + } + + public void updateObjects() { + super.updateObjects(); + if (fTreeHasFocus) { + setGlobalActions(); + getViewSite().getActionBars().updateActionBars(); + } + } + /** * Creates the actions that allow the orientation of the detail pane to be changed. * @@ -1020,10 +1058,9 @@ public class VariablesView extends AbstractDebugView implements IDebugContextLis * @param menu The menu to add the item to. */ protected void fillContextMenu(IMenuManager menu) { - menu.add(new Separator(IDebugUIConstants.EMPTY_VARIABLE_GROUP)); menu.add(new Separator(IDebugUIConstants.VARIABLE_GROUP)); - menu.add(getAction(VARIABLES_FIND_ELEMENT_ACTION)); + menu.add(getAction(FIND_ACTION)); ChangeVariableValueAction changeValueAction = (ChangeVariableValueAction)getAction("ChangeVariableValue"); //$NON-NLS-1$ if (changeValueAction.isApplicable()) { menu.add(changeValueAction); @@ -1182,6 +1219,9 @@ public class VariablesView extends AbstractDebugView implements IDebugContextLis */ protected void updateAction(String actionId) { IAction action= getAction(actionId); + if (action == null) { + action = (IAction)fGlobalActionMap.get(actionId); + } if (action instanceof IUpdate) { ((IUpdate) action).update(); } @@ -1365,7 +1405,7 @@ public class VariablesView extends AbstractDebugView implements IDebugContextLis fVisitor.reset(); delta.accept(fVisitor); - updateAction(VARIABLES_FIND_ELEMENT_ACTION); + updateAction(FIND_ACTION); updateAction("CollapseAll"); } @@ -1381,7 +1421,7 @@ public class VariablesView extends AbstractDebugView implements IDebugContextLis showViewer(); } if (TreePath.EMPTY.equals(update.getElementPath())) { - updateAction(VARIABLES_FIND_ELEMENT_ACTION); + updateAction(FIND_ACTION); updateAction("CollapseAll"); } } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/AbstractDebugView.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/AbstractDebugView.java index 4a0e03c..36ad556 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/AbstractDebugView.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/AbstractDebugView.java @@ -161,6 +161,7 @@ public abstract class AbstractDebugView extends PageBookView implements IDebugVi fgGlobalActionIds.add(FIND_ACTION); fgGlobalActionIds.add(ActionFactory.UNDO.getId()); fgGlobalActionIds.add(ActionFactory.REDO.getId()); + fgGlobalActionIds.add(ActionFactory.RENAME.getId()); } /** -- 1.7.5.4