1 19 20 package org.netbeans.modules.web.project.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.api.project.Project; 30 import org.netbeans.spi.project.support.ant.EditableProperties; 31 32 33 import java.util.Iterator ; 34 import java.util.Set ; 35 import org.netbeans.api.project.ProjectManager; 36 import org.openide.ErrorManager; 37 38 44 final class RemoveClassPathRootAction extends NodeAction { 45 46 51 static interface Removable { 52 56 public boolean canRemove (); 57 58 72 public abstract Project remove (); 73 } 74 75 protected void performAction(final Node[] activatedNodes) { 76 final Set changedProjectsSet = new HashSet (); 77 78 ProjectManager.mutex().writeAccess(new Runnable () { 79 public void run() { 80 for (int i = 0; i < activatedNodes.length; i++) { 81 Removable removable = (Removable) activatedNodes[i].getLookup().lookup(Removable.class); 82 if (removable == null) 83 continue; 84 85 Project p = removable.remove(); 86 if (p != null) 87 changedProjectsSet.add(p); 88 } 89 90 for (Iterator i = changedProjectsSet.iterator(); i.hasNext();) { 91 Project p = (Project)i.next(); 92 try { 93 ProjectManager.getDefault().saveProject(p); 94 } 95 catch (IOException e) { 96 ErrorManager.getDefault().notify(e); 97 } 98 } 99 } 100 }); 101 } 102 103 protected boolean enable(Node[] activatedNodes) { 104 for (int i=0; i<activatedNodes.length; i++) { 105 Removable removable = (Removable) activatedNodes[i].getLookup().lookup(Removable.class); 106 if (removable==null) { 107 return false; 108 } 109 if (!removable.canRemove()) { 110 return false; 111 } 112 } 113 return true; 114 } 115 116 public String getName() { 117 return NbBundle.getMessage (RemoveClassPathRootAction.class,"CTL_RemoveProject"); 118 } 119 120 public HelpCtx getHelpCtx() { 121 return new HelpCtx (RemoveClassPathRootAction.class); 122 } 123 124 protected boolean asynchronous() { 125 return false; 126 } 127 128 135 public static boolean isReferenced (EditableProperties[] props, String reference) { 136 for (int i=0; i< props.length; i++) { 137 for (Iterator it = props[i].values().iterator(); it.hasNext();) { 138 String value = (String ) it.next (); 139 if (value != null && value.indexOf(reference)>=0) { 140 return true; 141 } 142 } 143 } 144 return false; 145 } 146 } 147 | Popular Tags |