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-2006 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: package org.netbeans.modules.form.wizard;
043:
044: import javax.swing.event.*;
045: import java.lang.reflect.Method;
046:
047: import org.openide.awt.Mnemonics;
048: import org.openide.util.NbBundle;
049: import org.netbeans.modules.form.*;
050:
051: /**
052: * The UI component of the ConnectionWizardPanel3.
053: *
054: * @author Tomas Pavek
055: */
056:
057: class ConnectionPanel3 extends javax.swing.JPanel {
058:
059: private ConnectionWizardPanel3 wizardPanel;
060:
061: private Class[] parameters;
062: private ParametersPicker[] pickers;
063: private boolean valid = false;
064:
065: private ChangeListener paramsChangeListener = null;
066:
067: /** Creates new form ConnectionPanel3 */
068: public ConnectionPanel3(ConnectionWizardPanel3 wizardPanel) {
069: this .wizardPanel = wizardPanel;
070:
071: initComponents();
072:
073: java.util.ResourceBundle bundle = NbBundle
074: .getBundle(ConnectionPanel3.class);
075:
076: setName(bundle.getString("CTL_CW_Step3_Title")); // NOI18N
077:
078: paramsChangeListener = new ChangeListener() {
079: public void stateChanged(ChangeEvent evt) {
080: updatePreview();
081: }
082: };
083:
084: Mnemonics.setLocalizedText(paramLabel, bundle
085: .getString("CTL_CW_ParamTabs")); // NOI18N
086: Mnemonics.setLocalizedText(previewLabel, bundle
087: .getString("CTL_CW_GeneratedPreview")); // NOI18N
088: previewField.setText(bundle.getString("CTL_CW_Preview")); // NOI18N
089:
090: previewField.getAccessibleContext().setAccessibleDescription(
091: bundle.getString("ACSD_CW_Preview")); // NOI18N
092: parameterTabs.getAccessibleContext().setAccessibleDescription(
093: bundle.getString("ACSD_CW_ParamTabs")); // NOI18N
094: getAccessibleContext().setAccessibleDescription(
095: bundle.getString("ACSD_CW_ConnectionPanel3")); // NOI18N
096:
097: putClientProperty("WizardPanel_contentSelectedIndex",
098: new Integer(2)); // NOI18N
099: }
100:
101: @Override
102: public java.awt.Dimension getPreferredSize() {
103: return new java.awt.Dimension(450, 300);
104: }
105:
106: void setMethod(Method m) {
107: parameterTabs.removeChangeListener(paramsChangeListener);
108: parameterTabs.removeAll();
109:
110: parameters = m.getParameterTypes();
111: pickers = new ParametersPicker[parameters.length];
112: for (int i = 0; i < parameters.length; i++) {
113: pickers[i] = new ParametersPicker(wizardPanel
114: .getFormModel(), parameters[i]);
115: pickers[i].addChangeListener(new ChangeListener() {
116: public void stateChanged(ChangeEvent evt) {
117: updatePreview();
118: }
119: });
120: pickers[i].setBorder(new javax.swing.border.EmptyBorder(6,
121: 6, 5, 5));
122:
123: parameterTabs.addTab(org.openide.util.Utilities
124: .getShortClassName(parameters[i]), null,
125: pickers[i], parameters[i].getName());
126: }
127:
128: valid = isValid();
129: parameterTabs.addChangeListener(paramsChangeListener);
130: updatePreview();
131: }
132:
133: String getParametersText() {
134: StringBuffer buf = new StringBuffer();
135: for (int i = 0; i < pickers.length; i++) {
136: buf.append(pickers[i].getText());
137: if (i != pickers.length - 1)
138: buf.append(", "); // NOI18N
139: }
140: return buf.toString();
141: }
142:
143: Object[] getParameters() {
144: try {
145: Object values[] = new Object[pickers.length];
146: for (int i = 0; i < pickers.length; i++)
147: values[i] = pickers[i].getPropertyValue();
148:
149: return values;
150: } catch (IllegalStateException e) {
151: e.printStackTrace();
152: return null;
153: }
154: }
155:
156: private String getPreviewText() {
157: StringBuffer buf = new StringBuffer();
158: for (int i = 0; i < pickers.length; i++) {
159: buf.append(pickers[i].getPreviewText());
160: if (i != pickers.length - 1)
161: buf.append(", "); // NOI18N
162: }
163: return buf.toString();
164: }
165:
166: private void updatePreview() {
167: previewField.setText(getPreviewText());
168:
169: boolean now = isFilled();
170: if (now != valid) {
171: valid = now;
172: wizardPanel.fireStateChanged();
173: }
174: }
175:
176: boolean isFilled() {
177: for (int i = 0; i < pickers.length; i++)
178: if (!pickers[i].isFilled())
179: return false;
180: return true;
181: }
182:
183: /** This method is called from within the constructor to
184: * initialize the form.
185: * WARNING: Do NOT modify this code. The content of this method is
186: * always regenerated by the Form Editor.
187: */
188: private void initComponents() {//GEN-BEGIN:initComponents
189: java.awt.GridBagConstraints gridBagConstraints;
190:
191: paramLabel = new javax.swing.JLabel();
192: parameterTabs = new javax.swing.JTabbedPane();
193: previewLabel = new javax.swing.JLabel();
194: previewField = new javax.swing.JTextField();
195:
196: setLayout(new java.awt.GridBagLayout());
197:
198: paramLabel.setText("jLabel2");
199: paramLabel.setLabelFor(parameterTabs);
200: gridBagConstraints = new java.awt.GridBagConstraints();
201: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
202: gridBagConstraints.insets = new java.awt.Insets(0, 0, 2, 0);
203: add(paramLabel, gridBagConstraints);
204:
205: gridBagConstraints = new java.awt.GridBagConstraints();
206: gridBagConstraints.gridx = 0;
207: gridBagConstraints.gridy = 1;
208: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
209: gridBagConstraints.weightx = 1.0;
210: gridBagConstraints.weighty = 1.0;
211: gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 0);
212: add(parameterTabs, gridBagConstraints);
213:
214: previewLabel.setText("jLabel1");
215: previewLabel.setLabelFor(previewField);
216: gridBagConstraints = new java.awt.GridBagConstraints();
217: gridBagConstraints.gridx = 0;
218: gridBagConstraints.gridy = 2;
219: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
220: gridBagConstraints.insets = new java.awt.Insets(0, 0, 2, 0);
221: add(previewLabel, gridBagConstraints);
222:
223: previewField.setEditable(false);
224: previewField.setText("jTextField1");
225: gridBagConstraints = new java.awt.GridBagConstraints();
226: gridBagConstraints.gridx = 0;
227: gridBagConstraints.gridy = 3;
228: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
229: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
230: add(previewField, gridBagConstraints);
231:
232: }//GEN-END:initComponents
233:
234: // Variables declaration - do not modify//GEN-BEGIN:variables
235: private javax.swing.JLabel paramLabel;
236: private javax.swing.JTextField previewField;
237: private javax.swing.JLabel previewLabel;
238: private javax.swing.JTabbedPane parameterTabs;
239: // End of variables declaration//GEN-END:variables
240: }
|