1 19 20 package org.netbeans.modules.apisupport.project.metainf; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.util.ArrayList ; 25 import java.util.Iterator ; 26 import java.util.List ; 27 import java.util.Map ; 28 import java.util.WeakHashMap ; 29 import org.netbeans.api.project.Project; 30 import org.netbeans.api.project.ProjectManager; 31 import org.netbeans.api.project.ui.OpenProjects; 32 import org.netbeans.modules.apisupport.project.NbModuleProject; 33 import org.netbeans.modules.apisupport.project.spi.NbModuleProvider; 34 import org.netbeans.modules.apisupport.project.SuiteProvider; 35 import org.netbeans.modules.apisupport.project.suite.SuiteProject; 36 import org.netbeans.modules.apisupport.project.universe.ModuleList; 37 import org.netbeans.spi.project.SubprojectProvider; 38 import org.netbeans.spi.project.support.ant.PropertyEvaluator; 39 import org.openide.filesystems.FileObject; 40 import org.openide.filesystems.FileUtil; 41 42 45 final class ServiceViewUpdater { 46 private static Map <SuiteProject,List <Service>> suiteToServices = new WeakHashMap (); 47 48 49 51 public static void serviceUpdated(Service service,ServiceNodeHandler handler) throws IOException { 52 SuiteProject suite = getSuite(handler); 54 if (suite != null) { 55 SubprojectProvider spp = (SubprojectProvider) suite.getLookup().lookup(SubprojectProvider.class); 56 for (Iterator it = spp.getSubprojects().iterator(); it.hasNext() ; ) { 57 ServiceNodeHandler handler2 = (ServiceNodeHandler) ((Project)it.next()).getLookup().lookup(ServiceNodeHandler.class); 58 if (handler2 != null) { 59 handler2.updateService(service); 60 } 61 } 62 } else { 63 NbModuleProvider.NbModuleType type = ((NbModuleProvider) handler.getProject().getLookup().lookup(NbModuleProvider.class)).getModuleType(); 64 if (type == NbModuleProvider.STANDALONE) { 65 handler.updateService(service); 68 } else if (type == NbModuleProvider.NETBEANS_ORG) { 69 File nbroot = ModuleList.findNetBeansOrg(FileUtil.toFile(handler.getProject().getProjectDirectory())); 72 73 FileObject nbAllfo = FileUtil.toFileObject(nbroot); 74 if (nbAllfo != null) { 75 Project projects[] = OpenProjects.getDefault().getOpenProjects(); 76 for (int i = 0; i < projects.length; i++) { 78 if (projects[i] instanceof NbModuleProject) { 80 NbModuleProject prj = (NbModuleProject) projects[i]; 81 NbModuleProvider.NbModuleType prjType = ((NbModuleProvider) handler.getProject().getLookup().lookup(NbModuleProvider.class)).getModuleType(); 82 if (prjType == NbModuleProvider.NETBEANS_ORG && 83 FileUtil.isParentOf(nbAllfo,prj.getProjectDirectory())) { 84 ServiceNodeHandler handler2 = (ServiceNodeHandler) prj.getLookup().lookup(ServiceNodeHandler.class); 85 if (handler2 != null) { 86 handler2.updateService(service); 87 } 88 89 } 90 } 91 } 92 } 93 } 94 } 95 } 96 98 private static SuiteProject getSuite(ServiceNodeHandler handler) throws IOException { 99 SuiteProject retPrj = null; 100 NbModuleProject p = handler.getProject(); 101 NbModuleProvider.NbModuleType type = ((NbModuleProvider) p.getLookup().lookup(NbModuleProvider.class)).getModuleType(); 102 if (type == NbModuleProvider.SUITE_COMPONENT) { 103 SuiteProvider suiteProv = (SuiteProvider) p.getLookup().lookup(SuiteProvider.class); 104 assert suiteProv != null : p; 105 File suiteDir = suiteProv.getSuiteDirectory(); 106 if (suiteDir == null || !suiteDir.isDirectory()) { 107 throw new IOException ("Could not locate suite for " + p); } 109 Project prj = ProjectManager.getDefault().findProject(FileUtil.toFileObject(suiteDir)); 110 if (prj instanceof SuiteProject) { 111 retPrj = (SuiteProject)prj; 112 } 113 } 114 return retPrj; 115 } 116 117 118 120 static List getAllServices(ServiceNodeHandler serviceNodeHandler) throws IOException { 121 SuiteProject suite = getSuite(serviceNodeHandler); 122 if (suite != null) { 123 List <Service> services = (List ) suiteToServices.get(suite); 124 if (services == null) { 125 services = Service.getPlatfromServices(serviceNodeHandler.getProject()); 126 } 127 SubprojectProvider subprojects = (SubprojectProvider)suite.getLookup().lookup(SubprojectProvider.class); 128 for (Iterator sIt = subprojects.getSubprojects().iterator() ; sIt.hasNext() ; ) { 129 NbModuleProject project = (NbModuleProject)sIt.next(); 130 services.addAll(Service.getOnlyProjectServices(project)); 131 } 132 suiteToServices.put(suite,services); 133 return services; 134 } else { 135 return Service.getPlatfromServices(serviceNodeHandler.getProject()); 136 } 137 } 138 139 141 static List <Service> filterServices(List services,ServiceNodeHandler handler) throws IOException { 142 if (getSuite(handler) != null) { 143 List <Service> allServices = getAllServices(handler); 144 List <Service> retList = new ArrayList (); 145 String cnb = handler.getProject().getCodeNameBase(); 146 for (int i = 0 ; i < allServices.size() ; i++) { 147 Service service = (Service) allServices.get(i); 148 if (service.getCodebase().equals(cnb)) { 149 retList.add(service); 150 } 151 } 152 return retList; 153 } else { 154 return Service.getOnlyProjectServices(handler.getProject()); 155 } 156 } 157 } 158 | Popular Tags |