1 19 20 package org.netbeans.modules.j2ee.ejbfreeform; 21 22 import org.netbeans.api.project.Project; 23 import org.netbeans.modules.ant.freeform.spi.HelpIDFragmentProvider; 24 import org.netbeans.modules.ant.freeform.spi.ProjectAccessor; 25 import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider; 26 import org.netbeans.modules.j2ee.spi.ejbjar.support.EjbEnterpriseReferenceContainerSupport; 27 import org.netbeans.spi.project.AuxiliaryConfiguration; 28 import org.netbeans.spi.project.LookupProvider; 29 import org.netbeans.spi.project.support.ant.AntProjectEvent; 30 import org.netbeans.spi.project.support.ant.AntProjectHelper; 31 import org.netbeans.spi.project.support.ant.AntProjectListener; 32 import org.netbeans.spi.project.support.ant.PropertyEvaluator; 33 import org.netbeans.spi.project.ui.PrivilegedTemplates; 34 import org.netbeans.spi.project.ui.ProjectOpenedHook; 35 import org.netbeans.spi.project.ui.RecommendedTemplates; 36 import org.openide.util.Lookup; 37 import org.openide.util.lookup.Lookups; 38 import org.openide.util.lookup.ProxyLookup; 39 40 44 public class LookupProviderImpl implements LookupProvider { 45 46 private static final String HELP_ID_FRAGMENT = "ejb"; 48 49 public LookupProviderImpl() { 50 } 51 52 public Lookup createAdditionalLookup(Lookup baseContext) { 53 Project prj = (Project)baseContext.lookup(Project.class); 54 ProjectAccessor acc = (ProjectAccessor)baseContext.lookup(ProjectAccessor.class); 55 AuxiliaryConfiguration aux = (AuxiliaryConfiguration)baseContext.lookup(AuxiliaryConfiguration.class); 56 assert aux != null; 57 assert prj != null; 58 assert acc != null; 59 return new ProjectLookup(prj, acc.getHelper(), acc.getEvaluator(), aux); 60 } 61 62 private static Lookup initLookup(Project project, AntProjectHelper projectHelper, PropertyEvaluator projectEvaluator, AuxiliaryConfiguration aux) { 63 64 EJBFreeformProvider ejbFFProvider = new EJBFreeformProvider(project, projectHelper, projectEvaluator); 65 EJBFreeformModule ejbFFModule = new EJBFreeformModule(project, projectHelper, projectEvaluator); 66 ejbFFProvider.setJ2eeModule(ejbFFModule); 67 68 return Lookups.fixed(new Object [] { 69 ejbFFProvider, 70 ejbFFModule, 71 new EJBModules(project, projectHelper, projectEvaluator), new PrivilegedTemplatesImpl(), EjbEnterpriseReferenceContainerSupport.createEnterpriseReferenceContainer(project, projectHelper), 74 new EjbFreeFormActionProvider(project, projectHelper, aux), 75 new ProjectOpenedHookImpl(project), 76 new LookupMergerImpl(), 77 new HelpIDFragmentProviderImpl(), 78 }); 79 } 80 81 private static final class HelpIDFragmentProviderImpl implements HelpIDFragmentProvider { 82 public String getHelpIDFragment() { 83 return HELP_ID_FRAGMENT; 84 } 85 } 86 87 private static final class ProjectLookup extends ProxyLookup implements AntProjectListener { 88 89 private AntProjectHelper helper; 90 private PropertyEvaluator evaluator; 91 private Project project; 92 private AuxiliaryConfiguration aux; 93 private boolean isMyProject; 94 95 public ProjectLookup(Project project, AntProjectHelper helper, PropertyEvaluator evaluator, AuxiliaryConfiguration aux) { 96 super(new Lookup[0]); 97 this.project = project; 98 this.helper = helper; 99 this.evaluator = evaluator; 100 this.aux = aux; 101 this.isMyProject = EJBProjectNature.isMyProject(aux); 102 updateLookup(); 103 helper.addAntProjectListener(this); 104 } 105 106 private void updateLookup() { 107 Lookup l = Lookup.EMPTY; 108 if (isMyProject) { 109 l = initLookup(project, helper, evaluator, aux); 110 } 111 setLookups(new Lookup[]{l}); 112 } 113 114 public void configurationXmlChanged(AntProjectEvent ev) { 115 if (EJBProjectNature.isMyProject(aux) != isMyProject) { 116 isMyProject = !isMyProject; 117 updateLookup(); 118 } 119 } 120 121 public void propertiesChanged(AntProjectEvent ev) { 122 } 124 125 } 126 127 private static final class ProjectOpenedHookImpl extends ProjectOpenedHook { 128 129 private Project project; 130 131 public ProjectOpenedHookImpl(Project project) { 132 this.project = project; 133 } 134 135 protected void projectOpened() { 136 J2eeModuleProvider j2eeModule = (J2eeModuleProvider)project.getLookup().lookup(J2eeModuleProvider.class); 138 j2eeModule.getConfigSupport().ensureConfigurationReady(); 139 } 140 141 protected void projectClosed() { 142 } 143 } 144 145 private static final class PrivilegedTemplatesImpl implements PrivilegedTemplates, RecommendedTemplates { 146 147 private static final String [] PRIVILEGED_NAMES = new String [] { 148 "Templates/J2EE/Session", "Templates/J2EE/Entity", "Templates/J2EE/ServiceLocator.java", "Templates/Classes/Class.java" }; 153 154 private static final String [] RECOMENDED_TYPES = new String [] { 155 "java-classes", "ejb-types", "ejb-types_2_1", "j2ee-types", "java-beans", "oasis-XML-catalogs", "XML", "wsdl", "ant-script", "ant-task", "junit", "simple-files" }; 168 169 public String [] getPrivilegedTemplates() { 170 return PRIVILEGED_NAMES; 171 } 172 173 public String [] getRecommendedTypes() { 174 return RECOMENDED_TYPES; 175 } 176 177 178 179 } 180 181 182 } 183 | Popular Tags |