1 11 package org.eclipse.debug.internal.ui.actions; 12 13 14 import com.ibm.icu.text.MessageFormat; 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.core.runtime.IAdaptable; 17 import org.eclipse.debug.core.DebugPlugin; 18 import org.eclipse.debug.core.ILaunch; 19 import org.eclipse.debug.core.ILaunchConfiguration; 20 import org.eclipse.debug.core.model.IDebugElement; 21 import org.eclipse.debug.core.model.IProcess; 22 import org.eclipse.debug.internal.ui.DebugPluginImages; 23 import org.eclipse.debug.internal.ui.DebugUIPlugin; 24 import org.eclipse.debug.internal.ui.IDebugHelpContextIds; 25 import org.eclipse.debug.ui.DebugUITools; 26 import org.eclipse.debug.ui.ILaunchGroup; 27 import org.eclipse.jface.resource.ImageDescriptor; 28 import org.eclipse.jface.viewers.IStructuredSelection; 29 import org.eclipse.ui.PlatformUI; 30 import org.eclipse.ui.actions.SelectionListenerAction; 31 32 36 public class EditLaunchConfigurationAction extends SelectionListenerAction { 37 38 private ILaunchConfiguration fConfiguration = null; 39 private String fMode = null; 40 private boolean fTerminated = false; 41 42 45 public EditLaunchConfigurationAction() { 46 super(""); setEnabled(false); 48 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IDebugHelpContextIds.EDIT_LAUNCH_CONFIGURATION_ACTION); 49 } 50 51 54 protected boolean updateSelection(IStructuredSelection selection) { 55 setLaunchConfiguration(null); 56 setMode(null); 57 if (selection.size() == 1) { 58 Object object = selection.getFirstElement(); 59 ILaunch launch = null; 60 if (object instanceof IAdaptable) { 61 launch = (ILaunch)((IAdaptable)object).getAdapter(ILaunch.class); 62 } 63 if (launch == null) { 64 if (object instanceof ILaunch) { 65 launch = (ILaunch)object; 66 } else if (object instanceof IDebugElement) { 67 launch = ((IDebugElement)object).getLaunch(); 68 } else if (object instanceof IProcess) { 69 launch = ((IProcess)object).getLaunch(); 70 } 71 } 72 if (launch != null) { 73 ILaunchConfiguration configuration = launch.getLaunchConfiguration(); 74 if (configuration != null) { 75 try { 76 String underlyingHandle = configuration.getAttribute(DebugUIPlugin.ATTR_LAUNCHING_CONFIG_HANDLE, ""); if (underlyingHandle.length() > 0) { 82 ILaunchConfiguration underlyingConfig = DebugPlugin.getDefault().getLaunchManager().getLaunchConfiguration(underlyingHandle); 83 if (underlyingConfig != null) { 84 configuration = underlyingConfig; 85 } 86 } 87 } catch (CoreException e1) { 88 } 89 setLaunchConfiguration(configuration); 90 setMode(launch.getLaunchMode()); 91 setIsTerminated(launch.isTerminated()); 92 setText(MessageFormat.format(ActionMessages.EditLaunchConfigurationAction_1, new String []{configuration.getName()})); 93 ImageDescriptor descriptor = null; 94 try { 95 descriptor = DebugPluginImages.getImageDescriptor(configuration.getType().getIdentifier()); 96 } catch (CoreException e) { 97 DebugUIPlugin.log(e); 98 } 99 setImageDescriptor(descriptor); 100 } 101 } 102 } 103 104 ILaunchConfiguration config = getLaunchConfiguration(); 106 if (config == null) { 107 return false; 108 } 109 return !DebugUITools.isPrivate(config); 110 } 111 112 protected void setLaunchConfiguration(ILaunchConfiguration configuration) { 113 fConfiguration = configuration; 114 } 115 116 protected ILaunchConfiguration getLaunchConfiguration() { 117 return fConfiguration; 118 } 119 120 protected void setMode(String mode) { 121 fMode = mode; 122 } 123 124 protected String getMode() { 125 return fMode; 126 } 127 128 protected boolean isTerminated() { 129 return fTerminated; 130 } 131 132 protected void setIsTerminated(boolean terminated) { 133 fTerminated = terminated; 134 } 135 136 139 public void run() { 140 ILaunchGroup group = DebugUITools.getLaunchGroup(getLaunchConfiguration(), getMode()); 141 if (group != null) { 142 if(isTerminated()) { 143 DebugUITools.openLaunchConfigurationDialog( 144 DebugUIPlugin.getShell(), getLaunchConfiguration(), 145 group.getIdentifier(), null); 146 } 147 else { 148 DebugUIPlugin.openLaunchConfigurationEditDialog( 149 DebugUIPlugin.getShell(), getLaunchConfiguration(), 150 group.getIdentifier(), null, false); 151 } 152 } 153 } 154 155 } 156 | Popular Tags |