blob: 9f1ebac3ff799988e21ae6fdb5aafa33d2c834a6 (
plain) (
blame)
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
/*******************************************************************************
* Copyright (c) 2000, 2017 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
* Axel Richard (Obeo) - Bug 41353 - Launch configurations prototypes
*******************************************************************************/
package org.eclipse.debug.internal.ui.launchConfigurations;
import java.util.Iterator;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.internal.ui.DebugUIPlugin;
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
/**
* Deletes the selected launch configuration(s).
*/
public class DeleteLaunchConfigurationAction extends AbstractLaunchConfigurationAction {
/**
* Action identifier for IDebugView#getAction(String)
*/
public static final String ID_DELETE_ACTION = DebugUIPlugin.getUniqueIdentifier() + ".ID_DELETE_ACTION"; //$NON-NLS-1$
/**
* Constructs an action to delete launch configuration(s)
*/
public DeleteLaunchConfigurationAction(Viewer viewer, String mode) {
super(LaunchConfigurationsMessages.DeleteLaunchConfigurationAction_Dele_te_1, viewer, mode);
}
/**
* Determines if the action can delete the select launch configuration(s) or not
* @return true if the selected launch configuration(s) can be deleted or not
* @since 3.3
*/
protected boolean shouldDelete() {
IStructuredSelection selection = getStructuredSelection();
// Make the user confirm the deletion
String dialogMessage = selection.size() > 1 ? LaunchConfigurationsMessages.LaunchConfigurationDialog_Do_you_wish_to_delete_the_selected_launch_configurations__1 : LaunchConfigurationsMessages.LaunchConfigurationDialog_Do_you_wish_to_delete_the_selected_launch_configuration__2; //
return MessageDialog.open(MessageDialog.QUESTION, getShell(), LaunchConfigurationsMessages.LaunchConfigurationDialog_Confirm_Launch_Configuration_Deletion_3, dialogMessage, SWT.NONE, LaunchConfigurationsMessages.LaunchConfigurationSelectionDialog_deleteButtonLabel, IDialogConstants.CANCEL_LABEL) == Window.OK;
}
/**
* @see AbstractLaunchConfigurationAction#performAction()
*/
@Override
protected void performAction() {
if(!shouldDelete()) {
return;
}
IStructuredSelection selection = getStructuredSelection();
getViewer().getControl().setRedraw(false);
Iterator<?> iterator = selection.iterator();
while (iterator.hasNext()) {
ILaunchConfiguration configuration = (ILaunchConfiguration)iterator.next();
try {
configuration.delete(ILaunchConfiguration.UPDATE_PROTOTYPE_CHILDREN);
} catch (CoreException e) {
errorDialog(e);
}
}
getViewer().getControl().setRedraw(true);
}
/**
* @see org.eclipse.ui.actions.SelectionListenerAction#updateSelection(org.eclipse.jface.viewers.IStructuredSelection)
*/
@Override
protected boolean updateSelection(IStructuredSelection selection) {
if (selection.isEmpty()) {
return false;
}
Iterator<?> items = selection.iterator();
while (items.hasNext()) {
if (!(items.next() instanceof ILaunchConfiguration)) {
return false;
}
}
return true;
}
/* (non-Javadoc)
* @see org.eclipse.jface.action.Action#getDisabledImageDescriptor()
*/
@Override
public ImageDescriptor getDisabledImageDescriptor() {
return DebugUITools.getImageDescriptor(IInternalDebugUIConstants.IMG_DLCL_DELETE_CONFIG);
}
/* (non-Javadoc)
* @see org.eclipse.jface.action.Action#getImageDescriptor()
*/
@Override
public ImageDescriptor getImageDescriptor() {
return DebugUITools.getImageDescriptor(IInternalDebugUIConstants.IMG_ELCL_DELETE_CONFIG);
}
/* (non-Javadoc)
* @see org.eclipse.jface.action.Action#getToolTipText()
*/
@Override
public String getToolTipText() {
return LaunchConfigurationsMessages.LaunchConfigurationsDialog_1;
}
}
|