1 19 20 package org.netbeans.modules.websvc.dev.wizard; 21 22 import java.beans.PropertyChangeEvent ; 23 import java.beans.PropertyChangeListener ; 24 import javax.swing.border.EtchedBorder ; 25 import org.netbeans.modules.websvc.dev.wizard.nodes.PortNode; 26 import org.openide.nodes.Node; 27 import org.openide.nodes.NodeAcceptor; 28 import org.openide.util.NbBundle; 29 30 public class PortChooser extends javax.swing.JPanel { 31 32 public static final String IS_VALID = "portChooser_isValid"; 34 private NodeAcceptor nodeAcceptor; 35 private NodeDisplayPanel nodeDisplayPanel; 36 37 38 public PortChooser(Node root) { 39 initComponents(); 40 41 this.nodeAcceptor = new NodeAcceptorImpl(); 42 43 nodeDisplayPanel = new NodeDisplayPanel(root); 44 nodeDisplayPanel.setBorder(new EtchedBorder ()); 45 jPanelBeanTree.add(nodeDisplayPanel); 46 nodeDisplayPanel.addPropertyChangeListener(new PropertyChangeListener () { 47 public void propertyChange(PropertyChangeEvent pce) { 48 Node[] nodes = nodeDisplayPanel.getSelectedNodes(); 49 validateNodes(); 50 } 51 }); 52 53 validateNodes(); 54 } 55 56 private void validateNodes() { 57 boolean nodeAccepted = nodeAcceptor.acceptNodes(nodeDisplayPanel.getSelectedNodes()); 58 if (!nodeAccepted) 59 firePropertyChange(IS_VALID, Boolean.TRUE, Boolean.FALSE); 60 else 61 firePropertyChange(IS_VALID, Boolean.FALSE, Boolean.TRUE); 62 } 63 64 private void setErrorMessage(String message) { 65 if (message == null) 66 message = " "; 67 jLabelError.setText(message); 68 } 69 70 public Node[] getSelectedNodes() { 71 return nodeDisplayPanel.getSelectedNodes(); 72 } 73 74 public String getSelectedPortOwnerName() { 75 return nodeDisplayPanel.getSelectedNodes()[0].getParentNode().getDisplayName(); 76 } 77 78 83 private void initComponents() { 85 java.awt.GridBagConstraints gridBagConstraints; 86 87 jLabelDesc = new javax.swing.JLabel (); 88 jPanelBeanTree = new javax.swing.JPanel (); 89 jLabelError = new javax.swing.JLabel (); 90 91 setLayout(new java.awt.GridBagLayout ()); 92 93 jLabelDesc.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(PortChooser.class, "MNE_SelectBeanDescription").charAt(0)); 94 jLabelDesc.setLabelFor(jPanelBeanTree); 95 jLabelDesc.setText(org.openide.util.NbBundle.getMessage(PortChooser.class, "LBL_SelectPortDescription")); 96 gridBagConstraints = new java.awt.GridBagConstraints (); 97 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 98 gridBagConstraints.insets = new java.awt.Insets (11, 11, 0, 11); 99 add(jLabelDesc, gridBagConstraints); 100 jLabelDesc.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PortChooser.class, "LBL_SelectPortDescription")); 101 102 jPanelBeanTree.setLayout(new java.awt.BorderLayout ()); 103 104 gridBagConstraints = new java.awt.GridBagConstraints (); 105 gridBagConstraints.gridx = 0; 106 gridBagConstraints.gridy = 1; 107 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 108 gridBagConstraints.weightx = 1.0; 109 gridBagConstraints.weighty = 1.0; 110 gridBagConstraints.insets = new java.awt.Insets (11, 11, 11, 11); 111 add(jPanelBeanTree, gridBagConstraints); 112 jPanelBeanTree.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(PortChooser.class, "A11Y_PortTree_Name")); 113 jPanelBeanTree.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PortChooser.class, "A11Y_PortTree_Name")); 114 115 jLabelError.setForeground(new java.awt.Color (255, 0, 0)); 116 jLabelError.setLabelFor(jPanelBeanTree); 117 jLabelError.setText(" "); 118 gridBagConstraints = new java.awt.GridBagConstraints (); 119 gridBagConstraints.gridx = 0; 120 gridBagConstraints.gridy = 2; 121 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 122 gridBagConstraints.insets = new java.awt.Insets (0, 11, 0, 11); 123 add(jLabelError, gridBagConstraints); 124 jLabelError.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(PortChooser.class, "A11Y_PortTreeError_Name")); 125 jLabelError.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PortChooser.class, "A11Y_PortTreeError_Name")); 126 127 } 129 private javax.swing.JLabel jLabelDesc; 131 private javax.swing.JLabel jLabelError; 132 private javax.swing.JPanel jPanelBeanTree; 133 135 private class NodeAcceptorImpl implements NodeAcceptor { 136 public boolean acceptNodes(Node[] nodes) { 137 setErrorMessage(" "); 139 if (nodes.length == 0) { 141 setErrorMessage(NbBundle.getMessage(PortChooser.class, "LBL_SelectOnePort")); return false; 143 } 144 145 PortNode port = (PortNode) nodes[0].getLookup().lookup(PortNode.class); 146 if (port == null) { 148 setErrorMessage(NbBundle.getMessage(PortChooser.class, "LBL_NodeIsNotPort")); return false; 150 } 151 152 return true; 153 } 154 } 155 156 } 157 | Popular Tags |