1 19 20 package org.netbeans.modules.websvc.dev.wizard; 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 34 import org.openide.ErrorManager; 35 import org.openide.filesystems.FileObject; 36 import org.openide.nodes.Children; 37 import org.openide.nodes.Node; 38 39 42 public final class EJBListViewChildren extends Children.Keys { 43 44 public static final String KEY_EJBS = "ejbKey"; 46 private Sources sources; 47 private ClassPath cp; 48 private Project project; 49 50 public EJBListViewChildren(Project project) { 51 assert project != null; 52 this.project = project; 53 sources = ProjectUtils.getSources(project); 54 assert sources != null; 55 cp = org.netbeans.spi.java.classpath.support.ClassPathSupport.createClassPath(getRoots()); 56 } 57 58 private FileObject[] getRoots() { 59 SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); 60 FileObject[] roots = new FileObject[groups.length]; 61 for (int i = 0; i < groups.length; i++) { 62 roots[i] = groups[i].getRootFolder(); 63 } 64 return roots; 65 } 66 67 @Override 68 protected void addNotify() { 69 super.addNotify(); 70 createNodes(); 71 } 72 73 private void createNodes() { 74 List l = new ArrayList (); 75 l.add(KEY_EJBS); 76 setKeys(l); 77 } 78 79 @Override 80 protected void removeNotify() { 81 setKeys(Collections.EMPTY_SET); 82 super.removeNotify(); 83 } 84 85 public Node[] createNodes(Object key) { 86 Node n = null; 87 if (key == KEY_EJBS) { 88 EjbJar[] apiEjbJars = EjbJar.getEjbJars(project); 89 org.netbeans.modules.j2ee.dd.api.ejb.EjbJar ejbJar = null; 90 try { 91 ejbJar = org.netbeans.modules.j2ee.dd.api.ejb.DDProvider.getDefault().getMergedDDRoot(apiEjbJars[0].getMetadataUnit()); 92 } catch (IOException ioe) { 93 ErrorManager.getDefault().notify(ioe); 94 } 95 if (ejbJar != null) { 96 n = J2eeProjectView.createEjbsView(ejbJar, cp, apiEjbJars[0].getDeploymentDescriptor(), project); 97 } 98 } 99 return n == null ? new Node[0] : new Node[] {n}; 100 } 101 102 } 103 104 105 | Popular Tags |