KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > abe > nodes > properties > NamespacePanel


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /*
21  * NamespacePanel.java
22  *
23  * Created on December 20, 2005, 5:49 PM
24  */

25
26 package org.netbeans.modules.xml.schema.abe.nodes.properties;
27
28 import java.awt.event.ActionEvent JavaDoc;
29 import java.awt.event.ActionListener JavaDoc;
30 import java.util.Collection JavaDoc;
31 import javax.swing.event.DocumentEvent JavaDoc;
32 import javax.swing.event.DocumentListener JavaDoc;
33 import javax.swing.event.ListSelectionEvent JavaDoc;
34 import javax.swing.event.ListSelectionListener JavaDoc;
35
36 /**
37  *
38  * @author Todd Fast, todd.fast@sun.com
39  */

40 public class NamespacePanel extends javax.swing.JPanel JavaDoc
41         implements ActionListener JavaDoc, ListSelectionListener JavaDoc, DocumentListener JavaDoc {
42
43     static final long serialVersionUID = 1L;
44     public static final String JavaDoc PROP_VALID_SELECTION="validSelection";
45     private boolean isValid=true;
46     /** Creates new form NotationSystemForm */
47     public NamespacePanel(String JavaDoc currentTns, Collection JavaDoc<String JavaDoc> uris, Collection JavaDoc<NamespaceEditor.Option> options) {
48         initComponents();
49         initialize(currentTns,uris,options);
50     }
51
52     /** This method is called from within the constructor to
53      * initialize the form.
54      * WARNING: Do NOT modify this code. The content of this method is
55      * always regenerated by the Form Editor.
56      */

57     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
58
private void initComponents() {
59         buttonGroup1 = new javax.swing.ButtonGroup JavaDoc();
60         noNamespaceRadioButton = new javax.swing.JRadioButton JavaDoc();
61         schemaNamespaceRadioButton = new javax.swing.JRadioButton JavaDoc();
62         otherNamespaceRadioButton = new javax.swing.JRadioButton JavaDoc();
63         jScrollPane1 = new javax.swing.JScrollPane JavaDoc();
64         uriList = new javax.swing.JList JavaDoc();
65         otherNamespaceTextField = new javax.swing.JTextField JavaDoc();
66
67         noNamespaceRadioButton.setText(org.openide.util.NbBundle.getBundle(NamespacePanel.class).getString("LBL_NoNamespace"));
68         noNamespaceRadioButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
69         noNamespaceRadioButton.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
70         buttonGroup1.add(noNamespaceRadioButton);
71         noNamespaceRadioButton.addActionListener(this);
72
73         schemaNamespaceRadioButton.setText(org.openide.util.NbBundle.getBundle(NamespacePanel.class).getString("LBL_SchemaNamespace"));
74         schemaNamespaceRadioButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
75         schemaNamespaceRadioButton.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
76         buttonGroup1.add(schemaNamespaceRadioButton);
77         schemaNamespaceRadioButton.addActionListener(this);
78
79         otherNamespaceRadioButton.setText(org.openide.util.NbBundle.getBundle(NamespacePanel.class).getString("LBL_OtherNamespace"));
80         otherNamespaceRadioButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
81         otherNamespaceRadioButton.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
82         buttonGroup1.add(otherNamespaceRadioButton);
83         otherNamespaceRadioButton.addActionListener(this);
84
85         uriList.addListSelectionListener(this);
86         jScrollPane1.setViewportView(uriList);
87
88         otherNamespaceTextField.getDocument().addDocumentListener(this);
89
90         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
91         this.setLayout(layout);
92         layout.setHorizontalGroup(
93             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
94             .add(layout.createSequentialGroup()
95                 .addContainerGap()
96                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
97                     .add(layout.createSequentialGroup()
98                         .add(17, 17, 17)
99                         .add(otherNamespaceTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 363, Short.MAX_VALUE))
100                     .add(layout.createSequentialGroup()
101                         .add(17, 17, 17)
102                         .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 363, Short.MAX_VALUE))
103                     .add(schemaNamespaceRadioButton)
104                     .add(otherNamespaceRadioButton)
105                     .add(noNamespaceRadioButton))
106                 .addContainerGap())
107         );
108         layout.setVerticalGroup(
109             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
110             .add(layout.createSequentialGroup()
111                 .addContainerGap()
112                 .add(noNamespaceRadioButton)
113                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
114                 .add(schemaNamespaceRadioButton)
115                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
116                 .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 124, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
117                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
118                 .add(otherNamespaceRadioButton)
119                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
120                 .add(otherNamespaceTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
121                 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
122         );
123     }// </editor-fold>//GEN-END:initComponents
124

125
126     private void initialize(String JavaDoc currentTns, final Collection JavaDoc<String JavaDoc> uris, Collection JavaDoc<NamespaceEditor.Option> options) {
127         // hide radio button for uri list and uri list
128
if (uris==null || uris.isEmpty()) {
129             schemaNamespaceRadioButton.setVisible(false);
130             uriList.setVisible(false);
131         } else {
132             uriList.setListData(uris.toArray(new String JavaDoc[uris.size()]));
133         }
134         // hide other radio buttons if needed
135
if(!options.contains(NamespaceEditor.Option.None)) {
136             noNamespaceRadioButton.setSelected(false);
137             noNamespaceRadioButton.setVisible(false);
138         }
139         if(currentTns==null || currentTns.trim().length()==0) {
140             uriList.setEnabled(false);
141             if(noNamespaceRadioButton.isVisible()) {
142                 noNamespaceRadioButton.setSelected(true);
143                 otherNamespaceTextField.setEnabled(false);
144             } else if (otherNamespaceRadioButton.isVisible()) {
145                 otherNamespaceRadioButton.setSelected(true);
146                 otherNamespaceTextField.setEnabled(true);
147             }
148         } else if(uris!=null && uris.contains(currentTns)) {
149             schemaNamespaceRadioButton.setSelected(true);
150             uriList.setSelectedValue(currentTns,true);
151             uriList.setEnabled(true);
152             otherNamespaceTextField.setEnabled(false);
153         } else {
154             uriList.setEnabled(false);
155             if(otherNamespaceRadioButton.isVisible()) {
156                 otherNamespaceRadioButton.setSelected(true);
157                 otherNamespaceTextField.setText(currentTns);
158                 otherNamespaceTextField.setEnabled(true);
159             }
160         }
161     }
162     
163     public void checkValidity() {
164         boolean newValue = false;
165         if(noNamespaceRadioButton.isSelected()) {
166             newValue = true;
167         } else if(schemaNamespaceRadioButton.isSelected()) {
168             newValue = uriList.getSelectedValue()!=null;
169         } else if(otherNamespaceRadioButton.isSelected()) {
170             newValue = !otherNamespaceTextField.getText().equals("");
171         }
172         firePropertyChange(PROP_VALID_SELECTION,isValid,newValue);
173         isValid = newValue;
174     }
175
176     public String JavaDoc getCurrentSelection() {
177         if(schemaNamespaceRadioButton.isSelected()) {
178             return (String JavaDoc) uriList.getSelectedValue();
179         } else if (otherNamespaceRadioButton.isSelected()){
180             String JavaDoc otherUri = otherNamespaceTextField.getText().trim();
181             if (otherUri.length()>0) return otherUri;
182         }
183         return null;
184     }
185
186     public void actionPerformed(ActionEvent JavaDoc evt) {
187         Object JavaDoc source = evt.getSource();
188         if(source.equals(noNamespaceRadioButton)) {
189             uriList.setEnabled(false);
190             otherNamespaceTextField.setEnabled(false);
191         } else if(source.equals(otherNamespaceRadioButton)){
192             uriList.setEnabled(false);
193             otherNamespaceTextField.setEnabled(true);
194         } else if(source.equals(schemaNamespaceRadioButton)) {
195             otherNamespaceTextField.setEnabled(false);
196             uriList.setEnabled(true);
197         }
198         checkValidity();
199     }
200
201     public void valueChanged(ListSelectionEvent JavaDoc e) {
202         checkValidity();
203     }
204
205     public void insertUpdate(DocumentEvent JavaDoc e) {
206         checkValidity();
207     }
208
209     public void removeUpdate(DocumentEvent JavaDoc e) {
210         checkValidity();
211     }
212
213     public void changedUpdate(DocumentEvent JavaDoc e) {
214     }
215
216     // Variables declaration - do not modify//GEN-BEGIN:variables
217
public javax.swing.ButtonGroup JavaDoc buttonGroup1;
218     public javax.swing.JScrollPane JavaDoc jScrollPane1;
219     public javax.swing.JRadioButton JavaDoc noNamespaceRadioButton;
220     public javax.swing.JRadioButton JavaDoc otherNamespaceRadioButton;
221     public javax.swing.JTextField JavaDoc otherNamespaceTextField;
222     public javax.swing.JRadioButton JavaDoc schemaNamespaceRadioButton;
223     public javax.swing.JList JavaDoc uriList;
224     // End of variables declaration//GEN-END:variables
225

226 }
227
Popular Tags