001: /* Copyright (C) 2003 Finalist IT Group
002: *
003: * This file is part of JAG - the Java J2EE Application Generator
004: *
005: * JAG is free software; you can redistribute it and/or modify
006: * it under the terms of the GNU General Public License as published by
007: * the Free Software Foundation; either version 2 of the License, or
008: * (at your option) any later version.
009: * JAG is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: * You should have received a copy of the GNU General Public License
014: * along with JAG; if not, write to the Free Software
015: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
016: */
017:
018: package com.finalist.jaggenerator;
019:
020: import java.util.*;
021: import java.util.List;
022: import java.awt.*;
023: import java.awt.event.WindowAdapter;
024: import java.awt.event.WindowEvent;
025: import java.awt.event.ActionListener;
026: import java.awt.event.ActionEvent;
027: import javax.swing.*;
028:
029: /**
030: *
031: * @author hillie
032: */
033: public class SelectTablesDialog extends JDialog {
034: private DefaultListModel listModel = new DefaultListModel();
035:
036: private static final ArrayList tableList = new ArrayList();
037: private static final ArrayList alreadySelected = new ArrayList();
038:
039: /** Creates new form SelectTablesDialog */
040: public SelectTablesDialog(JagGenerator parent) {
041: super (parent, true);
042: initComponents();
043: this .setTitle("Select tables..");
044: setBounds(50, 10, 200, 700);
045:
046: ArrayList tables = DatabaseUtils.getTables();
047: if (tables != null) {
048: for (Iterator it = tables.iterator(); it.hasNext();) {
049: String table = (String) it.next();
050: if (!alreadySelected.contains(table)) {
051: listModel.addElement(table);
052: }
053: }
054: list.setModel(listModel);
055: }
056: }
057:
058: /**
059: * Once the user has selected tables using this dialog, this method returns the selected tables.
060: * @return the ArrayList of selected table names (String), never <code>null</code>.
061: */
062: public static ArrayList getTablelist() {
063: return tableList;
064: }
065:
066: /**
067: * By adding table names to this list, those tables are excluded from appearing in future dialogues.
068: *
069: * @return
070: */
071: public static List getAlreadyselected() {
072: return alreadySelected;
073: }
074:
075: /**
076: * clears all lists.
077: */
078: public static void clear() {
079: tableList.clear();
080: alreadySelected.clear();
081: }
082:
083: /** This method is called from within the constructor to
084: * initialize the form.
085: * WARNING: Do NOT modify this code. The content of this method is
086: * always regenerated by the Form Editor.
087: */
088: private void initComponents() {//GEN-BEGIN:initComponents
089: java.awt.GridBagConstraints gridBagConstraints;
090:
091: jScrollPane1 = new javax.swing.JScrollPane();
092: list = new javax.swing.JList();
093: jPanel1 = new javax.swing.JPanel();
094: selectButton = new javax.swing.JButton();
095: cancelButton = new javax.swing.JButton();
096:
097: getContentPane().setLayout(new java.awt.GridBagLayout());
098:
099: addWindowListener(new java.awt.event.WindowAdapter() {
100: public void windowClosing(java.awt.event.WindowEvent evt) {
101: closeDialog(evt);
102: }
103: });
104:
105: list.addMouseListener(new java.awt.event.MouseAdapter() {
106: public void mouseClicked(java.awt.event.MouseEvent evt) {
107: listMouseClicked(evt);
108: }
109: });
110:
111: jScrollPane1.setViewportView(list);
112:
113: gridBagConstraints = new java.awt.GridBagConstraints();
114: gridBagConstraints.gridx = 0;
115: gridBagConstraints.gridy = 0;
116: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
117: gridBagConstraints.weightx = 1.0;
118: gridBagConstraints.weighty = 1.0;
119: getContentPane().add(jScrollPane1, gridBagConstraints);
120:
121: selectButton.setText("Select");
122: selectButton.setSelected(true);
123: selectButton
124: .addActionListener(new java.awt.event.ActionListener() {
125: public void actionPerformed(
126: java.awt.event.ActionEvent evt) {
127: selectButtonActionPerformed(evt);
128: }
129: });
130:
131: jPanel1.add(selectButton);
132:
133: cancelButton.setText("Cancel");
134: cancelButton
135: .addActionListener(new java.awt.event.ActionListener() {
136: public void actionPerformed(
137: java.awt.event.ActionEvent evt) {
138: cancelButtonActionPerformed(evt);
139: }
140: });
141:
142: jPanel1.add(cancelButton);
143:
144: gridBagConstraints = new java.awt.GridBagConstraints();
145: gridBagConstraints.gridx = 0;
146: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
147: getContentPane().add(jPanel1, gridBagConstraints);
148:
149: pack();
150: }//GEN-END:initComponents
151:
152: private void listMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_listMouseClicked
153: if (evt.getClickCount() > 1) {
154: selectButtonActionPerformed(null);
155: }
156: }//GEN-LAST:event_listMouseClicked
157:
158: private void cancelButtonActionPerformed(
159: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
160: closeDialog(null);
161: }//GEN-LAST:event_cancelButtonActionPerformed
162:
163: private void selectButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_selectButtonActionPerformed
164: Object[] tables = list.getSelectedValues();
165: evt = null;
166: tableList.clear();
167: tableList.addAll(Arrays.asList(tables));
168: dispose();
169: }//GEN-LAST:event_selectButtonActionPerformed
170:
171: /** Closes the dialog */
172: private void closeDialog(WindowEvent evt) {//GEN-FIRST:event_closeDialog
173: tableList.clear();
174: evt = null;
175: this .dispose();
176: }//GEN-LAST:event_closeDialog
177:
178: // Variables declaration - do not modify//GEN-BEGIN:variables
179: private javax.swing.JButton cancelButton;
180: private javax.swing.JPanel jPanel1;
181: private javax.swing.JScrollPane jScrollPane1;
182: private javax.swing.JList list;
183: private javax.swing.JButton selectButton;
184: // End of variables declaration//GEN-END:variables
185:
186: }
|