KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > ui > view > BindingSubTypePanel


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  * BindingSubTypePanel.java
22  *
23  * Created on August 30, 2006, 7:04 PM
24  */

25
26 package org.netbeans.modules.xml.wsdl.ui.view;
27
28 import java.awt.event.ActionListener JavaDoc;
29 import java.util.ArrayList JavaDoc;
30 import java.util.Enumeration JavaDoc;
31 import java.util.Iterator JavaDoc;
32 import java.util.List JavaDoc;
33
34 import javax.swing.AbstractButton JavaDoc;
35 import javax.swing.ButtonGroup JavaDoc;
36 import javax.swing.ButtonModel JavaDoc;
37 import org.netbeans.modules.xml.wsdl.ui.view.wizard.ExtensibilityElementTemplateFactory;
38
39 import org.netbeans.modules.xml.wsdl.ui.view.wizard.TemplateGroup;
40 import org.netbeans.modules.xml.wsdl.ui.view.wizard.TemplateType;
41 import org.netbeans.modules.xml.wsdl.ui.view.wizard.localized.LocalizedTemplate;
42 import org.netbeans.modules.xml.wsdl.ui.view.wizard.localized.LocalizedTemplateGroup;
43
44 /**
45  *
46  * @author skini
47  */

48 public class BindingSubTypePanel extends javax.swing.JPanel JavaDoc {
49     
50     private String JavaDoc namespace;
51     private TemplateGroup group;
52     
53     private LocalizedTemplateGroup mLtg;
54     
55     private List JavaDoc<TemplatePanel> mPanels = new ArrayList JavaDoc();
56     
57     private ActionListener JavaDoc mButtonActionListener;
58     
59     /** Creates new form BindingSubTypePanel */
60     public BindingSubTypePanel(LocalizedTemplateGroup ltg, ActionListener JavaDoc buttonActionListener) {
61         this.mLtg = ltg;
62         this.mButtonActionListener = buttonActionListener;
63         initComponents();
64         initGUI();
65     }
66     
67     /** This method is called from within the constructor to
68      * initialize the form.
69      * WARNING: Do NOT modify this code. The content of this method is
70      * always regenerated by the Form Editor.
71      */

72     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
73
private void initComponents() {
74         buttonGroup1 = new javax.swing.ButtonGroup JavaDoc();
75
76         setLayout(new javax.swing.BoxLayout JavaDoc(this, javax.swing.BoxLayout.Y_AXIS));
77
78     }// </editor-fold>//GEN-END:initComponents
79

80     private void initGUI() {
81         boolean isDefaultAvailable = false;
82         
83         LocalizedTemplate[] templates = this.mLtg.getTemplate();
84         for (int i = 0; i < templates.length; i++) {
85             LocalizedTemplate template = templates[i];
86             TemplatePanel panel = new TemplatePanel(template, buttonGroup1);
87             panel.getRadioButton().addActionListener(this.mButtonActionListener);
88             mPanels.add(panel);
89             this.add(panel);
90             if(template.getDelegate().isDefault()) {
91                 setSelectedTemplateName(templates[i].getName());
92                 isDefaultAvailable = true;
93             }
94         }
95         if (!isDefaultAvailable && templates.length > 0) {
96             setSelectedTemplateName(templates[0].getName());
97         }
98     }
99         
100     public LocalizedTemplate getBindingSubType() {
101         Iterator JavaDoc<TemplatePanel> it = this.mPanels.iterator();
102         while(it.hasNext()) {
103             TemplatePanel p = it.next();
104             if(p.isSelected()) {
105                 return p.getTemplate();
106             }
107         }
108         return null;
109     }
110     
111     public void reset(LocalizedTemplateGroup ltg) {
112         this.removeAll();
113         Iterator JavaDoc<TemplatePanel> it = mPanels.iterator();
114         while(it.hasNext()) {
115             TemplatePanel panel = it.next();
116             panel.getRadioButton().removeActionListener(this.mButtonActionListener);
117             
118         }
119         mPanels.clear();
120         
121         this.mLtg = ltg;
122         initGUI();
123         revalidate();
124     }
125     
126     public void setSelectedTemplateName(String JavaDoc templateName) {
127         Enumeration JavaDoc<AbstractButton JavaDoc> buttons = buttonGroup1.getElements();
128         if (buttons != null) {
129             while (buttons.hasMoreElements()) {
130                 AbstractButton JavaDoc button = buttons.nextElement();
131                 if (button.getActionCommand().equals(templateName)) {
132                     button.setSelected(true);
133                 }
134             }
135         }
136     }
137     
138     public ButtonGroup JavaDoc getButtonGroup() {
139         return this.buttonGroup1;
140     }
141     
142     
143     // Variables declaration - do not modify//GEN-BEGIN:variables
144
private javax.swing.ButtonGroup JavaDoc buttonGroup1;
145     // End of variables declaration//GEN-END:variables
146

147 }
148
Popular Tags