1 19 20 package org.netbeans.modules.j2ee.ejbcore.ui.logicalview.entres; 21 import java.io.IOException ; 22 import java.util.ArrayList ; 23 import java.util.Collections ; 24 import java.util.List ; 25 import org.netbeans.api.java.classpath.ClassPath; 26 import org.netbeans.api.java.project.JavaProjectConstants; 27 import org.netbeans.api.project.Project; 28 import org.netbeans.api.project.ProjectUtils; 29 import org.netbeans.api.project.SourceGroup; 30 import org.netbeans.api.project.Sources; 31 import org.netbeans.modules.j2ee.api.ejbjar.EjbJar; 32 import org.netbeans.modules.j2ee.spi.ejbjar.support.J2eeProjectView; 33 import org.openide.ErrorManager; 34 import org.openide.filesystems.FileObject; 35 import org.openide.nodes.Children; 36 import org.openide.nodes.Node; 37 38 41 public final class EJBListViewChildren extends Children.Keys<EJBListViewChildren.KEY> { 42 43 public enum KEY { EJB } 44 45 private final Sources sources; 46 private final ClassPath classPath; 47 private final Project project; 48 49 public EJBListViewChildren(Project project) { 50 assert project != null; 51 this.project = project; 52 sources = ProjectUtils.getSources(project); 53 assert sources != null; 54 classPath = org.netbeans.spi.java.classpath.support.ClassPathSupport.createClassPath(getRoots()); 55 } 56 57 private FileObject[] getRoots() { 58 SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); 59 FileObject[] roots = new FileObject[groups.length]; 60 for (int i = 0; i < groups.length; i++) { 61 roots[i] = groups[i].getRootFolder(); 62 } 63 return roots; 64 } 65 66 @Override 67 protected void addNotify() { 68 super.addNotify(); 69 createNodes(); 70 } 71 72 private void createNodes() { 73 List <KEY> keys = new ArrayList <KEY>(); 74 keys.add(KEY.EJB); 75 setKeys(keys); 76 } 77 78 @Override 79 protected void removeNotify() { 80 setKeys(Collections.<KEY>emptySet()); 81 super.removeNotify(); 82 } 83 84 public Node[] createNodes(KEY key) { 85 Node node = null; 86 if (key == KEY.EJB) { 87 EjbJar[] apiEjbJars = EjbJar.getEjbJars(project); 88 org.netbeans.modules.j2ee.dd.api.ejb.EjbJar ejbJar = null; 89 try { 90 ejbJar = org.netbeans.modules.j2ee.dd.api.ejb.DDProvider.getDefault().getMergedDDRoot(apiEjbJars[0].getMetadataUnit()); 91 } catch (IOException ioe) { 92 ErrorManager.getDefault().notify(ioe); 93 } 94 if (ejbJar != null) { 95 node = J2eeProjectView.createEjbsView(ejbJar, classPath, apiEjbJars[0].getDeploymentDescriptor(), project); 96 } 97 } 98 return node == null ? new Node[0] : new Node[] {node}; 99 } 100 101 } 102 103 104 | Popular Tags |