1 19 20 package org.netbeans.modules.j2ee.ejbjarproject.ui.logicalview.libraries; 21 22 23 import java.io.IOException ; 24 import java.util.HashMap ; 25 import java.util.HashSet ; 26 import org.openide.nodes.Node; 27 import org.openide.util.NbBundle; 28 import org.openide.util.HelpCtx; 29 import org.openide.util.actions.NodeAction; 30 import org.netbeans.spi.project.support.ant.EditableProperties; 31 32 import java.util.Iterator ; 33 import java.util.List ; 34 import java.util.Map ; 35 import java.util.Set ; 36 import org.netbeans.api.project.FileOwnerQuery; 37 import org.netbeans.api.project.Project; 38 import org.netbeans.api.project.ProjectManager; 39 import org.netbeans.modules.j2ee.ejbjarproject.classpath.ClassPathSupport; 40 import org.netbeans.modules.j2ee.ejbjarproject.ui.customizer.EjbJarProjectProperties; 41 import org.netbeans.spi.project.support.ant.AntProjectHelper; 42 import org.netbeans.spi.project.support.ant.PropertyEvaluator; 43 import org.netbeans.spi.project.support.ant.ReferenceHelper; 44 import org.openide.ErrorManager; 45 import org.openide.util.Utilities; 46 47 53 final class RemoveClassPathRootAction extends NodeAction { 54 55 60 static interface Removable { 61 65 public boolean canRemove (); 66 67 81 public abstract Project remove (); 82 } 83 84 protected void performAction(final Node[] activatedNodes) { 85 final Set changedProjectsSet = new HashSet (); 86 87 ProjectManager.mutex().writeAccess(new Runnable () { 88 public void run() { 89 for (int i = 0; i < activatedNodes.length; i++) { 90 Removable removable = (Removable) activatedNodes[i].getLookup().lookup(Removable.class); 91 if (removable == null) 92 continue; 93 94 Project p = removable.remove(); 95 if (p != null) 96 changedProjectsSet.add(p); 97 } 98 99 for (Iterator i = changedProjectsSet.iterator(); i.hasNext();) { 100 Project p = (Project)i.next(); 101 try { 102 ProjectManager.getDefault().saveProject(p); 103 } 104 catch (IOException e) { 105 ErrorManager.getDefault().notify(e); 106 } 107 } 108 } 109 }); 110 } 111 112 protected boolean enable(Node[] activatedNodes) { 113 for (int i=0; i<activatedNodes.length; i++) { 114 Removable removable = (Removable) activatedNodes[i].getLookup().lookup(Removable.class); 115 if (removable==null) { 116 return false; 117 } 118 if (!removable.canRemove()) { 119 return false; 120 } 121 } 122 return true; 123 } 124 125 public String getName() { 126 return NbBundle.getMessage (RemoveClassPathRootAction.class,"CTL_RemoveProject"); 127 } 128 129 public HelpCtx getHelpCtx() { 130 return new HelpCtx (RemoveClassPathRootAction.class); 131 } 132 133 protected boolean asynchronous() { 134 return false; 135 } 136 137 144 public static boolean isReferenced (EditableProperties[] props, String reference) { 145 for (int i=0; i< props.length; i++) { 146 for (Iterator it = props[i].values().iterator(); it.hasNext();) { 147 String value = (String ) it.next (); 148 if (value != null && value.indexOf(reference)>=0) { 149 return true; 150 } 151 } 152 } 153 return false; 154 } 155 } 156 | Popular Tags |