-
Notifications
You must be signed in to change notification settings - Fork 24
/
LaunchOperation.java
103 lines (88 loc) · 3.94 KB
/
LaunchOperation.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Copyright (c) 2003-2008 by Leif Frenzel. All rights reserved.
// This code is made available under the terms of the Eclipse Public License,
// version 1.0 (EPL). See http://www.eclipse.org/legal/epl-v10.html
package net.sf.eclipsefp.haskell.debug.ui.internal.launch;
import java.util.ArrayList;
import java.util.List;
import net.sf.eclipsefp.compat.ILaunchManagerCompat;
import net.sf.eclipsefp.haskell.debug.core.internal.launch.HaskellLaunchDelegate;
import net.sf.eclipsefp.haskell.debug.core.internal.launch.ILaunchAttributes;
import net.sf.eclipsefp.haskell.debug.ui.internal.util.UITexts;
import net.sf.eclipsefp.haskell.ui.HaskellUIPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.debug.ui.IDebugModelPresentation;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.dialogs.ElementListSelectionDialog;
/** <p>super class for launch operations. Contains some common
* functionality.</p>
*
* @author Leif Frenzel
*/
public abstract class LaunchOperation {
static final String CONFIG_TYPE = HaskellLaunchDelegate.class.getName();
public static ILaunchConfiguration[] getConfigurations() throws CoreException {
ILaunchConfigurationType configType = getConfigType();
return getLaunchManager().getLaunchConfigurations( configType );
}
public static List<ILaunchConfiguration> getConfigurationsForProject(final String projectName) throws CoreException {
ILaunchConfigurationType configType = getConfigType();
ILaunchConfiguration[] configs=getLaunchManager().getLaunchConfigurations( configType );
List<ILaunchConfiguration> ret=new ArrayList<ILaunchConfiguration>();
for (ILaunchConfiguration config:configs){
if (projectName.equals(getProjectName(config))){
ret.add(config);
}
}
return ret;
}
public static ILaunchManager getLaunchManager() {
return DebugPlugin.getDefault().getLaunchManager();
}
String createConfigId( final String name ) {
ILaunchManager mgr = getLaunchManager();
// FIXME: Remove when Galileo is no longer supported.
return ILaunchManagerCompat.generateLaunchConfigurationName( mgr, name.replace( '/', '.' ) );
}
public static ILaunchConfigurationType getConfigType() {
return getLaunchManager().getLaunchConfigurationType( CONFIG_TYPE );
}
public static String getProjectName( final ILaunchConfiguration configuration )
throws CoreException {
String att = ILaunchAttributes.PROJECT_NAME;
return configuration.getAttribute( att, ILaunchAttributes.EMPTY );
}
String getExePath( final ILaunchConfiguration config ) throws CoreException {
String att = ILaunchAttributes.EXECUTABLE;
return config.getAttribute( att, ILaunchAttributes.EMPTY );
}
ILaunchConfiguration choose( final List<ILaunchConfiguration> configs ) {
IDebugModelPresentation pres = DebugUITools.newDebugModelPresentation();
Shell shell = getActiveShell();
ElementListSelectionDialog dialog = new ElementListSelectionDialog( shell,
pres );
dialog.setElements( configs.toArray() );
dialog.setTitle( UITexts.launchOperation_title );
dialog.setMessage( UITexts.launchOperation_msg );
dialog.setMultipleSelection( false );
ILaunchConfiguration result = null;
int returnVal = dialog.open();
pres.dispose();
if( returnVal == Window.OK ) {
result = ( ILaunchConfiguration )dialog.getFirstResult();
}
return result;
}
// helping methods
// ////////////////
private Shell getActiveShell() {
IWorkbench workbench = HaskellUIPlugin.getDefault().getWorkbench();
return workbench.getActiveWorkbenchWindow().getShell();
}
}