1 19 20 package org.netbeans.modules.j2ee.clientproject.ui; 21 22 23 import java.io.IOException ; 24 import java.util.HashSet ; 25 import org.openide.nodes.Node; 26 import org.openide.util.NbBundle; 27 import org.openide.util.HelpCtx; 28 import org.openide.util.actions.NodeAction; 29 import org.netbeans.spi.project.support.ant.EditableProperties; 30 31 import java.util.Iterator ; 32 import java.util.Set ; 33 import org.netbeans.api.project.Project; 34 import org.netbeans.api.project.ProjectManager; 35 import org.openide.ErrorManager; 36 37 43 final class RemoveClassPathRootAction extends NodeAction { 44 45 50 static interface Removable { 51 55 public boolean canRemove (); 56 57 60 public abstract Project remove (); 61 } 62 63 protected void performAction(final Node[] activatedNodes) { 64 final Set <Project> changedProjectsSet = new HashSet <Project>(); 65 66 ProjectManager.mutex().writeAccess(new Runnable () { 67 public void run() { 68 for (int i = 0; i < activatedNodes.length; i++) { 69 Removable removable = (Removable) activatedNodes[i].getLookup().lookup(Removable.class); 70 if (removable == null) 71 continue; 72 73 Project p = removable.remove(); 74 if (p != null) 75 changedProjectsSet.add(p); 76 } 77 78 for (Iterator <Project> i = changedProjectsSet.iterator(); i.hasNext();) { 79 Project p = i.next(); 80 try { 81 ProjectManager.getDefault().saveProject(p); 82 } 83 catch (IOException e) { 84 ErrorManager.getDefault().notify(e); 85 } 86 } 87 } 88 }); 89 } 90 91 protected boolean enable(Node[] activatedNodes) { 92 for (int i=0; i<activatedNodes.length; i++) { 93 Removable removable = (Removable) activatedNodes[i].getLookup().lookup(Removable.class); 94 if (removable==null) { 95 return false; 96 } 97 if (!removable.canRemove()) { 98 return false; 99 } 100 } 101 return true; 102 } 103 104 public String getName() { 105 return NbBundle.getMessage (RemoveClassPathRootAction.class,"CTL_RemoveProject"); 106 } 107 108 public HelpCtx getHelpCtx() { 109 return new HelpCtx (RemoveClassPathRootAction.class); 110 } 111 112 protected boolean asynchronous() { 113 return false; 114 } 115 116 123 public static boolean isReferenced (EditableProperties[] props, String reference) { 124 for (int i=0; i< props.length; i++) { 125 for (Iterator it = props[i].values().iterator(); it.hasNext();) { 126 String value = (String ) it.next (); 127 if (value != null && value.indexOf(reference)>=0) { 128 return true; 129 } 130 } 131 } 132 return false; 133 } 134 } 135 | Popular Tags |