1 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 45 public class OpenLaunchDialogAction extends Action implements IActionDelegate2, IWorkbenchWindowActionDelegate { 46 47 50 private String fIdentifier; 51 52 58 public OpenLaunchDialogAction(String identifier) { 59 fIdentifier = identifier; 60 ILaunchGroup group = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(fIdentifier); 61 if(group != null) { 62 setImageDescriptor(group.getImageDescriptor()); 63 String lbl = group.getLabel(); 64 String actionLabel = MessageFormat.format(ActionMessages.OpenLaunchDialogAction_1, new String [] {lbl}); 65 setText(DebugUIPlugin.adjustDBCSAccelerator(actionLabel)); 66 } 67 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IDebugHelpContextIds.OPEN_LAUNCH_CONFIGURATION_ACTION); 68 } 69 70 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 89 public void runWithEvent(IAction action, Event event) { 90 run(); 91 } 92 93 96 public void run(IAction action) { 97 run(); 98 } 99 100 103 public void dispose() {} 104 105 108 public void init(IAction action) { 109 if(action != null) { 110 action.setEnabled(existsConfigTypesForMode()); 111 } 112 } 113 114 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 135 public void init(IWorkbenchWindow window) {} 136 137 140 public void selectionChanged(IAction action, ISelection selection) {} 141 142 147 private String getMode() { 148 return DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(fIdentifier).getMode(); 149 } 150 } 151 | Popular Tags |