]> 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/AbstractOsgiLaunchShortcut.java
Restructure SLC development environment
[gpl/argeo-slc.git] / eclipse / plugins / org.argeo.slc.ide.ui / src / main / java / org / argeo / slc / ide / ui / launch / osgi / AbstractOsgiLaunchShortcut.java
1 package org.argeo.slc.ide.ui.launch.osgi;
2
3 import java.util.ArrayList;
4 import java.util.HashMap;
5 import java.util.List;
6 import java.util.Map;
7
8 import org.eclipse.core.runtime.CoreException;
9 import org.eclipse.debug.core.ILaunchConfiguration;
10 import org.eclipse.debug.core.ILaunchConfigurationType;
11 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
12 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
13 import org.eclipse.jdt.launching.IVMInstall;
14 import org.eclipse.jdt.launching.IVMInstall2;
15 import org.eclipse.jface.dialogs.ErrorDialog;
16 import org.eclipse.jface.viewers.ISelection;
17 import org.eclipse.pde.ui.launcher.OSGiLaunchShortcut;
18 import org.eclipse.swt.widgets.DirectoryDialog;
19 import org.eclipse.swt.widgets.Display;
20 import org.eclipse.swt.widgets.Shell;
21
22 public abstract class AbstractOsgiLaunchShortcut extends OSGiLaunchShortcut {
23 protected StringBuffer name = null;
24
25 protected List<String> bundlesToStart = new ArrayList<String>();
26 protected Map<String, String> systemPropertiesToAppend = new HashMap<String, String>();
27
28 @Override
29 public void launch(ISelection selection, String mode) {
30 super.launch(selection, mode);
31 name = null;
32 bundlesToStart.clear();
33 systemPropertiesToAppend.clear();
34 }
35
36 protected void initializeConfiguration(
37 ILaunchConfigurationWorkingCopy configuration) {
38 try {
39 super.initializeConfiguration(configuration);
40
41 configuration
42 .setAttribute(
43 OsgiLauncherConstants.ATTR_DEFAULT_VM_ARGS,
44 configuration
45 .getAttribute(
46 IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS,
47 ""));
48 String defaultProgArgs = configuration.getAttribute(
49 IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS,
50 "");
51 configuration.setAttribute(
52 OsgiLauncherConstants.ATTR_DEFAULT_PROGRAM_ARGS,
53 defaultProgArgs);
54
55 OsgiLaunchHelper.updateLaunchConfiguration(configuration,
56 bundlesToStart, systemPropertiesToAppend,
57 findWorkingDirectory(), null);
58 } catch (CoreException e) {
59 Shell shell = Display.getCurrent().getActiveShell();
60 ErrorDialog.openError(shell, "Error",
61 "Cannot execute initalize configuration", e.getStatus());
62 }
63
64 }
65
66 protected String findWorkingDirectory() {
67 // Choose working directory
68 Shell shell = Display.getCurrent().getActiveShell();
69 DirectoryDialog dirDialog = new DirectoryDialog(shell);
70 dirDialog.setText("Working Directory");
71 dirDialog.setMessage("Choose the working directory");
72 return dirDialog.open();
73 }
74
75 protected void printVm(String prefix, IVMInstall vmInstall) {
76 System.out.println(prefix + " vmInstall: id=" + vmInstall.getId()
77 + ", name=" + vmInstall.getName() + ", installLocation="
78 + vmInstall.getInstallLocation() + ", toString=" + vmInstall);
79 if (vmInstall instanceof IVMInstall2) {
80 IVMInstall2 vmInstall2 = (IVMInstall2) vmInstall;
81 System.out.println(" vmInstall: javaVersion="
82 + vmInstall2.getJavaVersion());
83 }
84 }
85
86 protected String getName(ILaunchConfigurationType type) {
87 if (name != null && !name.toString().trim().equals(""))
88 return name.toString();
89 else
90 return "SLC";
91 }
92
93 @Override
94 protected boolean isGoodMatch(ILaunchConfiguration configuration) {
95 if (name != null) {
96 return name.toString().equals(configuration.getName());
97 }
98 return super.isGoodMatch(configuration);
99 }
100
101 }