]> git.argeo.org Git - gpl/argeo-slc.git/blob - eclipse/plugins/org.argeo.slc.ide.ui/src/main/java/org/argeo/slc/ide/ui/launch/osgi/EclipseBootLaunchShortcut.java
NEW - bug 11: Introduce a simplified launch for RCP
[gpl/argeo-slc.git] / eclipse / plugins / org.argeo.slc.ide.ui / src / main / java / org / argeo / slc / ide / ui / launch / osgi / EclipseBootLaunchShortcut.java
1 package org.argeo.slc.ide.ui.launch.osgi;
2
3 import java.util.Iterator;
4
5 import org.eclipse.core.resources.IFile;
6 import org.eclipse.core.resources.IResource;
7 import org.eclipse.debug.core.DebugPlugin;
8 import org.eclipse.debug.core.ILaunchConfiguration;
9 import org.eclipse.debug.core.ILaunchConfigurationType;
10 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
11 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
12 import org.eclipse.jface.viewers.ISelection;
13 import org.eclipse.jface.viewers.IStructuredSelection;
14 import org.eclipse.pde.ui.launcher.EclipseLaunchShortcut;
15
16 /**
17 * Launch shortcut simplifying the launch of an Eclipse application (typically
18 * an RCP).
19 */
20 public class EclipseBootLaunchShortcut extends EclipseLaunchShortcut implements
21 OsgiLauncherConstants {
22 private StringBuffer name = null;
23 private IFile propertiesFile = null;
24
25 @Override
26 protected String getLaunchConfigurationTypeName() {
27 return EclipseBootLaunchConfiguration.ID;
28 }
29
30 @Override
31 public void launch(ISelection selection, String mode) {
32 // we assume that only one file is selected
33 IStructuredSelection sSelection = (IStructuredSelection) selection;
34 Iterator<?> it = sSelection.iterator();
35 propertiesFile = (IFile) it.next();
36
37 name = new StringBuffer(OsgiLaunchHelper.extractName(propertiesFile));
38
39 super.launch(selection, mode);
40 }
41
42 @Override
43 protected void initializeConfiguration(ILaunchConfigurationWorkingCopy wc) {
44 IResource[] resources = { propertiesFile };
45 wc.setMappedResources(resources);
46 super.initializeConfiguration(wc);
47
48 OsgiLaunchHelper.setDefaults(wc, true);
49 wc.setAttribute(
50 IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY,
51 OsgiLaunchHelper.findWorkingDirectory(propertiesFile));
52
53 OsgiLaunchHelper.updateLaunchConfiguration(wc, true);
54 }
55
56 protected String getName(ILaunchConfigurationType type) {
57 if (name != null && !name.toString().trim().equals(""))
58 return DebugPlugin.getDefault().getLaunchManager()
59 .generateLaunchConfigurationName(name.toString());
60 else
61 return DebugPlugin.getDefault().getLaunchManager()
62 .generateLaunchConfigurationName("SLC");
63 }
64
65 @Override
66 protected boolean isGoodMatch(ILaunchConfiguration configuration) {
67 if (name != null) {
68 return name.toString().equals(configuration.getName());
69 }
70 return super.isGoodMatch(configuration);
71 }
72 }