Added
Link Here
|
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2000, 2007 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
6 |
* http://www.eclipse.org/legal/epl-v10.html |
7 |
* |
8 |
* Contributors: |
9 |
* IBM Corporation - initial API and implementation |
10 |
*******************************************************************************/ |
11 |
package org.eclipse.debug.internal.ui.launchConfigurations; |
12 |
|
13 |
|
14 |
import java.util.ArrayList; |
15 |
import java.util.List; |
16 |
|
17 |
import org.eclipse.core.runtime.CoreException; |
18 |
import org.eclipse.core.runtime.IProgressMonitor; |
19 |
import org.eclipse.core.runtime.IStatus; |
20 |
import org.eclipse.core.runtime.Status; |
21 |
import org.eclipse.core.runtime.SubMonitor; |
22 |
import org.eclipse.core.runtime.jobs.Job; |
23 |
import org.eclipse.debug.core.DebugException; |
24 |
import org.eclipse.debug.core.ILaunch; |
25 |
import org.eclipse.debug.core.ILaunchConfiguration; |
26 |
import org.eclipse.debug.internal.ui.DebugUIPlugin; |
27 |
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; |
28 |
import org.eclipse.debug.ui.DebugUITools; |
29 |
import org.eclipse.jface.resource.ImageDescriptor; |
30 |
import org.eclipse.jface.viewers.IStructuredSelection; |
31 |
import org.eclipse.jface.viewers.Viewer; |
32 |
import org.eclipse.ui.statushandlers.StatusManager; |
33 |
|
34 |
/** |
35 |
* Launches all selected launch configurations. |
36 |
*/ |
37 |
public class MultiLaunchAction extends AbstractLaunchConfigurationAction { |
38 |
|
39 |
/** |
40 |
* Action identifier for IDebugView#getAction(String) |
41 |
*/ |
42 |
public static final String ID_MULTI_LAUNCH_ACTION = DebugUIPlugin.getUniqueIdentifier() + ".ID_MULTI_LAUNCH_ACTION"; //$NON-NLS-1$ |
43 |
|
44 |
/** |
45 |
* Constructs an action to launch multiple configurations |
46 |
*/ |
47 |
public MultiLaunchAction(Viewer viewer, String mode) { |
48 |
super(LaunchConfigurationsMessages.MultiLaunchAction__Launch_All_1, viewer, mode); |
49 |
} |
50 |
|
51 |
/** |
52 |
* @see AbstractLaunchConfigurationAction#performAction() |
53 |
*/ |
54 |
protected void performAction() { |
55 |
Object[] selection = getStructuredSelection().toArray(); |
56 |
List launches = new ArrayList(); |
57 |
for (int i = 0; i < selection.length; i++) { |
58 |
if (selection[i] instanceof ILaunchConfiguration) { |
59 |
launches.add(selection[i]); |
60 |
} |
61 |
} |
62 |
multiLaunchInBackground((ILaunchConfiguration[]) launches.toArray(new ILaunchConfiguration[launches.size()])); |
63 |
} |
64 |
|
65 |
private void multiLaunchInBackground(final ILaunchConfiguration[] launches) { |
66 |
new Job("Multi-Launch") { |
67 |
protected IStatus run(IProgressMonitor monitor) { |
68 |
SubMonitor sm = SubMonitor |
69 |
.convert( |
70 |
monitor, |
71 |
LaunchConfigurationsMessages.MultiLaunchAction__Launching_Multiple_1, |
72 |
launches.length); |
73 |
try { |
74 |
for (int i = 0; i < launches.length; i++) { |
75 |
ILaunch launch = launches[i].launch(getMode(), sm.newChild(1), true); |
76 |
while (!launch.isTerminated()) { |
77 |
try { |
78 |
Thread.sleep(1000); |
79 |
} catch (InterruptedException e) { |
80 |
Thread.currentThread().interrupt(); |
81 |
return Status.CANCEL_STATUS; |
82 |
} |
83 |
if (monitor.isCanceled()) { |
84 |
try { |
85 |
launch.terminate(); |
86 |
} catch (DebugException ex) { |
87 |
StatusManager.getManager().handle(new Status(IStatus.WARNING, DebugUIPlugin.getUniqueIdentifier(), ex |
88 |
.getLocalizedMessage(), ex), StatusManager.LOG); |
89 |
} |
90 |
return Status.CANCEL_STATUS; |
91 |
} |
92 |
} |
93 |
} |
94 |
} catch (CoreException coreException) { |
95 |
Status status = new Status(IStatus.ERROR, DebugUIPlugin.getUniqueIdentifier(), coreException |
96 |
.getLocalizedMessage(), coreException); |
97 |
StatusManager.getManager().handle(status, StatusManager.SHOW); |
98 |
return Status.OK_STATUS; |
99 |
} finally { |
100 |
monitor.done(); |
101 |
} |
102 |
return Status.OK_STATUS; |
103 |
} |
104 |
}.schedule(); |
105 |
} |
106 |
|
107 |
/** |
108 |
* @see org.eclipse.ui.actions.SelectionListenerAction#updateSelection(org.eclipse.jface.viewers.IStructuredSelection) |
109 |
*/ |
110 |
protected boolean updateSelection(IStructuredSelection selection) { |
111 |
if (selection.size() < 2) { |
112 |
return false; |
113 |
} |
114 |
Object[] launches = getStructuredSelection().toArray(); |
115 |
for (int i = 0; i < launches.length; i++) { |
116 |
if (!(launches[i] instanceof ILaunchConfiguration)) { |
117 |
return false; |
118 |
} |
119 |
} |
120 |
return true; |
121 |
} |
122 |
|
123 |
/* (non-Javadoc) |
124 |
* @see org.eclipse.jface.action.Action#getDisabledImageDescriptor() |
125 |
*/ |
126 |
public ImageDescriptor getDisabledImageDescriptor() { |
127 |
return DebugUITools.getImageDescriptor(IInternalDebugUIConstants.IMG_DLCL_DUPLICATE_CONFIG); |
128 |
} |
129 |
|
130 |
/* (non-Javadoc) |
131 |
* @see org.eclipse.jface.action.Action#getImageDescriptor() |
132 |
*/ |
133 |
public ImageDescriptor getImageDescriptor() { |
134 |
return DebugUITools.getImageDescriptor(IInternalDebugUIConstants.IMG_ELCL_DUPLICATE_CONFIG); |
135 |
} |
136 |
|
137 |
/* (non-Javadoc) |
138 |
* @see org.eclipse.jface.action.Action#getToolTipText() |
139 |
*/ |
140 |
public String getToolTipText() { |
141 |
return LaunchConfigurationsMessages.LaunchConfigurationsDialog_5; |
142 |
} |
143 |
|
144 |
} |