]> 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
Clean up code
[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 configuration.setAttribute(
56 IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY,
57 findWorkingDirectory());
58 OsgiLaunchHelper.updateLaunchConfiguration(configuration,
59 bundlesToStart, systemPropertiesToAppend, null);
60 } catch (CoreException e) {
61 Shell shell = Display.getCurrent().getActiveShell();
62 ErrorDialog.openError(shell, "Error",
63 "Cannot execute initalize configuration", e.getStatus());
64 }
65
66 }
67
68 protected String findWorkingDirectory() {
69 // Choose working directory
70 Shell shell = Display.getCurrent().getActiveShell();
71 DirectoryDialog dirDialog = new DirectoryDialog(shell);
72 dirDialog.setText("Working Directory");
73 dirDialog.setMessage("Choose the working directory");
74 return dirDialog.open();
75 }
76
77 protected void printVm(String prefix, IVMInstall vmInstall) {
78 System.out.println(prefix + " vmInstall: id=" + vmInstall.getId()
79 + ", name=" + vmInstall.getName() + ", installLocation="
80 + vmInstall.getInstallLocation() + ", toString=" + vmInstall);
81 if (vmInstall instanceof IVMInstall2) {
82 IVMInstall2 vmInstall2 = (IVMInstall2) vmInstall;
83 System.out.println(" vmInstall: javaVersion="
84 + vmInstall2.getJavaVersion());
85 }
86 }
87
88 protected String getName(ILaunchConfigurationType type) {
89 if (name != null && !name.toString().trim().equals(""))
90 return name.toString();
91 else
92 return "SLC";
93 }
94
95 @Override
96 protected boolean isGoodMatch(ILaunchConfiguration configuration) {
97 if (name != null) {
98 return name.toString().equals(configuration.getName());
99 }
100 return super.isGoodMatch(configuration);
101 }
102
103 }