KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > dev > wizard > PortChooser


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.websvc.dev.wizard;
21
22 import java.beans.PropertyChangeEvent JavaDoc;
23 import java.beans.PropertyChangeListener JavaDoc;
24 import javax.swing.border.EtchedBorder JavaDoc;
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 JavaDoc {
31     
32     public static final String JavaDoc IS_VALID = "portChooser_isValid"; //NOI18N
33

34     private NodeAcceptor nodeAcceptor;
35     private NodeDisplayPanel nodeDisplayPanel;
36     
37     /** Creates new form PortChooser */
38     public PortChooser(Node root) {
39         initComponents();
40
41         this.nodeAcceptor = new NodeAcceptorImpl();
42
43         nodeDisplayPanel = new NodeDisplayPanel(root);
44         nodeDisplayPanel.setBorder(new EtchedBorder JavaDoc());
45         jPanelBeanTree.add(nodeDisplayPanel);
46         nodeDisplayPanel.addPropertyChangeListener(new PropertyChangeListener JavaDoc() {
47             public void propertyChange(PropertyChangeEvent JavaDoc 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 JavaDoc 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 JavaDoc getSelectedPortOwnerName() {
75         return nodeDisplayPanel.getSelectedNodes()[0].getParentNode().getDisplayName();
76     }
77
78     /** This method is called from within the constructor to
79      * initialize the form.
80      * WARNING: Do NOT modify this code. The content of this method is
81      * always regenerated by the Form Editor.
82      */

83     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
84
private void initComponents() {
85         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
86
87         jLabelDesc = new javax.swing.JLabel JavaDoc();
88         jPanelBeanTree = new javax.swing.JPanel JavaDoc();
89         jLabelError = new javax.swing.JLabel JavaDoc();
90
91         setLayout(new java.awt.GridBagLayout JavaDoc());
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 JavaDoc();
97         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
98         gridBagConstraints.insets = new java.awt.Insets JavaDoc(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 JavaDoc());
103
104         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(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 JavaDoc(255, 0, 0));
116         jLabelError.setLabelFor(jPanelBeanTree);
117         jLabelError.setText(" ");
118         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
119         gridBagConstraints.gridx = 0;
120         gridBagConstraints.gridy = 2;
121         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
122         gridBagConstraints.insets = new java.awt.Insets JavaDoc(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     }// </editor-fold>//GEN-END:initComponents
128

129     // Variables declaration - do not modify//GEN-BEGIN:variables
130
private javax.swing.JLabel JavaDoc jLabelDesc;
131     private javax.swing.JLabel JavaDoc jLabelError;
132     private javax.swing.JPanel JavaDoc jPanelBeanTree;
133     // End of variables declaration//GEN-END:variables
134

135     private class NodeAcceptorImpl implements NodeAcceptor {
136         public boolean acceptNodes(Node[] nodes) {
137             setErrorMessage(" "); //NOI18N
138

139             // no node selected
140
if (nodes.length == 0) {
141                 setErrorMessage(NbBundle.getMessage(PortChooser.class, "LBL_SelectOnePort")); //NOI18N
142
return false;
143             }
144             
145             PortNode port = (PortNode) nodes[0].getLookup().lookup(PortNode.class);
146             // non-port node is selected
147
if (port == null) {
148                 setErrorMessage(NbBundle.getMessage(PortChooser.class, "LBL_NodeIsNotPort")); //NOI18N
149
return false;
150             }
151             
152             return true;
153         }
154     }
155
156 }
157
Popular Tags