KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > launchConfigurations > DeleteLaunchConfigurationAction


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.Iterator JavaDoc;
15
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.debug.core.ILaunchConfiguration;
18 import org.eclipse.debug.internal.ui.DebugUIPlugin;
19 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
20 import org.eclipse.debug.ui.DebugUITools;
21 import org.eclipse.jface.dialogs.MessageDialog;
22 import org.eclipse.jface.resource.ImageDescriptor;
23 import org.eclipse.jface.viewers.IStructuredSelection;
24 import org.eclipse.jface.viewers.Viewer;
25
26 /**
27  * Deletes the selected launch configuration(s).
28  */

29 public class DeleteLaunchConfigurationAction extends AbstractLaunchConfigurationAction {
30
31     /**
32      * Action identifier for IDebugView#getAction(String)
33      */

34     public static final String JavaDoc ID_DELETE_ACTION = DebugUIPlugin.getUniqueIdentifier() + ".ID_DELETE_ACTION"; //$NON-NLS-1$
35

36     /**
37      * Constructs an action to delete launch configuration(s)
38      */

39     public DeleteLaunchConfigurationAction(Viewer viewer, String JavaDoc mode) {
40         super(LaunchConfigurationsMessages.DeleteLaunchConfigurationAction_Dele_te_1, viewer, mode);
41     }
42
43     /**
44      * Determines if the action can delete the select launch configuration(s) or not
45      * @return true if the selected launch configuration(s) can be deleted or not
46      * @since 3.3
47      */

48     protected boolean shouldDelete() {
49         IStructuredSelection selection = getStructuredSelection();
50         // Make the user confirm the deletion
51
String JavaDoc 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; //
52
return MessageDialog.openQuestion(getShell(), LaunchConfigurationsMessages.LaunchConfigurationDialog_Confirm_Launch_Configuration_Deletion_3, dialogMessage);
53     }
54     
55     /**
56      * @see AbstractLaunchConfigurationAction#performAction()
57      */

58     protected void performAction() {
59         if(!shouldDelete()) {
60             return;
61         }
62         IStructuredSelection selection = getStructuredSelection();
63
64         getViewer().getControl().setRedraw(false);
65         Iterator JavaDoc iterator = selection.iterator();
66         while (iterator.hasNext()) {
67             ILaunchConfiguration configuration = (ILaunchConfiguration)iterator.next();
68             try {
69                 configuration.delete();
70             } catch (CoreException e) {
71                 errorDialog(e);
72             }
73         }
74         getViewer().getControl().setRedraw(true);
75     }
76
77     /**
78      * @see org.eclipse.ui.actions.SelectionListenerAction#updateSelection(org.eclipse.jface.viewers.IStructuredSelection)
79      */

80     protected boolean updateSelection(IStructuredSelection selection) {
81         if (selection.isEmpty()) {
82             return false;
83         }
84         Iterator JavaDoc items = selection.iterator();
85         while (items.hasNext()) {
86             if (!(items.next() instanceof ILaunchConfiguration)) {
87                 return false;
88             }
89         }
90         return true;
91     }
92
93     /* (non-Javadoc)
94      * @see org.eclipse.jface.action.Action#getDisabledImageDescriptor()
95      */

96     public ImageDescriptor getDisabledImageDescriptor() {
97         return DebugUITools.getImageDescriptor(IInternalDebugUIConstants.IMG_DLCL_DELETE_CONFIG);
98     }
99
100     /* (non-Javadoc)
101      * @see org.eclipse.jface.action.Action#getImageDescriptor()
102      */

103     public ImageDescriptor getImageDescriptor() {
104         return DebugUITools.getImageDescriptor(IInternalDebugUIConstants.IMG_ELCL_DELETE_CONFIG);
105     }
106
107     /* (non-Javadoc)
108      * @see org.eclipse.jface.action.Action#getToolTipText()
109      */

110     public String JavaDoc getToolTipText() {
111         return LaunchConfigurationsMessages.LaunchConfigurationsDialog_1;
112     }
113
114 }
115
Popular Tags