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.db.explorer.dlg;
043:
044: import java.sql.*;
045: import java.awt.*;
046: import java.awt.event.*;
047: import java.util.*;
048: import java.beans.*;
049: import java.util.logging.Level;
050: import java.util.logging.Logger;
051: import javax.swing.*;
052: import javax.swing.border.*;
053: import javax.swing.text.JTextComponent;
054: import org.netbeans.api.db.explorer.DatabaseException;
055: import org.openide.*;
056: import org.openide.util.NbBundle;
057: import org.netbeans.lib.ddl.impl.*;
058: import org.netbeans.lib.ddl.util.*;
059: import org.netbeans.modules.db.explorer.DbUtilities;
060: import org.netbeans.modules.db.util.*;
061: import org.netbeans.modules.db.explorer.infos.*;
062: import org.netbeans.modules.db.explorer.nodes.*;
063: import org.openide.awt.Mnemonics;
064:
065: public class AddTableColumnDialog {
066: static final Logger LOGGER = Logger
067: .getLogger(AddTableColumnDialog.class.getName());
068: boolean result = false;
069: Dialog dialog = null;
070: Specification spec;
071: AddTableColumnDDL ddl;
072: Map ixmap;
073: Map ix_uqmap;
074: String colname = null;
075: transient private static final String tempStr = new String();
076: JTextField colnamefield, colsizefield, colscalefield, defvalfield;
077: JTextArea checkfield;
078: JComboBox coltypecombo, idxcombo;
079: JCheckBox pkcheckbox, ixcheckbox, checkcheckbox, nullcheckbox,
080: uniquecheckbox;
081: DataModel dmodel = new DataModel();
082: private ResourceBundle bundle = NbBundle
083: .getBundle("org.netbeans.modules.db.resources.Bundle"); //NOI18N
084:
085: public AddTableColumnDialog(final Specification spe,
086: final DatabaseNodeInfo nfo) throws DatabaseException {
087: spec = spe;
088: try {
089: String table = (String) nfo.get(DatabaseNode.TABLE);
090: String schema = (String) nfo.get(DatabaseNodeInfo.SCHEMA);
091: DriverSpecification drvSpec = nfo.getDriverSpecification();
092: ddl = new AddTableColumnDDL(spec, drvSpec, schema, table);
093:
094: JLabel label;
095: JPanel pane = new JPanel();
096: pane.setBorder(new EmptyBorder(new Insets(12, 12, 5, 11)));
097: GridBagLayout layout = new GridBagLayout();
098: GridBagConstraints con;
099: pane.setLayout(layout);
100:
101: TextFieldListener fldlistener = new TextFieldListener(
102: dmodel);
103: IntegerFieldListener intfldlistener = new IntegerFieldListener(
104: dmodel);
105:
106: // Column name
107:
108: label = new JLabel();
109: Mnemonics.setLocalizedText(label, bundle
110: .getString("AddTableColumnName")); //NOI18N
111: label.getAccessibleContext().setAccessibleDescription(
112: bundle.getString("ACS_AddTableColumnNameA11yDesc"));
113: con = new GridBagConstraints();
114: con.gridx = 0;
115: con.gridy = 0;
116: con.gridwidth = 1;
117: con.gridheight = 1;
118: con.anchor = GridBagConstraints.WEST;
119: con.insets = new java.awt.Insets(0, 0, 0, 0);
120: con.weightx = 0.0;
121: con.weighty = 0.0;
122: pane.add(label, con);
123:
124: con = new GridBagConstraints();
125: con.gridx = 1;
126: con.gridy = 0;
127: con.gridwidth = 3;
128: con.gridheight = 1;
129: con.fill = GridBagConstraints.HORIZONTAL;
130: con.insets = new java.awt.Insets(0, 12, 0, 0);
131: con.weightx = 1.0;
132: con.weighty = 0.0;
133: colnamefield = new JTextField(35);
134: colnamefield.setName(ColumnItem.NAME);
135: colnamefield.addFocusListener(fldlistener);
136: colnamefield
137: .setToolTipText(bundle
138: .getString("ACS_AddTableColumnNameTextFieldA11yDesc"));
139: colnamefield
140: .getAccessibleContext()
141: .setAccessibleName(
142: bundle
143: .getString("ACS_AddTableColumnNameTextFieldA11yName"));
144: label.setLabelFor(colnamefield);
145: pane.add(colnamefield, con);
146:
147: // Column type
148:
149: Map tmap = spec.getTypeMap();
150: Vector ttab = new Vector(tmap.size());
151: Iterator iter = tmap.keySet().iterator();
152: while (iter.hasNext()) {
153: String iterkey = (String) iter.next();
154: String iterval = (String) tmap.get(iterkey);
155: ttab.add(new TypeElement(iterkey, iterval));
156: }
157:
158: ColumnItem item = new ColumnItem();
159: item.setProperty(ColumnItem.TYPE, ttab.elementAt(0));
160: dmodel.addRow(item);
161:
162: label = new JLabel();
163: Mnemonics.setLocalizedText(label, bundle
164: .getString("AddTableColumnType")); //NOI18N
165: label.getAccessibleContext().setAccessibleDescription(
166: bundle.getString("ACS_AddTableColumnTypeA11yDesc"));
167: con = new GridBagConstraints();
168: con.gridx = 0;
169: con.gridy = 1;
170: con.gridwidth = 1;
171: con.gridheight = 1;
172: con.anchor = GridBagConstraints.WEST;
173: con.insets = new java.awt.Insets(12, 0, 0, 0);
174: con.weightx = 0.0;
175: con.weighty = 0.0;
176: pane.add(label, con);
177:
178: con = new GridBagConstraints();
179: con.gridx = 1;
180: con.gridy = 1;
181: con.gridwidth = 3;
182: con.gridheight = 1;
183: con.fill = GridBagConstraints.HORIZONTAL;
184: con.insets = new java.awt.Insets(12, 12, 0, 0);
185: con.weightx = 1.0;
186: con.weighty = 0.0;
187: coltypecombo = new JComboBox(ttab);
188: coltypecombo
189: .addActionListener(new ComboBoxListener(dmodel));
190: coltypecombo.setName(ColumnItem.TYPE);
191: coltypecombo
192: .setToolTipText(bundle
193: .getString("ACS_AddTableColumnTypeComboBoxA11yDesc"));
194: coltypecombo
195: .getAccessibleContext()
196: .setAccessibleName(
197: bundle
198: .getString("ACS_AddTableColumnTypeComboBoxA11yName"));
199: label.setLabelFor(coltypecombo);
200: pane.add(coltypecombo, con);
201:
202: // Column size
203:
204: label = new JLabel();
205: Mnemonics.setLocalizedText(label, bundle
206: .getString("AddTableColumnSize")); //NOI18N
207: label.getAccessibleContext().setAccessibleDescription(
208: bundle.getString("ACS_AddTableColumnSizeA11yDesc"));
209: con = new GridBagConstraints();
210: con.gridx = 0;
211: con.gridy = 2;
212: con.gridwidth = 1;
213: con.gridheight = 1;
214: con.anchor = GridBagConstraints.WEST;
215: con.insets = new java.awt.Insets(12, 0, 0, 0);
216: con.weightx = 0.0;
217: con.weighty = 0.0;
218: pane.add(label, con);
219:
220: con = new GridBagConstraints();
221: con.gridx = 1;
222: con.gridy = 2;
223: con.gridwidth = 1;
224: con.gridheight = 1;
225: con.fill = GridBagConstraints.HORIZONTAL;
226: con.insets = new java.awt.Insets(12, 12, 0, 0);
227: con.weightx = 1.0;
228: con.weighty = 0.0;
229: colsizefield = new ValidableTextField(
230: new TextFieldValidator.integer());
231: colsizefield.setName(ColumnItem.SIZE);
232: colsizefield.addFocusListener(intfldlistener);
233: colsizefield
234: .setToolTipText(bundle
235: .getString("ACS_AddTableColumnSizeTextFieldA11yDesc"));
236: colsizefield
237: .getAccessibleContext()
238: .setAccessibleName(
239: bundle
240: .getString("ACS_AddTableColumnSizeTextFieldA11yName"));
241: label.setLabelFor(colsizefield);
242: pane.add(colsizefield, con);
243:
244: // Column scale
245:
246: label = new JLabel();
247: Mnemonics.setLocalizedText(label, bundle
248: .getString("AddTableColumnScale")); //NOI18N
249: label
250: .getAccessibleContext()
251: .setAccessibleDescription(
252: bundle
253: .getString("ACS_AddTableColumnScaleA11yDesc"));
254: con = new GridBagConstraints();
255: con.gridx = 2;
256: con.gridy = 2;
257: con.gridwidth = 1;
258: con.gridheight = 1;
259: con.anchor = GridBagConstraints.WEST;
260: con.insets = new java.awt.Insets(12, 12, 0, 0);
261: con.weightx = 0.0;
262: con.weighty = 0.0;
263: pane.add(label, con);
264:
265: con = new GridBagConstraints();
266: con.gridx = 3;
267: con.gridy = 2;
268: con.gridwidth = 1;
269: con.gridheight = 1;
270: con.fill = GridBagConstraints.HORIZONTAL;
271: con.insets = new java.awt.Insets(12, 12, 0, 0);
272: con.weightx = 1.0;
273: con.weighty = 0.0;
274: colscalefield = new ValidableTextField(
275: new TextFieldValidator.integer());
276: colscalefield.setName(ColumnItem.SCALE);
277: colscalefield.addFocusListener(intfldlistener);
278: colscalefield
279: .setToolTipText(bundle
280: .getString("ACS_AddTableColumnScaleTextFieldA11yDesc"));
281: colscalefield
282: .getAccessibleContext()
283: .setAccessibleName(
284: bundle
285: .getString("ACS_AddTableColumnScaleTextFieldA11yName"));
286: label.setLabelFor(colscalefield);
287: pane.add(colscalefield, con);
288:
289: // Column default value
290:
291: label = new JLabel();
292: Mnemonics.setLocalizedText(label, bundle
293: .getString("AddTableColumnDefault")); //NOI18N
294: label
295: .getAccessibleContext()
296: .setAccessibleDescription(
297: bundle
298: .getString("ACS_AddTableColumnDefaultA11yDesc"));
299: con = new GridBagConstraints();
300: con.gridx = 0;
301: con.gridy = 3;
302: con.gridwidth = 1;
303: con.gridheight = 1;
304: con.anchor = GridBagConstraints.WEST;
305: con.insets = new java.awt.Insets(12, 0, 0, 0);
306: con.weightx = 0.0;
307: con.weighty = 0.0;
308: pane.add(label, con);
309:
310: con = new GridBagConstraints();
311: con.gridx = 1;
312: con.gridy = 3;
313: con.gridwidth = 3;
314: con.gridheight = 1;
315: con.fill = GridBagConstraints.HORIZONTAL;
316: con.insets = new java.awt.Insets(12, 12, 0, 0);
317: con.weightx = 1.0;
318: con.weighty = 0.0;
319: defvalfield = new JTextField(35);
320: defvalfield.setName(ColumnItem.DEFVAL);
321: defvalfield.addFocusListener(fldlistener);
322: defvalfield
323: .setToolTipText(bundle
324: .getString("ACS_AddTableColumnDefaultTextFieldA11yDesc"));
325: defvalfield
326: .getAccessibleContext()
327: .setAccessibleName(
328: bundle
329: .getString("ACS_AddTableColumnDefaultTextFieldA11yName"));
330: label.setLabelFor(defvalfield);
331: layout.setConstraints(defvalfield, con);
332: pane.add(defvalfield);
333:
334: // Check subpane
335:
336: JPanel subpane = new JPanel();
337: subpane.setBorder(new TitledBorder(bundle
338: .getString("AddTableColumnConstraintsTitle"))); //NOI18N
339: GridBagLayout sublayout = new GridBagLayout();
340: subpane.setLayout(sublayout);
341:
342: ActionListener cbxlistener = new CheckBoxListener(dmodel);
343:
344: con = new GridBagConstraints();
345: con.gridx = 0;
346: con.gridy = 0;
347: con.gridwidth = 1;
348: con.gridheight = 1;
349: con.anchor = GridBagConstraints.WEST;
350: con.insets = new java.awt.Insets(0, 0, 0, 0);
351: con.weightx = 0.0;
352: con.weighty = 0.0;
353: pkcheckbox = new JCheckBox();
354: Mnemonics.setLocalizedText(pkcheckbox, bundle
355: .getString("AddTableColumnConstraintPKTitle")); //NOI18N
356: pkcheckbox.setName(ColumnItem.PRIMARY_KEY);
357: pkcheckbox.addActionListener(cbxlistener);
358: pkcheckbox
359: .setToolTipText(bundle
360: .getString("ACS_AddTableColumnConstraintPKTitleA11yDesc"));
361: subpane.add(pkcheckbox, con);
362:
363: con = new GridBagConstraints();
364: con.gridx = 1;
365: con.gridy = 0;
366: con.gridwidth = 1;
367: con.gridheight = 1;
368: con.anchor = GridBagConstraints.WEST;
369: con.insets = new java.awt.Insets(0, 12, 0, 0);
370: con.weightx = 0.0;
371: con.weighty = 0.0;
372: uniquecheckbox = new JCheckBox();
373: Mnemonics.setLocalizedText(uniquecheckbox, bundle
374: .getString("AddTableColumnConstraintUniqueTitle")); //NOI18N
375: uniquecheckbox.setName(ColumnItem.UNIQUE);
376: uniquecheckbox.addActionListener(cbxlistener);
377: uniquecheckbox
378: .setToolTipText(bundle
379: .getString("ACS_AddTableColumnConstraintUniqueTitleA11yDesc"));
380: subpane.add(uniquecheckbox, con);
381:
382: con = new GridBagConstraints();
383: con.gridx = 2;
384: con.gridy = 0;
385: con.gridwidth = 1;
386: con.gridheight = 1;
387: con.anchor = GridBagConstraints.WEST;
388: con.insets = new java.awt.Insets(0, 12, 0, 0);
389: con.weightx = 0.0;
390: con.weighty = 0.0;
391: nullcheckbox = new JCheckBox();
392: Mnemonics.setLocalizedText(nullcheckbox, bundle
393: .getString("AddTableColumnConstraintNullTitle")); //NOI18N
394: nullcheckbox.setName(ColumnItem.NULLABLE);
395: nullcheckbox.addActionListener(cbxlistener);
396: nullcheckbox
397: .setToolTipText(bundle
398: .getString("ACS_AddTableColumnConstraintNullTitleA11yDesc"));
399: subpane.add(nullcheckbox, con);
400:
401: // Insert subpane
402:
403: con = new GridBagConstraints();
404: con.gridx = 0;
405: con.gridy = 4;
406: con.gridwidth = 4;
407: con.gridheight = 1;
408: con.fill = GridBagConstraints.HORIZONTAL;
409: con.insets = new java.awt.Insets(12, 0, 0, 0);
410: con.weightx = 1.0;
411: con.weighty = 0.0;
412: pane.add(subpane, con);
413:
414: // are there primary keys?
415: boolean isPK = false;
416: try {
417: drvSpec.getPrimaryKeys(table);
418: ResultSet rs = drvSpec.getResultSet();
419:
420: if (rs != null) {
421: if (rs.next())
422: isPK = true;
423: rs.close();
424: }
425:
426: } catch (Exception e) {
427: Logger.getLogger("global").log(Level.INFO, null, e);
428: }
429:
430: // Index name combo
431:
432: con = new GridBagConstraints();
433: con.gridx = 0;
434: con.gridy = 5;
435: con.gridwidth = 1;
436: con.gridheight = 1;
437: con.anchor = GridBagConstraints.NORTHWEST;
438: con.insets = new java.awt.Insets(12, 0, 0, 0);
439: con.weightx = 0.0;
440: con.weighty = 0.0;
441: ixcheckbox = new JCheckBox();
442: Mnemonics.setLocalizedText(ixcheckbox, bundle
443: .getString("AddTableColumnIndexName")); //NOI18N
444: ixcheckbox.setName(ColumnItem.INDEX);
445: ixcheckbox.addActionListener(cbxlistener);
446: ixcheckbox.setToolTipText(bundle
447: .getString("ACS_AddTableColumnIndexNameA11yDesc"));
448: pane.add(ixcheckbox, con);
449:
450: ixmap = ddl.getIndexMap();
451: ix_uqmap = ddl.getUniqueIndexMap();
452:
453: con = new GridBagConstraints();
454: con.gridx = 1;
455: con.gridy = 5;
456: con.gridwidth = 3;
457: con.gridheight = 1;
458: con.fill = GridBagConstraints.HORIZONTAL;
459: con.insets = new java.awt.Insets(12, 12, 0, 0);
460: con.weightx = 1.0;
461: con.weighty = 0.0;
462: idxcombo = new JComboBox(new Vector(ixmap.keySet()));
463: idxcombo
464: .setToolTipText(bundle
465: .getString("ACS_AddTableColumnIndexNameComboBoxA11yDesc"));
466: idxcombo
467: .getAccessibleContext()
468: .setAccessibleName(
469: bundle
470: .getString("ACS_AddTableColumnIndexNameComboBoxA11yName"));
471: idxcombo
472: .getAccessibleContext()
473: .setAccessibleDescription(
474: bundle
475: .getString("ACS_AddTableColumnIndexNameComboBoxA11yDesc"));
476: //idxcombo.setSelectedIndex(0);
477: pane.add(idxcombo, con);
478:
479: // Check title and textarea
480:
481: con = new GridBagConstraints();
482: con.gridx = 0;
483: con.gridy = 6;
484: con.gridwidth = 1;
485: con.gridheight = 1;
486: con.anchor = GridBagConstraints.NORTHWEST;
487: con.insets = new java.awt.Insets(12, 0, 0, 0);
488: con.weightx = 0.0;
489: con.weighty = 0.0;
490: checkcheckbox = new JCheckBox();
491: Mnemonics.setLocalizedText(checkcheckbox, bundle
492: .getString("AddTableColumnConstraintCheckTitle")); //NOI18N
493: checkcheckbox.setName(ColumnItem.CHECK);
494: checkcheckbox.addActionListener(cbxlistener);
495: checkcheckbox.setToolTipText(bundle
496: .getString("ACS_AddTableColumnCheckTitleA11yDesc"));
497: pane.add(checkcheckbox, con);
498:
499: con = new GridBagConstraints();
500: con.gridx = 1;
501: con.gridy = 6;
502: con.gridwidth = 3;
503: con.gridheight = 1;
504: con.fill = GridBagConstraints.BOTH;
505: con.insets = new java.awt.Insets(12, 12, 0, 0);
506: con.weightx = 1.0;
507: con.weighty = 1.0;
508: checkfield = new JTextArea(3, 35);
509: checkfield.setName(ColumnItem.CHECK_CODE);
510: checkfield.addFocusListener(fldlistener);
511: checkfield
512: .setToolTipText(bundle
513: .getString("ACS_AddTableColumnCheckTextAreaA11yDesc"));
514: checkfield
515: .getAccessibleContext()
516: .setAccessibleName(
517: bundle
518: .getString("ACS_AddTableColumnCheckTextAreaA11yName"));
519: checkfield
520: .getAccessibleContext()
521: .setAccessibleDescription(
522: bundle
523: .getString("ACS_AddTableColumnCheckTextAreaA11yDesc"));
524: JScrollPane spane = new JScrollPane(checkfield);
525: pane.add(spane, con);
526:
527: checkcheckbox.setSelected(false);
528: checkcheckbox.setSelected(false);
529: nullcheckbox.setSelected(true);
530: uniquecheckbox.setSelected(false);
531: pkcheckbox.setEnabled(!isPK);
532: idxcombo.setEnabled(idxcombo.getItemCount() > 0);
533: ixcheckbox.setEnabled(idxcombo.isEnabled());
534:
535: item
536: .addPropertyChangeListener(new PropertyChangeListener() {
537: public void propertyChange(
538: PropertyChangeEvent evt) {
539: String pname = evt.getPropertyName();
540: Object nval = evt.getNewValue();
541: if (nval instanceof Boolean) {
542: boolean set = ((Boolean) nval)
543: .booleanValue();
544: if (pname
545: .equals(ColumnItem.PRIMARY_KEY)) {
546: pkcheckbox.setSelected(set);
547: //idxcombo.setEnabled(!set);
548: //ixcheckbox.setEnabled(!set);
549: //ixcheckbox.setSelected(set);
550: } else if (pname
551: .equals(ColumnItem.INDEX)) {
552: ixcheckbox.setSelected(set);
553: } else if (pname
554: .equals(ColumnItem.UNIQUE)) {
555: uniquecheckbox.setSelected(set);
556: idxcombo.setEnabled(!set);
557: ixcheckbox.setEnabled(!set);
558: ixcheckbox.setSelected(set);
559: if (set) {
560: idxcombo.addItem(tempStr);
561: idxcombo
562: .setSelectedItem(tempStr);
563: } else {
564: idxcombo.removeItem(tempStr);
565: idxcombo.setEnabled(idxcombo
566: .getItemCount() > 0);
567: ixcheckbox.setEnabled(idxcombo
568: .isEnabled());
569: }
570: } else if (pname
571: .equals(ColumnItem.NULLABLE)) {
572: nullcheckbox.setSelected(set);
573: }
574: }
575: }
576: });
577:
578: ActionListener listener = new ActionListener() {
579: public void actionPerformed(ActionEvent event) {
580: if (event.getSource() != DialogDescriptor.OK_OPTION) {
581: return;
582: }
583: result = validate();
584: if (!result) {
585: String msg = bundle
586: .getString("EXC_InsufficientAddColumnInfo");
587: DialogDisplayer
588: .getDefault()
589: .notify(
590: new NotifyDescriptor.Message(
591: msg,
592: NotifyDescriptor.ERROR_MESSAGE));
593: return;
594: }
595:
596: colname = colnamefield.getText();
597: ColumnItem citem = (ColumnItem) dmodel.getData()
598: .elementAt(0);
599: String indexName = (String) idxcombo
600: .getSelectedItem();
601: boolean wasException;
602: try {
603: wasException = ddl.execute(colname, citem,
604: indexName);
605: } catch (Exception e) {
606: LOGGER.log(Level.WARNING, null, e);
607:
608: DbUtilities.reportError(bundle
609: .getString("ERR_UnableToAddColumn"), e
610: .getMessage());
611: return;
612: }
613:
614: // was execution of commands with or without exception?
615: if (wasException) {
616: return;
617: }
618:
619: // dialog is closed after successfully add column
620: dialog.setVisible(false);
621: dialog.dispose();
622: }
623: };
624:
625: pane
626: .getAccessibleContext()
627: .setAccessibleDescription(
628: bundle
629: .getString("ACS_AddTableColumnDialogA11yDesc"));
630:
631: DialogDescriptor descriptor = new DialogDescriptor(pane,
632: bundle.getString("AddColumnDialogTitle"), true,
633: listener); //NOI18N
634: // inbuilt close of the dialog is only after CANCEL button click
635: // after OK button is dialog closed by hand
636: Object[] closingOptions = { DialogDescriptor.CANCEL_OPTION };
637: descriptor.setClosingOptions(closingOptions);
638: dialog = DialogDisplayer.getDefault().createDialog(
639: descriptor);
640: dialog.setResizable(true);
641: } catch (MissingResourceException e) {
642: e.printStackTrace();
643: }
644: }
645:
646: public boolean run() {
647: if (dialog != null)
648: dialog.setVisible(true);
649: return result;
650: }
651:
652: private boolean validate() {
653: Vector cols = dmodel.getData();
654: String colname = colnamefield.getText();
655: if (colname == null || colname.length() < 1)
656: return false;
657:
658: Enumeration colse = cols.elements();
659: while (colse.hasMoreElements())
660: if (!((ColumnItem) colse.nextElement()).validate())
661: return false;
662:
663: return true;
664: }
665:
666: public String getColumnName() {
667: return colname;
668: }
669:
670: class CheckBoxListener implements ActionListener {
671: private DataModel data;
672:
673: CheckBoxListener(DataModel data) {
674: this .data = data;
675: }
676:
677: public void actionPerformed(ActionEvent event) {
678: JCheckBox cbx = (JCheckBox) event.getSource();
679: String code = cbx.getName();
680: data.setValue(cbx.isSelected() ? Boolean.TRUE
681: : Boolean.FALSE, code, 0);
682: }
683: }
684:
685: class ComboBoxListener implements ActionListener {
686: private DataModel data;
687:
688: ComboBoxListener(DataModel data) {
689: this .data = data;
690: }
691:
692: public void actionPerformed(ActionEvent event) {
693: JComboBox cbx = (JComboBox) event.getSource();
694: String code = cbx.getName();
695: data.setValue(cbx.getSelectedItem(), code, 0);
696: }
697: }
698:
699: class TextFieldListener implements FocusListener {
700: private DataModel data;
701:
702: TextFieldListener(DataModel data) {
703: this .data = data;
704: }
705:
706: public void focusGained(FocusEvent event) {
707: }
708:
709: public void focusLost(FocusEvent event) {
710: JTextComponent fld = (JTextComponent) event.getSource();
711: String code = fld.getName();
712: data.setValue(fld.getText(), code, 0);
713: }
714: }
715:
716: class IntegerFieldListener implements FocusListener {
717: private DataModel data;
718:
719: IntegerFieldListener(DataModel data) {
720: this .data = data;
721: }
722:
723: public void focusGained(FocusEvent event) {
724: }
725:
726: public void focusLost(FocusEvent event) {
727: JTextComponent fld = (JTextComponent) event.getSource();
728: String code = fld.getName();
729: String numero = fld.getText();
730: Integer ival;
731: if (numero == null || numero.length() == 0)
732: numero = "0"; //NOI18N
733: ival = new Integer(numero);
734: data.setValue(ival, code, 0);
735: }
736: }
737: }
|