1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 17:05:26 +02:00

Bugzilla 276498: Support multiple selection in Launch Group feature

This commit is contained in:
John Cortell 2009-05-15 13:48:25 +00:00
parent cff7d18b90
commit 7e22c45fe6
4 changed files with 134 additions and 82 deletions

View file

@ -3,6 +3,7 @@ package org.eclipse.cdt.launch.internal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.eclipse.cdt.launch.internal.MultiLaunchConfigurationDelegate.LaunchElement.EPostLaunchAction;
@ -218,7 +219,7 @@ public class MultiLaunchConfigurationDelegate extends LaunchConfigurationDelegat
DebugUIPlugin.getDefault().getPreferenceStore().setValue(IDebugUIConstants.PREF_AUTO_REMOVE_OLD_LAUNCHES,
false);
final ArrayList<LaunchElement> input = createLaunchElements(configuration, new ArrayList<LaunchElement>());
final List<LaunchElement> input = createLaunchElements(configuration, new ArrayList<LaunchElement>());
MultiLaunchListener listener = new MultiLaunchListener(launch);
ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
launchManager.addLaunchListener(listener); // listener removed when launch is removed
@ -340,8 +341,8 @@ public class MultiLaunchConfigurationDelegate extends LaunchConfigurationDelegat
return null;
}
public static ArrayList<LaunchElement> createLaunchElements(ILaunchConfiguration configuration,
ArrayList<MultiLaunchConfigurationDelegate.LaunchElement> input) {
public static List<LaunchElement> createLaunchElements(ILaunchConfiguration configuration,
List<MultiLaunchConfigurationDelegate.LaunchElement> input) {
try {
Map<?,?> attrs = configuration.getAttributes();
for (Iterator<?> iterator = attrs.keySet().iterator(); iterator.hasNext();) {
@ -394,11 +395,10 @@ public class MultiLaunchConfigurationDelegate extends LaunchConfigurationDelegat
return input;
}
public static void storeLaunchElements(ILaunchConfigurationWorkingCopy configuration, ArrayList<LaunchElement> input) {
public static void storeLaunchElements(ILaunchConfigurationWorkingCopy configuration, List<LaunchElement> input) {
int i = 0;
removeLaunchElements(configuration);
for (Iterator<LaunchElement> iterator = input.iterator(); iterator.hasNext();) {
MultiLaunchConfigurationDelegate.LaunchElement el = iterator.next();
for (LaunchElement el : input) {
if (el == null) continue;
configuration.setAttribute(MultiLaunchConfigurationDelegate.getProp(i, NAME_PROP), el.getName());
configuration.setAttribute(MultiLaunchConfigurationDelegate.getProp(i, ACTION_PROP), el.getAction().toString());

View file

@ -159,13 +159,17 @@ MultiLaunchConfigurationDelegate.Action.Delay=Delay
MultiLaunchConfigurationDelegate.Action.WaitingForTermination=Waiting for termination of
MultiLaunchConfigurationDelegate.Action.Delaying=Delaying next launch by {0} seconds
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
MultiLaunchConfigurationSelectionDialog.7=Select a launch configuration
MultiLaunchConfigurationSelectionDialog.8=Post launch action:
MultiLaunchConfigurationSelectionDialog.9=Seconds:
MultiLaunchConfigurationSelectionDialog.10=Enter valid number of seconds
MultiLaunchConfigurationSelectionDialog.11=Select only one launch configuration
MultiLaunchConfigurationSelectionDialog.12=Add Launch Configuration
MultiLaunchConfigurationSelectionDialog.13=Edit Launch Configuration
MultiLaunchConfigurationSelectionDialog.14=Add one or more launch configurations to the launch group
MultiLaunchConfigurationSelectionDialog.15=Edit an existing entry in the launch group
MultiLaunchConfigurationTabGroup.1=Up
MultiLaunchConfigurationTabGroup.2=Down
MultiLaunchConfigurationTabGroup.3=Edit...
@ -173,8 +177,6 @@ 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
MultiLaunchConfigurationTabGroup.11=seconds
MultiLaunchConfigurationTabGroup.12=Action

View file

@ -1,8 +1,10 @@
package org.eclipse.cdt.launch.internal.ui;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.launch.internal.MultiLaunchConfigurationDelegate;
import org.eclipse.cdt.launch.internal.MultiLaunchConfigurationDelegate.LaunchElement;
@ -65,12 +67,14 @@ public class MultiLaunchConfigurationSelectionDialog extends TitleAreaDialog imp
private ComboControlledStackComposite fStackComposite;
private Label fDelayAmountLabel;
private Text fDelayAmountWidget; // in seconds
private boolean fForEditing; // true if dialog was opened to edit an entry, otherwise it was opened to add one
public MultiLaunchConfigurationSelectionDialog(Shell shell, String title, String initMode) {
public MultiLaunchConfigurationSelectionDialog(Shell shell, String initMode, boolean forEditing) {
super(shell);
LaunchConfigurationManager manager = DebugUIPlugin.getDefault().getLaunchConfigurationManager();
launchGroups = manager.getLaunchGroups();
mode = initMode;
fForEditing = forEditing;
fFilters = null;
setShellStyle(getShellStyle() | SWT.RESIZE);
emptyTypeFilter = new ViewerFilter() {
@ -100,10 +104,14 @@ public class MultiLaunchConfigurationSelectionDialog extends TitleAreaDialog imp
}
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);
// title bar
getShell().setText(fForEditing ? LaunchMessages.getString("MultiLaunchConfigurationSelectionDialog.13") : LaunchMessages.getString("MultiLaunchConfigurationSelectionDialog.12")); //$NON-NLS-1$ //$NON-NLS-2$
// dialog message area (not title bar)
setTitle(fForEditing ? LaunchMessages.getString("MultiLaunchConfigurationSelectionDialog.15") : LaunchMessages.getString("MultiLaunchConfigurationSelectionDialog.14")); //$NON-NLS-1$ //$NON-NLS-2$
fStackComposite = new ComboControlledStackComposite(comp, SWT.NONE);
HashMap<String, ILaunchGroup> modes = new HashMap<String, ILaunchGroup>();
for (ILaunchGroup launchGroup : launchGroups) {
@ -114,15 +122,17 @@ public class MultiLaunchConfigurationSelectionDialog extends TitleAreaDialog imp
if (this.mode.equals(MultiLaunchConfigurationDelegate.DEFAULT_MODE)) {
try {
this.mode = "run"; //$NON-NLS-1$
ILaunchConfiguration sel = getSelectedLaunchConfiguration();
if (sel != null)
ILaunchConfiguration[] configs = getSelectedLaunchConfigurations();
if (configs.length > 0) {
// we care only about the first selected element
for (Iterator<String> iterator = modes.keySet().iterator(); iterator.hasNext();) {
String mode = iterator.next();
if (sel.supportsMode(mode)) {
if (configs[0].supportsMode(mode)) {
this.mode = mode;
break;
}
}
}
} catch (Exception e) {
}
}
@ -235,13 +245,17 @@ public class MultiLaunchConfigurationSelectionDialog extends TitleAreaDialog imp
fDelayAmountWidget.setVisible(visible);
}
public ILaunchConfiguration getSelectedLaunchConfiguration() {
public ILaunchConfiguration[] getSelectedLaunchConfigurations() {
List<ILaunchConfiguration> configs = new ArrayList<ILaunchConfiguration>();
if (fSelection != null && !fSelection.isEmpty()) {
Object firstElement = ((IStructuredSelection) fSelection).getFirstElement();
if (firstElement instanceof ILaunchConfiguration)
return (ILaunchConfiguration) firstElement;
for (Iterator<?> iter = ((IStructuredSelection)fSelection).iterator(); iter.hasNext();) {
Object selection = iter.next();
if (selection instanceof ILaunchConfiguration) {
configs.add((ILaunchConfiguration)selection);
}
}
}
return null;
return configs.toArray(new ILaunchConfiguration[configs.size()]);
}
public String getMode() {
@ -256,8 +270,8 @@ public class MultiLaunchConfigurationSelectionDialog extends TitleAreaDialog imp
return actionParam;
}
public static MultiLaunchConfigurationSelectionDialog createDialog(Shell shell, String title, String groupId) {
return new MultiLaunchConfigurationSelectionDialog(shell, title, groupId);
public static MultiLaunchConfigurationSelectionDialog createDialog(Shell shell, String groupId, boolean forEditing) {
return new MultiLaunchConfigurationSelectionDialog(shell, groupId, forEditing);
}
/* (non-Javadoc)
@ -305,12 +319,22 @@ public class MultiLaunchConfigurationSelectionDialog extends TitleAreaDialog imp
protected void validate() {
Button ok_button = getButton(IDialogConstants.OK_ID);
boolean isValid = true;
if (getSelectedLaunchConfiguration() == null) {
if (getSelectedLaunchConfigurations().length < 1) {
setErrorMessage(LaunchMessages.getString("MultiLaunchConfigurationSelectionDialog.7")); //$NON-NLS-1$
isValid = false;
} else {
setErrorMessage(null);
}
if (isValid) {
if (fForEditing) {
// must have only one selection
if (getSelectedLaunchConfigurations().length > 1) {
setErrorMessage(LaunchMessages.getString("MultiLaunchConfigurationSelectionDialog.11")); //$NON-NLS-1$
isValid = false;
}
}
}
if (isValid) {
if (action == EPostLaunchAction.DELAY) {

View file

@ -2,6 +2,7 @@ package org.eclipse.cdt.launch.internal.ui;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.launch.internal.MultiLaunchConfigurationDelegate;
import org.eclipse.cdt.launch.internal.MultiLaunchConfigurationDelegate.LaunchElement;
@ -47,7 +48,7 @@ import org.eclipse.ui.PlatformUI;
*/
public class MultiLaunchConfigurationTabGroup extends AbstractLaunchConfigurationTabGroup {
static class ContentProvider implements IStructuredContentProvider, ITreeContentProvider {
protected ArrayList<LaunchElement> input;
protected List<LaunchElement> input;
public Object[] getElements(Object inputElement) {
return getChildren(inputElement);
@ -59,27 +60,20 @@ public class MultiLaunchConfigurationTabGroup extends AbstractLaunchConfiguratio
@SuppressWarnings("unchecked") // nothing we can do about this
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
if (newInput instanceof ArrayList<?>)
input = (ArrayList<LaunchElement>) newInput;
if (newInput instanceof List<?>)
input = (List<LaunchElement>) newInput;
}
public Object[] getChildren(Object parentElement) {
if (parentElement == input)
return input.toArray();
else
return null;
return (parentElement == input) ? input.toArray() : null;
}
public Object getParent(Object element) {
if (element == input)
return null;
return input;
return (element == input) ? null : input;
}
public boolean hasChildren(Object element) {
if (element == input)
return input.size() > 0;
return false;
return (element == input) ? (input.size() > 0) : false;
}
}
static class LabelProvider extends BaseLabelProvider implements ITableLabelProvider {
@ -213,7 +207,7 @@ public class MultiLaunchConfigurationTabGroup extends AbstractLaunchConfiguratio
}
static class GroupLaunchTab extends AbstractLaunchConfigurationTab {
protected CheckboxTreeViewer treeViewer;
protected ArrayList<LaunchElement> input = new ArrayList<LaunchElement>();
protected List<LaunchElement> input = new ArrayList<LaunchElement>();
private String mode;
public GroupLaunchTab(String mode) {
@ -245,23 +239,25 @@ public class MultiLaunchConfigurationTabGroup extends AbstractLaunchConfiguratio
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
);
MultiLaunchConfigurationSelectionDialog dialog =
MultiLaunchConfigurationSelectionDialog.createDialog(
treeViewer.getControl().getShell(), mode, false);
if (dialog.open() == Dialog.OK) {
ILaunchConfiguration conf = dialog.getSelectedLaunchConfiguration();
if (conf==null) return;
MultiLaunchConfigurationDelegate.LaunchElement el = new MultiLaunchConfigurationDelegate.LaunchElement();
input.add(el);
el.setIndex(input.size() - 1);
el.setEnabled(true);
el.setName(conf.getName());
el.setData(conf);
el.setMode(dialog.getMode());
el.setAction(dialog.getAction(), dialog.getActionParam());
treeViewer.refresh(true);
treeViewer.setChecked(el, el.isEnabled());
ILaunchConfiguration[] configs = dialog.getSelectedLaunchConfigurations();
if (configs.length < 1)
return;
for (ILaunchConfiguration config : configs) {
MultiLaunchConfigurationDelegate.LaunchElement el = new MultiLaunchConfigurationDelegate.LaunchElement();
input.add(el);
el.setIndex(input.size() - 1);
el.setEnabled(true);
el.setName(config.getName());
el.setData(config);
el.setMode(dialog.getMode());
el.setAction(dialog.getAction(), dialog.getActionParam());
treeViewer.refresh(true);
treeViewer.setChecked(el, el.isEnabled());
}
updateWidgetEnablement();
updateLaunchConfigurationDialog();
}
@ -269,27 +265,29 @@ public class MultiLaunchConfigurationTabGroup extends AbstractLaunchConfiguratio
protected void updateWidgetEnablement(){
downButton.setEnabled(isDownEnabled());
upButton.setEnabled(isUpEnabled());
int index = getSelIndex();
deleteButton.setEnabled(index>=0);
editButton.setEnabled(index>=0);
int selectionCount = getSelectionCount();
editButton.setEnabled(selectionCount == 1);
deleteButton.setEnabled(selectionCount > 0);
}
protected void editPressed() {
int index = getSelIndex();
int index = getSingleSelectionIndex();
if (index < 0)
return;
MultiLaunchConfigurationDelegate.LaunchElement el = input.get(index);
MultiLaunchConfigurationSelectionDialog dialog = MultiLaunchConfigurationSelectionDialog.createDialog(treeViewer
.getControl().getShell(), LaunchMessages.getString("MultiLaunchConfigurationTabGroup.9"), //$NON-NLS-1$
el.getMode()
);
MultiLaunchConfigurationSelectionDialog dialog =
MultiLaunchConfigurationSelectionDialog.createDialog(
treeViewer.getControl().getShell(), el.getMode(), true);
dialog.setInitialSelection(el);
if (dialog.open() == Dialog.OK) {
ILaunchConfiguration conf = dialog.getSelectedLaunchConfiguration();
if (conf==null) return;
el.setName(conf.getName());
el.setData(conf);
ILaunchConfiguration[] confs = dialog.getSelectedLaunchConfigurations();
if (confs.length < 0)
return;
assert confs.length == 1 : "invocation of the dialog for editing an entry sholdn't allow OK to be hit if the user chooses multiple launch configs in the dialog"; //$NON-NLS-1$
el.setName(confs[0].getName());
el.setData(confs[0]);
el.setMode(dialog.getMode());
el.setAction(dialog.getAction(), dialog.getActionParam());
treeViewer.refresh(true);
@ -298,27 +296,60 @@ public class MultiLaunchConfigurationTabGroup extends AbstractLaunchConfiguratio
}
}
protected void deletePressed() {
int index = getSelIndex();
if (index < 0)
int[] indices = getMultiSelectionIndices();
if (indices.length < 1)
return;
input.remove(index);
// need to delete from high to low
for (int i = indices.length - 1; i >= 0; i--) {
input.remove(indices[i]);
}
treeViewer.refresh(true);
updateWidgetEnablement();
updateLaunchConfigurationDialog();
}
private int getSelIndex() {
/**
* @return the index of the selection if a single item is
* selected. If zero or multiple are selected, -1 is
* returned
*/
private int getSingleSelectionIndex() {
StructuredSelection sel = (StructuredSelection) treeViewer.getSelection();
if (sel.isEmpty())
if (sel.size() != 1)
return -1;
MultiLaunchConfigurationDelegate.LaunchElement el = ((MultiLaunchConfigurationDelegate.LaunchElement) sel
.getFirstElement());
return input.indexOf(el);
}
/**
* @return the indices of one or more selected items. Indices
* are always returned in ascending order
*/
private int[] getMultiSelectionIndices() {
StructuredSelection sel = (StructuredSelection) treeViewer.getSelection();
List<Integer> indices = new ArrayList<Integer>();
for (Iterator<?> iter = sel.iterator(); iter.hasNext(); ) {
MultiLaunchConfigurationDelegate.LaunchElement el = (MultiLaunchConfigurationDelegate.LaunchElement)iter.next();
indices.add(input.indexOf(el));
}
int[] result = new int[indices.size()];
for (int i = 0; i < result.length; i++) {
result[i] = indices.get(i);
}
return result;
}
private int getSelectionCount() {
return ((StructuredSelection)treeViewer.getSelection()).size();
}
protected void downPressed() {
if (!isDownEnabled()) return;
int index = getSelIndex();
int index = getSingleSelectionIndex();
MultiLaunchConfigurationDelegate.LaunchElement x = input.get(index);
input.set(index, input.get(index + 1));
@ -329,22 +360,17 @@ public class MultiLaunchConfigurationTabGroup extends AbstractLaunchConfiguratio
}
protected boolean isDownEnabled() {
int index = getSelIndex();
if (index < 0 || index == input.size() - 1)
return false;
return true;
final int index = getSingleSelectionIndex();
return (index >= 0) && (index != input.size() - 1);
}
protected boolean isUpEnabled(){
int index = getSelIndex();
if (index <= 0)
return false;
return true;
return getSingleSelectionIndex() > 0;
}
protected void upPressed() {
if (!isUpEnabled()) return;
int index = getSelIndex();
int index = getSingleSelectionIndex();
MultiLaunchConfigurationDelegate.LaunchElement x = input.get(index);
input.set(index, input.get(index - 1));
input.set(index - 1, x);