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