KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > ui > basic > editors > DerivationTypeForm


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  * DerivationTypeForm.java
22  *
23  * Created on December 18, 2005, 9:21 PM
24  */

25
26 package org.netbeans.modules.xml.schema.ui.basic.editors;
27
28 import java.awt.event.ActionEvent JavaDoc;
29 import java.awt.event.ActionListener JavaDoc;
30 import java.util.HashSet JavaDoc;
31 import java.util.Set JavaDoc;
32 import org.netbeans.modules.xml.schema.model.Derivation;
33
34 /**
35  *
36  * @author Ajit Bhate
37  */

38 public class DerivationTypeForm extends javax.swing.JPanel JavaDoc implements ActionListener JavaDoc {
39
40     static final long serialVersionUID = 1L;
41     private String JavaDoc property = "final";
42     private Set JavaDoc<Derivation.Type> currentSelection;
43     private Set JavaDoc<Derivation.Type> supportedTypes;
44     private boolean isValid = true;
45     
46     /**
47      * Creates new form DerivationTypeForm
48      */

49     
50     public DerivationTypeForm(String JavaDoc property,
51             Set JavaDoc<Derivation.Type> initialSelection,
52             Set JavaDoc<Derivation.Type> supportedTypes) {
53         this.currentSelection = initialSelection==null?
54             new HashSet JavaDoc<Derivation.Type>():initialSelection;
55         this.property = property;
56         this.supportedTypes = supportedTypes;
57         initComponents();
58         initialize();
59     }
60
61     /** This method is called from within the constructor to
62      * initialize the form.
63      * WARNING: Do NOT modify this code. The content of this method is
64      * always regenerated by the Form Editor.
65      */

66     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
67
private void initComponents() {
68         radioButtonGroup = new javax.swing.ButtonGroup JavaDoc();
69         useDefaultRadioButton = new javax.swing.JRadioButton JavaDoc();
70         useDefaultLabel = new javax.swing.JLabel JavaDoc();
71         allowAllRadioButton = new javax.swing.JRadioButton JavaDoc();
72         preventTypeRadioButton = new javax.swing.JRadioButton JavaDoc();
73         extensionCheckBox = new javax.swing.JCheckBox JavaDoc();
74         restrictionCheckBox = new javax.swing.JCheckBox JavaDoc();
75         preventAllRadioButton = new javax.swing.JRadioButton JavaDoc();
76         listCheckBox = new javax.swing.JCheckBox JavaDoc();
77         unionCheckBox = new javax.swing.JCheckBox JavaDoc();
78         substitutionCheckBox = new javax.swing.JCheckBox JavaDoc();
79         dummyLabel1 = new javax.swing.JLabel JavaDoc();
80         dummyLabel2 = new javax.swing.JLabel JavaDoc();
81
82         org.openide.awt.Mnemonics.setLocalizedText(useDefaultRadioButton, org.openide.util.NbBundle.getBundle(DerivationTypeForm.class).getString("LBL_Use_Schema_Default_"+property));
83         useDefaultRadioButton.setToolTipText(org.openide.util.NbBundle.getBundle(DerivationTypeForm.class).getString("HINT_Use_Schema_Default_"+property));
84         useDefaultRadioButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
85         useDefaultRadioButton.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
86         useDefaultRadioButton.addActionListener(this);
87         radioButtonGroup.add(useDefaultRadioButton);
88
89         org.openide.awt.Mnemonics.setLocalizedText(useDefaultLabel, org.openide.util.NbBundle.getBundle(DerivationTypeForm.class).getString("LBL_Default_Value_"+property));
90         useDefaultLabel.setToolTipText(org.openide.util.NbBundle.getBundle(DerivationTypeForm.class).getString("HINT_Default_Value_"+property));
91
92         org.openide.awt.Mnemonics.setLocalizedText(allowAllRadioButton, org.openide.util.NbBundle.getBundle(DerivationTypeForm.class).getString("LBL_Allow_All_"+property));
93         allowAllRadioButton.setToolTipText(org.openide.util.NbBundle.getBundle(DerivationTypeForm.class).getString("HINT_Allow_All_"+property));
94         allowAllRadioButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
95         allowAllRadioButton.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
96         allowAllRadioButton.addActionListener(this);
97         radioButtonGroup.add(allowAllRadioButton);
98
99         org.openide.awt.Mnemonics.setLocalizedText(preventTypeRadioButton, org.openide.util.NbBundle.getBundle(DerivationTypeForm.class).getString("LBL_Prevent_Derivations_"+property));
100         preventTypeRadioButton.setToolTipText(org.openide.util.NbBundle.getBundle(DerivationTypeForm.class).getString("HINT_Prevent_Derivations_"+property));
101         preventTypeRadioButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
102         preventTypeRadioButton.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
103         preventTypeRadioButton.addActionListener(this);
104         radioButtonGroup.add(preventTypeRadioButton);
105
106         org.openide.awt.Mnemonics.setLocalizedText(extensionCheckBox, org.openide.util.NbBundle.getBundle(DerivationTypeForm.class).getString("LBL_Extension"));
107         extensionCheckBox.setToolTipText(org.openide.util.NbBundle.getBundle(DerivationTypeForm.class).getString("HINT_Extension"));
108         extensionCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
109         extensionCheckBox.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
110         extensionCheckBox.addActionListener(this);
111
112         org.openide.awt.Mnemonics.setLocalizedText(restrictionCheckBox, org.openide.util.NbBundle.getBundle(DerivationTypeForm.class).getString("LBL_Restriction"));
113         restrictionCheckBox.setToolTipText(org.openide.util.NbBundle.getBundle(DerivationTypeForm.class).getString("HINT_Restriction"));
114         restrictionCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
115         restrictionCheckBox.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
116         restrictionCheckBox.addActionListener(this);
117
118         org.openide.awt.Mnemonics.setLocalizedText(preventAllRadioButton, org.openide.util.NbBundle.getBundle(DerivationTypeForm.class).getString("LBL_Prevent_All_"+property));
119         preventAllRadioButton.setToolTipText(org.openide.util.NbBundle.getBundle(DerivationTypeForm.class).getString("HINT_Prevent_All_"+property));
120         preventAllRadioButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
121         preventAllRadioButton.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
122         preventAllRadioButton.addActionListener(this);
123         radioButtonGroup.add(preventAllRadioButton);
124
125         org.openide.awt.Mnemonics.setLocalizedText(listCheckBox, org.openide.util.NbBundle.getBundle(DerivationTypeForm.class).getString("LBL_List"));
126         listCheckBox.setToolTipText(org.openide.util.NbBundle.getBundle(DerivationTypeForm.class).getString("HINT_List"));
127         listCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
128         listCheckBox.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
129         listCheckBox.addActionListener(this);
130
131         org.openide.awt.Mnemonics.setLocalizedText(unionCheckBox, org.openide.util.NbBundle.getBundle(DerivationTypeForm.class).getString("LBL_Union"));
132         unionCheckBox.setToolTipText(org.openide.util.NbBundle.getBundle(DerivationTypeForm.class).getString("HINT_Union"));
133         unionCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
134         unionCheckBox.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
135         unionCheckBox.addActionListener(this);
136
137         org.openide.awt.Mnemonics.setLocalizedText(substitutionCheckBox, org.openide.util.NbBundle.getBundle(DerivationTypeForm.class).getString("LBL_Substitution"));
138         substitutionCheckBox.setToolTipText(org.openide.util.NbBundle.getBundle(DerivationTypeForm.class).getString("HINT_Substitution"));
139         substitutionCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
140         substitutionCheckBox.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
141         substitutionCheckBox.addActionListener(this);
142
143         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
144         this.setLayout(layout);
145         layout.setHorizontalGroup(
146             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
147             .add(layout.createSequentialGroup()
148                 .addContainerGap()
149                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
150                     .add(layout.createSequentialGroup()
151                         .add(17, 17, 17)
152                         .add(useDefaultLabel))
153                     .add(useDefaultRadioButton)
154                     .add(allowAllRadioButton)
155                     .add(preventAllRadioButton)
156                     .add(preventTypeRadioButton)
157                     .add(layout.createSequentialGroup()
158                         .add(17, 17, 17)
159                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
160                             .add(extensionCheckBox)
161                             .add(restrictionCheckBox)
162                             .add(substitutionCheckBox)
163                             .add(listCheckBox)
164                             .add(unionCheckBox)
165                             .add(dummyLabel2)
166                             .add(dummyLabel1))))
167                 .addContainerGap(227, Short.MAX_VALUE))
168         );
169         layout.setVerticalGroup(
170             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
171             .add(layout.createSequentialGroup()
172                 .addContainerGap()
173                 .add(useDefaultRadioButton)
174                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
175                 .add(useDefaultLabel)
176                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
177                 .add(allowAllRadioButton)
178                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
179                 .add(preventAllRadioButton)
180                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
181                 .add(preventTypeRadioButton)
182                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
183                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
184                     .add(dummyLabel1)
185                     .add(layout.createSequentialGroup()
186                         .add(extensionCheckBox)
187                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
188                         .add(restrictionCheckBox)
189                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
190                         .add(substitutionCheckBox)
191                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
192                         .add(dummyLabel2)
193                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
194                         .add(listCheckBox)
195                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
196                         .add(unionCheckBox)))
197                 .addContainerGap(102, Short.MAX_VALUE))
198         );
199     }// </editor-fold>//GEN-END:initComponents
200

201     private void initialize() {
202         if(!supportedTypes.contains(Derivation.Type.EXTENSION)) {
203             extensionCheckBox.setVisible(false);
204         }
205         if(!supportedTypes.contains(Derivation.Type.RESTRICTION)) {
206             restrictionCheckBox.setVisible(false);
207         }
208         if(!supportedTypes.contains(Derivation.Type.LIST)) {
209             listCheckBox.setVisible(false);
210         }
211         if(!supportedTypes.contains(Derivation.Type.UNION)) {
212             unionCheckBox.setVisible(false);
213         }
214         if (!supportedTypes.contains(Derivation.Type.SUBSTITUTION)) {
215             substitutionCheckBox.setVisible(false);
216         }
217
218         if (currentSelection.isEmpty()) {
219             useDefaultRadioButton.setSelected(true);
220         } else if (currentSelection.contains(Derivation.Type.EMPTY)){
221             allowAllRadioButton.setSelected(true);
222         } else if (currentSelection.contains(Derivation.Type.ALL)){
223             preventAllRadioButton.setSelected(true);
224         } else {
225             for (Derivation.Type type:currentSelection) {
226                 if(type == Derivation.Type.EXTENSION) {
227                     extensionCheckBox.setSelected(true);
228                 } else if(type == Derivation.Type.RESTRICTION) {
229                     restrictionCheckBox.setSelected(true);
230                 } else if(type == Derivation.Type.LIST) {
231                     listCheckBox.setSelected(true);
232                 } else if(type == Derivation.Type.UNION) {
233                     unionCheckBox.setSelected(true);
234                 } else if(type == Derivation.Type.SUBSTITUTION) {
235                     substitutionCheckBox.setSelected(true);
236                 }
237             }
238             if(checkBoxSelected()) preventTypeRadioButton.setSelected(true);
239         }
240     }
241
242     public void actionPerformed(ActionEvent JavaDoc ae) {
243         Object JavaDoc source = ae.getSource();
244         if(source instanceof javax.swing.JRadioButton JavaDoc) {
245             if (source.equals(useDefaultRadioButton)) {
246                 currentSelection.clear();
247                 setCheckBoxesSelected(false);
248             } else if (source.equals(allowAllRadioButton)) {
249                 currentSelection.clear();
250                 currentSelection.add(Derivation.Type.EMPTY);
251                 setCheckBoxesSelected(false);
252             } else if (source.equals(preventAllRadioButton)) {
253                 currentSelection.clear();
254                 currentSelection.add(Derivation.Type.ALL);
255                 setCheckBoxesSelected(false);
256             } else if (source.equals(preventTypeRadioButton)) {
257                 if (!checkBoxSelected()) currentSelection.clear();
258             }
259         } else if(source instanceof javax.swing.JCheckBox JavaDoc) {
260             if(((javax.swing.JCheckBox JavaDoc)source).isSelected() &&
261                     !preventTypeRadioButton.isSelected()) {
262                 preventTypeRadioButton.setSelected(true);
263                 currentSelection.clear();
264             }
265             if (source.equals(extensionCheckBox)) {
266                 if(extensionCheckBox.isSelected()) {
267                     currentSelection.add(Derivation.Type.EXTENSION);
268                 } else {
269                     currentSelection.remove(Derivation.Type.EXTENSION);
270                 }
271             } else if (source.equals(restrictionCheckBox)) {
272                 if(restrictionCheckBox.isSelected()) {
273                     currentSelection.add(Derivation.Type.RESTRICTION);
274                 } else {
275                     currentSelection.remove(Derivation.Type.RESTRICTION);
276                 }
277             } else if (source.equals(listCheckBox)) {
278                 if(listCheckBox.isSelected()) {
279                     currentSelection.add(Derivation.Type.LIST);
280                 } else {
281                     currentSelection.remove(Derivation.Type.LIST);
282                 }
283             } else if (source.equals(unionCheckBox)) {
284                 if(unionCheckBox.isSelected()) {
285                     currentSelection.add(Derivation.Type.UNION);
286                 } else {
287                     currentSelection.remove(Derivation.Type.UNION);
288                 }
289             } else if (source.equals(substitutionCheckBox)) {
290                 if(substitutionCheckBox.isSelected()) {
291                     currentSelection.add(Derivation.Type.SUBSTITUTION);
292                 } else {
293                     currentSelection.remove(Derivation.Type.SUBSTITUTION);
294                 }
295             }
296         }
297         // notify dialog to disable ok option if needed
298
firePropertyChange("valid", isValid, !currentSelection.isEmpty() ||
299                 !preventTypeRadioButton.isSelected());
300         isValid = !currentSelection.isEmpty() ||
301                 !preventTypeRadioButton.isSelected();
302     }
303     
304     public Set JavaDoc<Derivation.Type> getCurrentSelection() {
305         return currentSelection;
306     }
307
308     private boolean checkBoxSelected() {
309         return (extensionCheckBox.isSelected() ||
310                 restrictionCheckBox.isSelected() ||
311                 listCheckBox.isSelected() ||
312                 unionCheckBox.isSelected() ||
313                 substitutionCheckBox.isSelected());
314     }
315     
316     private void setCheckBoxesSelected(boolean flag) {
317         extensionCheckBox.setSelected(flag);
318         restrictionCheckBox.setSelected(flag);
319         listCheckBox.setSelected(flag);
320         unionCheckBox.setSelected(flag);
321         substitutionCheckBox.setSelected(flag);
322     }
323
324     // Variables declaration - do not modify//GEN-BEGIN:variables
325
private javax.swing.JRadioButton JavaDoc allowAllRadioButton;
326     private javax.swing.JLabel JavaDoc dummyLabel1;
327     private javax.swing.JLabel JavaDoc dummyLabel2;
328     private javax.swing.JCheckBox JavaDoc extensionCheckBox;
329     private javax.swing.JCheckBox JavaDoc listCheckBox;
330     private javax.swing.JRadioButton JavaDoc preventAllRadioButton;
331     private javax.swing.JRadioButton JavaDoc preventTypeRadioButton;
332     private javax.swing.ButtonGroup JavaDoc radioButtonGroup;
333     private javax.swing.JCheckBox JavaDoc restrictionCheckBox;
334     private javax.swing.JCheckBox JavaDoc substitutionCheckBox;
335     private javax.swing.JCheckBox JavaDoc unionCheckBox;
336     private javax.swing.JLabel JavaDoc useDefaultLabel;
337     private javax.swing.JRadioButton JavaDoc useDefaultRadioButton;
338     // End of variables declaration//GEN-END:variables
339

340 }
341
Popular Tags