diff options
author | ustieber | 2011-05-02 07:07:15 +0000 |
---|---|---|
committer | ustieber | 2011-05-02 07:07:15 +0000 |
commit | 8f829a933197b4b0a3b25e012b497c6801ad4dd5 (patch) | |
tree | 5677d0d8771241bba858af6464b10d4ed0a5ade1 | |
parent | 74485a49c1e1ddbfe47b80fdf2fbfbc040a4a9b3 (diff) | |
download | org.eclipse.tcf-8f829a933197b4b0a3b25e012b497c6801ad4dd5.tar.gz org.eclipse.tcf-8f829a933197b4b0a3b25e012b497c6801ad4dd5.tar.xz org.eclipse.tcf-8f829a933197b4b0a3b25e012b497c6801ad4dd5.zip |
Target Explorer: Allow custom double click handling via the Eclipse command framework
-rw-r--r-- | target_explorer/plugins/org.eclipse.tm.te.tcf.ui/plugin.xml | 4 | ||||
-rw-r--r-- | target_explorer/plugins/org.eclipse.tm.te.ui.views/plugin.properties | 3 | ||||
-rw-r--r-- | target_explorer/plugins/org.eclipse.tm.te.ui.views/plugin.xml | 42 | ||||
-rw-r--r-- | target_explorer/plugins/org.eclipse.tm.te.ui.views/src/org/eclipse/tm/te/ui/views/internal/View.java | 58 | ||||
-rw-r--r-- | target_explorer/plugins/org.eclipse.tm.te.ui.views/src/org/eclipse/tm/te/ui/views/internal/handler/OpenCommandHandler.java | 71 | ||||
-rw-r--r-- | target_explorer/plugins/org.eclipse.tm.te.ui.views/src/org/eclipse/tm/te/ui/views/internal/handler/PropertiesCommandHandler.java (renamed from target_explorer/plugins/org.eclipse.tm.te.ui.views/src/org/eclipse/tm/te/ui/views/internal/targets/handler/PropertiesCommandHandler.java) | 2 |
6 files changed, 176 insertions, 4 deletions
diff --git a/target_explorer/plugins/org.eclipse.tm.te.tcf.ui/plugin.xml b/target_explorer/plugins/org.eclipse.tm.te.tcf.ui/plugin.xml index aee18917d..d3f615e75 100644 --- a/target_explorer/plugins/org.eclipse.tm.te.tcf.ui/plugin.xml +++ b/target_explorer/plugins/org.eclipse.tm.te.tcf.ui/plugin.xml @@ -102,7 +102,7 @@ </menuContribution> </extension> -<!-- TCF data source command contributions --> +<!-- Target Explorer command contributions --> <extension point="org.eclipse.ui.commands"> <category id="org.eclipse.tm.te.tcf.ui.commands.category" @@ -122,7 +122,7 @@ </command> </extension> -<!-- TCF data source handler contributions --> +<!-- Target Explorer handler contributions --> <extension point="org.eclipse.ui.handlers"> <handler class="org.eclipse.tm.te.tcf.ui.internal.handler.RefreshCommandHandler" diff --git a/target_explorer/plugins/org.eclipse.tm.te.ui.views/plugin.properties b/target_explorer/plugins/org.eclipse.tm.te.ui.views/plugin.properties index 3b97b3b7c..0da27fad4 100644 --- a/target_explorer/plugins/org.eclipse.tm.te.ui.views/plugin.properties +++ b/target_explorer/plugins/org.eclipse.tm.te.ui.views/plugin.properties @@ -30,6 +30,9 @@ TargetExplorer.name=Target Explorer Editor.name=Target Explorer Details Editor # ***** Command and menu contributions ***** +Command.category.name=Target Explorer Commands + +Command.open.name=Open PropertiesAction.label=&Properties PropertiesAction.tooltip=Show Properties of Selection diff --git a/target_explorer/plugins/org.eclipse.tm.te.ui.views/plugin.xml b/target_explorer/plugins/org.eclipse.tm.te.ui.views/plugin.xml index 81443abd3..e6a5192c6 100644 --- a/target_explorer/plugins/org.eclipse.tm.te.ui.views/plugin.xml +++ b/target_explorer/plugins/org.eclipse.tm.te.ui.views/plugin.xml @@ -120,22 +120,62 @@ </menuContribution> </extension> +<!-- Command contributions --> + <extension point="org.eclipse.ui.commands"> + <category + id="org.eclipse.tm.te.ui.commands.category" + name="%Command.category.name"> + </category> + <!-- Definition of the Common Navigator global retargetable open + action id as command. + --> + <command + categoryId="org.eclipse.tm.te.ui.commands.category" + helpContextId="org.eclipse.ui.navigator.Open" + id="org.eclipse.ui.navigator.Open" + name="%Command.open.name"> + </command> + </extension> + <!-- Handler contributions --> <extension point="org.eclipse.ui.handlers"> <handler commandId="org.eclipse.ui.file.properties" - class="org.eclipse.tm.te.ui.views.internal.targets.handler.PropertiesCommandHandler"> + class="org.eclipse.tm.te.ui.views.internal.handler.PropertiesCommandHandler"> <enabledWhen> <with variable="selection"> <count value="1"/> </with> </enabledWhen> <activeWhen> + <and> + <with variable="activePartId"> + <equals value="org.eclipse.tm.te.ui.views.TargetExplorer"/> + </with> + <with variable="selection"> + <iterate operator="and" ifEmpty="false"> + <test property="org.eclipse.tm.te.ui.views.hasApplicableEditorBindings" value="true"/> + </iterate> + </with> + </and> + </activeWhen> + </handler> + + <handler + commandId="org.eclipse.ui.navigator.Open" + class="org.eclipse.tm.te.ui.views.internal.handler.OpenCommandHandler"> + <enabledWhen> + <with variable="selection"> + <count value="1"/> + </with> + </enabledWhen> + <activeWhen> <with variable="activePartId"> <equals value="org.eclipse.tm.te.ui.views.TargetExplorer"/> </with> </activeWhen> </handler> + </extension> <!-- Eclipse core expressions property tester --> diff --git a/target_explorer/plugins/org.eclipse.tm.te.ui.views/src/org/eclipse/tm/te/ui/views/internal/View.java b/target_explorer/plugins/org.eclipse.tm.te.ui.views/src/org/eclipse/tm/te/ui/views/internal/View.java index 1d2775c40..0f52be60c 100644 --- a/target_explorer/plugins/org.eclipse.tm.te.ui.views/src/org/eclipse/tm/te/ui/views/internal/View.java +++ b/target_explorer/plugins/org.eclipse.tm.te.ui.views/src/org/eclipse/tm/te/ui/views/internal/View.java @@ -9,14 +9,29 @@ *******************************************************************************/ package org.eclipse.tm.te.ui.views.internal; +import java.util.Collections; + +import org.eclipse.core.commands.Command; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.expressions.EvaluationContext; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.PlatformObject; +import org.eclipse.core.runtime.Status; import org.eclipse.jface.action.GroupMarker; import org.eclipse.jface.action.IToolBarManager; import org.eclipse.jface.action.Separator; +import org.eclipse.jface.viewers.DoubleClickEvent; +import org.eclipse.jface.viewers.ISelection; import org.eclipse.swt.widgets.Composite; +import org.eclipse.tm.te.ui.views.activator.UIPlugin; import org.eclipse.tm.te.ui.views.interfaces.IRoot; +import org.eclipse.ui.ISources; import org.eclipse.ui.IWorkbenchActionConstants; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.commands.ICommandService; import org.eclipse.ui.navigator.CommonNavigator; +import org.eclipse.ui.navigator.ICommonActionConstants; /** @@ -60,6 +75,14 @@ public class View extends CommonNavigator { public void createPartControl(Composite parent) { super.createPartControl(parent); + // Add the additional custom Target Explorer toolbar groups + addCustomToolbarGroups(); + } + + /** + * Adds the custom Target Explorer toolbar groups to the view toolbar. + */ + protected void addCustomToolbarGroups() { if (getViewSite() != null && getViewSite().getActionBars() != null) { IToolBarManager tbManager = getViewSite().getActionBars().getToolBarManager(); if (tbManager != null) { @@ -72,4 +95,39 @@ public class View extends CommonNavigator { } } } + + /* (non-Javadoc) + * @see org.eclipse.ui.navigator.CommonNavigator#handleDoubleClick(org.eclipse.jface.viewers.DoubleClickEvent) + */ + @Override + protected void handleDoubleClick(DoubleClickEvent dblClickEvent) { + // If an handled and enabled command is registered for the ICommonActionConstants.OPEN + // retargetable action id, redirect the double click handling to the command handler. + // + // Note: The default tree node expansion must be re-implemented in the active handler! + ICommandService service = (ICommandService)PlatformUI.getWorkbench().getService(ICommandService.class); + Command command = service != null ? service.getCommand(ICommonActionConstants.OPEN) : null; + if (command != null && command.isDefined() && command.isEnabled()) { + try { + ISelection selection = dblClickEvent.getSelection(); + EvaluationContext ctx = new EvaluationContext(null, selection); + ctx.addVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME, selection); + ctx.addVariable(ISources.ACTIVE_MENU_SELECTION_NAME, selection); + ctx.addVariable(ISources.ACTIVE_WORKBENCH_WINDOW_NAME, PlatformUI.getWorkbench().getActiveWorkbenchWindow()); + ctx.addVariable(ISources.ACTIVE_PART_ID_NAME, getViewSite().getId()); + ctx.addVariable(ISources.ACTIVE_PART_NAME, this); + ExecutionEvent event = new ExecutionEvent(command, Collections.EMPTY_MAP, this, ctx); + command.executeWithChecks(event); + } catch (Exception e) { + // If the platform is in debug mode, we print the exception to the log view + if (Platform.inDebugMode()) { + IStatus status = new Status(IStatus.ERROR, UIPlugin.getUniqueIdentifier(), e.getLocalizedMessage(), e); + UIPlugin.getDefault().getLog().log(status); + } + } + } else { + // Fallback to the default implementation + super.handleDoubleClick(dblClickEvent); + } + } } diff --git a/target_explorer/plugins/org.eclipse.tm.te.ui.views/src/org/eclipse/tm/te/ui/views/internal/handler/OpenCommandHandler.java b/target_explorer/plugins/org.eclipse.tm.te.ui.views/src/org/eclipse/tm/te/ui/views/internal/handler/OpenCommandHandler.java new file mode 100644 index 000000000..7cec97a40 --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tm.te.ui.views/src/org/eclipse/tm/te/ui/views/internal/handler/OpenCommandHandler.java @@ -0,0 +1,71 @@ +/*******************************************************************************
+ * Copyright (c) 2011 Wind River Systems, 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:
+ * Uwe Stieber (Wind River) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.tm.te.ui.views.internal.handler;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.Command;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.tm.te.ui.views.activator.UIPlugin;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.actions.ActionFactory;
+import org.eclipse.ui.commands.ICommandService;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.ui.navigator.CommonNavigator;
+
+/**
+ * Target Explorer: TCF tree elements open command handler implementation.
+ */
+public class OpenCommandHandler extends AbstractHandler {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ */
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ // The selection is the Target Explorer tree selection
+ ISelection selection = HandlerUtil.getCurrentSelection(event);
+ // The active part is the Target Explorer view instance
+ IWorkbenchPart part = HandlerUtil.getActivePart(event);
+
+ if (selection instanceof IStructuredSelection && !selection.isEmpty() && part instanceof CommonNavigator) {
+ // If the tree node is expandable, expand or collapse it
+ TreeViewer viewer = ((CommonNavigator)part).getCommonViewer();
+ Object element = ((IStructuredSelection)selection).getFirstElement();
+ if (viewer.isExpandable(element)) {
+ viewer.setExpandedState(element, !viewer.getExpandedState(element));
+ } else {
+ // Node is not an expandable node, forward to the properties action.
+ ICommandService service = (ICommandService)PlatformUI.getWorkbench().getService(ICommandService.class);
+ Command command = service != null ? service.getCommand(ActionFactory.PROPERTIES.getCommandId()) : null;
+ if (command != null && command.isDefined() && command.isEnabled()) {
+ try {
+ command.executeWithChecks(event);
+ } catch (Exception e) {
+ // If the platform is in debug mode, we print the exception to the log view
+ if (Platform.inDebugMode()) {
+ IStatus status = new Status(IStatus.ERROR, UIPlugin.getUniqueIdentifier(), e.getLocalizedMessage(), e);
+ UIPlugin.getDefault().getLog().log(status);
+ }
+ }
+ }
+ }
+ }
+
+ return null;
+ }
+
+}
diff --git a/target_explorer/plugins/org.eclipse.tm.te.ui.views/src/org/eclipse/tm/te/ui/views/internal/targets/handler/PropertiesCommandHandler.java b/target_explorer/plugins/org.eclipse.tm.te.ui.views/src/org/eclipse/tm/te/ui/views/internal/handler/PropertiesCommandHandler.java index ae76a2a03..59d59a889 100644 --- a/target_explorer/plugins/org.eclipse.tm.te.ui.views/src/org/eclipse/tm/te/ui/views/internal/targets/handler/PropertiesCommandHandler.java +++ b/target_explorer/plugins/org.eclipse.tm.te.ui.views/src/org/eclipse/tm/te/ui/views/internal/handler/PropertiesCommandHandler.java @@ -7,7 +7,7 @@ * Contributors: * Uwe Stieber (Wind River) - initial API and implementation *******************************************************************************/ -package org.eclipse.tm.te.ui.views.internal.targets.handler; +package org.eclipse.tm.te.ui.views.internal.handler; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; |