Source Code Cross Referenced for ColumnDetailDialog.java in  » Database-Client » squirrel-sql-2.6.5a » net » sourceforge » squirrel_sql » client » gui » db » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database Client » squirrel sql 2.6.5a » net.sourceforge.squirrel_sql.client.gui.db 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (C) 2006 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:
020:        package net.sourceforge.squirrel_sql.client.gui.db;
021:
022:        import java.awt.BorderLayout;
023:        import java.awt.Color;
024:        import java.awt.Container;
025:        import java.awt.Dimension;
026:        import java.awt.GridBagConstraints;
027:        import java.awt.GridBagLayout;
028:        import java.awt.Insets;
029:        import java.awt.event.ActionEvent;
030:        import java.awt.event.ActionListener;
031:        import java.awt.event.ComponentEvent;
032:        import java.awt.event.ComponentListener;
033:        import java.awt.event.ItemEvent;
034:        import java.awt.event.ItemListener;
035:        import java.awt.event.KeyAdapter;
036:        import java.awt.event.KeyEvent;
037:        import java.sql.DatabaseMetaData;
038:
039:        import javax.swing.JButton;
040:        import javax.swing.JCheckBox;
041:        import javax.swing.JComboBox;
042:        import javax.swing.JDialog;
043:        import javax.swing.JLabel;
044:        import javax.swing.JPanel;
045:        import javax.swing.JScrollPane;
046:        import javax.swing.JSpinner;
047:        import javax.swing.JTextArea;
048:        import javax.swing.JTextField;
049:        import javax.swing.SpinnerNumberModel;
050:        import javax.swing.SwingConstants;
051:        import javax.swing.border.Border;
052:        import javax.swing.border.EmptyBorder;
053:        import javax.swing.border.LineBorder;
054:
055:        import net.sourceforge.squirrel_sql.client.ApplicationArguments;
056:        import net.sourceforge.squirrel_sql.fw.dialects.DialectFactory;
057:        import net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect;
058:        import net.sourceforge.squirrel_sql.fw.sql.JDBCTypeMapper;
059:        import net.sourceforge.squirrel_sql.fw.sql.TableColumnInfo;
060:        import net.sourceforge.squirrel_sql.fw.util.StringManager;
061:        import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
062:
063:        /**
064:         * A dialog that can be used to get column info from the user for adding new 
065:         * columns or modifying existing ones.
066:         */
067:        public class ColumnDetailDialog extends JDialog {
068:
069:            private static final long serialVersionUID = 1L;
070:
071:            /** Internationalized strings for this class. */
072:            private static final StringManager s_stringMgr = StringManagerFactory
073:                    .getStringManager(ColumnDetailDialog.class);
074:
075:            private JLabel tableNameLabel = null;
076:            private JTextField tableNameTextField = null;
077:            private JLabel columnNameLabel = null;
078:            private JTextField columnNameTextField = null;
079:            private JLabel dialectLabel = null;
080:            private JComboBox dialectList = null;
081:            private JLabel typeLabel = null;
082:            private JComboBox typeList = null;
083:            private JLabel lengthLabel = null;
084:            private JSpinner lengthSpinner = null;
085:            private JLabel precisionLabel = null;
086:            private JSpinner precisionSpinner = null;
087:            private JLabel scaleLabel = null;
088:            private JSpinner scaleSpinner = null;
089:            private JLabel defaultLabel = null;
090:            private JTextField defaultTextField = null;
091:            private JLabel commentLabel = null;
092:            private JTextArea commentTextArea = null;
093:            private JLabel nullableLabel = null;
094:            private JCheckBox nullableCheckBox = null;
095:
096:            private JButton executeButton = null;
097:            private JButton editSQLButton = null;
098:            private JButton showSQLButton = null;
099:            private JButton cancelButton = null;
100:
101:            public static final int ADD_MODE = 0;
102:            public static final int MODIFY_MODE = 1;
103:
104:            private int _mode = ADD_MODE;
105:
106:            private interface i18n {
107:                //i18n[ColumnDetailsDialog.editButtonLabel=Edit SQL]        
108:                String EDIT_BUTTON_LABEL = s_stringMgr
109:                        .getString("ColumnDetailsDialog.editButtonLabel");
110:                //i18n[ColumnDetailsDialog.executeButtonLabel=Execute]
111:                String EXECUTE_BUTTON_LABEL = s_stringMgr
112:                        .getString("ColumnDetailsDialog.executeButtonLabel");
113:                //i18n[ColumnDetailsDialog.addColumnTitle=Add Column]
114:                String ADD_COLUMN_TITLE = s_stringMgr
115:                        .getString("ColumnDetailsDialog.addColumnTitle");
116:                //i18n[ColumnDetailsDialog.modifyColumnTitle=Modify Column]
117:                String MODIFY_COLUMN_TITLE = s_stringMgr
118:                        .getString("ColumnDetailsDialog.modifyColumnTitle");
119:                //i18n[ColumnDetailsDialog.cancelButtonLabel=Cancel]
120:                String CANCEL_BUTTON_LABEL = s_stringMgr
121:                        .getString("ColumnDetailsDialog.cancelButtonLabel");
122:                //i18n[ColumnDetailsDialog.columnNameLabel=Column Name: ]
123:                String COLUMN_NAME_LABEL = s_stringMgr
124:                        .getString("ColumnDetailsDialog.columnNameLabel");
125:                //i18n[ColumnDetailsDialog.commentLabel=Comment: ]        
126:                String COMMENT_LABEL = s_stringMgr
127:                        .getString("ColumnDetailsDialog.commentLabel");
128:                //i18n[ColumnDetailsDialog.defaultValueLabel=Default Value: ]
129:                String DEFAULT_VALUE_LABEL = s_stringMgr
130:                        .getString("ColumnDetailsDialog.defaultValueLabel");
131:                //i18n[ColumnDetailsDialog.dialectLabel=Dialect: ]
132:                String DIALECT_LABEL = s_stringMgr
133:                        .getString("ColumnDetailsDialog.dialectLabel");
134:                //i18n[ColumnDetailsDialog.lengthLabel=Length: ]
135:                String LENGTH_LABEL = s_stringMgr
136:                        .getString("ColumnDetailsDialog.lengthLabel");
137:                //i18n[ColumnDetailsDialog.modifyColumnTitle=Modify Column]
138:                String MODIFY_TITLE = s_stringMgr
139:                        .getString("ColumnDetailsDialog.modifyColumnTitle");
140:                //i18n[ColumnDetailsDialog.nullableLabel=Nullable: ]
141:                String NULLABLE_LABEL = s_stringMgr
142:                        .getString("ColumnDetailsDialog.nullableLabel");
143:                //i18n[ColumnDetailsDialog.newColumnValue=NewColumn]
144:                String NEW_COLUMN_VALUE = s_stringMgr
145:                        .getString("ColumnDetailsDialog.newColumnValue");
146:                //i18n[ColumnDetailsDialog.precisionLabel=Precision: ]
147:                String PRECISION_LABEL = s_stringMgr
148:                        .getString("ColumnDetailsDialog.precisionLabel");
149:                //i18n[ColumnDetailsDialog.scaleLabel=Scale: ]
150:                String SCALE_LABEL = s_stringMgr
151:                        .getString("ColumnDetailsDialog.scaleLabel");
152:                //i18n[ColumnDetailsDialog.showButtonLabel=Show SQL]
153:                String SHOW_BUTTON_LABEL = s_stringMgr
154:                        .getString("ColumnDetailsDialog.showButtonLabel");
155:                //i18n[ColumnDetailsDialog.tableNameLabel=Table Name: ]
156:                String TABLE_NAME_LABEL = s_stringMgr
157:                        .getString("ColumnDetailsDialog.tableNameLabel");
158:                //i18n[ColumnDetailsDialog.typeLabel=Type: ]
159:                String TYPE_LABEL = s_stringMgr
160:                        .getString("ColumnDetailsDialog.typeLabel");
161:            }
162:
163:            /**
164:             * 
165:             * @param tableName
166:             */
167:            public ColumnDetailDialog(int mode) {
168:                setMode(mode);
169:                init();
170:            }
171:
172:            public void setMode(int mode) {
173:                if (mode != ADD_MODE && mode != MODIFY_MODE) {
174:                    throw new IllegalArgumentException("Invalid mode - " + mode);
175:                }
176:                _mode = mode;
177:            }
178:
179:            /**
180:             * 
181:             * @param dbName
182:             */
183:            public void setSelectedDialect(String dbName) {
184:                dialectList.setSelectedItem(dbName);
185:            }
186:
187:            public String getSelectedDBName() {
188:                return (String) dialectList.getSelectedItem();
189:            }
190:
191:            public void setTableName(String tableName) {
192:                tableNameTextField.setText(tableName);
193:            }
194:
195:            public String getTableName() {
196:                return tableNameTextField.getText();
197:            }
198:
199:            public void setExistingColumnInfo(TableColumnInfo info) {
200:                tableNameTextField.setText(info.getTableName());
201:                columnNameTextField.setText(info.getColumnName());
202:                String dataType = JDBCTypeMapper.getJdbcTypeName(info
203:                        .getDataType());
204:                typeList.setSelectedItem(dataType);
205:                nullableCheckBox.setSelected(info.isNullable().equals("YES"));
206:
207:                if (JDBCTypeMapper.isNumberType(info.getDataType())) {
208:                    precisionSpinner.setValue(Integer.valueOf(info
209:                            .getColumnSize()));
210:                } else {
211:                    lengthSpinner.setValue(Integer
212:                            .valueOf(info.getColumnSize()));
213:                }
214:                commentTextArea.setText(info.getRemarks());
215:                defaultTextField.setText(info.getDefaultValue());
216:            }
217:
218:            public String getSelectedTypeName() {
219:                return (String) typeList.getSelectedItem();
220:            }
221:
222:            /**
223:             * Returns a TableColumnInfo representation of the user's settings for the
224:             * column.
225:             *  
226:             * @return 
227:             */
228:            public TableColumnInfo getColumnInfo() {
229:                String tableName = tableNameTextField.getText();
230:                String columnName = columnNameTextField.getText();
231:                String typeName = (String) typeList.getSelectedItem();
232:                int dataType = JDBCTypeMapper.getJdbcType(typeName);
233:
234:                SpinnerNumberModel sizeModel = null;
235:                if (JDBCTypeMapper.isNumberType(dataType)) {
236:                    sizeModel = (SpinnerNumberModel) precisionSpinner
237:                            .getModel();
238:                } else {
239:                    sizeModel = (SpinnerNumberModel) lengthSpinner.getModel();
240:                }
241:                int columnSize = sizeModel.getNumber().intValue();
242:                SpinnerNumberModel scaleModel = (SpinnerNumberModel) scaleSpinner
243:                        .getModel();
244:                int decimalDigits = scaleModel.getNumber().intValue();
245:
246:                int isNullAllowed = 1;
247:                String isNullable = null;
248:                if (nullableCheckBox.isSelected()) {
249:                    isNullAllowed = DatabaseMetaData.columnNullable;
250:                    isNullable = "YES";
251:                } else {
252:                    isNullAllowed = DatabaseMetaData.columnNoNulls;
253:                    isNullable = "NO";
254:                }
255:                String remarks = null;
256:                if (commentTextArea.isEditable()) {
257:                    remarks = commentTextArea.getText();
258:                }
259:                String defaultValue = defaultTextField.getText();
260:                // TODO Maybe we should have a checkbox to allow the user to toggle 
261:                // default value on/off.  Some dbs (like DB2) treat empty string "" as
262:                // a different default value than null.
263:                if ("".equals(defaultValue)) {
264:                    defaultValue = null;
265:                }
266:
267:                // These are not used
268:                String catalog = null;
269:                String schema = null;
270:                int octetLength = 1;
271:                int ordinalPosition = 1;
272:                int radix = 1;
273:
274:                TableColumnInfo result = new TableColumnInfo(catalog, schema,
275:                        tableName, columnName, dataType, typeName, columnSize,
276:                        decimalDigits, radix, isNullAllowed, remarks,
277:                        defaultValue, octetLength, ordinalPosition, isNullable);
278:                return result;
279:            }
280:
281:            public void addExecuteListener(ActionListener listener) {
282:                executeButton.addActionListener(listener);
283:            }
284:
285:            public void addEditSQLListener(ActionListener listener) {
286:                editSQLButton.addActionListener(listener);
287:            }
288:
289:            public void addShowSQLListener(ActionListener listener) {
290:                showSQLButton.addActionListener(listener);
291:            }
292:
293:            public void addDialectListListener(ItemListener listener) {
294:                dialectList.addItemListener(listener);
295:            }
296:
297:            public void setVisible(boolean visible) {
298:                super .setVisible(visible);
299:                columnNameTextField.requestFocus();
300:                columnNameTextField.select(0, columnNameTextField.getText()
301:                        .length());
302:            }
303:
304:            private GridBagConstraints getLabelConstraints(GridBagConstraints c) {
305:                c.gridx = 0;
306:                c.gridy++;
307:                c.anchor = GridBagConstraints.EAST;
308:                c.fill = GridBagConstraints.NONE;
309:                c.weightx = 0;
310:                c.weighty = 0;
311:                return c;
312:            }
313:
314:            private GridBagConstraints getFieldConstraints(GridBagConstraints c) {
315:                c.gridx++;
316:                c.anchor = GridBagConstraints.WEST;
317:                c.weightx = 1;
318:                c.weighty = 1;
319:                c.fill = GridBagConstraints.HORIZONTAL;
320:                return c;
321:            }
322:
323:            private JLabel getBorderedLabel(String text, Border border) {
324:                JLabel result = new JLabel(text);
325:                result.setBorder(border);
326:                result.setPreferredSize(new Dimension(115, 20));
327:                result.setHorizontalAlignment(SwingConstants.RIGHT);
328:                return result;
329:            }
330:
331:            private JTextField getSizedTextField(Dimension mediumField) {
332:                JTextField result = new JTextField();
333:                result.setPreferredSize(mediumField);
334:                return result;
335:            }
336:
337:            /**
338:             * Creates the UI for this dialog.
339:             */
340:            private void init() {
341:                super .setModal(true);
342:                if (_mode == ADD_MODE) {
343:                    setTitle(i18n.ADD_COLUMN_TITLE);
344:                } else {
345:                    setTitle(i18n.MODIFY_COLUMN_TITLE);
346:                }
347:
348:                setSize(375, 400);
349:                EmptyBorder border = new EmptyBorder(new Insets(5, 5, 5, 5));
350:                Dimension mediumField = new Dimension(126, 20);
351:                Dimension largeField = new Dimension(126, 60);
352:
353:                JPanel pane = new JPanel();
354:                pane.setLayout(new GridBagLayout());
355:                pane.setBorder(new EmptyBorder(0, 0, 0, 10));
356:
357:                GridBagConstraints c = new GridBagConstraints();
358:                c.gridx = 0;
359:                c.gridy = -1;
360:
361:                // Table name
362:                tableNameLabel = getBorderedLabel(i18n.TABLE_NAME_LABEL, border);
363:                pane.add(tableNameLabel, getLabelConstraints(c));
364:
365:                tableNameTextField = new JTextField();
366:                tableNameTextField.setPreferredSize(mediumField);
367:                tableNameTextField.setEditable(false);
368:                pane.add(tableNameTextField, getFieldConstraints(c));
369:
370:                // Column name
371:                columnNameLabel = getBorderedLabel(i18n.COLUMN_NAME_LABEL,
372:                        border);
373:                pane.add(columnNameLabel, getLabelConstraints(c));
374:
375:                columnNameTextField = getSizedTextField(mediumField);
376:                columnNameTextField.setText(i18n.NEW_COLUMN_VALUE);
377:                columnNameTextField.addKeyListener(new KeyAdapter() {
378:                    public void keyTyped(KeyEvent e) {
379:                        if (columnNameTextField.getText().length() == 0) {
380:                            executeButton.setEnabled(false);
381:                            showSQLButton.setEnabled(false);
382:                        } else {
383:                            executeButton.setEnabled(true);
384:                            showSQLButton.setEnabled(true);
385:                        }
386:                    }
387:                });
388:                pane.add(columnNameTextField, getFieldConstraints(c));
389:
390:                // Dialect list
391:                dialectLabel = getBorderedLabel(i18n.DIALECT_LABEL, border);
392:                pane.add(dialectLabel, getLabelConstraints(c));
393:
394:                Object[] dbNames = DialectFactory.getDbNames();
395:                dialectList = new JComboBox(dbNames);
396:                dialectList.setPreferredSize(mediumField);
397:                dialectList.addItemListener(new DialectTypeListListener());
398:                pane.add(dialectList, getFieldConstraints(c));
399:
400:                // Type list
401:                typeLabel = getBorderedLabel(i18n.TYPE_LABEL, border);
402:                pane.add(typeLabel, getLabelConstraints(c));
403:
404:                String[] jdbcTypes = JDBCTypeMapper.getJdbcTypeList();
405:                typeList = new JComboBox(jdbcTypes);
406:                typeList.addItemListener(new ColumnTypeListListener());
407:                typeList.setPreferredSize(mediumField);
408:                pane.add(typeList, getFieldConstraints(c));
409:
410:                // Length
411:                lengthLabel = getBorderedLabel(i18n.LENGTH_LABEL, border);
412:                pane.add(lengthLabel, getLabelConstraints(c));
413:
414:                lengthSpinner = new JSpinner();
415:                lengthSpinner.setPreferredSize(mediumField);
416:                double value = 10;
417:                double min = 1;
418:                double max = Long.MAX_VALUE;
419:                double step = 1;
420:                SpinnerNumberModel model = new SpinnerNumberModel(value, min,
421:                        max, step);
422:                lengthSpinner.setModel(model);
423:                lengthSpinner.setPreferredSize(mediumField);
424:                pane.add(lengthSpinner, getFieldConstraints(c));
425:
426:                precisionLabel = new JLabel(i18n.PRECISION_LABEL);
427:                precisionLabel.setBorder(border);
428:                pane.add(precisionLabel, getLabelConstraints(c));
429:
430:                // Precision
431:                precisionSpinner = new JSpinner();
432:                precisionSpinner.setPreferredSize(mediumField);
433:                value = 8;
434:                min = 0;
435:                max = Long.MAX_VALUE;
436:                step = 1;
437:                SpinnerNumberModel precisionModel = new SpinnerNumberModel(
438:                        value, min, max, step);
439:                precisionSpinner.setModel(precisionModel);
440:                precisionSpinner.setPreferredSize(mediumField);
441:                pane.add(precisionSpinner, getFieldConstraints(c));
442:
443:                // Scale
444:                scaleLabel = new JLabel(i18n.SCALE_LABEL);
445:                scaleLabel.setBorder(border);
446:                pane.add(scaleLabel, getLabelConstraints(c));
447:
448:                scaleSpinner = new JSpinner();
449:                scaleSpinner.setPreferredSize(mediumField);
450:                value = 8;
451:                min = 0;
452:                max = Long.MAX_VALUE;
453:                step = 1;
454:                SpinnerNumberModel scaleModel = new SpinnerNumberModel(value,
455:                        min, max, step);
456:                scaleSpinner.setModel(scaleModel);
457:                scaleSpinner.setPreferredSize(mediumField);
458:                pane.add(scaleSpinner, getFieldConstraints(c));
459:
460:                // Default value
461:                defaultLabel = new JLabel(i18n.DEFAULT_VALUE_LABEL);
462:                defaultLabel.setBorder(border);
463:                pane.add(defaultLabel, getLabelConstraints(c));
464:
465:                defaultTextField = new JTextField();
466:                defaultTextField.setPreferredSize(mediumField);
467:                pane.add(defaultTextField, getFieldConstraints(c));
468:
469:                // Nullable
470:                nullableLabel = new JLabel(i18n.NULLABLE_LABEL);
471:                nullableLabel.setBorder(border);
472:                pane.add(nullableLabel, getLabelConstraints(c));
473:
474:                nullableCheckBox = new JCheckBox("");
475:                nullableCheckBox.setSelected(true);
476:                pane.add(nullableCheckBox, getFieldConstraints(c));
477:
478:                // Comment
479:                commentLabel = new JLabel(i18n.COMMENT_LABEL);
480:                commentLabel.setBorder(border);
481:                pane.add(commentLabel, getLabelConstraints(c));
482:
483:                commentTextArea = new JTextArea();
484:                commentTextArea.setBorder(new LineBorder(Color.DARK_GRAY, 1));
485:                commentTextArea.setLineWrap(true);
486:                c = getFieldConstraints(c);
487:                c.weightx = 2;
488:                c.weighty = 2;
489:                c.fill = GridBagConstraints.BOTH;
490:                JScrollPane scrollPane = new JScrollPane();
491:                scrollPane.getViewport().add(commentTextArea);
492:                scrollPane.setPreferredSize(largeField);
493:                pane.add(scrollPane, c);
494:
495:                Container contentPane = super .getContentPane();
496:                contentPane.setLayout(new BorderLayout());
497:                contentPane.add(pane, BorderLayout.CENTER);
498:
499:                contentPane.add(getButtonPanel(), BorderLayout.SOUTH);
500:
501:            }
502:
503:            private JPanel getButtonPanel() {
504:                JPanel result = new JPanel();
505:                executeButton = new JButton(i18n.EXECUTE_BUTTON_LABEL);
506:
507:                editSQLButton = new JButton(i18n.EDIT_BUTTON_LABEL);
508:                showSQLButton = new JButton(i18n.SHOW_BUTTON_LABEL);
509:                cancelButton = new JButton(i18n.CANCEL_BUTTON_LABEL);
510:                cancelButton.addActionListener(new ActionListener() {
511:                    public void actionPerformed(ActionEvent e) {
512:                        setVisible(false);
513:                    }
514:                });
515:                result.add(executeButton);
516:                result.add(editSQLButton);
517:                result.add(showSQLButton);
518:                result.add(cancelButton);
519:                return result;
520:            }
521:
522:            /**
523:             * @param args
524:             */
525:            public static void main(String[] args) {
526:                ApplicationArguments.initialize(new String[] {});
527:                final ColumnDetailDialog c = new ColumnDetailDialog(ADD_MODE);
528:                c.setTableName("FooTable");
529:                c.addComponentListener(new ComponentListener() {
530:                    public void componentHidden(ComponentEvent e) {
531:                    }
532:
533:                    public void componentMoved(ComponentEvent e) {
534:                    }
535:
536:                    public void componentResized(ComponentEvent e) {
537:                        System.out.println("Current size = " + c.getSize());
538:                    }
539:
540:                    public void componentShown(ComponentEvent e) {
541:                    }
542:                });
543:                c.cancelButton.addActionListener(new ActionListener() {
544:                    public void actionPerformed(ActionEvent e) {
545:                        System.exit(1);
546:                    }
547:                });
548:                c.setVisible(true);
549:
550:            }
551:
552:            private class ColumnTypeListListener implements  ItemListener {
553:
554:                public void itemStateChanged(ItemEvent e) {
555:                    if (precisionSpinner == null) {
556:                        return;
557:                    }
558:                    String columnType = (String) typeList.getSelectedItem();
559:                    int jdbcType = JDBCTypeMapper.getJdbcType(columnType);
560:                    if (JDBCTypeMapper.isNumberType(jdbcType)) {
561:                        precisionSpinner.setEnabled(true);
562:                        scaleSpinner.setEnabled(true);
563:                        lengthSpinner.setEnabled(false);
564:                    } else {
565:                        if (JDBCTypeMapper.isDateType(jdbcType)) {
566:                            precisionSpinner.setEnabled(false);
567:                            scaleSpinner.setEnabled(false);
568:                            lengthSpinner.setEnabled(false);
569:                        } else {
570:                            precisionSpinner.setEnabled(false);
571:                            scaleSpinner.setEnabled(false);
572:                            lengthSpinner.setEnabled(true);
573:                        }
574:                    }
575:                }
576:
577:            }
578:
579:            private class DialectTypeListListener implements  ItemListener {
580:
581:                public void itemStateChanged(ItemEvent e) {
582:                    String dbName = (String) dialectList.getSelectedItem();
583:                    HibernateDialect dialect = DialectFactory
584:                            .getDialect(dbName);
585:                    if (!dialect.supportsColumnComment()) {
586:                        commentTextArea.setEditable(false);
587:                        //i18n[ColumnDetailsDialog.columnCommentLabel={0} does not 
588:                        //support column comments]
589:                        String noColumnSupportMsg = s_stringMgr.getString(
590:                                "ColumnDetailsDialog.columnCommentToolTip",
591:                                dbName);
592:                        commentTextArea.setToolTipText(noColumnSupportMsg);
593:                    } else {
594:                        commentTextArea.setEditable(true);
595:                        commentTextArea.setToolTipText(null);
596:                    }
597:                    if (_mode == MODIFY_MODE) {
598:                        if (!dialect.supportsAlterColumnNull()) {
599:                            nullableCheckBox.setEnabled(false);
600:                            //i18n[ColumnDetailsDialog.columnNullLabel={0} does not 
601:                            //support altering column nullability]
602:                            String noColumnSupportMsg = s_stringMgr.getString(
603:                                    "ColumnDetailsDialog.columnNullToolTip",
604:                                    dbName);
605:                            nullableCheckBox.setToolTipText(noColumnSupportMsg);
606:                        } else {
607:                            nullableCheckBox.setEnabled(true);
608:                            nullableCheckBox.setToolTipText(null);
609:                        }
610:                        if (!dialect.supportsRenameColumn()) {
611:                            //i18n[ColumnDetailsDialog.columnNameTootTip={0} does not 
612:                            //support altering column name]
613:                            String noColNameChange = s_stringMgr.getString(
614:                                    "ColumnDetailsDialog.columnNameTootTip",
615:                                    dbName);
616:                            columnNameTextField.setEditable(false);
617:                            columnNameTextField.setToolTipText(noColNameChange);
618:                        } else {
619:                            columnNameTextField.setEditable(true);
620:                            columnNameTextField.setToolTipText(null);
621:                        }
622:                        if (!dialect.supportsAlterColumnType()) {
623:                            //i18n[ColumnDetailsDialog.columnTypeTootTip={0} does not 
624:                            //support altering column type]     
625:                            String noColTypeChange = s_stringMgr.getString(
626:                                    "ColumnDetailsDialog.columnTypeTootTip",
627:                                    dbName);
628:                            typeList.setEnabled(false);
629:                            typeList.setToolTipText(noColTypeChange);
630:                            precisionSpinner.setEnabled(false);
631:                            precisionSpinner.setToolTipText(noColTypeChange);
632:                            lengthSpinner.setEnabled(false);
633:                            lengthSpinner.setToolTipText(noColTypeChange);
634:                            scaleSpinner.setEnabled(false);
635:                            scaleSpinner.setToolTipText(noColTypeChange);
636:                        } else {
637:                            typeList.setEnabled(true);
638:                            typeList.setToolTipText(null);
639:                            precisionSpinner.setToolTipText(null);
640:                            lengthSpinner.setToolTipText(null);
641:                            scaleSpinner.setToolTipText(null);
642:                        }
643:                    }
644:                }
645:            }
646:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.