1 11 package org.eclipse.ant.internal.ui.views.actions; 12 13 import java.util.Iterator ; 14 import org.eclipse.ant.internal.ui.AntUIImages; 15 import org.eclipse.ant.internal.ui.IAntUIConstants; 16 import org.eclipse.ant.internal.ui.IAntUIHelpContextIds; 17 import org.eclipse.ant.internal.ui.launchConfigurations.AntLaunchShortcut; 18 import org.eclipse.ant.internal.ui.model.AntElementNode; 19 import org.eclipse.ant.internal.ui.model.AntProjectNode; 20 import org.eclipse.ant.internal.ui.model.AntTargetNode; 21 import org.eclipse.ant.internal.ui.model.AntTaskNode; 22 import org.eclipse.ant.internal.ui.views.AntView; 23 import org.eclipse.core.runtime.IProgressMonitor; 24 import org.eclipse.core.runtime.IStatus; 25 import org.eclipse.core.runtime.Status; 26 import org.eclipse.debug.core.ILaunchManager; 27 import org.eclipse.jface.action.Action; 28 import org.eclipse.jface.viewers.IStructuredSelection; 29 import org.eclipse.ui.PlatformUI; 30 import org.eclipse.ui.progress.UIJob; 31 import org.eclipse.ui.texteditor.IUpdate; 32 33 37 public class RunTargetAction extends Action implements IUpdate { 38 39 private AntView fView; 40 41 47 public RunTargetAction(AntView view) { 48 49 setText(AntViewActionMessages.RunTargetAction_Run_1); 50 setImageDescriptor(AntUIImages.getImageDescriptor(IAntUIConstants.IMG_RUN)); 51 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IAntUIHelpContextIds.RUN_TARGET_ACTION); 52 53 setToolTipText(AntViewActionMessages.RunTargetAction_3); 54 fView= view; 55 } 56 57 60 public void run() { 61 run(getSelectedElement()); 62 } 63 64 67 public void run(final AntElementNode selectedElement) { 68 UIJob job= new UIJob(AntViewActionMessages.RunTargetAction_2) { 69 public IStatus runInUIThread(IProgressMonitor monitor) { 70 launch(selectedElement); 71 return Status.OK_STATUS; 72 } 73 }; 74 job.schedule(); 75 } 76 77 82 public void launch(AntElementNode node) { 83 AntLaunchShortcut shortcut= new AntLaunchShortcut(); 84 shortcut.setShowDialog(false); 85 shortcut.launch(node, ILaunchManager.RUN_MODE); 86 } 87 88 91 public void update() { 92 AntElementNode selection= getSelectedElement(); 93 boolean enabled= false; 94 if (selection instanceof AntTargetNode) { 95 if (!((AntTargetNode) selection).isErrorNode()) { 96 setToolTipText(AntViewActionMessages.RunTargetAction_4); 97 enabled= true; 98 } 99 } else if (selection instanceof AntProjectNode) { 100 if (!((AntProjectNode) selection).isErrorNode()) { 101 enabled= true; 102 setToolTipText(AntViewActionMessages.RunTargetAction_3); 103 } 104 } else if (selection instanceof AntTaskNode) { 105 if (!((AntTaskNode) selection).isErrorNode()) { 106 enabled= true; 107 setToolTipText(AntViewActionMessages.RunTargetAction_0); 108 } 109 } 110 setEnabled(enabled); 111 } 112 113 118 private AntElementNode getSelectedElement() { 119 IStructuredSelection selection= (IStructuredSelection) fView.getViewer().getSelection(); 120 if (selection.isEmpty()) { 121 return null; 122 } 123 Iterator iter= selection.iterator(); 124 Object data= iter.next(); 125 if (iter.hasNext()) { 126 return null; 127 } 128 return (AntElementNode) data; 129 } 130 } 131 | Popular Tags |