Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scripting2 menu #1

Open
wants to merge 1 commit into
base: scripting2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.ease,
org.eclipse.tracecompass.tmf.core,
org.eclipse.tracecompass.tmf.analysis.xml.ui,
org.eclipse.tracecompass.tmf.analysis.xml.core
org.eclipse.tracecompass.tmf.analysis.xml.core,
org.eclipse.tracecompass.tmf.ui,
org.eclipse.debug.ui,
org.eclipse.ui.views,
org.eclipse.ease.ui,
org.eclipse.core.expressions
Export-Package: org.eclipse.tracecompass.incubator.internal.scripting.ui;x-internal:=true,
org.eclipse.tracecompass.incubator.internal.scripting.ui.views;x-internal:=true
Automatic-Module-Name: org.eclipse.tracecompass.incubator.scripting.ui
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ bin.includes = META-INF/,\
.,\
about.html,\
plugin.properties,\
plugin.xml
plugin.xml,\
icons/,\
build.properties
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@
Bundle-Vendor = Eclipse Trace Compass Incubator
Bundle-Name = Trace Compass Scripting UI Plug-in (Incubator)

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
100 changes: 100 additions & 0 deletions analyses/org.eclipse.tracecompass.incubator.scripting.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,104 @@
<activityPatternBinding activityId="org.eclipse.tracecompass.scriptDebug" pattern="org\.eclipse\.debug.*" />
<defaultEnablement id="org.eclipse.tracecompass.scriptDebug" />
</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.run_as_ease_script.type"
optional="false">
</commandParameter>
<commandParameter
id="org.eclipse.tracecompass.incubator.scripting.ui.commandparameter.launch_as_ease_script.mode"
name="%command.run_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>
Original file line number Diff line number Diff line change
@@ -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>> selectedTraceTypes = new HashSet<>();
selectedTraceTypes.add(new Pair<>(EASE_LAUNCH_SHORTCUT, Objects.requireNonNull(Messages.Scripting_RunAsScriptName)));
return selectedTraceTypes;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}

}
Loading