1 19 20 package org.netbeans.modules.websvc.dev.wizard; 21 22 import javax.swing.JPanel ; 23 24 import java.awt.BorderLayout ; 25 import java.awt.Component ; 26 import java.awt.Dimension ; 27 import java.util.List ; 28 import java.beans.PropertyChangeEvent ; 29 import java.beans.PropertyChangeListener ; 30 import java.util.LinkedList ; 31 import javax.swing.event.ChangeEvent ; 32 import javax.swing.event.ChangeListener ; 33 import org.netbeans.api.project.Project; 34 import org.openide.explorer.ExplorerManager; 35 import org.openide.explorer.view.BeanTreeView; 36 import org.openide.nodes.AbstractNode; 37 import org.openide.nodes.Node; 38 import org.openide.util.HelpCtx; 39 import org.openide.util.NbBundle; 40 import org.openide.WizardDescriptor; 41 import org.netbeans.api.project.ui.OpenProjects; 42 import org.netbeans.spi.project.ui.LogicalViewProvider; 43 import org.openide.nodes.Children; 44 import org.netbeans.modules.j2ee.api.ejbjar.EjbReference; 45 46 public class CreateWebServiceFromExistingCodePanel extends JPanel 47 implements WizardDescriptor.FinishablePanel, ExplorerManager.Provider, WebServiceWizard.HasWizardHelper { 48 private ExplorerManager manager; 49 private JPanel panel; 50 private Node[] selectedNodes; 51 private ChangeListener listener; 52 private WebServiceWizardHelper helper; 53 54 public CreateWebServiceFromExistingCodePanel(WebServiceWizardHelper helper) { 55 this.helper = helper; 56 initComponents(); 57 manager = new ExplorerManager(); 58 manager.addPropertyChangeListener( 59 new PropertyChangeListener () { 60 public void propertyChange(PropertyChangeEvent pce) { 61 selectedNodes = manager.getSelectedNodes(); 62 fireStateChange(); 63 } 64 }); 65 } 66 67 68 private void initComponents() { 69 panel = new JPanel (); 70 setLayout(new BorderLayout ()); 71 setPreferredSize(new Dimension (550, 440)); 72 panel.setLayout(new BorderLayout ()); 73 add(panel, BorderLayout.CENTER); 74 75 BeanTreeView btv = new BeanTreeView(); 76 btv.getAccessibleContext(). 77 setAccessibleName(NbBundle.getMessage(CreateWebServiceFromExistingCodePanel.class, 78 "LBL_ExistingCode_Tree")); btv.getAccessibleContext().setAccessibleDescription 80 (NbBundle.getMessage(CreateWebServiceFromExistingCodePanel.class, 81 "LBL_SelectExistingCode")); 83 panel.add(btv, "Center"); panel.validate(); 85 validate(); 86 } 87 88 public ExplorerManager getExplorerManager() { 89 return manager; 90 } 91 92 public void addChangeListener(ChangeListener l) { 93 listener = l; 94 } 95 96 private void fireStateChange() { 97 if (listener != null) { 98 ChangeEvent evt = new ChangeEvent (this); 99 listener.stateChanged(evt); 100 } 101 } 102 103 public Component getComponent() { 104 return this; 105 } 106 107 public HelpCtx getHelp() { 108 return null; 109 } 110 111 public boolean isValid() { 112 for(int i = 0; i < selectedNodes.length; i++) { 113 Node node = selectedNodes[i]; 114 if (node.getCookie(EjbReference.class) == null) { 115 return false; 116 } 117 143 } 144 return true; 145 } 146 147 public void readSettings(Object settings) { 148 Project[] allProjects = OpenProjects.getDefault().getOpenProjects(); 149 List projectNodes = new LinkedList (); 150 for(int i = 0; i < allProjects.length; i++) { 151 LogicalViewProvider lvp = (LogicalViewProvider)allProjects[i].getLookup().lookup(LogicalViewProvider.class); 152 if(lvp != null) { 153 projectNodes.add(lvp.createLogicalView()); 154 } 155 } 156 Children.Array children = new Children.Array(); 157 children.add((Node[])projectNodes.toArray(new Node[projectNodes.size()])); 158 Node root = new AbstractNode(children); 159 root.setDisplayName(NbBundle.getMessage(CreateWebServiceFromExistingCodePanel.class, "LBL_Available_Projects")); 160 manager.setRootContext(root); 161 } 162 163 public void removeChangeListener(ChangeListener l) { 164 if (listener == l) { 165 listener = null; 166 } 167 } 168 169 public void storeSettings(Object settings) { 170 helper.setExistingCodeNodes(selectedNodes); 171 } 172 173 public boolean isFinishPanel() { 174 return true; 175 } 176 177 public void setWizardHelper(WebServiceWizardHelper h) { 178 helper = h; 179 } 180 } 181 | Popular Tags |