001: /*
002: * Copyright (C) 2005 Rob Manning
003: * manningr@users.sourceforge.net
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: */
019: package net.sourceforge.squirrel_sql.plugins.dbcopy.gui;
020:
021: import java.awt.Component;
022: import java.awt.GridBagConstraints;
023: import java.awt.GridBagLayout;
024: import java.awt.Insets;
025: import java.awt.event.ActionEvent;
026: import java.awt.event.ActionListener;
027:
028: import javax.swing.JCheckBox;
029: import javax.swing.JLabel;
030: import javax.swing.JPanel;
031: import javax.swing.JTextField;
032: import javax.swing.border.Border;
033: import javax.swing.border.CompoundBorder;
034: import javax.swing.border.EmptyBorder;
035: import javax.swing.border.TitledBorder;
036:
037: import net.sourceforge.squirrel_sql.fw.util.StringManager;
038: import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
039: import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
040: import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
041: import net.sourceforge.squirrel_sql.plugins.dbcopy.prefs.DBCopyPreferenceBean;
042: import net.sourceforge.squirrel_sql.plugins.dbcopy.prefs.PreferencesManager;
043:
044: public class PreferencesPanel extends JPanel {
045:
046: DBCopyPreferenceBean _prefs = null;
047:
048: JCheckBox truncateCheckBox = null;
049:
050: JCheckBox fileCachingCheckBox = null;
051:
052: JTextField bufferSizeTextField = null;
053:
054: JLabel bufferSizeLabel = null;
055:
056: JCheckBox autoCommitCheckBox = null;
057:
058: JCheckBox commitAfterCreateTableCheckBox = null;
059:
060: JLabel commitRecordCountLabel = null;
061:
062: JTextField commitRecordCountTextField = null;
063:
064: JCheckBox saveScriptCheckBox = null;
065:
066: JCheckBox copyTableRecords = null;
067:
068: JCheckBox copyIndexDefs = null;
069:
070: JCheckBox copyForeignKeys = null;
071:
072: JCheckBox copyPrimaryKeys = null;
073:
074: JCheckBox pruneDuplicateIndexDefs = null;
075:
076: JCheckBox writeScriptCheckBox = null;
077:
078: JCheckBox promptForHibernateCheckBox = null;
079:
080: JCheckBox checkKeywordsCheckBox = null;
081:
082: JCheckBox testColumnNamesCheckBox = null;
083:
084: JLabel selectFetchSizeLabel = null;
085:
086: JTextField selectFetchSizeTextField = null;
087:
088: JCheckBox delayBetweenObjects = null;
089:
090: JLabel delayTablesLabel = null;
091:
092: JTextField delayTablesTextField = null;
093:
094: JLabel delayRecordsLabel = null;
095:
096: JTextField delayRecordsTextField = null;
097:
098: /** Logger for this class. */
099: private final static ILogger log = LoggerController
100: .createLogger(PreferencesPanel.class);
101:
102: /** Internationalized strings for this class. */
103: private static final StringManager s_stringMgr = StringManagerFactory
104: .getStringManager(PreferencesPanel.class);
105:
106: public PreferencesPanel(DBCopyPreferenceBean prefs) {
107:
108: super ();
109: _prefs = prefs;
110: createGUI();
111: loadData();
112: }
113:
114: private void createGUI() {
115: this .setLayout(new GridBagLayout());
116: GridBagConstraints c = new GridBagConstraints();
117: c.gridx = 0; // Column 0
118: c.gridy = 0; // Row 0
119: c.fill = GridBagConstraints.BOTH;
120: c.weightx = 1;
121: c.weighty = .40;
122: add(createTopPanel(), c);
123:
124: c = new GridBagConstraints();
125: c.gridx = 0; // Column 0
126: c.gridy = 1; // Row 1
127: c.fill = GridBagConstraints.BOTH;
128: c.weightx = 1;
129: c.weighty = .60;
130: add(createBottomPanel(), c);
131: }
132:
133: private JPanel createTopPanel() {
134: JPanel result = new JPanel(new GridBagLayout());
135: //i18n[PreferencesPanel.transferOptionsBorderLabel=Transfer Options]
136: String tranferOptionsBorderLabel = s_stringMgr
137: .getString("PreferencesPanel.transferOptionsBorderLabel");
138: result.setBorder(getTitledBorder(tranferOptionsBorderLabel));
139: String cbLabel = s_stringMgr
140: .getString("PreferencesPanel.truncateLabel");
141: truncateCheckBox = new JCheckBox(cbLabel);
142:
143: addUseTruncateCheckBox(result, 0, 0);
144: addCopyTableRecordsCheckBox(result, 0, 1);
145:
146: addFetchSizeLabel(result, 0, 2);
147: addFetchSizeTextField(result, 1, 2);
148:
149: addCopyPrimaryKeysCheckBox(result, 0, 3);
150: addCopyForeignKeysCheckBox(result, 0, 4);
151: addCopyIndexDefsCheckBox(result, 0, 5);
152: addPruneDuplicateIndexDefsCheckBox(result, 0, 6);
153: addFileCacheCheckBox(result, 0, 7);
154:
155: addBufferSizeLabel(result, 0, 8);
156: addBufferSizeTextField(result, 1, 8);
157:
158: addAutoCommitCheckcBox(result, 0, 9);
159: addCommitAfterCreateTableCheckBox(result, 0, 10);
160:
161: addRecordCountLabel(result, 0, 11);
162: addCommitRecordCountTextField(result, 1, 11);
163:
164: addDelayCheckBox(result, 0, 12);
165:
166: addDelayTablesLabel(result, 0, 13);
167: addDelayTablesTextField(result, 1, 13);
168:
169: addDelayRecordsLabel(result, 0, 14);
170: addDelayRecordsTextField(result, 1, 14);
171:
172: addWriteScriptCheckBox(result, 0, 15);
173:
174: return result;
175: }
176:
177: private void addPruneDuplicateIndexDefsCheckBox(JPanel panel,
178: int col, int row) {
179: GridBagConstraints c = new GridBagConstraints();
180: c.gridx = col;
181: c.gridy = row;
182: c.gridwidth = 2; // Span across two columns
183: //c.ipadx = 40;
184: c.insets = new Insets(10, 25, 0, 0);
185: c.anchor = GridBagConstraints.WEST;
186: String cbLabelStr = s_stringMgr
187: .getString("PreferencesPanel.pruneDuplicateIndexDefs");
188: String toolTipText = s_stringMgr
189: .getString("PreferencesPanel.pruneDuplicateIndexDefsToolTip");
190: pruneDuplicateIndexDefs = new JCheckBox(cbLabelStr);
191: pruneDuplicateIndexDefs.setToolTipText(toolTipText);
192: panel.add(pruneDuplicateIndexDefs, c);
193: }
194:
195: private void addWriteScriptCheckBox(JPanel panel, int col, int row) {
196: GridBagConstraints c = new GridBagConstraints();
197: c.gridx = col;
198: c.gridy = row;
199: c.gridwidth = 2; // Span across two columns
200: c.insets = new Insets(10, 0, 0, 0);
201: c.anchor = GridBagConstraints.WEST;
202: String cbLabelStr = s_stringMgr
203: .getString("PreferencesPanel.writeScript");
204: String toolTipText = s_stringMgr
205: .getString("PreferencesPanel.writeScriptToolTip");
206: writeScriptCheckBox = new JCheckBox(cbLabelStr);
207: writeScriptCheckBox.setToolTipText(toolTipText);
208: panel.add(writeScriptCheckBox, c);
209: }
210:
211: private void addUseTruncateCheckBox(JPanel panel, int col, int row) {
212: GridBagConstraints c = new GridBagConstraints();
213: c.gridx = col;
214: c.gridy = row;
215: c.gridwidth = 2; // Span across two columns
216: String cbToolTipText = s_stringMgr
217: .getString("PreferencesPanel.truncateLabelTipText");
218: truncateCheckBox.setToolTipText(cbToolTipText);
219: panel.add(truncateCheckBox, c);
220: }
221:
222: private void addCopyTableRecordsCheckBox(JPanel panel, int col,
223: int row) {
224: GridBagConstraints c = new GridBagConstraints();
225: c.gridx = col;
226: c.gridy = row;
227: c.gridwidth = 2; // Span across two columns
228: c.insets = new Insets(10, 0, 0, 0);
229: c.anchor = GridBagConstraints.WEST;
230: String cbLabelStr = s_stringMgr
231: .getString("PreferencesPanel.copyTableRecords");
232: String toolTipText = s_stringMgr
233: .getString("PreferencesPanel.copyTableRecordsToolTip");
234: copyTableRecords = new JCheckBox(cbLabelStr);
235: copyTableRecords.setToolTipText(toolTipText);
236: copyTableRecords.addActionListener(new ActionListener() {
237: public void actionPerformed(ActionEvent e) {
238: selectFetchSizeLabel.setEnabled(copyTableRecords
239: .isSelected());
240: selectFetchSizeTextField.setEnabled(copyTableRecords
241: .isSelected());
242: }
243: });
244: panel.add(copyTableRecords, c);
245: }
246:
247: private void addFetchSizeLabel(JPanel panel, int col, int row) {
248: GridBagConstraints c = new GridBagConstraints();
249: c.gridx = col;
250: c.gridy = row;
251: c.insets = new Insets(5, 25, 0, 0);
252: String bsLabel = s_stringMgr
253: .getString("PreferencesPanel.fetchSizeLabel");
254: selectFetchSizeLabel = new JLabel(bsLabel);
255: selectFetchSizeLabel.setHorizontalAlignment(JLabel.LEFT);
256: String labelToolTipText = s_stringMgr
257: .getString("PreferencesPanel.fetchSizeToolTip");
258: selectFetchSizeLabel.setToolTipText(labelToolTipText);
259: panel.add(selectFetchSizeLabel, c);
260: }
261:
262: private void addFetchSizeTextField(JPanel panel, int col, int row) {
263: GridBagConstraints c = new GridBagConstraints();
264: c.gridx = col;
265: c.gridy = row;
266: c.ipadx = 40; // Increases component width by 40 pixels
267: c.insets = new Insets(5, 5, 0, 0);
268: c.anchor = GridBagConstraints.WEST;
269: selectFetchSizeTextField = new JTextField(10);
270:
271: selectFetchSizeTextField
272: .setHorizontalAlignment(JTextField.RIGHT);
273: String toolTip = s_stringMgr
274: .getString("PreferencesPanel.fetchSizeTextFieldToolTip");
275: selectFetchSizeTextField.setToolTipText(toolTip);
276: panel.add(selectFetchSizeTextField, c);
277: }
278:
279: private void addCopyPrimaryKeysCheckBox(JPanel panel, int col,
280: int row) {
281: GridBagConstraints c = new GridBagConstraints();
282: c.gridx = col;
283: c.gridy = row;
284: c.gridwidth = 2; // Span across two columns
285: c.insets = new Insets(10, 0, 0, 0);
286: c.anchor = GridBagConstraints.WEST;
287: String cbLabelStr = s_stringMgr
288: .getString("PreferencesPanel.copyPrimaryKeys");
289: String toolTipText = s_stringMgr
290: .getString("PreferencesPanel.copyPrimaryKeysToolTip");
291: copyPrimaryKeys = new JCheckBox(cbLabelStr);
292: copyPrimaryKeys.setToolTipText(toolTipText);
293: panel.add(copyPrimaryKeys, c);
294: }
295:
296: private void addCopyForeignKeysCheckBox(JPanel panel, int col,
297: int row) {
298: GridBagConstraints c = new GridBagConstraints();
299: c.gridx = col;
300: c.gridy = row;
301: c.gridwidth = 2; // Span across two columns
302: c.insets = new Insets(10, 0, 0, 0);
303: c.anchor = GridBagConstraints.WEST;
304: String cbLabelStr = s_stringMgr
305: .getString("PreferencesPanel.copyForeignKeys");
306: String toolTipText = s_stringMgr
307: .getString("PreferencesPanel.copyForeignKeysToolTip");
308: copyForeignKeys = new JCheckBox(cbLabelStr);
309: copyForeignKeys.setToolTipText(toolTipText);
310: panel.add(copyForeignKeys, c);
311: }
312:
313: private void addCopyIndexDefsCheckBox(JPanel panel, int col, int row) {
314: GridBagConstraints c = new GridBagConstraints();
315: c.gridx = col;
316: c.gridy = row;
317: c.gridwidth = 2; // Span across two columns
318: c.insets = new Insets(10, 0, 0, 0);
319: c.anchor = GridBagConstraints.WEST;
320: String cbLabelStr = s_stringMgr
321: .getString("PreferencesPanel.copyIndexDefs");
322: String toolTipText = s_stringMgr
323: .getString("PreferencesPanel.copyIndexDefsToolTip");
324: copyIndexDefs = new JCheckBox(cbLabelStr);
325: copyIndexDefs.addActionListener(new ActionListener() {
326: public void actionPerformed(ActionEvent e) {
327: if (copyIndexDefs.isSelected()) {
328: pruneDuplicateIndexDefs.setEnabled(true);
329: } else {
330: pruneDuplicateIndexDefs.setEnabled(false);
331: }
332: }
333: });
334: copyIndexDefs.setToolTipText(toolTipText);
335: panel.add(copyIndexDefs, c);
336: }
337:
338: private void addFileCacheCheckBox(JPanel panel, int col, int row) {
339: GridBagConstraints c = new GridBagConstraints();
340: c.gridx = col;
341: c.gridy = row;
342: c.gridwidth = 2; // Span across two columns
343: c.insets = new Insets(10, 0, 0, 0);
344: c.anchor = GridBagConstraints.WEST;
345: String cbLabelStr = s_stringMgr
346: .getString("PreferencesPanel.useFileCachingLabel");
347: fileCachingCheckBox = new JCheckBox(cbLabelStr);
348: fileCachingCheckBox.addActionListener(new ActionListener() {
349: public void actionPerformed(ActionEvent e) {
350: if (fileCachingCheckBox.isSelected()) {
351: bufferSizeTextField.setEnabled(true);
352: bufferSizeLabel.setEnabled(true);
353: } else {
354: bufferSizeTextField.setEnabled(false);
355: bufferSizeLabel.setEnabled(false);
356: }
357: }
358: });
359: String toolTipText = s_stringMgr
360: .getString("PreferencesPanel.useFileCachingToolTip");
361: fileCachingCheckBox.setToolTipText(toolTipText);
362: panel.add(fileCachingCheckBox, c);
363: }
364:
365: private void addBufferSizeLabel(JPanel panel, int col, int row) {
366: GridBagConstraints c = new GridBagConstraints();
367: c.gridx = col;
368: c.gridy = row;
369: c.insets = new Insets(5, 25, 0, 0);
370: String bsLabel = s_stringMgr
371: .getString("PreferencesPanel.copyBufferSizeLabel");
372: bufferSizeLabel = new JLabel(bsLabel);
373: bufferSizeLabel.setHorizontalAlignment(JLabel.LEFT);
374: String labelToolTipText = s_stringMgr
375: .getString("PreferencesPanel.copyBufferSizeToolTip");
376: bufferSizeLabel.setToolTipText(labelToolTipText);
377: panel.add(bufferSizeLabel, c);
378: }
379:
380: private void addBufferSizeTextField(JPanel panel, int col, int row) {
381: GridBagConstraints c = new GridBagConstraints();
382: c.gridx = col;
383: c.gridy = row;
384: c.ipadx = 40; // Increases component width by 40 pixels
385: c.insets = new Insets(5, 5, 0, 0);
386: c.anchor = GridBagConstraints.WEST;
387: bufferSizeTextField = new JTextField(10);
388: bufferSizeTextField.setHorizontalAlignment(JTextField.RIGHT);
389: String toolTip = s_stringMgr
390: .getString("PreferencesPanel.bufferSizeTextFieldToolTip");
391: bufferSizeTextField.setToolTipText(toolTip);
392: panel.add(bufferSizeTextField, c);
393: }
394:
395: private void addAutoCommitCheckcBox(JPanel panel, int col, int row) {
396: GridBagConstraints c = new GridBagConstraints();
397: c.gridx = col;
398: c.gridy = row;
399: c.gridwidth = 2; // Span across two columns
400: c.insets = new Insets(10, 0, 0, 0);
401: c.anchor = GridBagConstraints.WEST;
402: String cbLabelStr = s_stringMgr
403: .getString("PreferencesPanel.autoCommitLabel");
404: autoCommitCheckBox = new JCheckBox(cbLabelStr);
405: autoCommitCheckBox.addActionListener(new ActionListener() {
406: public void actionPerformed(ActionEvent e) {
407: if (autoCommitCheckBox.isSelected()) {
408: commitRecordCountLabel.setEnabled(false);
409: commitRecordCountTextField.setEnabled(false);
410: commitAfterCreateTableCheckBox.setEnabled(false);
411: } else {
412: commitRecordCountLabel.setEnabled(true);
413: commitRecordCountTextField.setEnabled(true);
414: commitAfterCreateTableCheckBox.setEnabled(true);
415: }
416: }
417: });
418: panel.add(autoCommitCheckBox, c);
419: }
420:
421: private void addCommitAfterCreateTableCheckBox(JPanel panel,
422: int col, int row) {
423: GridBagConstraints c = new GridBagConstraints();
424: c.gridx = col;
425: c.gridy = row;
426: c.gridwidth = 2; // Span across two columns
427: //c.ipadx = 40;
428: c.insets = new Insets(10, 25, 0, 0);
429: c.anchor = GridBagConstraints.WEST;
430: String cbLabelStr = s_stringMgr
431: .getString("PreferencesPanel.commitAfterCreateTable");
432: String toolTipText = s_stringMgr
433: .getString("PreferencesPanel.commitAfterCreateTableToolTip");
434: commitAfterCreateTableCheckBox = new JCheckBox(cbLabelStr);
435: commitAfterCreateTableCheckBox.setToolTipText(toolTipText);
436: panel.add(commitAfterCreateTableCheckBox, c);
437: }
438:
439: private void addRecordCountLabel(JPanel panel, int col, int row) {
440: GridBagConstraints c = new GridBagConstraints();
441: c.gridx = col;
442: c.gridy = row;
443: c.insets = new Insets(5, 25, 0, 0);
444: String commitLabel = s_stringMgr
445: .getString("PreferencesPanel.commitRecordCountLabel");
446: commitRecordCountLabel = new JLabel(commitLabel);
447: commitRecordCountLabel.setHorizontalAlignment(JLabel.RIGHT);
448: String commitlabelToolTipText = s_stringMgr
449: .getString("PreferencesPanel.commitRecordCountToolTip");
450: commitRecordCountLabel.setToolTipText(commitlabelToolTipText);
451: panel.add(commitRecordCountLabel, c);
452: }
453:
454: private void addCommitRecordCountTextField(JPanel panel, int col,
455: int row) {
456: GridBagConstraints c = new GridBagConstraints();
457: c.gridx = col;
458: c.gridy = row;
459: c.ipadx = 40; // Increases component width by 20 pixels
460: c.insets = new Insets(5, 5, 0, 0);
461: c.anchor = GridBagConstraints.WEST;
462: commitRecordCountTextField = new JTextField(10);
463: commitRecordCountTextField
464: .setHorizontalAlignment(JTextField.RIGHT);
465: String commitlabelToolTipText = s_stringMgr
466: .getString("PreferencesPanel.commitRecordCountToolTip");
467: commitRecordCountTextField
468: .setToolTipText(commitlabelToolTipText);
469: panel.add(commitRecordCountTextField, c);
470: }
471:
472: private void addDelayCheckBox(JPanel panel, int col, int row) {
473: GridBagConstraints c = new GridBagConstraints();
474: c.gridx = col;
475: c.gridy = row;
476: c.gridwidth = 2; // Span across two columns
477: c.insets = new Insets(10, 0, 0, 0);
478: c.anchor = GridBagConstraints.WEST;
479: String label = s_stringMgr
480: .getString("PreferencesPanel.delayLabel");
481: delayBetweenObjects = new JCheckBox(label);
482: //selectFetchSizeLabel.setHorizontalAlignment(JLabel.LEFT);
483: String delayToolTip = s_stringMgr
484: .getString("PreferencesPanel.delayToolTip");
485: delayBetweenObjects.setToolTipText(delayToolTip);
486: delayBetweenObjects.addActionListener(new ActionListener() {
487: public void actionPerformed(ActionEvent e) {
488: delayRecordsLabel.setEnabled(delayBetweenObjects
489: .isSelected());
490: delayRecordsTextField.setEnabled(delayBetweenObjects
491: .isSelected());
492: delayTablesLabel.setEnabled(delayBetweenObjects
493: .isSelected());
494: delayTablesTextField.setEnabled(delayBetweenObjects
495: .isSelected());
496: }
497: });
498: panel.add(delayBetweenObjects, c);
499: }
500:
501: private void addDelayTablesLabel(JPanel panel, int col, int row) {
502: GridBagConstraints c = new GridBagConstraints();
503: c.gridx = col;
504: c.gridy = row;
505: c.insets = new Insets(5, 25, 0, 0);
506: String label = s_stringMgr
507: .getString("PreferencesPanel.delayTablesLabel");
508: delayTablesLabel = new JLabel(label);
509: delayTablesLabel.setHorizontalAlignment(JLabel.LEFT);
510: panel.add(delayTablesLabel, c);
511: }
512:
513: private void addDelayTablesTextField(JPanel panel, int col, int row) {
514: GridBagConstraints c = new GridBagConstraints();
515: c.gridx = col;
516: c.gridy = row;
517: c.ipadx = 40; // Increases component width by 40 pixels
518: c.insets = new Insets(5, 5, 0, 0);
519: c.anchor = GridBagConstraints.WEST;
520: delayTablesTextField = new JTextField(10);
521:
522: delayTablesTextField.setHorizontalAlignment(JTextField.RIGHT);
523: panel.add(delayTablesTextField, c);
524: }
525:
526: private void addDelayRecordsLabel(JPanel panel, int col, int row) {
527: GridBagConstraints c = new GridBagConstraints();
528: c.gridx = col;
529: c.gridy = row;
530: c.insets = new Insets(5, 25, 0, 0);
531: String label = s_stringMgr
532: .getString("PreferencesPanel.delayRecordsLabel");
533: delayRecordsLabel = new JLabel(label);
534: delayRecordsLabel.setHorizontalAlignment(JLabel.LEFT);
535: panel.add(delayRecordsLabel, c);
536: }
537:
538: private void addDelayRecordsTextField(JPanel panel, int col, int row) {
539: GridBagConstraints c = new GridBagConstraints();
540: c.gridx = col;
541: c.gridy = row;
542: c.ipadx = 40; // Increases component width by 40 pixels
543: c.insets = new Insets(5, 5, 0, 0);
544: c.anchor = GridBagConstraints.WEST;
545: delayRecordsTextField = new JTextField(10);
546:
547: delayRecordsTextField.setHorizontalAlignment(JTextField.RIGHT);
548: panel.add(delayRecordsTextField, c);
549: }
550:
551: private JPanel createBottomPanel() {
552: JPanel result = new JPanel(new GridBagLayout());
553:
554: //i18n[PreferencesPanel.colTypeMappingBorderLabel=Column Type Mapping]
555: String colTypeMappingBorderLabel = s_stringMgr
556: .getString("PreferencesPanel.colTypeMappingBorderLabel");
557:
558: result.setBorder(getTitledBorder(colTypeMappingBorderLabel));
559:
560: addPromptForHibernateCheckBox(result, 0, 0);
561:
562: addCheckKeywordsCheckBox(result, 0, 1);
563:
564: addTestColumnNamesCheckBox(result, 0, 2);
565:
566: return result;
567: }
568:
569: private void addPromptForHibernateCheckBox(JPanel panel, int col,
570: int row) {
571: GridBagConstraints c = new GridBagConstraints();
572: c.gridx = col;
573: c.gridy = row;
574: c.anchor = GridBagConstraints.WEST;
575: String cbLabelStr = s_stringMgr
576: .getString("PreferencesPanel.promptForHibernate");
577: String cbToolTipText = s_stringMgr
578: .getString("PreferencesPanel.promptForHibernateToolTip");
579: promptForHibernateCheckBox = new JCheckBox(cbLabelStr);
580: promptForHibernateCheckBox.setToolTipText(cbToolTipText);
581: panel.add(promptForHibernateCheckBox, c);
582: }
583:
584: private void addCheckKeywordsCheckBox(JPanel panel, int col, int row) {
585: GridBagConstraints c = new GridBagConstraints();
586: c.gridx = col;
587: c.gridy = row;
588: c.anchor = GridBagConstraints.WEST;
589: String cbLabelStr = s_stringMgr
590: .getString("PreferencesPanel.checkKeywords");
591: String cbToolTipText = s_stringMgr
592: .getString("PreferencesPanel.checkKeywordsToolTip");
593:
594: checkKeywordsCheckBox = new JCheckBox(cbLabelStr);
595: checkKeywordsCheckBox.setToolTipText(cbToolTipText);
596: panel.add(checkKeywordsCheckBox, c);
597: }
598:
599: private void addTestColumnNamesCheckBox(JPanel panel, int col,
600: int row) {
601: GridBagConstraints c = new GridBagConstraints();
602: c.gridx = col;
603: c.gridy = row;
604: c.anchor = GridBagConstraints.WEST;
605: String cbLabelStr = s_stringMgr
606: .getString("PreferencesPanel.testColumnNames");
607: String cbToolTipText = s_stringMgr
608: .getString("PreferencesPanel.testColumnNamesToolTip");
609: testColumnNamesCheckBox = new JCheckBox(cbLabelStr);
610: testColumnNamesCheckBox.setToolTipText(cbToolTipText);
611: panel.add(testColumnNamesCheckBox, c);
612: }
613:
614: private Border getTitledBorder(String title) {
615: CompoundBorder border = new CompoundBorder(new EmptyBorder(10,
616: 10, 10, 10), new TitledBorder(title));
617: return border;
618: }
619:
620: private void loadData() {
621: fileCachingCheckBox.setSelected(_prefs.isUseFileCaching());
622: bufferSizeTextField.setText(""
623: + _prefs.getFileCacheBufferSize());
624: commitRecordCountTextField
625: .setText("" + _prefs.getCommitCount());
626: autoCommitCheckBox.setSelected(_prefs.isAutoCommitEnabled());
627: if (_prefs.isUseFileCaching()) {
628: bufferSizeLabel.setEnabled(true);
629: bufferSizeTextField.setEnabled(true);
630: } else {
631: bufferSizeLabel.setEnabled(false);
632: bufferSizeTextField.setEnabled(false);
633: }
634: if (_prefs.isAutoCommitEnabled()) {
635: commitRecordCountLabel.setEnabled(false);
636: commitRecordCountTextField.setEnabled(false);
637: commitAfterCreateTableCheckBox.setEnabled(false);
638: } else {
639: commitRecordCountLabel.setEnabled(true);
640: commitRecordCountTextField.setEnabled(true);
641: commitAfterCreateTableCheckBox.setEnabled(true);
642: }
643: truncateCheckBox.setSelected(_prefs.isUseTruncate());
644: copyTableRecords.setSelected(_prefs.isCopyData());
645: selectFetchSizeLabel.setEnabled(_prefs.isCopyData());
646: selectFetchSizeTextField.setEnabled(_prefs.isCopyData());
647: selectFetchSizeTextField.setText(""
648: + _prefs.getSelectFetchSize());
649: copyIndexDefs.setSelected(_prefs.isCopyIndexDefs());
650: copyForeignKeys.setSelected(_prefs.isCopyForeignKeys());
651: copyPrimaryKeys.setSelected(_prefs.isCopyPrimaryKeys());
652: writeScriptCheckBox.setSelected(_prefs.isWriteScript());
653: pruneDuplicateIndexDefs.setSelected(_prefs
654: .isPruneDuplicateIndexDefs());
655: commitAfterCreateTableCheckBox.setSelected(_prefs
656: .isCommitAfterTableDefs());
657: promptForHibernateCheckBox.setSelected(_prefs
658: .isPromptForDialect());
659: checkKeywordsCheckBox.setSelected(_prefs.isCheckKeywords());
660: testColumnNamesCheckBox.setSelected(_prefs.isTestColumnNames());
661: delayTablesTextField.setText("" + _prefs.getTableDelayMillis());
662: delayRecordsTextField.setText(""
663: + _prefs.getRecordDelayMillis());
664: delayTablesTextField.setEnabled(_prefs.isDelayBetweenObjects());
665: delayRecordsTextField
666: .setEnabled(_prefs.isDelayBetweenObjects());
667: delayBetweenObjects.setSelected(_prefs.isDelayBetweenObjects());
668: delayTablesLabel.setEnabled(_prefs.isDelayBetweenObjects());
669: delayRecordsLabel.setEnabled(_prefs.isDelayBetweenObjects());
670: }
671:
672: private void save() {
673: _prefs.setUseFileCaching(fileCachingCheckBox.isSelected());
674: _prefs.setUseTruncate(truncateCheckBox.isSelected());
675: _prefs.setCopyData(copyTableRecords.isSelected());
676: _prefs.setCopyIndexDefs(copyIndexDefs.isSelected());
677: _prefs.setAutoCommitEnabled(autoCommitCheckBox.isSelected());
678: _prefs.setCopyForeignKeys(copyForeignKeys.isSelected());
679: _prefs.setCopyPrimaryKeys(copyPrimaryKeys.isSelected());
680: _prefs.setWriteScript(writeScriptCheckBox.isSelected());
681: _prefs.setPruneDuplicateIndexDefs(pruneDuplicateIndexDefs
682: .isSelected());
683: _prefs.setCommitAfterTableDefs(commitAfterCreateTableCheckBox
684: .isSelected());
685: _prefs.setPromptForDialect(promptForHibernateCheckBox
686: .isSelected());
687: _prefs.setCheckKeywords(checkKeywordsCheckBox.isSelected());
688: _prefs.setTestColumnNames(testColumnNamesCheckBox.isSelected());
689: _prefs.setDelayBetweenObjects(delayBetweenObjects.isSelected());
690: try {
691: String value = bufferSizeTextField.getText();
692: _prefs.setFileCacheBufferSize(Integer.parseInt(value));
693: } catch (Exception e) {
694: // Do nothing.
695: }
696: try {
697: String value = commitRecordCountTextField.getText();
698: _prefs.setCommitCount(Integer.parseInt(value));
699: } catch (Exception e) {
700: // Do nothing.
701: }
702: try {
703: String value = selectFetchSizeTextField.getText();
704: _prefs.setSelectFetchSize(Integer.parseInt(value));
705: } catch (Exception e) {
706: // Do nothing.
707: }
708: try {
709: String value = delayRecordsTextField.getText();
710: _prefs.setRecordDelayMillis(Long.parseLong(value));
711: } catch (Exception e) {
712: // Do nothing.
713: }
714: try {
715: String value = delayTablesTextField.getText();
716: _prefs.setTableDelayMillis(Long.parseLong(value));
717: } catch (Exception e) {
718: // Do nothing.
719: }
720: PreferencesManager.savePrefs();
721: }
722:
723: /* (non-Javadoc)
724: * @see net.sourceforge.squirrel_sql.client.util.IOptionPanel#applyChanges()
725: */
726: public void applyChanges() {
727: save();
728: }
729:
730: /* (non-Javadoc)
731: * @see net.sourceforge.squirrel_sql.client.util.IOptionPanel#getPanelComponent()
732: */
733: public Component getPanelComponent() {
734: return this;
735: }
736: }
|