mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 17:05:26 +02:00
[270671] - implemented support for group launch in cdt
This commit is contained in:
parent
b941cf44b8
commit
b813ee9976
7 changed files with 964 additions and 1 deletions
|
@ -17,6 +17,8 @@ LocalAttachCDTLaunch.name=Standard Attach to Process
|
|||
LocalAttachCDTLaunch.description=Attach standard debugger to a running program using.
|
||||
CoreFileCDTLaunch.name=Standard Postmortem Debugger
|
||||
CoreFileCDTLaunch.description=Load an application dump into the standard debugger.
|
||||
LaunchGroup.name=Launch Group
|
||||
LaunchGroup.description=Launch several other configurations sequentially
|
||||
|
||||
MainLaunchTab.name=Main
|
||||
ArgumentsLaunchTab.name=Arguments
|
||||
|
@ -26,3 +28,4 @@ SourceLookupLaunchTab.name=Source
|
|||
CommonLaunchTab.name=Common
|
||||
CoreFileLaunchTab.name=Debugger
|
||||
RefreshLaunchTab.name=Refresh
|
||||
|
||||
|
|
|
@ -34,6 +34,16 @@
|
|||
sourceLocatorId="org.eclipse.cdt.debug.core.sourceLocator"
|
||||
sourcePathComputerId="org.eclipse.cdt.debug.core.sourcePathComputer">
|
||||
</launchDelegate>
|
||||
<launchDelegate
|
||||
delegate="org.eclipse.cdt.launch.internal.MultiLaunchConfigurationDelegate"
|
||||
delegateDescription="%LaunchGroup.description"
|
||||
id="org.eclipse.cdt.launch.launchGroup.delegate"
|
||||
type="org.eclipse.cdt.launch.launchGroup"
|
||||
modes="run,debug,profile"
|
||||
name="%LaunchGroup.name"
|
||||
sourceLocatorId="org.eclipse.cdt.debug.core.sourceLocator"
|
||||
sourcePathComputerId="org.eclipse.cdt.debug.core.sourcePathComputer">
|
||||
</launchDelegate>
|
||||
</extension>
|
||||
|
||||
<extension
|
||||
|
@ -192,5 +202,31 @@
|
|||
id="org.eclipse.cdt.launch.statusHandler.coreFilePrompter">
|
||||
</statusHandler>
|
||||
</extension>
|
||||
|
||||
|
||||
<extension
|
||||
point="org.eclipse.debug.core.launchConfigurationTypes">
|
||||
<launchConfigurationType
|
||||
id="org.eclipse.cdt.launch.launchGroup"
|
||||
name="%LaunchGroup.name"
|
||||
public="true">
|
||||
</launchConfigurationType>
|
||||
</extension>
|
||||
|
||||
<extension
|
||||
point="org.eclipse.debug.ui.launchConfigurationTabGroups">
|
||||
<launchConfigurationTabGroup
|
||||
class="org.eclipse.cdt.launch.internal.MultiLaunchConfigurationTabGroup"
|
||||
id="org.eclipse.cdt.launch.launchGroup.tabgroup"
|
||||
type="org.eclipse.cdt.launch.launchGroup">
|
||||
</launchConfigurationTabGroup>
|
||||
</extension>
|
||||
|
||||
<extension
|
||||
point="org.eclipse.debug.ui.launchConfigurationTypeImages">
|
||||
<launchConfigurationTypeImage
|
||||
icon="icons/obj16/exec_obj.gif"
|
||||
configTypeID="org.eclipse.cdt.launch.launchGroup"
|
||||
id="org.eclipse.cdt.launch.launchGroup.image">
|
||||
</launchConfigurationTypeImage>
|
||||
</extension>
|
||||
</plugin>
|
||||
|
|
|
@ -0,0 +1,206 @@
|
|||
package org.eclipse.cdt.launch.internal;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
import org.eclipse.cdt.launch.internal.ui.LaunchMessages;
|
||||
import org.eclipse.cdt.launch.internal.ui.LaunchUIPlugin;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.SubProgressMonitor;
|
||||
import org.eclipse.debug.core.DebugPlugin;
|
||||
import org.eclipse.debug.core.ILaunch;
|
||||
import org.eclipse.debug.core.ILaunchConfiguration;
|
||||
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
|
||||
import org.eclipse.debug.core.ILaunchManager;
|
||||
import org.eclipse.debug.core.model.ILaunchConfigurationDelegate;
|
||||
import org.eclipse.debug.core.model.IProcess;
|
||||
import org.eclipse.debug.core.model.LaunchConfigurationDelegate;
|
||||
import org.eclipse.debug.internal.ui.DebugUIPlugin;
|
||||
import org.eclipse.debug.ui.DebugUITools;
|
||||
import org.eclipse.debug.ui.IDebugUIConstants;
|
||||
import org.eclipse.debug.ui.ILaunchGroup;
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
|
||||
/**
|
||||
* Group Launch delegate. Launches each configuration in the user selected mode
|
||||
*/
|
||||
public class MultiLaunchConfigurationDelegate extends LaunchConfigurationDelegate implements ILaunchConfigurationDelegate {
|
||||
static final String DEFAULT_MODE = "default"; //$NON-NLS-1$
|
||||
private static final String NAME_PROP = "name"; //$NON-NLS-1$
|
||||
private static final String ENABLED_PROP = "enabled"; //$NON-NLS-1$
|
||||
private static final String MODE_PROP = "mode"; //$NON-NLS-1$
|
||||
private static final String ACTION_PROP = "action"; //$NON-NLS-1$
|
||||
public static String MULTI_LAUNCH_CONSTANTS_PREFIX = "org.eclipse.cdt.launch.launchGroup"; //$NON-NLS-1$
|
||||
|
||||
static class LaunchElement {
|
||||
int index;
|
||||
boolean enabled;
|
||||
String mode;
|
||||
String action;
|
||||
String name;
|
||||
ILaunchConfiguration data;
|
||||
}
|
||||
|
||||
public MultiLaunchConfigurationDelegate() {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor)
|
||||
throws CoreException {
|
||||
// have to unset "remove terminated launches when new one created"
|
||||
// because it does not work good for multilaunch
|
||||
boolean dstore = DebugUIPlugin.getDefault().getPreferenceStore()
|
||||
.getBoolean(IDebugUIConstants.PREF_AUTO_REMOVE_OLD_LAUNCHES);
|
||||
ArrayList<LaunchElement> input = createLaunchElements(configuration, new ArrayList<LaunchElement>());
|
||||
try {
|
||||
|
||||
monitor.beginTask(LaunchMessages.getString("MultiLaunchConfigurationDelegate.0") + configuration.getName(), 1000); //$NON-NLS-1$
|
||||
DebugUIPlugin.getDefault().getPreferenceStore().setValue(IDebugUIConstants.PREF_AUTO_REMOVE_OLD_LAUNCHES, false);
|
||||
for (Iterator<LaunchElement> iterator = input.iterator(); iterator.hasNext();) {
|
||||
LaunchElement le = iterator.next();
|
||||
final ILaunchConfiguration conf = findLaunch(le.name);
|
||||
if (le.enabled==false) continue;
|
||||
if (conf==null) continue;
|
||||
final String localMode;
|
||||
if (le.mode != null && !le.mode.equals(DEFAULT_MODE)) {
|
||||
localMode = le.mode;
|
||||
} else {
|
||||
localMode = mode;
|
||||
}
|
||||
ILaunchGroup launchGroup = DebugUITools.getLaunchGroup(conf, localMode);
|
||||
if (launchGroup==null) {
|
||||
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
|
||||
public void run() {
|
||||
MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), LaunchMessages.getString("LaunchUIPlugin.Error"), //$NON-NLS-1$
|
||||
LaunchMessages.getFormattedString("MultiLaunchConfigurationDelegate.Cannot", //$NON-NLS-1$
|
||||
new String[]{conf.toString(), localMode})
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
continue;
|
||||
}
|
||||
ILaunch launch2 = DebugUIPlugin.buildAndLaunch(conf, localMode,
|
||||
new SubProgressMonitor(monitor, 1000 / input.size()));
|
||||
IProcess[] processes = launch2.getProcesses();
|
||||
for (int i = 0; i < processes.length; i++) {
|
||||
IProcess process = processes[i];
|
||||
launch.addProcess(process);
|
||||
|
||||
}
|
||||
}
|
||||
if (!launch.hasChildren()) {
|
||||
ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
|
||||
launchManager.removeLaunch(launch);
|
||||
}
|
||||
} finally {
|
||||
DebugUIPlugin.getDefault().getPreferenceStore().setValue(IDebugUIConstants.PREF_AUTO_REMOVE_OLD_LAUNCHES, dstore);
|
||||
monitor.done();
|
||||
}
|
||||
}
|
||||
|
||||
protected void buildProjects(IProject[] projects, IProgressMonitor monitor) throws CoreException {
|
||||
// do nothing, project can be rebuild for each launch individually
|
||||
|
||||
}
|
||||
|
||||
public boolean buildForLaunch(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor) throws CoreException {
|
||||
// not build for this one
|
||||
return false;
|
||||
}
|
||||
|
||||
protected static ILaunchConfiguration findLaunch(String name) throws CoreException {
|
||||
ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
|
||||
ILaunchConfiguration[] launchConfigurations = launchManager.getLaunchConfigurations();
|
||||
for (int i = 0; i < launchConfigurations.length; i++) {
|
||||
ILaunchConfiguration lConf = launchConfigurations[i];
|
||||
if (lConf.getName().equals(name))
|
||||
return lConf;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ArrayList<LaunchElement> createLaunchElements(ILaunchConfiguration configuration, ArrayList<MultiLaunchConfigurationDelegate.LaunchElement> input) {
|
||||
try {
|
||||
Map attrs = configuration.getAttributes();
|
||||
for (Iterator iterator = attrs.keySet().iterator(); iterator.hasNext();) {
|
||||
String attr = (String) iterator.next();
|
||||
try {
|
||||
if (attr.startsWith(MultiLaunchConfigurationDelegate.MULTI_LAUNCH_CONSTANTS_PREFIX)) {
|
||||
String prop = attr
|
||||
.substring(MultiLaunchConfigurationDelegate.MULTI_LAUNCH_CONSTANTS_PREFIX.length() + 1);
|
||||
int k = prop.indexOf('.');
|
||||
String num = prop.substring(0, k);
|
||||
int index = Integer.parseInt(num);
|
||||
String name = prop.substring(k + 1);
|
||||
if (name.equals(NAME_PROP)) {
|
||||
MultiLaunchConfigurationDelegate.LaunchElement el = new MultiLaunchConfigurationDelegate.LaunchElement();
|
||||
el.index = index;
|
||||
el.name = (String) attrs.get(attr);
|
||||
el.action = (String) attrs.get(getProp(index, ACTION_PROP));
|
||||
el.mode = (String) attrs.get(getProp(index, MODE_PROP));
|
||||
el.enabled = "true".equals(attrs.get(getProp(index, ENABLED_PROP))); //$NON-NLS-1$
|
||||
try {
|
||||
el.data = findLaunch(el.name);
|
||||
} catch (Exception e) {
|
||||
el.data = null;
|
||||
}
|
||||
while (index >= input.size()) {
|
||||
input.add(null);
|
||||
}
|
||||
input.set(index, el);
|
||||
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LaunchUIPlugin.log(e);
|
||||
}
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
LaunchUIPlugin.log(e);
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
public static void storeLaunchElements(ILaunchConfigurationWorkingCopy configuration,
|
||||
ArrayList<LaunchElement> input) {
|
||||
int i = 0;
|
||||
removeLaunchElements(configuration);
|
||||
for (Iterator<LaunchElement> iterator = input.iterator(); iterator.hasNext();) {
|
||||
MultiLaunchConfigurationDelegate.LaunchElement el = iterator.next();
|
||||
if (el == null) continue;
|
||||
configuration.setAttribute(MultiLaunchConfigurationDelegate.getProp(i, NAME_PROP), el.name);
|
||||
configuration.setAttribute(MultiLaunchConfigurationDelegate.getProp(i, ACTION_PROP), el.action);
|
||||
configuration.setAttribute(MultiLaunchConfigurationDelegate.getProp(i, MODE_PROP), el.mode);
|
||||
configuration.setAttribute(MultiLaunchConfigurationDelegate.getProp(i, ENABLED_PROP), el.enabled + ""); //$NON-NLS-1$
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
public static void removeLaunchElements(ILaunchConfigurationWorkingCopy configuration) {
|
||||
try {
|
||||
Map attrs = configuration.getAttributes();
|
||||
for (Iterator iterator = attrs.keySet().iterator(); iterator.hasNext();) {
|
||||
String attr = (String) iterator.next();
|
||||
try {
|
||||
if (attr.startsWith(MultiLaunchConfigurationDelegate.MULTI_LAUNCH_CONSTANTS_PREFIX)) {
|
||||
configuration.removeAttribute(attr);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LaunchUIPlugin.log(e);
|
||||
}
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
LaunchUIPlugin.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static String getProp(int index, String string) {
|
||||
return MultiLaunchConfigurationDelegate.MULTI_LAUNCH_CONSTANTS_PREFIX + "." + index + "." + string; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
}
|
|
@ -0,0 +1,207 @@
|
|||
package org.eclipse.cdt.launch.internal;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.eclipse.cdt.launch.internal.ui.LaunchMessages;
|
||||
import org.eclipse.cdt.launch.ui.ComboControlledStackComposite;
|
||||
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.internal.ui.DebugUIPlugin;
|
||||
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationFilteredTree;
|
||||
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationManager;
|
||||
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchGroupFilter;
|
||||
import org.eclipse.debug.ui.ILaunchGroup;
|
||||
import org.eclipse.jface.dialogs.IDialogConstants;
|
||||
import org.eclipse.jface.dialogs.TitleAreaDialog;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.jface.viewers.SelectionChangedEvent;
|
||||
import org.eclipse.jface.viewers.StructuredSelection;
|
||||
import org.eclipse.jface.viewers.Viewer;
|
||||
import org.eclipse.jface.viewers.ViewerFilter;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.graphics.Rectangle;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Combo;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.ui.dialogs.PatternFilter;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Dialog to select launch configuration(s)
|
||||
*/
|
||||
public class MultiLaunchConfigurationSelectionDialog extends TitleAreaDialog implements ISelectionChangedListener {
|
||||
private ViewerFilter[] fFilters = null;
|
||||
private ISelection fSelection;
|
||||
private ILaunchGroup[] launchGroups;
|
||||
private String mode;
|
||||
private boolean isDefaultMode;
|
||||
private ViewerFilter emptyTypeFilter;
|
||||
private IStructuredSelection fInitialSelection;
|
||||
|
||||
public MultiLaunchConfigurationSelectionDialog(Shell shell, String title, String initMode) {
|
||||
super(shell);
|
||||
LaunchConfigurationManager manager = DebugUIPlugin.getDefault().getLaunchConfigurationManager();
|
||||
launchGroups = manager.getLaunchGroups();
|
||||
mode = initMode;
|
||||
fFilters = null;
|
||||
setShellStyle(getShellStyle() | SWT.RESIZE);
|
||||
emptyTypeFilter = new ViewerFilter() {
|
||||
public boolean select(Viewer viewer, Object parentElement, Object element) {
|
||||
if (element instanceof ILaunchConfigurationType) {
|
||||
try {
|
||||
ILaunchConfigurationType type = (ILaunchConfigurationType) element;
|
||||
return getLaunchManager().getLaunchConfigurations(type).length > 0;
|
||||
} catch (CoreException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected ILaunchManager getLaunchManager() {
|
||||
return DebugPlugin.getDefault().getLaunchManager();
|
||||
}
|
||||
|
||||
protected Control createContents(Composite parent) {
|
||||
Control x = super.createContents(parent);
|
||||
validate();
|
||||
setErrorMessage(null);
|
||||
return x;
|
||||
}
|
||||
|
||||
protected Control createDialogArea(Composite parent2) {
|
||||
getShell().setText(LaunchMessages.getString("MultiLaunchConfigurationSelectionDialog.0")); //$NON-NLS-1$
|
||||
setTitle(LaunchMessages.getString("MultiLaunchConfigurationSelectionDialog.1")); //$NON-NLS-1$
|
||||
//setMessage("Select a Launch Configuration and a Launch Mode");
|
||||
Composite comp = (Composite) super.createDialogArea(parent2);
|
||||
ComboControlledStackComposite scomp = new ComboControlledStackComposite(comp, SWT.NONE);
|
||||
HashMap modes = new HashMap();
|
||||
for (int i = 0; i < launchGroups.length; i++) {
|
||||
ILaunchGroup g = launchGroups[i];
|
||||
if (!modes.containsKey(g.getMode())) {
|
||||
modes.put(g.getMode(), g);
|
||||
}
|
||||
}
|
||||
if (this.mode.equals(MultiLaunchConfigurationDelegate.DEFAULT_MODE)) { //$NON-NLS-1$
|
||||
try {
|
||||
this.mode = "run"; //$NON-NLS-1$
|
||||
ILaunchConfiguration sel = getSelectedLaunchConfiguration();
|
||||
if (sel != null)
|
||||
for (Iterator iterator = modes.keySet().iterator(); iterator.hasNext();) {
|
||||
String mode = (String) iterator.next();
|
||||
if (sel.supportsMode(mode)) {
|
||||
this.mode = mode;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
for (Iterator iterator = modes.keySet().iterator(); iterator.hasNext();) {
|
||||
String mode = (String) iterator.next();
|
||||
ILaunchGroup g = (ILaunchGroup) modes.get(mode);
|
||||
LaunchConfigurationFilteredTree fTree = new LaunchConfigurationFilteredTree(scomp.getStackParent(), SWT.MULTI
|
||||
| SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER, new PatternFilter(), g, fFilters);
|
||||
String label = mode;
|
||||
scomp.addItem(label, fTree);
|
||||
fTree.createViewControl();
|
||||
ViewerFilter[] filters = fTree.getViewer().getFilters();
|
||||
for (int i = 0; i < filters.length; i++) {
|
||||
ViewerFilter viewerFilter = filters[i];
|
||||
if (viewerFilter instanceof LaunchGroupFilter) {
|
||||
fTree.getViewer().removeFilter(viewerFilter);
|
||||
}
|
||||
}
|
||||
fTree.getViewer().addFilter(emptyTypeFilter);
|
||||
fTree.getViewer().addSelectionChangedListener(this);
|
||||
if (g.getMode().equals(this.mode)) {
|
||||
scomp.setSelection(label);
|
||||
}
|
||||
if (fInitialSelection!=null) {
|
||||
|
||||
fTree.getViewer().setSelection(fInitialSelection, true);
|
||||
}
|
||||
}
|
||||
scomp.setLabelText(LaunchMessages.getString("MultiLaunchConfigurationSelectionDialog.4")); //$NON-NLS-1$
|
||||
scomp.pack();
|
||||
Rectangle bounds = scomp.getBounds();
|
||||
// adjust size
|
||||
GridData data = ((GridData) scomp.getLayoutData());
|
||||
if (data == null) {
|
||||
data = new GridData(GridData.FILL_BOTH);
|
||||
scomp.setLayoutData(data);
|
||||
}
|
||||
data.heightHint = Math.max(convertHeightInCharsToPixels(15), bounds.height);
|
||||
data.widthHint = Math.max(convertWidthInCharsToPixels(40), bounds.width);
|
||||
scomp.getCombo().addSelectionListener(new SelectionAdapter() {
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
mode = ((Combo) e.widget).getText();
|
||||
}
|
||||
});
|
||||
// Use default checkbox
|
||||
Button checkBox = new Button(comp, SWT.CHECK);
|
||||
checkBox.setText(LaunchMessages.getString("MultiLaunchConfigurationSelectionDialog.5")); //$NON-NLS-1$
|
||||
checkBox.addSelectionListener(new SelectionAdapter() {
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
isDefaultMode = ((Button) e.widget).getSelection();
|
||||
}
|
||||
});
|
||||
return comp;
|
||||
}
|
||||
|
||||
public ILaunchConfiguration getSelectedLaunchConfiguration() {
|
||||
if (fSelection != null && !fSelection.isEmpty()) {
|
||||
Object firstElement = ((IStructuredSelection) fSelection).getFirstElement();
|
||||
if (firstElement instanceof ILaunchConfiguration)
|
||||
return (ILaunchConfiguration) firstElement;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getMode() {
|
||||
if (isDefaultMode)
|
||||
return MultiLaunchConfigurationDelegate.DEFAULT_MODE; //$NON-NLS-1$
|
||||
else
|
||||
return mode;
|
||||
}
|
||||
|
||||
public static MultiLaunchConfigurationSelectionDialog createDialog(Shell shell, String title, String groupId) {
|
||||
return new MultiLaunchConfigurationSelectionDialog(shell, title, groupId);
|
||||
}
|
||||
|
||||
public void selectionChanged(SelectionChangedEvent event) {
|
||||
fSelection = event.getSelection();
|
||||
|
||||
validate();
|
||||
}
|
||||
|
||||
protected void validate() {
|
||||
Button ok_button = getButton(IDialogConstants.OK_ID);
|
||||
if (getSelectedLaunchConfiguration() == null) {
|
||||
setErrorMessage(LaunchMessages.getString("MultiLaunchConfigurationSelectionDialog.7")); //$NON-NLS-1$
|
||||
if (ok_button!=null) ok_button.setEnabled(false);
|
||||
} else {
|
||||
setErrorMessage(null);
|
||||
if (ok_button!=null) ok_button.setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void setInitialSelection(ILaunchConfiguration data) {
|
||||
fInitialSelection = new StructuredSelection(data);
|
||||
fSelection = fInitialSelection;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,373 @@
|
|||
package org.eclipse.cdt.launch.internal;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.eclipse.cdt.launch.internal.ui.LaunchMessages;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.debug.core.ILaunchConfiguration;
|
||||
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
|
||||
import org.eclipse.debug.internal.ui.DebugPluginImages;
|
||||
import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
|
||||
import org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup;
|
||||
import org.eclipse.debug.ui.ILaunchConfigurationDialog;
|
||||
import org.eclipse.debug.ui.ILaunchConfigurationTab;
|
||||
import org.eclipse.jface.dialogs.Dialog;
|
||||
import org.eclipse.jface.viewers.BaseLabelProvider;
|
||||
import org.eclipse.jface.viewers.CheckboxTreeViewer;
|
||||
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
||||
import org.eclipse.jface.viewers.IStructuredContentProvider;
|
||||
import org.eclipse.jface.viewers.ITableLabelProvider;
|
||||
import org.eclipse.jface.viewers.ITreeContentProvider;
|
||||
import org.eclipse.jface.viewers.SelectionChangedEvent;
|
||||
import org.eclipse.jface.viewers.StructuredSelection;
|
||||
import org.eclipse.jface.viewers.Viewer;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.events.SelectionListener;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Tree;
|
||||
import org.eclipse.swt.widgets.TreeColumn;
|
||||
import org.eclipse.swt.widgets.Widget;
|
||||
import org.eclipse.ui.ISharedImages;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
|
||||
/**
|
||||
* Tab group for Launch Group. Only one tab.
|
||||
*/
|
||||
public class MultiLaunchConfigurationTabGroup extends AbstractLaunchConfigurationTabGroup {
|
||||
static class ContentProvider implements IStructuredContentProvider, ITreeContentProvider {
|
||||
protected ArrayList input;
|
||||
|
||||
public Object[] getElements(Object inputElement) {
|
||||
return getChildren(inputElement);
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
input = null;
|
||||
}
|
||||
|
||||
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
|
||||
if (newInput instanceof ArrayList)
|
||||
input = (ArrayList) newInput;
|
||||
}
|
||||
|
||||
public Object[] getChildren(Object parentElement) {
|
||||
if (parentElement == input)
|
||||
return input.toArray();
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object getParent(Object element) {
|
||||
if (element == input)
|
||||
return null;
|
||||
return input;
|
||||
}
|
||||
|
||||
public boolean hasChildren(Object element) {
|
||||
if (element == input)
|
||||
return input.size() > 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
static class LabelProvider extends BaseLabelProvider implements ITableLabelProvider {
|
||||
public Image getColumnImage(Object element, int columnIndex) {
|
||||
if (!(element instanceof MultiLaunchConfigurationDelegate.LaunchElement))
|
||||
return null;
|
||||
if (columnIndex == 0) {
|
||||
MultiLaunchConfigurationDelegate.LaunchElement el = (MultiLaunchConfigurationDelegate.LaunchElement) element;
|
||||
if (el.data == null) {
|
||||
Image errorImage = PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_ERROR_TSK);
|
||||
return errorImage;
|
||||
}
|
||||
|
||||
try {
|
||||
String key = el.data.getType().getIdentifier();
|
||||
return DebugPluginImages.getImage(key);
|
||||
} catch (CoreException e) {
|
||||
Image errorImage = PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_ERROR_TSK);
|
||||
return errorImage;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getColumnText(Object element, int columnIndex) {
|
||||
if (!(element instanceof MultiLaunchConfigurationDelegate.LaunchElement))
|
||||
return null;
|
||||
MultiLaunchConfigurationDelegate.LaunchElement el = (MultiLaunchConfigurationDelegate.LaunchElement) element;
|
||||
if (columnIndex == 0)
|
||||
try {
|
||||
return (el.data != null) ? el.data.getType().getName() + "::" + el.name : el.name; //$NON-NLS-1$
|
||||
} catch (CoreException e) {
|
||||
return el.name;
|
||||
}
|
||||
if (columnIndex == 1)
|
||||
return el.mode;
|
||||
if (columnIndex == 2)
|
||||
return el.action;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
static abstract class ButtonComposite extends Composite implements SelectionListener {
|
||||
Button upButton;
|
||||
Button downButton;
|
||||
Button addButton;
|
||||
Button deleteButton;
|
||||
Button editButton;
|
||||
|
||||
public ButtonComposite(Composite parent, int style) {
|
||||
super(parent, style);
|
||||
setLayout(new GridLayout());
|
||||
upButton = createPushButton(this, LaunchMessages.getString("MultiLaunchConfigurationTabGroup.1")); //$NON-NLS-1$
|
||||
downButton = createPushButton(this, LaunchMessages.getString("MultiLaunchConfigurationTabGroup.2")); //$NON-NLS-1$
|
||||
editButton = createPushButton(this, LaunchMessages.getString("MultiLaunchConfigurationTabGroup.3")); //$NON-NLS-1$
|
||||
addButton = createPushButton(this, LaunchMessages.getString("MultiLaunchConfigurationTabGroup.4")); //$NON-NLS-1$
|
||||
deleteButton = createPushButton(this, LaunchMessages.getString("MultiLaunchConfigurationTabGroup.5")); //$NON-NLS-1$
|
||||
|
||||
}
|
||||
|
||||
protected void updateWidgetEnablement(){
|
||||
|
||||
}
|
||||
/**
|
||||
* Helper method to create a push button.
|
||||
*
|
||||
* @param parent
|
||||
* the parent control
|
||||
* @param key
|
||||
* the resource name used to supply the button's label text
|
||||
* @return Button
|
||||
*/
|
||||
protected Button createPushButton(Composite parent, String key) {
|
||||
Button button = new Button(parent, SWT.PUSH);
|
||||
button.setText(key);
|
||||
button.setFont(parent.getFont());
|
||||
GridData data = new GridData(GridData.FILL_HORIZONTAL);
|
||||
button.setLayoutData(data);
|
||||
button.addSelectionListener(this);
|
||||
return button;
|
||||
}
|
||||
|
||||
public void widgetDefaultSelected(SelectionEvent e) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
Widget widget = e.widget;
|
||||
if (widget == upButton) {
|
||||
upPressed();
|
||||
} else if (widget == downButton) {
|
||||
downPressed();
|
||||
} else if (widget == addButton) {
|
||||
addPressed();
|
||||
} else if (widget == deleteButton) {
|
||||
deletePressed();
|
||||
} else if (widget == editButton) {
|
||||
editPressed();
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void addPressed();
|
||||
|
||||
protected abstract void editPressed();
|
||||
|
||||
protected abstract void deletePressed();
|
||||
|
||||
protected abstract void downPressed();
|
||||
|
||||
protected abstract void upPressed();
|
||||
}
|
||||
static class GroupLaunchTab extends AbstractLaunchConfigurationTab {
|
||||
protected CheckboxTreeViewer treeViewer;
|
||||
protected ArrayList input = new ArrayList();
|
||||
private String mode;
|
||||
|
||||
public GroupLaunchTab(String mode) {
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
public void createControl(Composite parent) {
|
||||
Composite comp = new Composite(parent, SWT.NONE);
|
||||
setControl(comp);
|
||||
//comp.setBackground(PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_DARK_GREEN));
|
||||
comp.setLayout(new GridLayout(2, false));
|
||||
treeViewer = new CheckboxTreeViewer(comp, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
|
||||
Tree table = treeViewer.getTree();
|
||||
table.setFont(parent.getFont());
|
||||
treeViewer.setContentProvider(new ContentProvider());
|
||||
treeViewer.setLabelProvider(new LabelProvider());
|
||||
table.setHeaderVisible(true);
|
||||
table.setLayoutData(new GridData(GridData.FILL_BOTH));
|
||||
TreeColumn col1 = new TreeColumn(table, SWT.NONE);
|
||||
col1.setText(LaunchMessages.getString("MultiLaunchConfigurationTabGroup.6")); //$NON-NLS-1$
|
||||
col1.setWidth(300);
|
||||
TreeColumn col2 = new TreeColumn(table, SWT.NONE);
|
||||
col2.setText(LaunchMessages.getString("MultiLaunchConfigurationTabGroup.7")); //$NON-NLS-1$
|
||||
col2.setWidth(100);
|
||||
|
||||
treeViewer.setInput(input);
|
||||
final ButtonComposite buts = new ButtonComposite(comp, SWT.NONE) {
|
||||
protected void addPressed() {
|
||||
MultiLaunchConfigurationSelectionDialog dialog = MultiLaunchConfigurationSelectionDialog.createDialog(treeViewer
|
||||
.getControl().getShell(), LaunchMessages.getString("MultiLaunchConfigurationTabGroup.8"), //$NON-NLS-1$
|
||||
mode
|
||||
);
|
||||
if (dialog.open() == Dialog.OK) {
|
||||
ILaunchConfiguration conf = dialog.getSelectedLaunchConfiguration();
|
||||
if (conf==null) return;
|
||||
MultiLaunchConfigurationDelegate.LaunchElement el = new MultiLaunchConfigurationDelegate.LaunchElement();
|
||||
input.add(el);
|
||||
el.index = input.size() - 1;
|
||||
el.enabled = true;
|
||||
el.name = conf.getName();
|
||||
el.data = conf;
|
||||
el.mode = dialog.getMode();
|
||||
treeViewer.refresh(true);
|
||||
treeViewer.setChecked(el, el.enabled);
|
||||
updateWidgetEnablement();
|
||||
updateLaunchConfigurationDialog();
|
||||
}
|
||||
}
|
||||
protected void updateWidgetEnablement(){
|
||||
downButton.setEnabled(isDownEnabled());
|
||||
upButton.setEnabled(isUpEnabled());
|
||||
int index = getSelIndex();
|
||||
deleteButton.setEnabled(index>=0);
|
||||
editButton.setEnabled(index>=0);
|
||||
}
|
||||
|
||||
|
||||
protected void editPressed() {
|
||||
int index = getSelIndex();
|
||||
if (index < 0)
|
||||
return;
|
||||
MultiLaunchConfigurationDelegate.LaunchElement el = (MultiLaunchConfigurationDelegate.LaunchElement) input
|
||||
.get(index);
|
||||
MultiLaunchConfigurationSelectionDialog dialog = MultiLaunchConfigurationSelectionDialog.createDialog(treeViewer
|
||||
.getControl().getShell(), LaunchMessages.getString("MultiLaunchConfigurationTabGroup.9"), //$NON-NLS-1$
|
||||
el.mode
|
||||
);
|
||||
dialog.setInitialSelection(el.data);
|
||||
if (dialog.open() == Dialog.OK) {
|
||||
ILaunchConfiguration conf = dialog.getSelectedLaunchConfiguration();
|
||||
if (conf==null) return;
|
||||
el.name = conf.getName();
|
||||
el.data = conf;
|
||||
el.mode = dialog.getMode();
|
||||
treeViewer.refresh(true);
|
||||
treeViewer.setChecked(el, el.enabled);
|
||||
updateWidgetEnablement();
|
||||
updateLaunchConfigurationDialog();
|
||||
}
|
||||
}
|
||||
protected void deletePressed() {
|
||||
int index = getSelIndex();
|
||||
if (index < 0)
|
||||
return;
|
||||
input.remove(index);
|
||||
treeViewer.refresh(true);
|
||||
updateWidgetEnablement();
|
||||
updateLaunchConfigurationDialog();
|
||||
}
|
||||
|
||||
private int getSelIndex() {
|
||||
StructuredSelection sel = (StructuredSelection) treeViewer.getSelection();
|
||||
if (sel.isEmpty())
|
||||
return -1;
|
||||
MultiLaunchConfigurationDelegate.LaunchElement el = ((MultiLaunchConfigurationDelegate.LaunchElement) sel
|
||||
.getFirstElement());
|
||||
return input.indexOf(el);
|
||||
}
|
||||
|
||||
protected void downPressed() {
|
||||
if (!isDownEnabled()) return;
|
||||
int index = getSelIndex();
|
||||
|
||||
MultiLaunchConfigurationDelegate.LaunchElement x = (MultiLaunchConfigurationDelegate.LaunchElement) input
|
||||
.get(index);
|
||||
input.set(index, input.get(index + 1));
|
||||
input.set(index + 1, x);
|
||||
treeViewer.refresh(true);
|
||||
updateWidgetEnablement();
|
||||
updateLaunchConfigurationDialog();
|
||||
}
|
||||
|
||||
protected boolean isDownEnabled() {
|
||||
int index = getSelIndex();
|
||||
if (index < 0 || index == input.size() - 1)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
protected boolean isUpEnabled(){
|
||||
int index = getSelIndex();
|
||||
if (index <= 0)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void upPressed() {
|
||||
if (!isUpEnabled()) return;
|
||||
int index = getSelIndex();
|
||||
MultiLaunchConfigurationDelegate.LaunchElement x = (MultiLaunchConfigurationDelegate.LaunchElement) input
|
||||
.get(index);
|
||||
input.set(index, input.get(index - 1));
|
||||
input.set(index - 1, x);
|
||||
treeViewer.refresh(true);
|
||||
updateWidgetEnablement();
|
||||
updateLaunchConfigurationDialog();
|
||||
}
|
||||
};
|
||||
treeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
|
||||
public void selectionChanged(SelectionChangedEvent event) {
|
||||
buts.updateWidgetEnablement();
|
||||
}
|
||||
});
|
||||
buts.updateWidgetEnablement();
|
||||
GridData layoutData = new GridData(GridData.GRAB_VERTICAL);
|
||||
layoutData.verticalAlignment = SWT.BEGINNING;
|
||||
buts.setLayoutData(layoutData);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return LaunchMessages.getString("MultiLaunchConfigurationTabGroup.10"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public void initializeFrom(ILaunchConfiguration configuration) {
|
||||
MultiLaunchConfigurationDelegate.createLaunchElements(configuration, input);
|
||||
if (treeViewer != null) {
|
||||
for (Iterator iterator = input.iterator(); iterator.hasNext();) {
|
||||
MultiLaunchConfigurationDelegate.LaunchElement el = (MultiLaunchConfigurationDelegate.LaunchElement) iterator
|
||||
.next();
|
||||
treeViewer.setChecked(el, el.enabled);
|
||||
}
|
||||
treeViewer.refresh(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void performApply(ILaunchConfigurationWorkingCopy configuration) {
|
||||
MultiLaunchConfigurationDelegate.storeLaunchElements(configuration, input);
|
||||
}
|
||||
|
||||
public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
|
||||
// defaults is empty list
|
||||
}
|
||||
}
|
||||
|
||||
public MultiLaunchConfigurationTabGroup() {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void createTabs(ILaunchConfigurationDialog dialog, String mode) {
|
||||
ILaunchConfigurationTab[] tabs = new ILaunchConfigurationTab[] {//
|
||||
new GroupLaunchTab(mode) //
|
||||
};
|
||||
setTabs(tabs);
|
||||
}
|
||||
}
|
|
@ -147,3 +147,20 @@ LocalCDILaunchDelegate.7=Core file does not exist or is not readable.
|
|||
LocalCDILaunchDelegate.8=Error starting process.
|
||||
LocalCDILaunchDelegate.9=Eclipse runtime does not support working directory.
|
||||
LocalCDILaunchDelegate.10=Failed to set program arguments, environment or working directory.
|
||||
MultiLaunchConfigurationDelegate.0=Launching
|
||||
MultiLaunchConfigurationDelegate.Cannot=Cannot launch ''{0}'' in the ''{1}'' mode
|
||||
MultiLaunchConfigurationSelectionDialog.0=Launch Configuration Selector
|
||||
MultiLaunchConfigurationSelectionDialog.1=Select a Launch Configuration and a Launch Mode
|
||||
MultiLaunchConfigurationSelectionDialog.4=Launch Mode:
|
||||
MultiLaunchConfigurationSelectionDialog.5=Use default mode when launching
|
||||
MultiLaunchConfigurationSelectionDialog.7=Select a Launch Configuration
|
||||
MultiLaunchConfigurationTabGroup.1=Up
|
||||
MultiLaunchConfigurationTabGroup.2=Down
|
||||
MultiLaunchConfigurationTabGroup.3=Edit...
|
||||
MultiLaunchConfigurationTabGroup.4=Add...
|
||||
MultiLaunchConfigurationTabGroup.5=Remove
|
||||
MultiLaunchConfigurationTabGroup.6=Name
|
||||
MultiLaunchConfigurationTabGroup.7=Mode
|
||||
MultiLaunchConfigurationTabGroup.8=Select Launch Configuration
|
||||
MultiLaunchConfigurationTabGroup.9=Edit Launch Configuration
|
||||
MultiLaunchConfigurationTabGroup.10=Launches
|
||||
|
|
|
@ -0,0 +1,121 @@
|
|||
package org.eclipse.cdt.launch.ui;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.custom.StackLayout;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Combo;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
|
||||
/**
|
||||
* Stack Composite - Switch between panes controlled by combo box
|
||||
* @since 6.0
|
||||
*/
|
||||
public class ComboControlledStackComposite extends Composite {
|
||||
private Composite fArea;
|
||||
private Combo fCombo;
|
||||
private Map tabMap;
|
||||
private StackLayout layout;
|
||||
private Label fLabel;
|
||||
|
||||
public ComboControlledStackComposite(Composite parent, int style) {
|
||||
super(parent, style);
|
||||
tabMap = new LinkedHashMap();
|
||||
setLayout(new GridLayout(2, false));
|
||||
createContents(this);
|
||||
}
|
||||
|
||||
public void setLabelText(String label) {
|
||||
fLabel.setText(label);
|
||||
}
|
||||
public void addItem(String label, Composite tab) {
|
||||
tabMap.put(label, tab);
|
||||
fCombo.add(label);
|
||||
if (layout.topControl==null) {
|
||||
layout.topControl = tab;
|
||||
fCombo.setText(label);
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteItem(String label) {
|
||||
if (fCombo.getText().equals(label)) {
|
||||
setSelection(fCombo.getItem(0));
|
||||
}
|
||||
Composite tab = (Composite) tabMap.get(label);
|
||||
if (tab != null) {
|
||||
tab.dispose();
|
||||
tabMap.remove(label);
|
||||
}
|
||||
}
|
||||
|
||||
public void setSelection(String label) {
|
||||
fCombo.setText(label);
|
||||
setPage(label);
|
||||
}
|
||||
|
||||
protected void createContents(Composite parent) {
|
||||
fLabel = createLabel(this);
|
||||
fCombo = createCombo(this);
|
||||
GridData cgd = new GridData(GridData.FILL_HORIZONTAL);
|
||||
|
||||
fCombo.setLayoutData(cgd);
|
||||
fArea = createTabArea(this);
|
||||
GridData agd = new GridData(GridData.FILL_BOTH);
|
||||
agd.horizontalSpan = 2;
|
||||
fArea.setLayoutData(agd);
|
||||
}
|
||||
|
||||
|
||||
public Composite getStackParent() {
|
||||
return fArea;
|
||||
}
|
||||
|
||||
public Label getLabel() {
|
||||
return fLabel;
|
||||
}
|
||||
|
||||
public Combo getCombo() {
|
||||
return fCombo;
|
||||
}
|
||||
|
||||
protected Composite createTabArea(Composite parent) {
|
||||
Composite comp = new Composite(parent, SWT.NONE);
|
||||
layout = new StackLayout();
|
||||
comp.setLayout(layout);
|
||||
|
||||
return comp;
|
||||
}
|
||||
|
||||
|
||||
protected Label createLabel(Composite parent) {
|
||||
Label label = new Label(parent, SWT.WRAP);
|
||||
return label;
|
||||
}
|
||||
|
||||
protected Combo createCombo(Composite parent) {
|
||||
Combo box = new Combo(parent, SWT.READ_ONLY);
|
||||
box.addSelectionListener(new SelectionAdapter() {
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
String name = fCombo.getText();
|
||||
comboSelected(name);
|
||||
}
|
||||
});
|
||||
return box;
|
||||
}
|
||||
|
||||
protected void comboSelected(String label) {
|
||||
setPage(label);
|
||||
}
|
||||
|
||||
protected void setPage(String label) {
|
||||
layout.topControl = (Control) tabMap.get(label);
|
||||
getStackParent().layout();
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue