1 19 20 package org.netbeans.modules.websvc.core.webservices.ui.panels; 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 SelectHandlerPanel extends JPanel implements ExplorerManager.Provider { 51 52 private ExplorerManager manager; 53 private Node[] selectedNodes; 54 private JPanel panel; 55 private Project project; 56 57 58 public SelectHandlerPanel(Project project) { 59 this.project = project; 60 initComponents(); 61 manager = new ExplorerManager(); 62 manager.addPropertyChangeListener( 63 new PropertyChangeListener () { 64 public void propertyChange(PropertyChangeEvent pce) { 65 selectedNodes = manager.getSelectedNodes(); 66 } 67 }); 68 populateTree(); 69 } 70 71 public Node[] getSelectedNodes(){ 72 return selectedNodes; 73 } 74 75 public ExplorerManager getExplorerManager() { 76 return manager; 77 } 78 79 private void populateTree(){ 80 LogicalViewProvider lvp = (LogicalViewProvider)project.getLookup().lookup(LogicalViewProvider.class); 81 Node projectView = lvp.createLogicalView(); 82 Children.Array children = new Children.Array(); 83 FilterNode filter = new FilterNode(projectView, new SourceListViewChildren()); 84 children.add(new FilterNode[] {filter}); 85 Node root = new AbstractNode(children); 86 manager.setRootContext(filter); 87 88 } 89 90 private void initComponents() { 91 panel = new JPanel (); 92 setLayout(new BorderLayout ()); 93 BorderLayout bl = new BorderLayout (); 94 panel.setLayout(bl); 95 bl.setVgap(10); 96 add(panel, BorderLayout.CENTER); 97 98 BeanTreeView btv = new BeanTreeView(); 99 btv.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1)); 100 btv.getAccessibleContext(). 101 setAccessibleName(NbBundle.getMessage(SelectHandlerPanel.class,"LBL_Class_Tree")); 102 btv.getAccessibleContext().setAccessibleDescription 103 (NbBundle.getMessage(SelectHandlerPanel.class,"TTL_SelectHandler")); 104 String projectName = project.getProjectDirectory().getName(); 105 String classesLabel = projectName + " " + 106 NbBundle.getMessage(SelectHandlerPanel.class, "LBL_PROJECT_CLASSES") + ":"; 107 JLabel label = new JLabel (classesLabel); 108 panel.add(label, BorderLayout.NORTH); 109 panel.add(btv, BorderLayout.CENTER); panel.validate(); 111 validate(); 112 } 113 114 115 class SourceListViewChildren extends Children.Keys { 116 public static final String KEY_SOURCES = "sourcesKey"; 118 protected Node[] createNodes(Object key) { 119 Node n = null; 120 List <Node> sourceNodes = new LinkedList <Node>(); 121 if (key == KEY_SOURCES) { 122 Sources sources = ProjectUtils.getSources(project); 123 SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); 124 for(int i = 0; i < groups.length; i++){ 125 sourceNodes.add(PackageView.createPackageView(groups[i])); 126 } 127 } 128 return sourceNodes.<Node>toArray(new Node[sourceNodes.size()]); 129 } 130 131 @Override 132 protected void addNotify() { 133 super.addNotify(); 134 createNodes(); 135 } 136 137 private void createNodes() { 138 List l = new ArrayList (); 139 l.add(KEY_SOURCES); 140 setKeys(l); 141 } 142 143 @Override 144 protected void removeNotify() { 145 setKeys(Collections.EMPTY_SET); 146 super.removeNotify(); 147 } 148 149 } 150 } 151 | Popular Tags |