KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > actions > ExecutionAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.actions;
12
13
14 import org.eclipse.debug.core.ILaunchConfiguration;
15 import org.eclipse.debug.internal.ui.DebugUIPlugin;
16 import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationManager;
17 import org.eclipse.debug.ui.DebugUITools;
18 import org.eclipse.jface.action.IAction;
19 import org.eclipse.jface.viewers.ISelection;
20 import org.eclipse.jface.viewers.StructuredSelection;
21 import org.eclipse.swt.widgets.Event;
22 import org.eclipse.ui.IActionDelegate2;
23 import org.eclipse.ui.IWorkbenchWindow;
24
25 /**
26  * This is the super class of the Run & Debug actions which appears in the desktop menu and toolbar.
27  */

28 public abstract class ExecutionAction implements IActionDelegate2 {
29     
30     private String JavaDoc fLaunchGroupIdentifier;
31     
32     public ExecutionAction(String JavaDoc launchGroupIdentifier) {
33         fLaunchGroupIdentifier = launchGroupIdentifier;
34     }
35     
36     /**
37      * @see IActionDelegate2#runWithEvent(IAction, Event)
38      */

39     public void runWithEvent(IAction action, Event event) {
40         run(action);
41     }
42
43     /**
44      * Open the launch configuration dialog, passing in the current workbench selection.
45      */

46     private void openLaunchConfigurationDialog() {
47         IWorkbenchWindow dwindow= DebugUIPlugin.getActiveWorkbenchWindow();
48         if (dwindow == null) {
49             return;
50         }
51         DebugUITools.openLaunchConfigurationDialogOnGroup(DebugUIPlugin.getShell(), new StructuredSelection(), fLaunchGroupIdentifier);
52     }
53     
54     protected LaunchConfigurationManager getLaunchConfigurationManager() {
55         return DebugUIPlugin.getDefault().getLaunchConfigurationManager();
56     }
57     
58     /**
59      * Returns the mode of a launcher to use for this action
60      */

61     protected abstract String JavaDoc getMode();
62     
63     /**
64      * @see org.eclipse.ui.IActionDelegate2#dispose()
65      */

66     public void dispose() {
67     }
68
69     /**
70      * @see org.eclipse.ui.IActionDelegate2#init(org.eclipse.jface.action.IAction)
71      */

72     public void init(IAction action) {
73     }
74
75     /**
76      * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
77      */

78     public void run(IAction action) {
79         ILaunchConfiguration configuration = getLaunchConfigurationManager().getLastLaunch(fLaunchGroupIdentifier);
80         if (configuration == null) {
81             openLaunchConfigurationDialog();
82         } else {
83             DebugUITools.launch(configuration, getMode());
84         }
85     }
86
87     /**
88      * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
89      */

90     public void selectionChanged(IAction action, ISelection selection) {
91     }
92
93 }
94
Popular Tags