1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package com.finalist.jaggenerator;
19
20 import java.util.*;
21 import java.util.List;
22 import java.awt.*;
23 import java.awt.event.WindowAdapter;
24 import java.awt.event.WindowEvent;
25 import java.awt.event.ActionListener;
26 import java.awt.event.ActionEvent;
27 import javax.swing.*;
28
29 /***
30 *
31 * @author hillie
32 */
33 public class SelectTablesDialog extends JDialog {
34 private DefaultListModel listModel = new DefaultListModel();
35
36 private static final ArrayList tableList = new ArrayList();
37 private static final ArrayList alreadySelected = new ArrayList();
38
39
40 /*** Creates new form SelectTablesDialog */
41 public SelectTablesDialog(JagGenerator parent) {
42 super(parent, true);
43 initComponents();
44 this.setTitle("Select tables..");
45 setBounds(50, 10, 200, 700);
46
47 ArrayList tables = DatabaseUtils.getTables();
48 if (tables != null) {
49 for (Iterator it = tables.iterator(); it.hasNext();) {
50 String table = (String) it.next();
51 if (!alreadySelected.contains(table)) {
52 listModel.addElement(table);
53 }
54 }
55 list.setModel(listModel);
56 }
57 }
58
59 /***
60 * Once the user has selected tables using this dialog, this method returns the selected tables.
61 * @return the ArrayList of selected table names (String), never <code>null</code>.
62 */
63 public static ArrayList getTablelist() {
64 return tableList;
65 }
66
67 /***
68 * By adding table names to this list, those tables are excluded from appearing in future dialogues.
69 *
70 * @return
71 */
72 public static List getAlreadyselected() {
73 return alreadySelected;
74 }
75
76 /***
77 * clears all lists.
78 */
79 public static void clear() {
80 tableList.clear();
81 alreadySelected.clear();
82 }
83
84 /*** This method is called from within the constructor to
85 * initialize the form.
86 * WARNING: Do NOT modify this code. The content of this method is
87 * always regenerated by the Form Editor.
88 */
89 private void initComponents() {
90 java.awt.GridBagConstraints gridBagConstraints;
91
92 jScrollPane1 = new javax.swing.JScrollPane();
93 list = new javax.swing.JList();
94 jPanel1 = new javax.swing.JPanel();
95 selectButton = new javax.swing.JButton();
96 cancelButton = new javax.swing.JButton();
97
98 getContentPane().setLayout(new java.awt.GridBagLayout());
99
100 addWindowListener(new java.awt.event.WindowAdapter() {
101 public void windowClosing(java.awt.event.WindowEvent evt) {
102 closeDialog(evt);
103 }
104 });
105
106 list.addMouseListener(new java.awt.event.MouseAdapter() {
107 public void mouseClicked(java.awt.event.MouseEvent evt) {
108 listMouseClicked(evt);
109 }
110 });
111
112 jScrollPane1.setViewportView(list);
113
114 gridBagConstraints = new java.awt.GridBagConstraints();
115 gridBagConstraints.gridx = 0;
116 gridBagConstraints.gridy = 0;
117 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
118 gridBagConstraints.weightx = 1.0;
119 gridBagConstraints.weighty = 1.0;
120 getContentPane().add(jScrollPane1, gridBagConstraints);
121
122 selectButton.setText("Select");
123 selectButton.setSelected(true);
124 selectButton.addActionListener(new java.awt.event.ActionListener() {
125 public void actionPerformed(java.awt.event.ActionEvent evt) {
126 selectButtonActionPerformed(evt);
127 }
128 });
129
130 jPanel1.add(selectButton);
131
132 cancelButton.setText("Cancel");
133 cancelButton.addActionListener(new java.awt.event.ActionListener() {
134 public void actionPerformed(java.awt.event.ActionEvent evt) {
135 cancelButtonActionPerformed(evt);
136 }
137 });
138
139 jPanel1.add(cancelButton);
140
141 gridBagConstraints = new java.awt.GridBagConstraints();
142 gridBagConstraints.gridx = 0;
143 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
144 getContentPane().add(jPanel1, gridBagConstraints);
145
146 pack();
147 }
148
149 private void listMouseClicked(java.awt.event.MouseEvent evt) {
150 if (evt.getClickCount() > 1) {
151 selectButtonActionPerformed(null);
152 }
153 }
154
155 private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {
156 closeDialog(null);
157 }
158
159
160 private void selectButtonActionPerformed(ActionEvent evt) {
161 Object[] tables = list.getSelectedValues();
162 evt = null;
163 tableList.clear();
164 tableList.addAll(Arrays.asList(tables));
165 dispose();
166 }
167
168
169 /*** Closes the dialog */
170 private void closeDialog(WindowEvent evt) {
171 tableList.clear();
172 evt = null;
173 this.dispose();
174 }
175
176
177 private javax.swing.JButton cancelButton;
178 private javax.swing.JPanel jPanel1;
179 private javax.swing.JScrollPane jScrollPane1;
180 private javax.swing.JList list;
181 private javax.swing.JButton selectButton;
182
183
184
185 }