1 11 package org.eclipse.ant.internal.ui.views.actions; 12 import java.util.ArrayList ; 13 import java.util.Iterator ; 14 import java.util.List ; 15 import org.eclipse.ant.internal.ui.AntUIImages; 16 import org.eclipse.ant.internal.ui.IAntUIConstants; 17 import org.eclipse.ant.internal.ui.IAntUIHelpContextIds; 18 import org.eclipse.ant.internal.ui.model.AntProjectNode; 19 import org.eclipse.ant.internal.ui.views.AntView; 20 import org.eclipse.jface.action.Action; 21 import org.eclipse.jface.viewers.IStructuredSelection; 22 import org.eclipse.ui.PlatformUI; 23 import org.eclipse.ui.texteditor.IUpdate; 24 25 28 public class RemoveProjectAction extends Action implements IUpdate { 29 30 private AntView view; 31 32 public RemoveProjectAction(AntView view) { 33 super(AntViewActionMessages.RemoveProjectAction_Remove, AntUIImages.getImageDescriptor(IAntUIConstants.IMG_REMOVE)); 34 this.view= view; 35 setToolTipText(AntViewActionMessages.RemoveProjectAction_Remove_2); 36 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IAntUIHelpContextIds.REMOVE_PROJECT_ACTION); 37 } 38 39 42 public void run() { 43 IStructuredSelection selection= (IStructuredSelection) view.getViewer().getSelection(); 44 Iterator iter= selection.iterator(); 45 Object element; 46 List projectNodes= new ArrayList (); 47 while (iter.hasNext()) { 48 element= iter.next(); 49 if (element instanceof AntProjectNode) { 50 projectNodes.add(element); 51 } 52 } 53 view.removeProjects(projectNodes); 54 } 55 56 59 public void update() { 60 IStructuredSelection selection= (IStructuredSelection) view.getViewer().getSelection(); 61 if (selection.isEmpty()) { 62 setEnabled(false); 63 return; 64 } 65 Object element; 66 Iterator iter= selection.iterator(); 67 while (iter.hasNext()) { 68 element= iter.next(); 69 if (!(element instanceof AntProjectNode)) { 70 setEnabled(false); 71 return; 72 } 73 } 74 setEnabled(true); 75 } 76 77 } 78 | Popular Tags |