KickJava   Java API By Example, From Geeks To Geeks.

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


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.ILaunchConfiguration;
15 import org.eclipse.debug.internal.ui.DebugUIPlugin;
16 import org.eclipse.debug.internal.ui.contextlaunching.ContextRunner;
17 import org.eclipse.debug.internal.ui.contextlaunching.LaunchingResourceManager;
18 import org.eclipse.debug.internal.ui.launchConfigurations.OrganizeFavoritesAction;
19 import org.eclipse.debug.ui.DebugUITools;
20 import org.eclipse.jface.action.IAction;
21 import org.eclipse.jface.viewers.StructuredSelection;
22 import org.eclipse.swt.widgets.Menu;
23
24 /**
25  * A launch history action that also includes launch shortcut actions (run/debug
26  * as), and an action to open the launch configuration dialog.
27  * <p>
28  * Clients may subclass this class.
29  * </p>
30  * @since 2.1
31  */

32 public class AbstractLaunchToolbarAction extends AbstractLaunchHistoryAction {
33
34
35     /**
36      * Constructs a launch toolbar action.
37      *
38      * @param launchGroupIdentifier unique identifier of the launch group
39      * extension that this action displays a launch history, shortcuts, and
40      * launch configuration dialog for.
41      */

42     public AbstractLaunchToolbarAction(String JavaDoc launchGroupIdentifier) {
43         super(launchGroupIdentifier);
44     }
45
46     /**
47      * Fills the drop-down menu with favorites and launch history,
48      * launch shortcuts, and an action to open the launch configuration dialog.
49      *
50      * @param menu the menu to fill
51      */

52     protected void fillMenu(Menu menu) {
53         super.fillMenu(menu);
54         // Separator between history and common actions
55
if (menu.getItemCount() > 0) {
56             addSeparator(menu);
57         }
58         addToMenu(menu, new LaunchShortcutsAction(getLaunchGroupIdentifier()), -1);
59         addToMenu(menu, getOpenDialogAction(), -1);
60         addToMenu(menu, new OrganizeFavoritesAction(getLaunchGroupIdentifier()), -1);
61     }
62     
63     /**
64      * Returns an action to open the launch dialog
65      * @since 3.1
66      */

67     protected IAction getOpenDialogAction() {
68         return new OpenLaunchDialogAction(getLaunchGroupIdentifier());
69     }
70     
71     /**
72      * Launch the last launch, or open the launch config dialog if none.
73      *
74      * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
75      */

76     public void run(IAction action) {
77         //always ignore external tools during context launching
78
if(LaunchingResourceManager.isContextLaunchEnabled() &&
79                 !getLaunchGroupIdentifier().equals("org.eclipse.ui.externaltools.launchGroup")) { //$NON-NLS-1$
80
ContextRunner.getDefault().launch(DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(getLaunchGroupIdentifier()));
81         }
82         else {
83             ILaunchConfiguration configuration = getLastLaunch();
84             if (configuration == null) {
85                 DebugUITools.openLaunchConfigurationDialogOnGroup(DebugUIPlugin.getShell(), new StructuredSelection(), getLaunchGroupIdentifier());
86             } else {
87                 DebugUITools.launch(configuration, getMode());
88             }
89         }
90     }
91 }
92
Popular Tags