From 66fbc197a05c15c438887d40eeec73efefd59df1 Mon Sep 17 00:00:00 2001
From: Darin Wright
Date: Tue, 29 Jan 2008 04:01:21 +0000
Subject: Launch shortcut for MIDI files
---
org.eclipse.debug.examples.ui/plugin.xml | 21 +++
.../ui/midi/launcher/MidiLaunchShortcut.java | 163 +++++++++++++++++++++
.../examples/ui/midi/launcher/MidiMainTab.java | 9 ++
.../debug/examples/ui/pda/DebugUIPlugin.java | 24 +++
4 files changed, 217 insertions(+)
create mode 100644 org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/midi/launcher/MidiLaunchShortcut.java
(limited to 'org.eclipse.debug.examples.ui')
diff --git a/org.eclipse.debug.examples.ui/plugin.xml b/org.eclipse.debug.examples.ui/plugin.xml
index 6809c0442..41fd1c716 100644
--- a/org.eclipse.debug.examples.ui/plugin.xml
+++ b/org.eclipse.debug.examples.ui/plugin.xml
@@ -49,6 +49,27 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
null to cancel. Creates a new configuration
+ * if required.
+ *
+ * @param file file
+ * @return associated launch configuration or null
+ */
+ private ILaunchConfiguration getConfiguration(IFile file) {
+ List candiates = new ArrayList();
+ try {
+ ILaunchConfiguration[] configurations = getLaunchManager().getLaunchConfigurations(getLaunchType());
+ for (int i = 0; i < configurations.length; i++) {
+ ILaunchConfiguration configuration = configurations[i];
+ IResource[] resources = configuration.getMappedResources();
+ if (resources != null && resources.length == 1 &&
+ resources[0].equals(file)) {
+ candiates.add(configuration);
+ }
+ }
+ } catch (CoreException e) {
+ }
+ if (!candiates.isEmpty()) {
+ return chooseConfiguration(candiates);
+ }
+ return newConfiguration(file);
+ }
+
+ /**
+ * Returns the MIDI launch configuration type.
+ *
+ * @return the MIDI launch configuration type
+ */
+ private ILaunchConfigurationType getLaunchType() {
+ ILaunchManager manager = getLaunchManager();
+ ILaunchConfigurationType type = manager.getLaunchConfigurationType(MidiLaunchDelegate.ID_MIDI_LAUNCH_CONFIGURATION_TYPE);
+ return type;
+ }
+
+ /**
+ * Returns the launch manager.
+ *
+ * @return launch manager
+ */
+ private ILaunchManager getLaunchManager() {
+ ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
+ return manager;
+ }
+
+ /**
+ * Returns a configuration from the given collection of configurations that should be launched,
+ * or null
to cancel.
+ *
+ * @param configList list of configurations to choose from
+ * @return configuration to launch or null
to cancel
+ */
+ private ILaunchConfiguration chooseConfiguration(List configList) {
+ if (configList.size() == 1) {
+ return (ILaunchConfiguration) configList.get(0);
+ }
+ IDebugModelPresentation labelProvider = DebugUITools.newDebugModelPresentation();
+ ElementListSelectionDialog dialog= new ElementListSelectionDialog(DebugUIPlugin.getActiveWorkbenchShell(), labelProvider);
+ dialog.setElements(configList.toArray());
+ dialog.setTitle("Select Configuraiton");
+ dialog.setMessage("&Select an existing configuration:");
+ dialog.setMultipleSelection(false);
+ int result = dialog.open();
+ labelProvider.dispose();
+ if (result == Window.OK) {
+ return (ILaunchConfiguration) dialog.getFirstResult();
+ }
+ return null;
+ }
+
+ /**
+ * Creates and returns a new MIDI launch configuration for the
+ * given file.
+ *
+ * @param file MIDI file
+ * @return new launch configuration
+ */
+ private ILaunchConfiguration newConfiguration(IFile file) {
+ ILaunchConfigurationType type = getLaunchType();
+ try {
+ ILaunchConfigurationWorkingCopy workingCopy = type.newInstance(null, getLaunchManager().
+ generateUniqueLaunchConfigurationNameFrom(
+ "[" + file.getProject().getName() + "] " + file.getName()));
+ workingCopy.setAttribute(MidiLaunchDelegate.ATTR_MIDI_FILE, file.getFullPath().toString());
+ workingCopy.setMappedResources(new IResource[]{file});
+ return workingCopy.doSave();
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.ui.ILaunchShortcut#launch(org.eclipse.ui.IEditorPart, java.lang.String)
+ */
+ public void launch(IEditorPart editor, String mode) {
+ // nothing - currently no editor
+ }
+}
diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/midi/launcher/MidiMainTab.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/midi/launcher/MidiMainTab.java
index 80dff6a7b..fca24e5b4 100644
--- a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/midi/launcher/MidiMainTab.java
+++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/midi/launcher/MidiMainTab.java
@@ -130,7 +130,16 @@ public class MidiMainTab extends AbstractLaunchConfigurationTab {
if (file.length() == 0) {
file = null;
}
+ IResource[] resources = null;
+ if (file!= null) {
+ IPath path = new Path(file);
+ IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
+ if (res != null) {
+ resources = new IResource[]{res};
+ }
+ }
configuration.setAttribute(MidiLaunchDelegate.ATTR_MIDI_FILE, file);
+ configuration.setMappedResources(resources);
}
/* (non-Javadoc)
diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/DebugUIPlugin.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/DebugUIPlugin.java
index 743b82ffd..f46234338 100644
--- a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/DebugUIPlugin.java
+++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/DebugUIPlugin.java
@@ -24,6 +24,8 @@ import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.internal.util.BundleUtility;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
@@ -185,4 +187,26 @@ public class DebugUIPlugin extends AbstractUIPlugin {
return color;
}
+ /**
+ * Returns the active workbench window
+ *
+ * @return the active workbench window
+ */
+ public static IWorkbenchWindow getActiveWorkbenchWindow() {
+ return getDefault().getWorkbench().getActiveWorkbenchWindow();
+ }
+
+ /**
+ * Returns the active workbench shell or null
if none
+ *
+ * @return the active workbench shell or null
if none
+ */
+ public static Shell getActiveWorkbenchShell() {
+ IWorkbenchWindow window = getActiveWorkbenchWindow();
+ if (window != null) {
+ return window.getShell();
+ }
+ return null;
+ }
+
}
--
cgit v1.2.3