1 11 package org.eclipse.debug.internal.ui.commands.actions; 12 13 import org.eclipse.debug.core.ILaunch; 14 import org.eclipse.debug.core.ILaunchConfiguration; 15 import org.eclipse.debug.core.IRequest; 16 import org.eclipse.debug.core.commands.ITerminateHandler; 17 import org.eclipse.debug.internal.ui.DebugPluginImages; 18 import org.eclipse.debug.internal.ui.DebugUIPlugin; 19 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; 20 import org.eclipse.debug.internal.ui.actions.ActionMessages; 21 import org.eclipse.debug.internal.ui.actions.RelaunchActionDelegate; 22 import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationManager; 23 import org.eclipse.debug.ui.contexts.DebugContextEvent; 24 import org.eclipse.jface.resource.ImageDescriptor; 25 import org.eclipse.jface.viewers.ISelection; 26 import org.eclipse.jface.viewers.IStructuredSelection; 27 28 31 public class TerminateAndRelaunchAction extends DebugCommandAction { 32 33 class Particiapnt implements ICommandParticipant { 34 35 private Object [] fTargets; 36 37 public Particiapnt(Object [] targets) { 38 fTargets = targets; 39 } 40 41 44 public void requestDone(IRequest request) { 45 if (request.getStatus() == null || request.getStatus().isOK()) { 46 DebugUIPlugin.getStandardDisplay().asyncExec(new Runnable () { 47 public void run() { 48 for (int i = 0; i < fTargets.length; i++) { 51 ILaunch launch = RelaunchActionDelegate.getLaunch(fTargets[i]); 52 RelaunchActionDelegate.relaunch(launch.getLaunchConfiguration(), launch.getLaunchMode()); 53 } 54 } 55 }); 56 } 57 } 58 59 } 60 61 protected ICommandParticipant getCommandParticipant(Object [] targets) { 62 return new Particiapnt(targets); 63 } 64 65 protected Class getCommandType() { 66 return ITerminateHandler.class; 67 } 68 69 public void debugContextChanged(DebugContextEvent event) { 70 ISelection context = event.getContext(); 71 if (context instanceof IStructuredSelection) { 72 Object [] elements = ((IStructuredSelection)context).toArray(); 73 for (int i = 0; i < elements.length; i++) { 74 if (!canRelaunch(elements[i])) { 75 setEnabled(false); 76 return; 77 } 78 } 79 } 80 super.debugContextChanged(event); 81 } 82 83 protected boolean canRelaunch(Object element) { 84 ILaunch launch = RelaunchActionDelegate.getLaunch(element); 85 if (launch != null) { 86 ILaunchConfiguration configuration = launch.getLaunchConfiguration(); 87 if (configuration != null) { 88 return LaunchConfigurationManager.isVisible(configuration); 89 } 90 } 91 return false; 92 } 93 94 public String getActionDefinitionId() { 95 return ActionMessages.TerminateAndRelaunchAction_0; 96 } 97 98 public String getHelpContextId() { 99 return "org.eclipse.debug.ui.terminate_and_relaunch_action_context"; } 101 102 public String getId() { 103 return "org.eclipse.debug.ui.debugview.popupMenu.TerminateAndRelaunch"; } 105 106 public String getText() { 107 return ActionMessages.TerminateAndRelaunchAction_3; 108 } 109 110 public String getToolTipText() { 111 return ActionMessages.TerminateAndRelaunchAction_4; 112 } 113 114 public ImageDescriptor getDisabledImageDescriptor() { 115 return DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_DLCL_TERMINATE_AND_RELAUNCH); 116 } 117 118 public ImageDescriptor getHoverImageDescriptor() { 119 return DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_ELCL_TERMINATE_AND_RELAUNCH); 120 } 121 122 public ImageDescriptor getImageDescriptor() { 123 return DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_ELCL_TERMINATE_AND_RELAUNCH); 124 } 125 } 126 | Popular Tags |