Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBernd Hufmann2019-05-01 00:36:11 +0000
committerBernd Hufmann2019-05-28 15:02:29 +0000
commit1d666d481d4d1353eaa1bda33b2073cb4ef6a1f1 (patch)
tree76170b7906e99337b6b8371bc85ac7d18c2acf9d
parent1b93dd3b1dfff5866f124e4699d82ec31c3fcf40 (diff)
downloadorg.eclipse.tracecompass.incubator-1d666d481d4d1353eaa1bda33b2073cb4ef6a1f1.tar.gz
org.eclipse.tracecompass.incubator-1d666d481d4d1353eaa1bda33b2073cb4ef6a1f1.tar.xz
org.eclipse.tracecompass.incubator-1d666d481d4d1353eaa1bda33b2073cb4ef6a1f1.zip
scripting: Allow launching of scripts from tracing projects
uses internal APIs of DebugUI and Ease This adds a Run As/Debug As -> Ease Script menu for scripts files that are imported as traces under a Traces folder. Change-Id: I65bd805afa1afdacdc08f2e73928ed40fa3fa109 Signed-off-by: Bernd Hufmann <Bernd.Hufmann@ericsson.com> Reviewed-on: https://git.eclipse.org/r/141535 Tested-by: CI Bot Reviewed-by: Genevieve Bastien <gbastien+lttng@versatic.net> Tested-by: Genevieve Bastien <gbastien+lttng@versatic.net>
-rw-r--r--analyses/org.eclipse.tracecompass.incubator.scripting.ui/META-INF/MANIFEST.MF8
-rw-r--r--analyses/org.eclipse.tracecompass.incubator.scripting.ui/build.properties4
-rw-r--r--analyses/org.eclipse.tracecompass.incubator.scripting.ui/icons/etool16/debug_exc.pngbin0 -> 531 bytes
-rw-r--r--analyses/org.eclipse.tracecompass.incubator.scripting.ui/icons/etool16/debug_exc@2x.pngbin0 -> 1457 bytes
-rw-r--r--analyses/org.eclipse.tracecompass.incubator.scripting.ui/icons/etool16/run_exc.pngbin0 -> 616 bytes
-rw-r--r--analyses/org.eclipse.tracecompass.incubator.scripting.ui/icons/etool16/run_exc@2x.pngbin0 -> 1224 bytes
-rw-r--r--analyses/org.eclipse.tracecompass.incubator.scripting.ui/plugin.properties8
-rw-r--r--analyses/org.eclipse.tracecompass.incubator.scripting.ui/plugin.xml105
-rw-r--r--analyses/org.eclipse.tracecompass.incubator.scripting.ui/src/org/eclipse/tracecompass/incubator/scripting/ui/project/handlers/DebugAsElementTypeContributionItem.java39
-rw-r--r--analyses/org.eclipse.tracecompass.incubator.scripting.ui/src/org/eclipse/tracecompass/incubator/scripting/ui/project/handlers/LaunchAsEaseScriptHandler.java153
-rw-r--r--analyses/org.eclipse.tracecompass.incubator.scripting.ui/src/org/eclipse/tracecompass/incubator/scripting/ui/project/handlers/LaunchElementTypeContributionItem.java133
-rw-r--r--analyses/org.eclipse.tracecompass.incubator.scripting.ui/src/org/eclipse/tracecompass/incubator/scripting/ui/project/handlers/Messages.java30
-rw-r--r--analyses/org.eclipse.tracecompass.incubator.scripting.ui/src/org/eclipse/tracecompass/incubator/scripting/ui/project/handlers/RunAsElementTypeContributionItem.java39
-rw-r--r--analyses/org.eclipse.tracecompass.incubator.scripting.ui/src/org/eclipse/tracecompass/incubator/scripting/ui/project/handlers/ScriptEngineTester.java50
-rw-r--r--analyses/org.eclipse.tracecompass.incubator.scripting.ui/src/org/eclipse/tracecompass/incubator/scripting/ui/project/handlers/messages.properties10
-rw-r--r--analyses/org.eclipse.tracecompass.incubator.scripting.ui/src/org/eclipse/tracecompass/incubator/scripting/ui/project/handlers/package-info.java11
16 files changed, 582 insertions, 8 deletions
diff --git a/analyses/org.eclipse.tracecompass.incubator.scripting.ui/META-INF/MANIFEST.MF b/analyses/org.eclipse.tracecompass.incubator.scripting.ui/META-INF/MANIFEST.MF
index a736a4e17..367fffbf4 100644
--- a/analyses/org.eclipse.tracecompass.incubator.scripting.ui/META-INF/MANIFEST.MF
+++ b/analyses/org.eclipse.tracecompass.incubator.scripting.ui/META-INF/MANIFEST.MF
@@ -19,8 +19,12 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.tracecompass.tmf.analysis.xml.core,
org.eclipse.tracecompass.tmf.ui,
org.eclipse.debug.core,
- org.eclipse.debug.ui
+ org.eclipse.debug.ui,
+ org.eclipse.ui.views,
+ org.eclipse.ease.ui,
+ org.eclipse.core.expressions
Export-Package: org.eclipse.tracecompass.incubator.internal.provisional.scripting.ui.views;x-internal:=true,
org.eclipse.tracecompass.incubator.internal.scripting.ui;x-internal:=true,
- org.eclipse.tracecompass.incubator.internal.scripting.ui.views.timegraph;x-internal:=true
+ org.eclipse.tracecompass.incubator.internal.scripting.ui.views.timegraph;x-internal:=true,
+ org.eclipse.tracecompass.incubator.scripting.ui.project.handlers
Automatic-Module-Name: org.eclipse.tracecompass.incubator.scripting.ui
diff --git a/analyses/org.eclipse.tracecompass.incubator.scripting.ui/build.properties b/analyses/org.eclipse.tracecompass.incubator.scripting.ui/build.properties
index 5ae48ac26..1b7f6b6b8 100644
--- a/analyses/org.eclipse.tracecompass.incubator.scripting.ui/build.properties
+++ b/analyses/org.eclipse.tracecompass.incubator.scripting.ui/build.properties
@@ -13,4 +13,6 @@ bin.includes = META-INF/,\
.,\
about.html,\
plugin.properties,\
- plugin.xml
+ plugin.xml,\
+ icons/,\
+ build.properties
diff --git a/analyses/org.eclipse.tracecompass.incubator.scripting.ui/icons/etool16/debug_exc.png b/analyses/org.eclipse.tracecompass.incubator.scripting.ui/icons/etool16/debug_exc.png
new file mode 100644
index 000000000..17bb448f0
--- /dev/null
+++ b/analyses/org.eclipse.tracecompass.incubator.scripting.ui/icons/etool16/debug_exc.png
Binary files differ
diff --git a/analyses/org.eclipse.tracecompass.incubator.scripting.ui/icons/etool16/debug_exc@2x.png b/analyses/org.eclipse.tracecompass.incubator.scripting.ui/icons/etool16/debug_exc@2x.png
new file mode 100644
index 000000000..8c168ee66
--- /dev/null
+++ b/analyses/org.eclipse.tracecompass.incubator.scripting.ui/icons/etool16/debug_exc@2x.png
Binary files differ
diff --git a/analyses/org.eclipse.tracecompass.incubator.scripting.ui/icons/etool16/run_exc.png b/analyses/org.eclipse.tracecompass.incubator.scripting.ui/icons/etool16/run_exc.png
new file mode 100644
index 000000000..c06ce07b5
--- /dev/null
+++ b/analyses/org.eclipse.tracecompass.incubator.scripting.ui/icons/etool16/run_exc.png
Binary files differ
diff --git a/analyses/org.eclipse.tracecompass.incubator.scripting.ui/icons/etool16/run_exc@2x.png b/analyses/org.eclipse.tracecompass.incubator.scripting.ui/icons/etool16/run_exc@2x.png
new file mode 100644
index 000000000..d1a4b9109
--- /dev/null
+++ b/analyses/org.eclipse.tracecompass.incubator.scripting.ui/icons/etool16/run_exc@2x.png
Binary files differ
diff --git a/analyses/org.eclipse.tracecompass.incubator.scripting.ui/plugin.properties b/analyses/org.eclipse.tracecompass.incubator.scripting.ui/plugin.properties
index 5c1940a5b..67e8030a5 100644
--- a/analyses/org.eclipse.tracecompass.incubator.scripting.ui/plugin.properties
+++ b/analyses/org.eclipse.tracecompass.incubator.scripting.ui/plugin.properties
@@ -11,3 +11,11 @@ Bundle-Vendor = Eclipse Trace Compass Incubator
Bundle-Name = Trace Compass Scripting UI Plug-in (Incubator)
view.scripted = Scripted View
+
+command.run_as_ease_script = Run As...
+command.run_as_ease_script.description = Run as ease script
+command.launch_as_ease_script.type = Launch Type
+command.launch_as_ease_script.mode = Launch Mode
+
+command.debug_as_ease_script = Debug As...
+command.debug_as_ease_script.description = Debug as ease script
diff --git a/analyses/org.eclipse.tracecompass.incubator.scripting.ui/plugin.xml b/analyses/org.eclipse.tracecompass.incubator.scripting.ui/plugin.xml
index 41c41524a..e4611bc4e 100644
--- a/analyses/org.eclipse.tracecompass.incubator.scripting.ui/plugin.xml
+++ b/analyses/org.eclipse.tracecompass.incubator.scripting.ui/plugin.xml
@@ -11,11 +11,6 @@
visible="true">
</module>
</extension>
- <extension point="org.eclipse.ui.activities">
- <activity name="%activity.name.debugPerspective" id="org.eclipse.tracecompass.scriptDebug" description="%activity.description.debugPerspective" />
- <activityPatternBinding activityId="org.eclipse.tracecompass.scriptDebug" pattern="org\.eclipse\.debug.*" />
- <defaultEnablement id="org.eclipse.tracecompass.scriptDebug" />
- </extension>
<extension
point="org.eclipse.ui.views">
<view
@@ -27,4 +22,104 @@
restorable="true">
</view>
</extension>
+ <extension
+ point="org.eclipse.ui.commands">
+ <command
+ categoryId="org.eclipse.ui.category.file"
+ defaultHandler="org.eclipse.tracecompass.incubator.scripting.ui.project.handlers.LaunchAsEaseScriptHandler"
+ description="%command.run_as_ease_script.description"
+ id="org.eclipse.tracecompass.incubator.scripting.ui.command.launch_as_ease_script"
+ name="%command.run_as_ease_script">
+ <commandParameter
+ id="org.eclipse.tracecompass.incubator.scripting.ui.commandparameter.launch_as_ease_script.type"
+ name="%command.launch_as_ease_script.type"
+ optional="false">
+ </commandParameter>
+ <commandParameter
+ id="org.eclipse.tracecompass.incubator.scripting.ui.commandparameter.launch_as_ease_script.mode"
+ name="%command.launch_as_ease_script.mode"
+ optional="false">
+ </commandParameter>
+ </command>
+ </extension>
+ <extension
+ point="org.eclipse.ui.menus">
+ <menuContribution
+ locationURI="popup:org.eclipse.ui.popup.any?after=additions">
+ <menu
+ icon="icons/etool16/run_exc.png"
+ label="%command.run_as_ease_script"
+ tooltip="%command.run_as_ease_script.description">
+ <dynamic
+ class="org.eclipse.tracecompass.incubator.scripting.ui.project.handlers.RunAsElementTypeContributionItem"
+ id="org.eclipse.tracecompass.incubator.scripting.ui.command.run_as_ease_script.dynamic">
+ </dynamic>
+ <visibleWhen
+ checkEnabled="false">
+ <with
+ variable="selection">
+ <and>
+ <iterate
+ ifEmpty="false"
+ operator="and">
+ <or>
+ <instanceof
+ value="org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement">
+ </instanceof>
+ </or>
+ </iterate>
+ <test
+ forcePluginActivation="true"
+ property="org.eclipse.tracecompass.incubator.scripting.ui.hasEngine">
+ </test>
+ </and>
+ </with>
+ </visibleWhen>
+ </menu>
+ </menuContribution>
+ <menuContribution
+ locationURI="popup:org.eclipse.ui.popup.any?after=additions">
+ <menu
+ icon="icons/etool16/debug_exc.png"
+ label="%command.debug_as_ease_script"
+ tooltip="%command.debug_as_ease_script.description">
+ <dynamic
+ class="org.eclipse.tracecompass.incubator.scripting.ui.project.handlers.DebugAsElementTypeContributionItem"
+ id="org.eclipse.tracecompass.incubator.scripting.ui.command.debug_as_ease_script.dynamic">
+ </dynamic>
+ <visibleWhen
+ checkEnabled="false">
+ <with
+ variable="selection">
+ <and>
+ <iterate
+ ifEmpty="false"
+ operator="and">
+ <or>
+ <instanceof
+ value="org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement">
+ </instanceof>
+ </or>
+ </iterate>
+ <test
+ forcePluginActivation="true"
+ property="org.eclipse.tracecompass.incubator.scripting.ui.hasDebugEngine">
+ </test>
+ </and>
+ </with>
+ </visibleWhen>
+
+ </menu>
+ </menuContribution>
+ </extension>
+ <extension
+ point="org.eclipse.core.expressions.propertyTesters">
+ <propertyTester
+ class="org.eclipse.tracecompass.incubator.scripting.ui.project.handlers.ScriptEngineTester"
+ id="org.eclipse.tracecompass.incubator.scripting.ui.engine"
+ namespace="org.eclipse.tracecompass.incubator.scripting.ui"
+ properties="hasEngine,hasDebugEngine"
+ type="java.lang.Object">
+ </propertyTester>
+ </extension>
</plugin>
diff --git a/analyses/org.eclipse.tracecompass.incubator.scripting.ui/src/org/eclipse/tracecompass/incubator/scripting/ui/project/handlers/DebugAsElementTypeContributionItem.java b/analyses/org.eclipse.tracecompass.incubator.scripting.ui/src/org/eclipse/tracecompass/incubator/scripting/ui/project/handlers/DebugAsElementTypeContributionItem.java
new file mode 100644
index 000000000..1bd054522
--- /dev/null
+++ b/analyses/org.eclipse.tracecompass.incubator.scripting.ui/src/org/eclipse/tracecompass/incubator/scripting/ui/project/handlers/DebugAsElementTypeContributionItem.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * Copyright (c) 2019 Ericsson
+ *
+ * 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
+ *******************************************************************************/
+package org.eclipse.tracecompass.incubator.scripting.ui.project.handlers;
+
+import java.util.HashSet;
+import java.util.Objects;
+import java.util.Set;
+
+import org.eclipse.debug.core.ILaunchManager;
+import org.eclipse.tracecompass.tmf.core.util.Pair;
+
+/**
+ * ContributionItem for the Debug As -> <launch shortcut>.
+ *
+ * @author Bernd Hufmann
+ *
+ */
+public class DebugAsElementTypeContributionItem extends LaunchElementTypeContributionItem {
+
+ private static final String EASE_LAUNCH_SHORTCUT = "org.eclipse.ease.launchShortcut"; //$NON-NLS-1$
+
+ @Override
+ protected String getLaunchMode() {
+ return Objects.requireNonNull(ILaunchManager.DEBUG_MODE);
+ }
+
+ @Override
+ protected Set<Pair<String, String>> getParam() {
+ Set<Pair<String, String>> debugShortcuts = new HashSet<>();
+ debugShortcuts.add(new Pair<>(EASE_LAUNCH_SHORTCUT, Objects.requireNonNull(Messages.Scripting_RunAsScriptName)));
+ return debugShortcuts;
+ }
+}
diff --git a/analyses/org.eclipse.tracecompass.incubator.scripting.ui/src/org/eclipse/tracecompass/incubator/scripting/ui/project/handlers/LaunchAsEaseScriptHandler.java b/analyses/org.eclipse.tracecompass.incubator.scripting.ui/src/org/eclipse/tracecompass/incubator/scripting/ui/project/handlers/LaunchAsEaseScriptHandler.java
new file mode 100644
index 000000000..f40b4b384
--- /dev/null
+++ b/analyses/org.eclipse.tracecompass.incubator.scripting.ui/src/org/eclipse/tracecompass/incubator/scripting/ui/project/handlers/LaunchAsEaseScriptHandler.java
@@ -0,0 +1,153 @@
+/*******************************************************************************
+ * Copyright (c) 2019 Ericsson, École Polytechnique de Montréal
+ *
+ * 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
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.incubator.scripting.ui.project.handlers;
+
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.debug.core.ILaunchManager;
+import org.eclipse.debug.internal.ui.DebugUIPlugin;
+import org.eclipse.debug.internal.ui.actions.OpenDebugConfigurations;
+import org.eclipse.debug.internal.ui.actions.OpenRunConfigurations;
+import org.eclipse.debug.internal.ui.launchConfigurations.LaunchShortcutExtension;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TreeSelection;
+import org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement;
+import org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * Command Handler to run scripts.
+ *
+ * @author Bernd Hufmann
+ */
+@SuppressWarnings({ "restriction", "null" })
+public class LaunchAsEaseScriptHandler extends AbstractHandler {
+
+ // ------------------------------------------------------------------------
+ // Constants
+ // ------------------------------------------------------------------------
+
+ private static final String TYPE_PARAMETER = "org.eclipse.tracecompass.incubator.scripting.ui.commandparameter.launch_as_ease_script.type"; //$NON-NLS-1$
+ private static final String MODE_PARAMETER = "org.eclipse.tracecompass.incubator.scripting.ui.commandparameter.launch_as_ease_script.mode"; //$NON-NLS-1$
+
+ // ------------------------------------------------------------------------
+ // Attributes
+ // ------------------------------------------------------------------------
+
+ @Nullable
+ private TreeSelection fSelection = null;
+
+ // ------------------------------------------------------------------------
+ // Validation
+ // ------------------------------------------------------------------------
+
+ @Override
+ public boolean isEnabled() {
+
+ // Check if we are closing down
+ IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ if (window == null) {
+ return false;
+ }
+
+ // Get the selection
+ IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ IWorkbenchPart part = page.getActivePart();
+ if (part == null) {
+ return false;
+ }
+ ISelectionProvider selectionProvider = part.getSite().getSelectionProvider();
+ if (selectionProvider == null) {
+ return false;
+ }
+ ISelection selection = selectionProvider.getSelection();
+
+ // Make sure selection contains only traces
+ fSelection = null;
+ if (selection instanceof TreeSelection) {
+ fSelection = (TreeSelection) selection;
+ Iterator<Object> iterator = fSelection.iterator();
+ while (iterator.hasNext()) {
+ Object element = iterator.next();
+ if (!(element instanceof TmfCommonProjectElement)) {
+ return false;
+ }
+ }
+ }
+
+ // If we get here, either nothing is selected or everything is a trace
+ return !selection.isEmpty();
+ }
+
+ // ------------------------------------------------------------------------
+ // Execution
+ // ------------------------------------------------------------------------
+
+ @Override
+ public @Nullable Object execute(@Nullable ExecutionEvent event) throws ExecutionException {
+
+ TreeSelection selection = fSelection;
+ // Check if we are closing down
+ IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ if (window == null || event == null || selection == null) {
+ return null;
+ }
+
+ List<LaunchShortcutExtension> allShortCuts = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchShortcuts();
+ if (allShortCuts == null) {
+ return null;
+ }
+ for (Object element : selection.toList()) {
+ TmfCommonProjectElement trace = (TmfCommonProjectElement) element;
+ if (trace instanceof TmfTraceElement) {
+ trace = ((TmfTraceElement) trace).getElementUnderTraceFolder();
+ }
+ IResource resource = trace.getResource();
+ String type = event.getParameter(TYPE_PARAMETER);
+ String mode = event.getParameter(MODE_PARAMETER);
+ if (resource != null) {
+ IStructuredSelection s = new StructuredSelection(Arrays.asList(resource));
+ if (type.equals(LaunchElementTypeContributionItem.LAUNCH_DIALOG_CONFIG_ID)) {
+ if (mode.equals(ILaunchManager.RUN_MODE)) {
+ OpenRunConfigurations r = new OpenRunConfigurations();
+ r.run(null);
+ }
+
+ if (mode.equals(ILaunchManager.DEBUG_MODE)) {
+ OpenDebugConfigurations r = new OpenDebugConfigurations();
+ r.run(null);
+ }
+ } else {
+ for (LaunchShortcutExtension launchShortcutExtension : allShortCuts) {
+ if (type.equals(launchShortcutExtension.getId())) {
+ launchShortcutExtension.launch(s, mode);
+ break;
+ }
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+}
diff --git a/analyses/org.eclipse.tracecompass.incubator.scripting.ui/src/org/eclipse/tracecompass/incubator/scripting/ui/project/handlers/LaunchElementTypeContributionItem.java b/analyses/org.eclipse.tracecompass.incubator.scripting.ui/src/org/eclipse/tracecompass/incubator/scripting/ui/project/handlers/LaunchElementTypeContributionItem.java
new file mode 100644
index 000000000..542f08587
--- /dev/null
+++ b/analyses/org.eclipse.tracecompass.incubator.scripting.ui/src/org/eclipse/tracecompass/incubator/scripting/ui/project/handlers/LaunchElementTypeContributionItem.java
@@ -0,0 +1,133 @@
+/*******************************************************************************
+ * Copyright (c) 2019 Ericsson
+ *
+ * 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
+ *******************************************************************************/
+package org.eclipse.tracecompass.incubator.scripting.ui.project.handlers;
+
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.debug.core.ILaunchManager;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.jface.action.IContributionItem;
+import org.eclipse.tracecompass.tmf.core.util.Pair;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.actions.CompoundContributionItem;
+import org.eclipse.ui.menus.CommandContributionItem;
+import org.eclipse.ui.menus.CommandContributionItemParameter;
+
+
+/**
+ * Base ContributionItem for the Run As -> <launch shortcut> or Debug As -> <launch shortcut>.
+ *
+ * @author Bernd Hufmann
+ *
+ */
+public abstract class LaunchElementTypeContributionItem extends CompoundContributionItem {
+
+ private static final String TYPE_PARAMETER = "org.eclipse.tracecompass.incubator.scripting.ui.commandparameter.launch_as_ease_script.type"; //$NON-NLS-1$
+ private static final String MODE_PARAMETER = "org.eclipse.tracecompass.incubator.scripting.ui.commandparameter.launch_as_ease_script.mode"; //$NON-NLS-1$
+ private static final String LAUNCH_AS_EASE_SCRIPT_COMMAND_ID = "org.eclipse.tracecompass.incubator.scripting.ui.command.launch_as_ease_script"; //$NON-NLS-1$
+ private static final String LAUCH_DIALOG_STRING = "Configuration..."; //$NON-NLS-1$
+ private static final String RUN_STRING = "Run"; //$NON-NLS-1$
+ private static final String DEBUG_STRING = "Debug"; //$NON-NLS-1$
+ private static final String LAUNCH_COMMAND_CONTRIBUTION_ITEM_ID = "org.eclipse.tracecompass.incubator.scripting.contribution.item.id"; //$NON-NLS-1$
+ private static final Comparator<IContributionItem> ITEM_COMPARATOR = new ItemComparator();
+
+ /** ID to identify the Open Run/Debug dialog menu item */
+ public static final String LAUNCH_DIALOG_CONFIG_ID = "org.eclipse.tracecompass.incubator.scripting.ui.launch-dialog"; //$NON-NLS-1$
+
+ private static final class ItemComparator implements Comparator<IContributionItem> {
+ @Override
+ public int compare(IContributionItem o1, IContributionItem o2) {
+ CommandContributionItem c1 = (CommandContributionItem) o1;
+ CommandContributionItem c2 = (CommandContributionItem) o2;
+ if (c1.getData().label.equals(c2.getData().label)) {
+ return 0;
+ }
+ if (c1.getData().label.endsWith(LAUCH_DIALOG_STRING)) {
+ return 1;
+ }
+ if (c2.getData().label.endsWith(LAUCH_DIALOG_STRING)) {
+ return -1;
+ }
+ return c1.getData().label.compareTo(c2.getData().label);
+ }
+ }
+
+ @Override
+ protected IContributionItem[] getContributionItems() {
+
+ /*
+ * Fill-in the available shortcuts
+ */
+ Set<Pair<String, String>> availableShortcuts = new HashSet<>(getParam());
+ Pair<String, String> launchConfiguration = getLaunchConfigurationParam();
+ if (launchConfiguration != null) {
+ availableShortcuts.add(launchConfiguration);
+ }
+
+ List<IContributionItem> list = new LinkedList<>();
+ for (Pair<String, String> item : availableShortcuts) {
+ Map<String, String> params = new HashMap<>();
+ params.put(TYPE_PARAMETER, item.getFirst());
+ params.put(MODE_PARAMETER, getLaunchMode());
+ CommandContributionItemParameter param = new CommandContributionItemParameter(
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow(),
+ LAUNCH_COMMAND_CONTRIBUTION_ITEM_ID,
+ getContributionItemCommandId(),
+ CommandContributionItem.STYLE_PUSH
+ );
+ param.parameters = params;
+ param.label = item.getSecond();
+ param.visibleEnabled = true;
+ list.add(new CommandContributionItem(param));
+ }
+ Collections.sort(list, ITEM_COMPARATOR);
+ return list.toArray(new IContributionItem[list.size()]);
+ }
+
+ /**
+ * Returns the command id to use for contribution items
+ *
+ * @return the command id
+ */
+ protected String getContributionItemCommandId() {
+ return LAUNCH_AS_EASE_SCRIPT_COMMAND_ID;
+ }
+
+ /**
+ * Get the launch mode
+ *
+ * @return one of {@link ILaunchManager#RUN_MODE} or {@link ILaunchManager#DEBUG_MODE}
+ */
+ protected abstract String getLaunchMode();
+
+ /**
+ * Pairs of launch shortcut ID to shortcut label
+ *
+ * @return Pairs of launch shortcut ID to shortcut label
+ */
+ protected abstract Set<Pair<String, String>> getParam();
+
+ @Nullable private Pair<String, String> getLaunchConfigurationParam() {
+ if (getLaunchMode().equals(ILaunchManager.RUN_MODE)) {
+ return new Pair<>(LAUNCH_DIALOG_CONFIG_ID, RUN_STRING + ' ' + LAUCH_DIALOG_STRING);
+ }
+ if (getLaunchMode().equals(ILaunchManager.DEBUG_MODE)) {
+ return new Pair<>(LAUNCH_DIALOG_CONFIG_ID, DEBUG_STRING + ' ' + LAUCH_DIALOG_STRING);
+ }
+ return null;
+ }
+
+}
diff --git a/analyses/org.eclipse.tracecompass.incubator.scripting.ui/src/org/eclipse/tracecompass/incubator/scripting/ui/project/handlers/Messages.java b/analyses/org.eclipse.tracecompass.incubator.scripting.ui/src/org/eclipse/tracecompass/incubator/scripting/ui/project/handlers/Messages.java
new file mode 100644
index 000000000..58af19648
--- /dev/null
+++ b/analyses/org.eclipse.tracecompass.incubator.scripting.ui/src/org/eclipse/tracecompass/incubator/scripting/ui/project/handlers/Messages.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2019 Ericsson
+ * 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
+ *******************************************************************************/
+package org.eclipse.tracecompass.incubator.scripting.ui.project.handlers;
+
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * Messages class
+ *
+ * @author Bernd Hufmann
+ *
+ */
+public class Messages extends NLS {
+ private static final String BUNDLE_NAME = "org.eclipse.tracecompass.incubator.scripting.ui.project.handlers.messages"; //$NON-NLS-1$
+ /** Menu entry for run/debug as menu*/
+ public static @Nullable String Scripting_RunAsScriptName;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/analyses/org.eclipse.tracecompass.incubator.scripting.ui/src/org/eclipse/tracecompass/incubator/scripting/ui/project/handlers/RunAsElementTypeContributionItem.java b/analyses/org.eclipse.tracecompass.incubator.scripting.ui/src/org/eclipse/tracecompass/incubator/scripting/ui/project/handlers/RunAsElementTypeContributionItem.java
new file mode 100644
index 000000000..e9c3fed2b
--- /dev/null
+++ b/analyses/org.eclipse.tracecompass.incubator.scripting.ui/src/org/eclipse/tracecompass/incubator/scripting/ui/project/handlers/RunAsElementTypeContributionItem.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * Copyright (c) 2019 Ericsson
+ *
+ * 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
+ *******************************************************************************/
+package org.eclipse.tracecompass.incubator.scripting.ui.project.handlers;
+
+import java.util.HashSet;
+import java.util.Objects;
+import java.util.Set;
+
+import org.eclipse.debug.core.ILaunchManager;
+import org.eclipse.tracecompass.tmf.core.util.Pair;
+
+/**
+ * ContributionItem for the Run As -> <launch shortcut>.
+ *
+ * @author Bernd Hufmann
+ *
+ */
+public class RunAsElementTypeContributionItem extends LaunchElementTypeContributionItem {
+
+ private static final String EASE_LAUNCH_SHORTCUT = "org.eclipse.ease.launchShortcut"; //$NON-NLS-1$
+
+ @Override
+ protected String getLaunchMode() {
+ return Objects.requireNonNull(ILaunchManager.RUN_MODE);
+ }
+
+ @Override
+ protected Set<Pair<String, String>> getParam() {
+ Set<Pair<String, String>> selectedTraceTypes = new HashSet<>();
+ selectedTraceTypes.add(new Pair<>(EASE_LAUNCH_SHORTCUT, Objects.requireNonNull(Messages.Scripting_RunAsScriptName)));
+ return selectedTraceTypes;
+ }
+}
diff --git a/analyses/org.eclipse.tracecompass.incubator.scripting.ui/src/org/eclipse/tracecompass/incubator/scripting/ui/project/handlers/ScriptEngineTester.java b/analyses/org.eclipse.tracecompass.incubator.scripting.ui/src/org/eclipse/tracecompass/incubator/scripting/ui/project/handlers/ScriptEngineTester.java
new file mode 100644
index 000000000..4d915b9b9
--- /dev/null
+++ b/analyses/org.eclipse.tracecompass.incubator.scripting.ui/src/org/eclipse/tracecompass/incubator/scripting/ui/project/handlers/ScriptEngineTester.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 2019 Ericsson
+ *
+ * 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
+ *******************************************************************************/
+package org.eclipse.tracecompass.incubator.scripting.ui.project.handlers;
+
+import java.util.Iterator;
+
+import org.eclipse.core.expressions.PropertyTester;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.ease.ui.propertytester.EngineTester;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.jface.viewers.TreeSelection;
+import org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement;
+
+/**
+ * Checks if a script has as an engine for installed.
+ *
+ * @author Bernd Hufmann
+ *
+ */
+@SuppressWarnings("restriction")
+public class ScriptEngineTester extends PropertyTester {
+ // Engine tester from EASE project
+ private EngineTester fDelegateTester = new EngineTester();
+
+ @Override
+ public boolean test(@Nullable Object receiver, @Nullable String property, Object @Nullable [] args, @Nullable Object expectedValue) {
+ if (receiver instanceof TreeSelection) {
+ TreeSelection selection = (TreeSelection) receiver;
+ Iterator<Object> iterator = selection.iterator();
+ while (iterator.hasNext()) {
+ Object element = iterator.next();
+ if (element instanceof TmfTraceElement) {
+ IResource resource = ((TmfTraceElement) element).getResource();
+ if (resource instanceof IFile) {
+ return fDelegateTester.test(resource, property, args, expectedValue);
+ }
+ }
+ break;
+ }
+ }
+ return false;
+ }
+}
diff --git a/analyses/org.eclipse.tracecompass.incubator.scripting.ui/src/org/eclipse/tracecompass/incubator/scripting/ui/project/handlers/messages.properties b/analyses/org.eclipse.tracecompass.incubator.scripting.ui/src/org/eclipse/tracecompass/incubator/scripting/ui/project/handlers/messages.properties
new file mode 100644
index 000000000..11309a247
--- /dev/null
+++ b/analyses/org.eclipse.tracecompass.incubator.scripting.ui/src/org/eclipse/tracecompass/incubator/scripting/ui/project/handlers/messages.properties
@@ -0,0 +1,10 @@
+###############################################################################
+# Copyright (c) 2019 Ericsson
+#
+# 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
+###############################################################################
+
+Scripting_RunAsScriptName=Ease Script
diff --git a/analyses/org.eclipse.tracecompass.incubator.scripting.ui/src/org/eclipse/tracecompass/incubator/scripting/ui/project/handlers/package-info.java b/analyses/org.eclipse.tracecompass.incubator.scripting.ui/src/org/eclipse/tracecompass/incubator/scripting/ui/project/handlers/package-info.java
new file mode 100644
index 000000000..e521213ce
--- /dev/null
+++ b/analyses/org.eclipse.tracecompass.incubator.scripting.ui/src/org/eclipse/tracecompass/incubator/scripting/ui/project/handlers/package-info.java
@@ -0,0 +1,11 @@
+/*******************************************************************************
+ * Copyright (c) 2016 École Polytechnique de Montréal
+ *
+ * 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
+ *******************************************************************************/
+
+@org.eclipse.jdt.annotation.NonNullByDefault
+package org.eclipse.tracecompass.incubator.scripting.ui.project.handlers;

Back to the top