1 19 20 package org.netbeans.modules.websvc.wsdl.wizard; 21 22 import javax.swing.JPanel ; 23 import org.openide.explorer.ExplorerManager; 24 import org.openide.nodes.Node; 25 import java.awt.BorderLayout ; 26 import java.awt.Dimension ; 27 import org.openide.explorer.view.BeanTreeView; 28 import org.openide.util.NbBundle; 29 import java.beans.PropertyChangeEvent ; 30 import java.beans.PropertyChangeListener ; 31 import java.util.ArrayList ; 32 import java.util.Collections ; 33 import java.util.LinkedList ; 34 import java.util.List ; 35 import javax.swing.JLabel ; 36 import org.netbeans.api.project.Project; 37 import org.openide.nodes.Children; 38 import org.netbeans.api.java.project.JavaProjectConstants; 39 import org.netbeans.api.project.ProjectUtils; 40 import org.netbeans.api.project.SourceGroup; 41 import org.netbeans.api.project.Sources; 42 import org.netbeans.spi.java.project.support.ui.PackageView; 43 import org.netbeans.spi.project.ui.LogicalViewProvider; 44 import org.openide.nodes.AbstractNode; 45 import org.openide.nodes.FilterNode; 46 47 50 public class SelectSchemaPanel extends JPanel implements ExplorerManager.Provider { 51 52 private ExplorerManager manager; 53 private Node[] selectedNodes; 54 private JPanel panel; 55 private Project project; 56 57 60 public SelectSchemaPanel(Project project) { 61 this.project = project; 62 initComponents(); 63 manager = new ExplorerManager(); 64 manager.addPropertyChangeListener( 65 new PropertyChangeListener () { 66 public void propertyChange(PropertyChangeEvent pce) { 67 selectedNodes = manager.getSelectedNodes(); 68 } 69 }); 70 populateTree(); 71 } 72 73 public Node[] getSelectedNodes(){ 74 return selectedNodes; 75 } 76 77 public ExplorerManager getExplorerManager() { 78 return manager; 79 } 80 81 private void populateTree(){ 82 LogicalViewProvider lvp = (LogicalViewProvider)project.getLookup().lookup(LogicalViewProvider.class); 83 Node projectView = lvp.createLogicalView(); 84 Children.Array children = new Children.Array(); 85 FilterNode filter = new FilterNode(projectView, new SourceListViewChildren()); 86 children.add(new FilterNode[] {filter}); 87 Node root = new AbstractNode(children); 88 manager.setRootContext(filter); 89 90 } 91 92 private void initComponents() { 93 panel = new JPanel (); 94 setLayout(new BorderLayout ()); 95 BorderLayout bl = new BorderLayout (); 96 panel.setLayout(bl); 97 bl.setVgap(10); 98 add(panel, BorderLayout.CENTER); 99 100 BeanTreeView btv = new BeanTreeView(); 101 btv.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1)); 102 btv.getAccessibleContext(). 103 setAccessibleName(NbBundle.getMessage(SelectSchemaPanel.class,"LBL_Schemas")); 104 btv.getAccessibleContext().setAccessibleDescription 105 (NbBundle.getMessage(SelectSchemaPanel.class,"TTL_SelectSchemas")); 106 String projectName = project.getProjectDirectory().getName(); 107 String classesLabel = projectName + " " + 108 NbBundle.getMessage(SelectSchemaPanel.class, "LBL_Schemas") + ":"; 109 JLabel label = new JLabel (classesLabel); 110 panel.add(label, BorderLayout.NORTH); 111 panel.add(btv, BorderLayout.CENTER); panel.validate(); 113 validate(); 114 } 115 116 117 class SourceListViewChildren extends Children.Keys { 118 public static final String KEY_SOURCES = "sourcesKey"; 120 protected Node[] createNodes(Object key) { 121 Node n = null; 122 List <Node> sourceNodes = new LinkedList <Node>(); 123 if (key == KEY_SOURCES) { 124 Sources sources = ProjectUtils.getSources(project); 125 SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); 126 for(int i = 0; i < groups.length; i++){ 127 sourceNodes.add(PackageView.createPackageView(groups[i])); 128 } 129 } 130 return (Node[])sourceNodes.toArray(new Node[sourceNodes.size()]); 131 } 132 133 @Override 134 protected void addNotify() { 135 super.addNotify(); 136 createNodes(); 137 } 138 139 private void createNodes() { 140 List l = new ArrayList (); 141 l.add(KEY_SOURCES); 142 setKeys(l); 143 } 144 145 @Override 146 protected void removeNotify() { 147 setKeys(Collections.EMPTY_SET); 148 super.removeNotify(); 149 } 150 151 } 152 } 153 | Popular Tags |