diff options
author | Pawel Piech | 2012-03-09 23:11:22 +0000 |
---|---|---|
committer | Pawel Piech | 2012-03-09 23:11:22 +0000 |
commit | 64678065cd9fed43d2a1141912ece7672ca192c6 (patch) | |
tree | 165ce61655cf40e327456742db25b973cb8defd6 | |
parent | c98ef3633d90d05ac5a82c928a9e20cd46435f3f (diff) | |
download | eclipse.platform.debug-64678065cd9fed43d2a1141912ece7672ca192c6.tar.gz eclipse.platform.debug-64678065cd9fed43d2a1141912ece7672ca192c6.tar.xz eclipse.platform.debug-64678065cd9fed43d2a1141912ece7672ca192c6.zip |
Bug 344023 - [var] Need a way to override Find action of Variablesv20120309-2311
view and its derived classes
Standardized action IDs used in variables views.
11 files changed, 531 insertions, 125 deletions
diff --git a/org.eclipse.debug.examples.ui/META-INF/MANIFEST.MF b/org.eclipse.debug.examples.ui/META-INF/MANIFEST.MF index a6f793240..1aef3d1ad 100644 --- a/org.eclipse.debug.examples.ui/META-INF/MANIFEST.MF +++ b/org.eclipse.debug.examples.ui/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %Bundle-Name Bundle-SymbolicName: org.eclipse.debug.examples.ui;singleton:=true -Bundle-Version: 1.3.100.qualifier +Bundle-Version: 1.4.0.qualifier Bundle-Activator: org.eclipse.debug.examples.ui.pda.DebugUIPlugin Require-Bundle: org.eclipse.core.runtime, org.eclipse.core.resources, diff --git a/org.eclipse.debug.examples.ui/plugin.xml b/org.eclipse.debug.examples.ui/plugin.xml index f773254fd..5b1382d09 100644 --- a/org.eclipse.debug.examples.ui/plugin.xml +++ b/org.eclipse.debug.examples.ui/plugin.xml @@ -229,7 +229,6 @@ </adapter> </factory> --> -<!-- FLEXIBLE HIERARCHY EXAMPLE <factory adaptableType="org.eclipse.debug.examples.core.pda.model.PDADebugTarget" class="org.eclipse.debug.examples.ui.pda.adapters.AdapterFactory"> @@ -240,7 +239,13 @@ type="org.eclipse.debug.internal.ui.viewers.model.provisional.IModelProxyFactory"> </adapter> </factory> ---> + <factory + adaptableType="org.eclipse.debug.examples.core.pda.model.PDAStackFrame" + class="org.eclipse.debug.examples.ui.pda.adapters.AdapterFactory"> + <adapter + type="org.eclipse.debug.internal.ui.viewers.model.provisional.IViewActionProvider"> + </adapter> + </factory> </extension> <extension diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/adapters/AdapterFactory.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/adapters/AdapterFactory.java index 3e4153fd5..7034432bc 100644 --- a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/adapters/AdapterFactory.java +++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/adapters/AdapterFactory.java @@ -13,8 +13,10 @@ package org.eclipse.debug.examples.ui.pda.adapters; import org.eclipse.core.runtime.IAdapterFactory; import org.eclipse.debug.examples.core.pda.model.PDADebugTarget; +import org.eclipse.debug.examples.core.pda.model.PDAStackFrame; import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementContentProvider; import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelProxyFactory; +import org.eclipse.debug.internal.ui.viewers.model.provisional.IViewActionProvider; /** @@ -26,6 +28,7 @@ public class AdapterFactory implements IAdapterFactory { private static IElementContentProvider fgTargetAdapter = new PDADebugTargetContentProvider(); private static IModelProxyFactory fgFactory = new ModelProxyFactory(); + private static IViewActionProvider fgViewActionProvider = new PDAViewActionProvider(); public Object getAdapter(Object adaptableObject, Class adapterType) { if (IElementContentProvider.class.equals(adapterType)) { @@ -38,11 +41,16 @@ public class AdapterFactory implements IAdapterFactory { return fgFactory; } } + if (IViewActionProvider.class.equals(adapterType)) { + if (adaptableObject instanceof PDAStackFrame) { + return fgViewActionProvider; + } + } return null; } public Class[] getAdapterList() { - return new Class[]{IElementContentProvider.class, IModelProxyFactory.class}; + return new Class[]{IElementContentProvider.class, IModelProxyFactory.class, IViewActionProvider.class}; } } diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/adapters/PDAViewActionProvider.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/adapters/PDAViewActionProvider.java new file mode 100644 index 000000000..cb575878e --- /dev/null +++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/adapters/PDAViewActionProvider.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2012 Wind River Systems 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: + * Wind River Systems - initial implementation + */ +package org.eclipse.debug.examples.ui.pda.adapters; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext; +import org.eclipse.debug.internal.ui.viewers.model.provisional.IViewActionProvider; +import org.eclipse.debug.ui.IDebugUIConstants; +import org.eclipse.debug.ui.IDebugView; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IAction; + +/** + * View action provider that returns a custom find action for the PDA debugger + * in the variables view. + * @since 3.8 + */ +public class PDAViewActionProvider 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; + } +} diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/adapters/PDAVirtualFindAction.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/adapters/PDAVirtualFindAction.java new file mode 100644 index 000000000..bf0792e96 --- /dev/null +++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/adapters/PDAVirtualFindAction.java @@ -0,0 +1,317 @@ +/******************************************************************************* + * Copyright (c) 2004, 2010 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 implementation + * Pawel Piech (Wind River) - added a breadcrumb mode to Debug view (Bug 252677) + * Wind River Systems - refactored on top of VirtualTreeModelViewer + *******************************************************************************/ +package org.eclipse.debug.examples.ui.pda.adapters; + +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +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.IDebugHelpContextIds; +import org.eclipse.debug.internal.ui.viewers.FindElementDialog; +import org.eclipse.debug.internal.ui.viewers.model.ILabelUpdateListener; +import org.eclipse.debug.internal.ui.viewers.model.TimeTriggeredProgressMonitorDialog; +import org.eclipse.debug.internal.ui.viewers.model.provisional.IChildrenUpdate; +import org.eclipse.debug.internal.ui.viewers.model.provisional.ILabelUpdate; +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.IPresentationContext; +import org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerUpdate; +import org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerUpdateListener; +import org.eclipse.debug.internal.ui.viewers.model.provisional.ModelDelta; +import org.eclipse.debug.internal.ui.viewers.model.provisional.PresentationContext; +import org.eclipse.debug.internal.ui.viewers.model.provisional.TreeModelViewer; +import org.eclipse.debug.internal.ui.viewers.model.provisional.VirtualItem; +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.dialogs.ProgressMonitorDialog; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.TreePath; +import org.eclipse.jface.window.Window; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +import org.eclipse.ui.IWorkbenchCommandConstants; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.texteditor.IUpdate; + +/** + * Action which prompts user with a filtered list selection dialog to find an element in tree. + * + * @since 3.3 + */ +public class PDAVirtualFindAction extends Action implements IUpdate { + + private TreeModelViewer fClientViewer; + + protected class VirtualViewerListener implements IViewerUpdateListener, ILabelUpdateListener { + + private boolean fViewerUpdatesComplete = false; + private boolean fLabelUpdatesComplete = false; + private IProgressMonitor fProgressMonitor; + private int fRemainingUpdatesCount = 0; + + public void labelUpdateStarted(ILabelUpdate update) {} + public void labelUpdateComplete(ILabelUpdate update) { + incrementProgress(1); + } + public void labelUpdatesBegin() { + fLabelUpdatesComplete = false; + } + public void labelUpdatesComplete() { + fLabelUpdatesComplete = true; + completeProgress(); + } + + public void updateStarted(IViewerUpdate update) {} + public void updateComplete(IViewerUpdate update) { + if (update instanceof IChildrenUpdate) { + incrementProgress(((IChildrenUpdate)update).getLength()); + } + } + public void viewerUpdatesBegin() { + fViewerUpdatesComplete = false; + } + public void viewerUpdatesComplete() { + fViewerUpdatesComplete = true; + completeProgress(); + } + + private void completeProgress() { + IProgressMonitor pm; + synchronized (this) { + pm = fProgressMonitor; + } + if (pm != null && fLabelUpdatesComplete && fViewerUpdatesComplete) { + pm.done(); + } + } + + private void incrementProgress(int count) { + IProgressMonitor pm; + synchronized (this) { + pm = fProgressMonitor; + fRemainingUpdatesCount -= count; + } + if (pm != null && fLabelUpdatesComplete && fViewerUpdatesComplete) { + pm.worked(count); + } + } + + } + + private static class FindLabelProvider extends LabelProvider { + private VirtualTreeModelViewer fVirtualViewer; + private Map fTextCache = new HashMap(); + public FindLabelProvider(VirtualTreeModelViewer viewer, List items) { + fVirtualViewer = viewer; + for (int i = 0; i < items.size(); i++) { + VirtualItem item = (VirtualItem)items.get(i); + fTextCache.put(item, fVirtualViewer.getText(item, 0)); + } + } + + public Image getImage(Object element) { + return fVirtualViewer.getImage((VirtualItem) element, 0); + } + + public String getText(Object element) { + return (String)fTextCache.get(element); + } + } + + public PDAVirtualFindAction(IPresentationContext context) { + setText("Find"); + setId(DebugUIPlugin.getUniqueIdentifier() + ".FindElementAction"); //$NON-NLS-1$ + PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IDebugHelpContextIds.FIND_ELEMENT_ACTION); + setActionDefinitionId(IWorkbenchCommandConstants.EDIT_FIND_AND_REPLACE); + fClientViewer = (TreeModelViewer)((IDebugView)context.getPart()).getViewer(); + } + + protected VirtualTreeModelViewer initVirtualViewer(TreeModelViewer clientViewer, VirtualViewerListener listener) { + Object input = clientViewer.getInput(); + ModelDelta stateDelta = new ModelDelta(input, IModelDelta.NO_CHANGE); + clientViewer.saveElementState(TreePath.EMPTY, stateDelta, IModelDelta.EXPAND); + listener.fRemainingUpdatesCount = calcUpdatesCount(stateDelta); + VirtualTreeModelViewer fVirtualViewer = new VirtualTreeModelViewer( + clientViewer.getDisplay(), + SWT.NONE, + makeVirtualPresentationContext(clientViewer.getPresentationContext())); + fVirtualViewer.addViewerUpdateListener(listener); + fVirtualViewer.addLabelUpdateListener(listener); + fVirtualViewer.setInput(input); + if (fVirtualViewer.canToggleColumns()) { + fVirtualViewer.setShowColumns(clientViewer.isShowColumns()); + } + fVirtualViewer.updateViewer(stateDelta); + return fVirtualViewer; + } + + protected IPresentationContext makeVirtualPresentationContext(final IPresentationContext clientViewerContext) { + return new PresentationContext(clientViewerContext.getId()) { + + { + String[] clientProperties = clientViewerContext.getProperties(); + for (int i = 0; i < clientProperties.length; i++) { + setProperty(clientProperties[i], clientViewerContext.getProperty(clientProperties[i])); + } + + } + + public String[] getColumns() { + String[] clientColumns = super.getColumns(); + + if (clientColumns == null || clientColumns.length == 0) { + // No columns are used. + return null; + } + + // Try to find the name column. + for (int i = 0; i < clientColumns.length; i++) { + if (IDebugUIConstants.COLUMN_ID_VARIABLE_NAME.equals(clientColumns[i])) { + return new String[] { IDebugUIConstants.COLUMN_ID_VARIABLE_NAME }; + } + } + + return new String[] { clientColumns[0] }; + } + }; + } + + public void run() { + final VirtualViewerListener listener = new VirtualViewerListener(); + VirtualTreeModelViewer virtualViewer = initVirtualViewer(fClientViewer, listener); + + ProgressMonitorDialog dialog = new TimeTriggeredProgressMonitorDialog(fClientViewer.getControl().getShell(), 500); + final IProgressMonitor monitor = dialog.getProgressMonitor(); + dialog.setCancelable(true); + + try { + dialog.run( + true, true, + new IRunnableWithProgress() { + public void run(final IProgressMonitor m) throws InvocationTargetException, InterruptedException { + synchronized(listener) { + listener.fProgressMonitor = m; + listener.fProgressMonitor.beginTask(DebugUIPlugin.removeAccelerators(getText()), listener.fRemainingUpdatesCount); + } + + while ((!listener.fLabelUpdatesComplete || !listener.fViewerUpdatesComplete) && !listener.fProgressMonitor.isCanceled()) { + Thread.sleep(1); + } + synchronized(listener) { + listener.fProgressMonitor = null; + } + } + }); + } catch (InvocationTargetException e) { + DebugUIPlugin.log(e); + return; + } catch (InterruptedException e) { + return; + } + + VirtualItem root = virtualViewer.getTree(); + if (!monitor.isCanceled()) { + List list = new ArrayList(); + collectAllChildren(root, list); + FindLabelProvider labelProvider = new FindLabelProvider(virtualViewer, list); + VirtualItem result = performFind(list, labelProvider); + if (result != null) { + setSelectionToClient(virtualViewer, labelProvider, result); + } + } + + virtualViewer.removeLabelUpdateListener(listener); + virtualViewer.removeViewerUpdateListener(listener); + virtualViewer.dispose(); + } + + private int calcUpdatesCount(IModelDelta stateDelta) { + final int[] count = new int[] {0}; + stateDelta.accept( new IModelDeltaVisitor() { + public boolean visit(IModelDelta delta, int depth) { + if ((delta.getFlags() & IModelDelta.EXPAND) != 0) { + count[0] += delta.getChildCount(); + return true; + } + return false; + } + }); + + // Double it to account for separate element and label update ticks. + return count[0] * 2; + } + + private void collectAllChildren(VirtualItem element, List collect) { + VirtualItem[] children = element.getItems(); + if (children != null) { + for (int i = 0; i < children.length; i++) { + if (!children[i].needsLabelUpdate()) { + collect.add(children[i]); + collectAllChildren(children[i], collect); + } + } + } + } + + protected VirtualItem performFind(List items, FindLabelProvider labelProvider) { + FindElementDialog dialog = new FindElementDialog( + fClientViewer.getControl().getShell(), + labelProvider, + items.toArray()); + dialog.setTitle("PDA Variables View Find"); + dialog.setMessage("&Specify an element to select (? = any character, * = any String):"); + if (dialog.open() == Window.OK) { + Object[] elements = dialog.getResult(); + if (elements.length == 1) { + return (VirtualItem)elements[0]; + } + } + return null; + } + + protected void setSelectionToClient(VirtualTreeModelViewer virtualViewer, ILabelProvider labelProvider, VirtualItem findItem) { + virtualViewer.getTree().setSelection(new VirtualItem[] { findItem } ); + ModelDelta stateDelta = new ModelDelta(virtualViewer.getInput(), IModelDelta.NO_CHANGE); + virtualViewer.saveElementState(TreePath.EMPTY, stateDelta, IModelDelta.SELECT); + fClientViewer.updateViewer(stateDelta); + + ISelection selection = fClientViewer.getSelection(); + if (!selection.isEmpty() && + selection instanceof IStructuredSelection && + ((IStructuredSelection)selection).getFirstElement().equals(findItem.getData()) ) { + } else { + DebugUIPlugin.errorDialog( + fClientViewer.getControl().getShell(), + "Error", + "Could not select item:" + labelProvider.getText(findItem), + new Status(IStatus.ERROR, DebugUIPlugin.getUniqueIdentifier(), "Element no longer in viewer.")); + } + } + + public void update() { + setEnabled( fClientViewer.getInput() != null && fClientViewer.getChildCount(TreePath.EMPTY) > 0 ); + } + +} diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/provisional/IViewActionOverride.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/provisional/IViewActionProvider.java index 931d12369..b493d2ac8 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/provisional/IViewActionOverride.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/provisional/IViewActionProvider.java @@ -1,5 +1,5 @@ /***************************************************************** - * Copyright (c) 2011 Texas Instruments and others + * 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 @@ -14,22 +14,21 @@ import org.eclipse.jface.action.IAction; /** - * An interface that allows an implementation to provide (contribute) its own - * action which is used to override an action for the same action id. + * 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.7 + * @since 3.8 */ -public interface IViewActionOverride { +public interface IViewActionProvider { /** - * Get action for a given presentation context and action id. Implementation - * class can use presentation context to figure out the view part or view - * model (IVMProvider) which wants to provide (contribute) an action. Once - * the view part or view model is known, the dedicated action for the view - * can be figured out by the implementation, view model, or some other - * classes. + * 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 register 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 + * @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 10e6855e4..0a58e131e 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 @@ -18,41 +18,8 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; -import org.eclipse.swt.SWT; -import org.eclipse.swt.dnd.Clipboard; -import org.eclipse.swt.dnd.DND; -import org.eclipse.swt.dnd.Transfer; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.TreeItem; - import org.eclipse.core.commands.operations.IUndoContext; - import org.eclipse.core.runtime.IStatus; - -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.IToolBarManager; -import org.eclipse.jface.action.Separator; -import org.eclipse.jface.util.LocalSelectionTransfer; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.ITreeSelection; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.TreePath; -import org.eclipse.jface.viewers.Viewer; - -import org.eclipse.ui.IActionBars; -import org.eclipse.ui.IMemento; -import org.eclipse.ui.ISharedImages; -import org.eclipse.ui.IWorkbenchActionConstants; -import org.eclipse.ui.IWorkbenchCommandConstants; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.actions.ActionFactory; -import org.eclipse.ui.actions.SelectionListenerAction; -import org.eclipse.ui.operations.RedoActionHandler; -import org.eclipse.ui.operations.UndoActionHandler; - import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.IBreakpointManagerListener; import org.eclipse.debug.core.model.IBreakpoint; @@ -69,6 +36,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; @@ -81,11 +49,37 @@ import org.eclipse.debug.internal.ui.viewers.model.provisional.VirtualTreeModelV import org.eclipse.debug.internal.ui.views.DebugUIViewsMessages; import org.eclipse.debug.internal.ui.views.variables.VariablesView; import org.eclipse.debug.internal.ui.views.variables.details.AvailableDetailPanesAction; - import org.eclipse.debug.ui.DebugUITools; import org.eclipse.debug.ui.IBreakpointOrganizerDelegateExtension; import org.eclipse.debug.ui.IDebugModelPresentation; import org.eclipse.debug.ui.IDebugUIConstants; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.action.Separator; +import org.eclipse.jface.util.LocalSelectionTransfer; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.ITreeSelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TreePath; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.dnd.Clipboard; +import org.eclipse.swt.dnd.DND; +import org.eclipse.swt.dnd.Transfer; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.TreeItem; +import org.eclipse.ui.IMemento; +import org.eclipse.ui.ISharedImages; +import org.eclipse.ui.IWorkbenchActionConstants; +import org.eclipse.ui.IWorkbenchCommandConstants; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.actions.ActionFactory; +import org.eclipse.ui.actions.SelectionListenerAction; +import org.eclipse.ui.operations.RedoActionHandler; +import org.eclipse.ui.operations.UndoActionHandler; /** * This class implements the breakpoints view. @@ -245,12 +239,12 @@ public class BreakpointsView extends VariablesView implements IBreakpointManager DebugPlugin.getDefault().getBreakpointManager().addBreakpointManagerListener(this); fClipboard = new Clipboard(getSite().getShell().getDisplay()); - IActionBars actionBars= getViewSite().getActionBars(); 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 +257,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 5cc4ef9e8..c92b88ce3 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 2a98515d5..dfe0b55d3 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 615faa630..df9af2dd3 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,14 +24,17 @@ 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.IAdaptable; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; 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; @@ -44,15 +47,13 @@ import org.eclipse.debug.internal.ui.actions.variables.ChangeVariableValueAction import org.eclipse.debug.internal.ui.actions.variables.ShowTypesAction; import org.eclipse.debug.internal.ui.actions.variables.ToggleDetailPaneAction; import org.eclipse.debug.internal.ui.preferences.IDebugPreferenceConstants; -import org.eclipse.debug.internal.ui.viewers.model.ViewerAdapterService; import org.eclipse.debug.internal.ui.viewers.model.VirtualFindAction; import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelChangedListener; 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.IViewActionOverride; -import org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerInputProvider; +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; @@ -288,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. @@ -337,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 */ @@ -453,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); } @@ -595,7 +577,7 @@ public class VariablesView extends AbstractDebugView implements IDebugContextLis /** * Returns sash weights stored in the given memento or <code>null</code> if none. * - * @param memento + * @param memento Memento to read sash weights from * @return sash weights or <code>null</code> */ private int[] getWeights(IMemento memento) { @@ -661,9 +643,11 @@ 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. + * @param parent Viewer's parent control + * @return The created viewer. */ protected TreeModelViewer createTreeViewer(Composite parent) { @@ -675,11 +659,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){ @@ -687,10 +667,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(); } }); @@ -712,12 +689,33 @@ 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(); + } + + private void clearGlobalActions() { + for (Iterator keyItr = fGlobalActionMap.keySet().iterator(); keyItr.hasNext();) { + String id = (String)keyItr.next(); + setAction(id, null); + } + getViewSite().getActionBars().updateActionBars(); + } + /** * Returns the active debug context for this view based on the view's * site IDs. * + * @return Active debug context for this view. + * * @since 3.7 */ protected ISelection getDebugContext() { @@ -793,6 +791,11 @@ public class VariablesView extends AbstractDebugView implements IDebugContextLis * - underneath the main tree view * - to the right of the main tree view * - not visible + * @param orientation Detail pane orientation to set. + * + * @see IDebugPreferenceConstants#VARIABLES_DETAIL_PANE_AUTO + * @see IDebugPreferenceConstants#VARIABLES_DETAIL_PANE_HIDDEN + * @see IDebugPreferenceConstants#VARIABLES_DETAIL_PANE_UNDERNEATH */ public void setDetailPaneOrientation(String orientation) { if (!IDebugPreferenceConstants.VARIABLES_DETAIL_PANE_AUTO.equals(orientation) && orientation.equals(fCurrentDetailPaneOrientation)) { @@ -891,6 +894,7 @@ public class VariablesView extends AbstractDebugView implements IDebugContextLis * <li> both panes have not yet been made visible</li> * <li> one of the values persisted before is an invalid value</li> * </ul> + * @return The last sash weights. */ protected int[] getLastSashWeights() { if (fLastSashWeights == null) { @@ -906,6 +910,7 @@ public class VariablesView extends AbstractDebugView implements IDebugContextLis /** * Set the current relative weights of the controls in the sash form, so that * the sash form can be reset to this layout at a later time. + * @param weights Weight to add. */ protected void setLastSashWeights(int[] weights) { fLastSashWeights = weights; @@ -933,40 +938,63 @@ 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); } - + /** + * 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. + * + * @param actionID Action ID that the given action implements. + * @param action Action implementation. + * + * @since 3.8 + */ + protected void setGlobalAction(String actionID, IAction action) { + fGlobalActionMap.put(actionID, action); + } + public IAction getAction(String actionID) { - IViewerInputProvider inputProvider = ViewerAdapterService.getInputProvider(getViewer().getInput()); - if (inputProvider instanceof IAdaptable) { - Object x = ((IAdaptable) inputProvider).getAdapter(IViewActionOverride.class); - if (x instanceof IViewActionOverride) { - IAction action = ((IViewActionOverride) x).getAction(getPresentationContext(), 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 super.getAction(actionID); + return null; } - /* (non-Javadoc) - * - * Save the copy action so we can restore it on focus lost/gain - * - * @see org.eclipse.debug.ui.AbstractDebugView#createContextMenu(org.eclipse.swt.widgets.Control) - */ - protected void createContextMenu(Control menuControl) { - super.createContextMenu(menuControl); - setAction(VARIABLES_COPY_ACTION, getAction(COPY_ACTION)); - setAction(VARIABLES_PASTE_ACTION, getAction(PASTE_ACTION)); + 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. * - * @param viewer + * @param viewer Viewer to create actions for. */ private void createOrientationActions(TreeModelViewer viewer) { IActionBars actionBars = getViewSite().getActionBars(); @@ -1039,10 +1067,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); @@ -1064,6 +1091,8 @@ public class VariablesView extends AbstractDebugView implements IDebugContextLis /** * Lazily instantiate and return a selection listener that populates the detail pane, * but only if the detail is currently visible. + * + * @return Created selection listener */ protected ISelectionChangedListener getTreeSelectionChangedListener() { if (fTreeSelectionChangedListener == null) { @@ -1201,6 +1230,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(); } @@ -1238,7 +1270,7 @@ public class VariablesView extends AbstractDebugView implements IDebugContextLis /** * Updates actions and sets the viewer input when a context is activated. - * @param selection + * @param selection New selection to activate. */ protected void contextActivated(ISelection selection) { if (!isAvailable() || !isVisible()) { @@ -1315,13 +1347,15 @@ public class VariablesView extends AbstractDebugView implements IDebugContextLis /** * Sets whether logical structures are being displayed + * @param flag If true, turns the logical structures on. */ public void setShowLogicalStructure(boolean flag) { getPresentationContext().setProperty(PRESENTATION_SHOW_LOGICAL_STRUCTURES, Boolean.valueOf(flag)); } /** - * Returns whether logical structures are being displayed + * Returns whether logical structures are being displayed + * @return Returns true if logical structures should be shown. */ public boolean isShowLogicalStructure() { Boolean show = (Boolean) getPresentationContext().getProperty(PRESENTATION_SHOW_LOGICAL_STRUCTURES); @@ -1384,7 +1418,7 @@ public class VariablesView extends AbstractDebugView implements IDebugContextLis fVisitor.reset(); delta.accept(fVisitor); - updateAction(VARIABLES_FIND_ELEMENT_ACTION); + updateAction(FIND_ACTION); updateAction("CollapseAll"); } @@ -1400,7 +1434,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 4a0e03cbd..36ad5566d 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()); } /** |