KickJava   Java API By Example, From Geeks To Geeks.

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


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.debug.core.DebugPlugin;
16 import org.eclipse.debug.core.ILaunchConfiguration;
17 import org.eclipse.debug.core.ILaunchConfigurationType;
18 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
19 import org.eclipse.debug.internal.ui.DebugUIPlugin;
20 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
21 import org.eclipse.debug.ui.DebugUITools;
22 import org.eclipse.debug.ui.ILaunchConfigurationDialog;
23 import org.eclipse.debug.ui.ILaunchConfigurationTab;
24 import org.eclipse.debug.ui.ILaunchConfigurationTabGroup;
25 import org.eclipse.jface.resource.ImageDescriptor;
26 import org.eclipse.jface.viewers.IStructuredSelection;
27 import org.eclipse.jface.viewers.Viewer;
28
29 /**
30  * Creates a new launch configuration based on the selection.
31  */

32 public class CreateLaunchConfigurationAction extends AbstractLaunchConfigurationAction {
33
34     /**
35      * Action identifier for IDebugView#getAction(String)
36      */

37     public static final String JavaDoc ID_CREATE_ACTION = DebugUIPlugin.getUniqueIdentifier() + ".ID_CREATE_ACTION"; //$NON-NLS-1$
38

39     /**
40      * Constructs an action to create a launch configuration
41      */

42     public CreateLaunchConfigurationAction(Viewer viewer, String JavaDoc mode) {
43         super(LaunchConfigurationsMessages.CreateLaunchConfigurationAction_Ne_w_1, viewer, mode);
44     }
45
46     /**
47      * @see AbstractLaunchConfigurationAction#performAction()
48      */

49     protected void performAction() {
50         Object JavaDoc object = getStructuredSelection().getFirstElement();
51         //double click with Ctrl key mask results in empty selection: bug 156087
52
//do no work if the selection is null
53
if(object != null) {
54             ILaunchConfigurationType type= null;
55             // Construct a new config of the selected type
56
if (object instanceof ILaunchConfiguration) {
57                 ILaunchConfiguration config= (ILaunchConfiguration) object;
58                 try {
59                     type = config.getType();
60                 } catch (CoreException e) {
61                     errorDialog(e);
62                     return;
63                 }
64             } else {
65                 type = (ILaunchConfigurationType) object;
66             }
67             try {
68                 ILaunchConfigurationWorkingCopy wc = type.newInstance(null, DebugPlugin.getDefault().getLaunchManager().generateUniqueLaunchConfigurationNameFrom(LaunchConfigurationsMessages.CreateLaunchConfigurationAction_New_configuration_2));
69                 ILaunchConfigurationTabGroup tabGroup = LaunchConfigurationPresentationManager.getDefault().getTabGroup(wc, getMode());
70                 // this only works because this action is only present when the dialog is open
71
ILaunchConfigurationDialog dialog = LaunchConfigurationsDialog.getCurrentlyVisibleLaunchConfigurationDialog();
72                 tabGroup.createTabs(dialog, dialog.getMode());
73                 ILaunchConfigurationTab[] tabs = tabGroup.getTabs();
74                 for (int i = 0; i < tabs.length; i++) {
75                     tabs[i].setLaunchConfigurationDialog(dialog);
76                 }
77                 tabGroup.setDefaults(wc);
78                 tabGroup.dispose();
79                 wc.doSave();
80             } catch (CoreException e) {
81                 errorDialog(e);
82                 return;
83             }
84         }
85     }
86
87     /**
88      * @see org.eclipse.ui.actions.SelectionListenerAction#updateSelection(org.eclipse.jface.viewers.IStructuredSelection)
89      */

90     protected boolean updateSelection(IStructuredSelection selection) {
91         return selection.size() == 1;
92     }
93
94     /* (non-Javadoc)
95      * @see org.eclipse.jface.action.Action#getDisabledImageDescriptor()
96      */

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

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

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