KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > ui > actions > OpenLaunchDialogAction


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.ui.actions;
12
13
14 import org.eclipse.debug.core.DebugPlugin;
15 import org.eclipse.debug.core.ILaunchConfiguration;
16 import org.eclipse.debug.core.ILaunchConfigurationType;
17 import org.eclipse.debug.internal.ui.DebugUIPlugin;
18 import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
19 import org.eclipse.debug.internal.ui.actions.ActionMessages;
20 import org.eclipse.debug.internal.ui.launchConfigurations.LaunchHistory;
21 import org.eclipse.debug.ui.DebugUITools;
22 import org.eclipse.debug.ui.ILaunchGroup;
23 import org.eclipse.jface.action.Action;
24 import org.eclipse.jface.action.IAction;
25 import org.eclipse.jface.viewers.ISelection;
26 import org.eclipse.jface.viewers.IStructuredSelection;
27 import org.eclipse.jface.viewers.StructuredSelection;
28 import org.eclipse.jface.window.Window;
29 import org.eclipse.swt.widgets.Event;
30 import org.eclipse.ui.IActionDelegate2;
31 import org.eclipse.ui.IWorkbenchWindow;
32 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
33 import org.eclipse.ui.PlatformUI;
34
35 import com.ibm.icu.text.MessageFormat;
36
37 /**
38  * Opens the launch configuration dialog in the context of a launch group.
39  * <p>
40  * Clients are not intended to subclass this class; clients may instantiate this
41  * class.
42  * </p>
43  * @since 2.1
44  */

45 public class OpenLaunchDialogAction extends Action implements IActionDelegate2, IWorkbenchWindowActionDelegate {
46
47     /**
48      * Launch group identifier
49      */

50     private String JavaDoc fIdentifier;
51     
52     /**
53      * Constructs an action that opens the launch configuration dialog in
54      * the context of the specified launch group.
55      *
56      * @param identifier unique identifier of a launch group extension
57      */

58     public OpenLaunchDialogAction(String JavaDoc identifier) {
59         fIdentifier = identifier;
60         ILaunchGroup group = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(fIdentifier);
61         if(group != null) {
62             setImageDescriptor(group.getImageDescriptor());
63             String JavaDoc lbl = group.getLabel();
64             String JavaDoc actionLabel = MessageFormat.format(ActionMessages.OpenLaunchDialogAction_1, new String JavaDoc[] {lbl});
65             setText(DebugUIPlugin.adjustDBCSAccelerator(actionLabel));
66         }
67         PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IDebugHelpContextIds.OPEN_LAUNCH_CONFIGURATION_ACTION);
68     }
69     
70     /**
71      * @see org.eclipse.jface.action.IAction#run()
72      */

73     public void run() {
74         LaunchHistory history = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchHistory(fIdentifier);
75         ILaunchConfiguration configuration = history.getRecentLaunch();
76         IStructuredSelection selection = null;
77         if (configuration == null) {
78             selection = new StructuredSelection();
79         } else {
80             selection = new StructuredSelection(configuration);
81         }
82         int result = DebugUITools.openLaunchConfigurationDialogOnGroup(DebugUIPlugin.getShell(), selection, fIdentifier);
83         notifyResult(result == Window.OK);
84     }
85     
86     /* (non-Javadoc)
87      * @see org.eclipse.ui.IActionDelegate2#runWithEvent(org.eclipse.jface.action.IAction, org.eclipse.swt.widgets.Event)
88      */

89     public void runWithEvent(IAction action, Event event) {
90         run();
91     }
92     
93     /* (non-Javadoc)
94      * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
95      */

96     public void run(IAction action) {
97         run();
98     }
99     
100     /**
101      * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
102      */

103     public void dispose() {}
104
105     /* (non-Javadoc)
106      * @see org.eclipse.ui.IActionDelegate2#init(org.eclipse.jface.action.IAction)
107      */

108     public void init(IAction action) {
109         if(action != null) {
110             action.setEnabled(existsConfigTypesForMode());
111         }
112     }
113     
114     /**
115      * Return whether there are any registered launch configuration types for
116      * the mode of this action.
117      *
118      * @return whether there are any registered launch configuration types for
119      * the mode of this action
120      */

121     private boolean existsConfigTypesForMode() {
122         ILaunchConfigurationType[] configTypes = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurationTypes();
123         for (int i = 0; i < configTypes.length; i++) {
124             ILaunchConfigurationType configType = configTypes[i];
125             if (configType.supportsMode(getMode())) {
126                 return true;
127             }
128         }
129         return false;
130     }
131     
132     /* (non-Javadoc)
133      * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow)
134      */

135     public void init(IWorkbenchWindow window) {}
136     
137     /**
138      * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
139      */

140     public void selectionChanged(IAction action, ISelection selection) {}
141     
142     /**
143      * Returns the launch mode for this action.
144      *
145      * @return launch mode
146      */

147     private String JavaDoc getMode() {
148         return DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(fIdentifier).getMode();
149     }
150 }
151
Popular Tags