1 19 20 package org.netbeans.modules.j2ee.earproject.ui; 21 22 import java.util.Collections ; 23 import java.util.HashMap ; 24 import java.util.List ; 25 import org.netbeans.api.project.FileOwnerQuery; 26 import org.netbeans.api.project.Project; 27 import org.netbeans.api.project.ant.AntArtifact; 28 import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider; 29 import org.netbeans.modules.j2ee.earproject.EarProject; 30 import org.netbeans.modules.j2ee.earproject.ui.customizer.VisualClassPathItem; 31 import org.netbeans.spi.project.support.ant.AntProjectEvent; 32 import org.netbeans.spi.project.support.ant.AntProjectHelper; 33 import org.netbeans.spi.project.support.ant.AntProjectListener; 34 import org.openide.ErrorManager; 35 import org.openide.nodes.Children; 36 import org.openide.nodes.Node; 37 import org.openide.util.RequestProcessor; 38 39 46 public class LogicalViewChildren extends Children.Keys implements AntProjectListener { 47 48 private final AntProjectHelper model; 49 private java.util.Map <String , VisualClassPathItem> vcpItems; 50 51 public LogicalViewChildren(AntProjectHelper model) { 52 if (null == model) { 53 throw new IllegalArgumentException ("model cannot be null"); } 55 this.model = model; 56 } 57 58 protected void addNotify() { 59 super.addNotify(); 60 updateKeys(); 62 model.addAntProjectListener(this); 64 } 65 66 private void updateKeys() { 67 Project p = FileOwnerQuery.getOwner(model.getProjectDirectory()); 68 if(p == null) { 70 ErrorManager.getDefault().notify(ErrorManager.WARNING, 71 new IllegalStateException ("FileOwnerQuery.getOwner("+ model.getProjectDirectory() + ") returned null. " + "Please report this with the situation description to issue #62823 " + "(http://www.netbeans.org/issues/show_bug.cgi?id=62823).")); 74 return ; 75 } 76 77 EarProject earProject = (EarProject) p.getLookup().lookup(EarProject.class); 78 List <VisualClassPathItem> vcpis = earProject.getProjectProperties().getJarContentAdditional(); 79 vcpItems = new HashMap <String , VisualClassPathItem>(); 80 for (VisualClassPathItem vcpi : vcpis) { 81 Object obj = vcpi.getObject(); 82 if (!(obj instanceof AntArtifact)) { 83 continue; 84 } 85 AntArtifact aa = (AntArtifact) obj; 86 Project vcpiProject = aa.getProject(); 87 J2eeModuleProvider jmp = (J2eeModuleProvider) vcpiProject.getLookup().lookup(J2eeModuleProvider.class); 88 if (null != jmp) { 89 vcpItems.put(vcpi.getRaw(), vcpi); 90 } 91 } 92 setKeys(vcpItems.keySet()); 93 } 94 95 protected void removeNotify() { 96 model.removeAntProjectListener(this); 97 setKeys(Collections.EMPTY_SET); 98 super.removeNotify(); 99 } 100 101 protected Node[] createNodes(Object key) { 102 VisualClassPathItem vcpItem = vcpItems.get((String ) key); 103 return new Node[] { new ModuleNode(vcpItem, model.getProjectDirectory() ) }; 104 } 105 106 public void modelChanged(Object ev) { 107 updateKeys(); 109 } 110 111 public void configurationXmlChanged(AntProjectEvent ape) { 112 RequestProcessor.getDefault().post(new Runnable () { 115 public void run() { 116 updateKeys(); 117 } 118 }); 119 } 120 121 public void propertiesChanged(final AntProjectEvent ape) { 122 RequestProcessor.getDefault().post(new Runnable () { 125 public void run() { 126 updateKeys(); 127 } 128 }); 129 } 130 131 } 132 | Popular Tags |