KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.eclipse.core.runtime.CoreException;
15 import org.eclipse.jface.dialogs.ErrorDialog;
16 import org.eclipse.jface.viewers.Viewer;
17 import org.eclipse.swt.custom.BusyIndicator;
18 import org.eclipse.swt.widgets.Shell;
19 import org.eclipse.ui.actions.SelectionListenerAction;
20
21 /**
22  * Common function/behavior for launch configuration view actions
23  */

24 public abstract class AbstractLaunchConfigurationAction extends SelectionListenerAction {
25     
26     /**
27      * The mode this action was created in (run, debug, ...)
28      */

29     private String JavaDoc fMode;
30     
31     /**
32      * Allows a requestor to abort this action.
33      */

34     public interface IConfirmationRequestor {
35         /**
36          * Returns whether this action should proceed. Confirmation is requested
37          * when an action is run.
38          *
39          * @return whether this action should proceed
40          */

41         public boolean getConfirmation();
42     }
43     
44     /**
45      * This action's confirmation requestor or <code>null</code> if none
46      */

47     private IConfirmationRequestor fConfirmationRequestor;
48     
49     /**
50      * The viewer this action is working on
51      */

52     private Viewer fViewer;
53
54     /**
55      * Constructor for AbstractLaunchConfigurationAction.
56      * @param text
57      */

58     public AbstractLaunchConfigurationAction(String JavaDoc text, Viewer viewer, String JavaDoc mode) {
59         super(text);
60         fViewer = viewer;
61         fViewer.addSelectionChangedListener(this);
62         fMode = mode;
63     }
64
65     /**
66      * Returns the shell this action is contained in.
67      *
68      * @return the shell this action is contained in
69      */

70     protected Shell getShell() {
71         return getViewer().getControl().getShell();
72     }
73     
74     /**
75      * Returns the viewer this action is working on
76      *
77      * @return the viewer this action is working on
78      */

79     protected Viewer getViewer() {
80         return fViewer;
81     }
82     
83     /**
84      * Performs this action once confirmation has been aquired. Subclasses
85      * should override this method.
86      */

87     protected abstract void performAction();
88     
89     /**
90      * @see org.eclipse.jface.action.IAction#run()
91      */

92     public final void run() {
93         if (fConfirmationRequestor != null) {
94             if (!fConfirmationRequestor.getConfirmation()) {
95                 return;
96             }
97         }
98         Runnable JavaDoc r = new Runnable JavaDoc() {
99             /**
100              * @see java.lang.Runnable#run()
101              */

102             public void run() {
103                 performAction();
104             }
105         };
106         BusyIndicator.showWhile(getShell().getDisplay(), r);
107     }
108     
109     /**
110      * Sets this action's confirmation requestor.
111      *
112      * @param confirmationRequestor
113      */

114     public void setConfirmationRequestor(IConfirmationRequestor confirmationRequestor) {
115         fConfirmationRequestor = confirmationRequestor;
116     }
117     
118     /**
119      * Disposes this action
120      */

121     public void dispose() {
122         fViewer.removeSelectionChangedListener(this);
123     }
124     
125     /**
126      * Show an error dialog on the given exception.
127      *
128      * @param exception
129      */

130     protected void errorDialog(CoreException exception) {
131         ErrorDialog.openError(getShell(), null, null, exception.getStatus());
132     }
133
134     /**
135      * Return this action's mode.
136      *
137      * @return launch mode
138      */

139     protected String JavaDoc getMode() {
140         return fMode;
141     }
142 }
143
Popular Tags