1 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 32 public class CreateLaunchConfigurationAction extends AbstractLaunchConfigurationAction { 33 34 37 public static final String ID_CREATE_ACTION = DebugUIPlugin.getUniqueIdentifier() + ".ID_CREATE_ACTION"; 39 42 public CreateLaunchConfigurationAction(Viewer viewer, String mode) { 43 super(LaunchConfigurationsMessages.CreateLaunchConfigurationAction_Ne_w_1, viewer, mode); 44 } 45 46 49 protected void performAction() { 50 Object object = getStructuredSelection().getFirstElement(); 51 if(object != null) { 54 ILaunchConfigurationType type= null; 55 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 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 90 protected boolean updateSelection(IStructuredSelection selection) { 91 return selection.size() == 1; 92 } 93 94 97 public ImageDescriptor getDisabledImageDescriptor() { 98 return DebugUITools.getImageDescriptor(IInternalDebugUIConstants.IMG_DLCL_NEW_CONFIG); 99 } 100 101 104 public ImageDescriptor getImageDescriptor() { 105 return DebugUITools.getImageDescriptor(IInternalDebugUIConstants.IMG_ELCL_NEW_CONFIG); 106 } 107 108 111 public String getToolTipText() { 112 return LaunchConfigurationsMessages.LaunchConfigurationsDialog_0; 113 } 114 115 } 116 | Popular Tags |