Source Code Cross Referenced for ErdEditTableDialog.java in  » Database-Client » executequery » org » executequery » gui » erd » 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 » executequery » org.executequery.gui.erd 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * ErdEditTableDialog.java
003:         *
004:         * Copyright (C) 2002, 2003, 2004, 2005, 2006 Takis Diakoumis
005:         *
006:         * This program is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU General Public License
008:         * as published by the Free Software Foundation; either version 2
009:         * of the License, or any later version.
010:         *
011:         * This program is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014:         * GNU General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU General Public License
017:         * along with this program; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
019:         *
020:         */
021:
022:        package org.executequery.gui.erd;
023:
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.FocusEvent;
032:        import java.awt.event.FocusListener;
033:
034:        import java.util.Vector;
035:
036:        import javax.swing.BorderFactory;
037:        import javax.swing.JButton;
038:        import javax.swing.JDialog;
039:        import javax.swing.JLabel;
040:        import javax.swing.JPanel;
041:        import javax.swing.*;
042:        import javax.swing.JTable;
043:        import javax.swing.event.ChangeEvent;
044:        import javax.swing.event.ChangeListener;
045:        import org.executequery.Constants;
046:        import org.executequery.databasemediators.MetaDataValues;
047:
048:        import org.executequery.gui.table.*;
049:        import org.executequery.gui.browser.ColumnConstraint;
050:        import org.executequery.gui.browser.ColumnData;
051:        import org.underworldlabs.swing.table.ComboBoxCellEditor;
052:        import org.underworldlabs.swing.DisabledField;
053:
054:        /* ----------------------------------------------------------
055:         * CVS NOTE: Changes to the CVS repository prior to the 
056:         *           release of version 3.0.0beta1 has meant a 
057:         *           resetting of CVS revision numbers.
058:         * ----------------------------------------------------------
059:         */
060:
061:        /**
062:         *
063:         * @author   Takis Diakoumis
064:         * @version  $Revision: 1.4 $
065:         * @date     $Date: 2006/05/14 06:56:52 $
066:         */
067:        public class ErdEditTableDialog extends ErdPrintableDialog implements 
068:                TableFunction, TableConstraintFunction {
069:
070:            /** The ERD parent panel */
071:            private ErdViewerPanel parent;
072:
073:            /** The <code>ErdTable</code> representing this dialog */
074:            private ErdTable erdTable;
075:
076:            /** Contains the column descriptions for a selected table */
077:            private EditTablePanel columnDataTable;
078:
079:            /** The panel displaying the table's constraints */
080:            private EditErdTableConstraintsPanel conPanel;
081:
082:            /** The table name field (non-editable) */
083:            private DisabledField tableNameField;
084:
085:            /** The buffer off all SQL generated */
086:            private StringBuffer sqlBuffer;
087:
088:            /** The table currently in focus */
089:            private JTable focusTable;
090:
091:            /** The tool bar */
092:            private CreateTableToolBar tools;
093:
094:            /** The tabbed pane display */
095:            private JTabbedPane tabs;
096:
097:            public ErdEditTableDialog(ErdViewerPanel parent, ErdTable erdTable) {
098:                super ("Table Description: " + erdTable.getTableName());
099:
100:                this .parent = parent;
101:                this .erdTable = erdTable;
102:
103:                try {
104:                    jbInit();
105:                } catch (Exception e) {
106:                    e.printStackTrace();
107:                }
108:
109:                display();
110:
111:            }
112:
113:            private void jbInit() throws Exception {
114:
115:                JButton closeButton = new JButton("Close");
116:                JButton applyButton = new JButton("Apply");
117:
118:                ActionListener btnListener = new ActionListener() {
119:                    public void actionPerformed(ActionEvent e) {
120:                        buttons_actionPerformed(e);
121:                    }
122:                };
123:
124:                closeButton.addActionListener(btnListener);
125:                applyButton.addActionListener(btnListener);
126:
127:                closeButton.setPreferredSize(Constants.BUTTON_SIZE);
128:                applyButton.setPreferredSize(Constants.BUTTON_SIZE);
129:
130:                ColumnData[] columns = erdTable.getTableColumns();
131:                // make a copy of the current columns
132:                ColumnData[] _columns = new ColumnData[columns.length];
133:
134:                for (int i = 0; i < columns.length; i++) {
135:                    _columns[i] = new ColumnData();
136:                    _columns[i].setValues(columns[i]);
137:                }
138:
139:                columnDataTable = new EditTablePanel(this );
140:                columnDataTable.setColumnDataArray(_columns, null);
141:                columnDataTable.setOriginalData(erdTable
142:                        .getOriginalTableColumns());
143:                columnDataTable.setSQLChangesHash(erdTable.getAlterTableHash());
144:
145:                conPanel = new EditErdTableConstraintsPanel(this , _columns);
146:
147:                JPanel conBase = new JPanel(new GridBagLayout());
148:                conBase.add(conPanel, new GridBagConstraints(1, 1, 1, 1, 1.0,
149:                        1.0, GridBagConstraints.SOUTHEAST,
150:                        GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0));
151:
152:                // set up and add the focus listener for the tables
153:                FocusListener tableFocusListener = new FocusListener() {
154:                    public void focusGained(FocusEvent e) {
155:                        focusTable = (JTable) e.getSource();
156:                    }
157:
158:                    public void focusLost(FocusEvent e) {
159:                    }
160:                };
161:
162:                columnDataTable.addTableFocusListener(tableFocusListener);
163:                conPanel.addTableFocusListener(tableFocusListener);
164:
165:                tabs = new JTabbedPane();
166:                tabs.add("Columns", columnDataTable);
167:                tabs.add("Constraints", conBase);
168:
169:                tabs.addChangeListener(new ChangeListener() {
170:                    public void stateChanged(ChangeEvent e) {
171:                        if (tabs.getSelectedIndex() == 1)
172:                            tools.enableButtons(false);
173:                        else
174:                            tools.enableButtons(true);
175:                    }
176:                });
177:
178:                tools = new CreateTableToolBar(this , false);
179:
180:                sqlText.setSQLText(erdTable.getAlterTableScript());
181:
182:                JPanel mainPanel = new JPanel(new GridBagLayout());
183:                mainPanel.setBorder(BorderFactory.createEtchedBorder());
184:
185:                tableNameField = new DisabledField(erdTable.getTableName());
186:
187:                GridBagConstraints gbc = new GridBagConstraints();
188:                gbc.insets = new Insets(10, 10, 10, 10);
189:                gbc.gridx = 0;
190:                gbc.anchor = GridBagConstraints.NORTHWEST;
191:                gbc.gridwidth = 2;
192:                mainPanel.add(new JLabel("Table Name:"), gbc);
193:                gbc.gridwidth = GridBagConstraints.REMAINDER;
194:                gbc.insets.left = 0;
195:                gbc.gridx = 2;
196:                gbc.fill = GridBagConstraints.HORIZONTAL;
197:                gbc.weightx = 1.0;
198:                mainPanel.add(tableNameField, gbc);
199:                gbc.insets.left = 10;
200:                gbc.weightx = 0;
201:                gbc.insets.top = 0;
202:                gbc.gridwidth = 1;
203:                gbc.gridx = 0;
204:                gbc.gridy = 2;
205:                gbc.fill = GridBagConstraints.VERTICAL;
206:                gbc.insets.right = 0;
207:                mainPanel.add(tools, gbc);
208:                gbc.insets.left = 0;
209:                gbc.insets.right = 10;
210:                gbc.gridwidth = GridBagConstraints.REMAINDER;
211:                gbc.insets.left = 5;
212:                gbc.gridx = 1;
213:                gbc.fill = GridBagConstraints.BOTH;
214:                gbc.weighty = 0.8;
215:                mainPanel.add(tabs, gbc);
216:                gbc.gridx = 0;
217:                gbc.gridy = 3;
218:                gbc.weighty = 0.6;
219:                gbc.insets.left = 10;
220:                gbc.insets.bottom = 0;
221:                mainPanel.add(sqlText, gbc);
222:                gbc.weighty = 0;
223:                gbc.weightx = 0;
224:                gbc.gridy = 4;
225:                gbc.gridx = 4;
226:                gbc.gridwidth = 1;
227:                gbc.fill = GridBagConstraints.VERTICAL;
228:                gbc.insets.left = 7;
229:                gbc.insets.top = 7;
230:                gbc.insets.bottom = 10;
231:                gbc.anchor = GridBagConstraints.SOUTHEAST;
232:                mainPanel.add(closeButton, gbc);
233:                gbc.insets.right = 0;
234:                gbc.gridx = 3;
235:                gbc.weightx = 1.0;
236:                mainPanel.add(applyButton, gbc);
237:
238:                mainPanel.setPreferredSize(new Dimension(520, 375));
239:
240:                Container c = this .getContentPane();
241:                c.setLayout(new GridBagLayout());
242:                c.add(mainPanel, new GridBagConstraints(1, 1, 1, 1, 1.0, 1.0,
243:                        GridBagConstraints.SOUTHEAST, GridBagConstraints.BOTH,
244:                        new Insets(7, 7, 7, 7), 0, 0));
245:
246:                this .setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
247:                sqlBuffer = new StringBuffer();
248:            }
249:
250:            // -----------------------------------------------
251:            // -------- TableFunction implementations --------
252:            // -----------------------------------------------
253:
254:            public void setSQLText() {
255:                sqlText.setSQLText(columnDataTable.getSQLText()
256:                        + conPanel.getSQLText());
257:            }
258:
259:            public void setSQLText(String values, int type) {
260:                sqlBuffer.delete(0, sqlBuffer.length());
261:
262:                if (type == TableModifier.COLUMN_VALUES)
263:                    sqlBuffer.append(values).append(conPanel.getSQLText());
264:
265:                else if (type == TableModifier.CONSTRAINT_VALUES)
266:                    sqlBuffer.append(columnDataTable.getSQLText()).append(
267:                            values);
268:
269:                sqlText.setSQLText(sqlBuffer.toString());
270:            }
271:
272:            public String getSQLText() {
273:                return sqlText.getSQLText();
274:            }
275:
276:            public String getTableName() {
277:                return erdTable.getTableName();
278:            }
279:
280:            /** <p>Inserts a row before the selection. */
281:            public void insertBefore() {
282:                if (focusTable == columnDataTable.getTable())
283:                    columnDataTable.insertBefore();
284:            }
285:
286:            /** <p>Inserts a row after the selection. */
287:            public void insertAfter() {
288:
289:                if (focusTable == columnDataTable.getTable())
290:                    columnDataTable.insertAfter();
291:
292:                else if (focusTable == conPanel.getTable()) {
293:                    conPanel.insertRowAfter();
294:                    conPanel.setCellEditor(2, new ComboBoxCellEditor(
295:                            columnDataTable.getTableColumnData()));
296:                }
297:
298:            }
299:
300:            /** <p>Deletes the selected row. */
301:            public void deleteRow() {
302:
303:                if (focusTable == columnDataTable.getTable())
304:                    columnDataTable.deleteRow();
305:
306:                else if (focusTable == conPanel.getTable())
307:                    conPanel.dropConstraint();
308:
309:            }
310:
311:            /** <p>Moves the selected row up. */
312:            public void moveColumnUp() {
313:            }
314:
315:            /** <p>Moves the selected row down. */
316:            public void moveColumnDown() {
317:            }
318:
319:            // -----------------------------------------------
320:
321:            /**
322:             * Retrieves the meta data retrieval object for the 
323:             * selected/current connection as associated with this 
324:             * table edit function.
325:             *
326:             * @return the meta data values object
327:             */
328:            public MetaDataValues getMetaDataValues() {
329:                // TODO: COMPLETE ME
330:                return null;
331:            }
332:
333:            public Vector getHostedSchemasVector() {
334:                return new Vector(0);
335:            }
336:
337:            public Vector getSchemaTables(String schemaName) {
338:                Vector _tables = parent.getAllComponentsVector();
339:
340:                int size = _tables.size();
341:                Vector tableNames = new Vector(size);
342:
343:                for (int i = 0; i < size; i++) {
344:                    tableNames.add(_tables.elementAt(i).toString());
345:                }
346:
347:                return tableNames;
348:            }
349:
350:            public Vector getTableColumnDataVector() {
351:                return columnDataTable.getTableColumnDataVector();
352:            }
353:
354:            public ColumnData[] getTableColumnData() {
355:                return columnDataTable.getTableColumnData();
356:            }
357:
358:            public Vector getColumnNamesVector(String tableName,
359:                    String schemaName) {
360:                return parent.getTableColumnsVector(tableName);
361:            }
362:
363:            private void buttons_actionPerformed(ActionEvent e) {
364:                String command = e.getActionCommand();
365:
366:                if (command.equals("Close"))
367:                    dispose();
368:
369:                else if (command.equals("Apply")) {
370:                    columnDataTable.fireEditingStopped();
371:                    conPanel.fireEditingStopped();
372:
373:                    String tableName = tableNameField.getText();
374:
375:                    String conColumn = null;
376:                    ColumnConstraint[] constraints = conPanel
377:                            .getColumnConstraintArray();
378:                    ColumnData[] cda = columnDataTable.getTableColumnData();
379:
380:                    for (int i = 0; i < cda.length; i++) {
381:
382:                        // reset the keys
383:                        cda[i].setPrimaryKey(false);
384:                        cda[i].setForeignKey(false);
385:                        cda[i].resetConstraints();
386:
387:                        for (int j = 0; j < constraints.length; j++) {
388:
389:                            conColumn = constraints[j].getColumn();
390:
391:                            if (conColumn.equalsIgnoreCase(cda[i]
392:                                    .getColumnName())) {
393:
394:                                constraints[j].setTable(tableName);
395:
396:                                if (constraints[j].isPrimaryKey())
397:                                    cda[i].setPrimaryKey(true);
398:                                else if (constraints[j].isForeignKey())
399:                                    cda[i].setForeignKey(true);
400:
401:                                cda[i].addConstraint(constraints[j]);
402:
403:                            }
404:
405:                        }
406:
407:                        cda[i].setTableName(tableName);
408:                        cda[i].setNamesToUpper();
409:
410:                    }
411:
412:                    erdTable.setTableColumns(cda);
413:                    erdTable.setAlterTableHash(columnDataTable
414:                            .getSQLChangesHash());
415:                    erdTable.setAlterTableScript(sqlText.getSQLText());
416:                    erdTable.tableColumnsChanged();
417:
418:                    SwingUtilities.invokeLater(new Runnable() {
419:                        public void run() {
420:                            parent.updateTableRelationships();
421:                        }
422:                    });
423:
424:                    columnDataTable = null;
425:                    conPanel = null;
426:                    sqlText = null;
427:                    tabs = null;
428:
429:                    dispose();
430:
431:                }
432:
433:            }
434:
435:            class EditErdTableConstraintsPanel extends
436:                    EditTableConstraintsPanel {
437:
438:                private ColumnData[] columnData;
439:
440:                public EditErdTableConstraintsPanel(
441:                        TableConstraintFunction creator, ColumnData[] columnData) {
442:
443:                    super (creator);
444:                    this .columnData = columnData;
445:
446:                    Vector constraints = new Vector();
447:
448:                    for (int i = 0; i < columnData.length; i++) {
449:
450:                        Vector _constraints = columnData[i]
451:                                .getColumnConstraintsVector();
452:
453:                        if (_constraints == null)
454:                            continue;
455:
456:                        for (int j = 0, k = _constraints.size(); j < k; j++) {
457:                            constraints.add(_constraints.elementAt(j));
458:                        }
459:
460:                    }
461:
462:                    setData(constraints, true);
463:                    setOriginalData();
464:
465:                }
466:
467:                public void dropConstraint() {
468:                    int row = table.getSelectedRow();
469:
470:                    if (row == -1)
471:                        return;
472:
473:                    table.editingStopped(null);
474:
475:                    if (table.isEditing())
476:                        table.removeEditor();
477:
478:                    ColumnConstraint cc = getConstraintAt(row);
479:
480:                    for (int i = 0; i < columnData.length; i++) {
481:
482:                        Vector _constraints = columnData[i]
483:                                .getColumnConstraintsVector();
484:
485:                        if (_constraints == null)
486:                            continue;
487:
488:                        for (int j = 0, k = _constraints.size(); j < k; j++) {
489:
490:                            if (_constraints.elementAt(j) == cc) {
491:                                deleteSelectedRow();
492:                                columnData[i].removeConstraint(cc);
493:                                columnData[i].setForeignKey(false);
494:                                break;
495:                            }
496:
497:                        }
498:
499:                    }
500:
501:                    if (cc.isNewConstraint())
502:                        removeFromBuffer(ADD_CONSTRAINT + row);
503:                    else {
504:                        String query = ALTER_TABLE + erdTable.getTableName()
505:                                + DROP_CONSTRAINT + cc.getName() + SEMI_COLON
506:                                + NEW_LINE;
507:
508:                        addToBuffer(DROP_CONSTRAINT + row, query);
509:                    }
510:
511:                    generateSQL();
512:                    setSQLText();
513:                    cc = null;
514:                }
515:
516:            } // class EditErdTableConstraintsPanel
517:
518:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.