001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: /*
043: * BindingSubTypePanel.java
044: *
045: * Created on August 30, 2006, 7:04 PM
046: */
047:
048: package org.netbeans.modules.xml.wsdl.ui.view;
049:
050: import java.awt.event.ActionListener;
051: import java.util.ArrayList;
052: import java.util.Enumeration;
053: import java.util.Iterator;
054: import java.util.List;
055:
056: import javax.swing.AbstractButton;
057: import javax.swing.ButtonGroup;
058:
059: import org.netbeans.modules.xml.wsdl.bindingsupport.template.localized.LocalizedTemplate;
060: import org.netbeans.modules.xml.wsdl.bindingsupport.template.localized.LocalizedTemplateGroup;
061:
062: /**
063: *
064: * @author skini
065: */
066: public class BindingSubTypePanel extends javax.swing.JPanel {
067:
068: private LocalizedTemplateGroup mLtg;
069:
070: private List<TemplatePanel> mPanels = new ArrayList<TemplatePanel>();
071:
072: private ActionListener mButtonActionListener;
073:
074: /** Creates new form BindingSubTypePanel */
075: public BindingSubTypePanel(LocalizedTemplateGroup ltg,
076: ActionListener buttonActionListener) {
077: this .mLtg = ltg;
078: this .mButtonActionListener = buttonActionListener;
079: initComponents();
080: initGUI();
081: }
082:
083: void setPanelEnabled(boolean enabled) {
084: Enumeration<AbstractButton> elements = buttonGroup1
085: .getElements();
086: while (elements.hasMoreElements()) {
087: elements.nextElement().setEnabled(enabled);
088: }
089: }
090:
091: /** This method is called from within the constructor to
092: * initialize the form.
093: * WARNING: Do NOT modify this code. The content of this method is
094: * always regenerated by the Form Editor.
095: */
096: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
097: private void initComponents() {
098: buttonGroup1 = new javax.swing.ButtonGroup();
099:
100: setLayout(new javax.swing.BoxLayout(this ,
101: javax.swing.BoxLayout.Y_AXIS));
102:
103: }// </editor-fold>//GEN-END:initComponents
104:
105: private void initGUI() {
106: boolean isDefaultAvailable = false;
107:
108: LocalizedTemplate[] templates = this .mLtg.getTemplate();
109: for (int i = 0; i < templates.length; i++) {
110: LocalizedTemplate template = templates[i];
111: TemplatePanel panel = new TemplatePanel(template,
112: buttonGroup1);
113: panel.getRadioButton().addActionListener(
114: this .mButtonActionListener);
115: mPanels.add(panel);
116: this .add(panel);
117: if (template.getDelegate().isDefault()) {
118: setSelectedTemplateName(templates[i].getName());
119: isDefaultAvailable = true;
120: }
121: }
122: if (!isDefaultAvailable && templates.length > 0) {
123: setSelectedTemplateName(templates[0].getName());
124: }
125: }
126:
127: public LocalizedTemplate getBindingSubType() {
128: Iterator<TemplatePanel> it = this .mPanels.iterator();
129: while (it.hasNext()) {
130: TemplatePanel p = it.next();
131: if (p.isSelected()) {
132: return p.getTemplate();
133: }
134: }
135: return null;
136: }
137:
138: public void reset(LocalizedTemplateGroup ltg) {
139: this .removeAll();
140: Iterator<TemplatePanel> it = mPanels.iterator();
141: while (it.hasNext()) {
142: TemplatePanel panel = it.next();
143: panel.getRadioButton().removeActionListener(
144: this .mButtonActionListener);
145:
146: }
147: mPanels.clear();
148:
149: this .mLtg = ltg;
150: initGUI();
151: revalidate();
152: }
153:
154: public void setSelectedTemplateName(String templateName) {
155: Enumeration<AbstractButton> buttons = buttonGroup1
156: .getElements();
157: if (buttons != null) {
158: while (buttons.hasMoreElements()) {
159: AbstractButton button = buttons.nextElement();
160: if (button.getActionCommand().equals(templateName)) {
161: button.setSelected(true);
162: }
163: }
164: }
165: }
166:
167: public ButtonGroup getButtonGroup() {
168: return this .buttonGroup1;
169: }
170:
171: // Variables declaration - do not modify//GEN-BEGIN:variables
172: private javax.swing.ButtonGroup buttonGroup1;
173: // End of variables declaration//GEN-END:variables
174:
175: }
|