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


0001:        package org.jsqltool.gui;
0002:
0003:        import javax.swing.*;
0004:        import javax.swing.table.*;
0005:        import javax.swing.event.*;
0006:        import java.awt.*;
0007:        import org.jsqltool.conn.DbConnectionUtil;
0008:        import java.awt.event.*;
0009:        import org.jsqltool.gui.panel.*;
0010:        import org.jsqltool.gui.tablepanel.*;
0011:        import org.jsqltool.utils.Options;
0012:        import org.jsqltool.utils.ImageLoader;
0013:        import org.jgraph.JGraph;
0014:        import org.jsqltool.jgraph.gui.EntityVertexView;
0015:        import org.jgraph.graph.*;
0016:        import org.jsqltool.jgraph.gui.EntityPanel;
0017:        import java.awt.geom.*;
0018:        import java.util.HashSet;
0019:        import java.util.ArrayList;
0020:        import java.awt.print.Printable;
0021:        import java.awt.print.PageFormat;
0022:        import java.awt.print.PrinterJob;
0023:        import java.awt.print.PrinterException;
0024:        import java.util.Hashtable;
0025:        import java.io.File;
0026:        import java.io.FileFilter;
0027:        import java.io.PrintWriter;
0028:        import java.io.FileOutputStream;
0029:        import java.io.*;
0030:        import java.awt.geom.Rectangle2D;
0031:        import org.jsqltool.jgraph.gui.LoadFileDialog;
0032:        import java.util.StringTokenizer;
0033:
0034:        import com.lowagie.text.Document;
0035:        import com.lowagie.text.DocumentException;
0036:        import com.lowagie.text.FontFactory;
0037:        import com.lowagie.text.pdf.DefaultFontMapper;
0038:        import com.lowagie.text.pdf.PdfContentByte;
0039:        import com.lowagie.text.pdf.PdfTemplate;
0040:        import com.lowagie.text.pdf.PdfWriter;
0041:
0042:        import java.awt.dnd.*;
0043:        import java.awt.datatransfer.StringSelection;
0044:        import java.awt.datatransfer.Transferable;
0045:        import java.awt.datatransfer.DataFlavor;
0046:
0047:        /**
0048:         * <p>Title: JSqlTool Project</p>
0049:         * <p>Description: Window used to view in a schema a set of tables/views/synonyms (with related foreign key relations).
0050:         * </p>
0051:         * <p>Copyright: Copyright (C) 2006 Mauro Carniel</p>
0052:         *
0053:         * <p> This file is part of JSqlTool project.
0054:         * This library is free software; you can redistribute it and/or
0055:         * modify it under the terms of the (LGPL) Lesser General Public
0056:         * License as published by the Free Software Foundation;
0057:         *
0058:         *                GNU LESSER GENERAL PUBLIC LICENSE
0059:         *                 Version 2.1, February 1999
0060:         *
0061:         * This library is distributed in the hope that it will be useful,
0062:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
0063:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0064:         * Library General Public License for more details.
0065:         *
0066:         * You should have received a copy of the GNU Library General Public
0067:         * License along with this library; if not, write to the Free
0068:         * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
0069:         *
0070:         *       The author may be contacted at:
0071:         *           maurocarniel@tin.it</p>
0072:         *
0073:         * @author Mauro Carniel
0074:         * @version 1.0
0075:         */
0076:        public class SchemaFrame extends JInternalFrame implements 
0077:                DbConnWindow, DragSourceListener, DropTargetListener {
0078:
0079:            JPanel mainPanel = new JPanel();
0080:            JSplitPane splitPane = new JSplitPane();
0081:            JScrollPane schemaScrollPane = new JScrollPane();
0082:            BorderLayout borderLayout1 = new BorderLayout();
0083:            JTabbedPane tableTabbedPane = new JTabbedPane();
0084:            JScrollPane tableScrollPane = new JScrollPane();
0085:            JScrollPane viewScrollPane = new JScrollPane();
0086:            JScrollPane sinScrollPane = new JScrollPane();
0087:            JList tablesList = new JList();
0088:            JList viewList = new JList();
0089:            JList sinList = new JList();
0090:            private DbConnectionUtil dbConnUtil = null;
0091:            JPanel tablesPanel = new JPanel();
0092:            BorderLayout borderLayout2 = new BorderLayout();
0093:            JPanel catPanel = new JPanel();
0094:            JLabel catLabel = new JLabel();
0095:            JComboBox catComboBox = new JComboBox();
0096:            GridBagLayout gridBagLayout1 = new GridBagLayout();
0097:            JPanel tablePanel = new JPanel();
0098:            JPanel viewPanel = new JPanel();
0099:            JPanel synPanel = new JPanel();
0100:            BorderLayout borderLayout3 = new BorderLayout();
0101:            BorderLayout borderLayout4 = new BorderLayout();
0102:            BorderLayout borderLayout5 = new BorderLayout();
0103:            BorderLayout borderLayout6 = new BorderLayout();
0104:            JPanel toolbarPanel = new JPanel();
0105:            JPanel schemaPanel = new JPanel();
0106:            JButton printButton = new JButton();
0107:            ImageIcon printImage;
0108:            JButton printFitButton = new JButton();
0109:            ImageIcon printFitImage;
0110:            JButton loadButton = new JButton();
0111:            ImageIcon loadImage;
0112:            JButton saveButton = new JButton();
0113:            ImageIcon saveImage;
0114:            JButton expButton = new JButton();
0115:            ImageIcon expImage;
0116:            FlowLayout flowLayout1 = new FlowLayout();
0117:
0118:            private FilterListPanel tableFilterListPanel = new FilterListPanel(
0119:                    tablesList, new TableFilterController());
0120:            private FilterListPanel viewFilterListPanel = new FilterListPanel(
0121:                    viewList, new ViewFilterController());
0122:            private FilterListPanel synFilterListPanel = new FilterListPanel(
0123:                    sinList, new SynFilterController());
0124:
0125:            /** current selected schema name (if combo is empty, then schemaName is set to "" */
0126:            private String schemaName = "";
0127:
0128:            /** JGraph model */
0129:            private GraphModel model = new DefaultGraphModel();
0130:
0131:            /** JGraph view */
0132:            private GraphLayoutCache view = new GraphLayoutCache(model,
0133:                    new DefaultCellViewFactory() {
0134:                        protected PortView createPortView(Object object) {
0135:                            return super .createPortView(object);
0136:                        }
0137:
0138:                        /**
0139:                         * This method id overridded to create a new vertex type
0140:                         */
0141:                        protected VertexView createVertexView(Object object) {
0142:                            return new EntityVertexView(
0143:                                    (DefaultGraphCell) object);
0144:                        }
0145:
0146:                    });
0147:
0148:            /** JGraph diagram */
0149:            private JGraph graph = new JGraph(model, view);
0150:
0151:            /** entities already inserted into the graph */
0152:            private Hashtable entitiesAlreadyInserted = new Hashtable();
0153:
0154:            /** parent frame */
0155:            private MainFrame parent = null;
0156:
0157:            JComboBox zoomComboBox = new JComboBox();
0158:
0159:            private static final String ZOOM200 = "Zoom 200%";
0160:            private static final String ZOOM150 = "Zoom 150%";
0161:            private static final String ZOOM100 = "Zoom 100%";
0162:            private static final String ZOOM75 = "Zoom 75%";
0163:            private static final String ZOOM50 = "Zoom 50%";
0164:            private static final String ZOOM25 = "Zoom 25%";
0165:            private static final String ZOOM10 = "Zoom 10%";
0166:
0167:            /** drag sources */
0168:            private DragSource dragSource1 = new DragSource();
0169:            private DragSource dragSource2 = new DragSource();
0170:            private DragSource dragSource3 = new DragSource();
0171:
0172:            /** grid identifier, used for DnD */
0173:            private String gridId = null;
0174:
0175:            /** drop gesture */
0176:            private DropTarget dropTarget = new DropTarget(graph, this );
0177:
0178:            public SchemaFrame(MainFrame parent, DbConnectionUtil dbConnUtil) {
0179:                super (Options.getInstance().getResource("database schema")
0180:                        + " - " + dbConnUtil.getDbConnection().getName(), true,
0181:                        true, true, true);
0182:                this .dbConnUtil = dbConnUtil;
0183:                this .parent = parent;
0184:                try {
0185:                    jbInit();
0186:                    new Thread() {
0187:                        public void run() {
0188:                            ProgressDialog.getInstance().startProgress();
0189:                            try {
0190:                                SchemaFrame.this .init();
0191:                            } catch (Throwable ex) {
0192:                            } finally {
0193:                                ProgressDialog.getInstance().stopProgress();
0194:                            }
0195:                        }
0196:                    }.start();
0197:                } catch (Exception e) {
0198:                    e.printStackTrace();
0199:                }
0200:            }
0201:
0202:            public SchemaFrame() {
0203:                this (null, null);
0204:            }
0205:
0206:            private void init() {
0207:                // fill in the zoom combo box...
0208:                zoomComboBox.addItem(ZOOM200);
0209:                zoomComboBox.addItem(ZOOM150);
0210:                zoomComboBox.addItem(ZOOM100);
0211:                zoomComboBox.addItem(ZOOM75);
0212:                zoomComboBox.addItem(ZOOM50);
0213:                zoomComboBox.addItem(ZOOM25);
0214:                zoomComboBox.addItem(ZOOM10);
0215:                zoomComboBox.setSelectedIndex(2);
0216:
0217:                // catalogs list...
0218:                java.util.List cats = dbConnUtil.getSchemas();
0219:                for (int i = 0; i < cats.size(); i++)
0220:                    if (cats.get(i) != null)
0221:                        catComboBox.addItem(cats.get(i));
0222:                if (catComboBox.getItemCount() == 0)
0223:                    catComboBox.addItem("");
0224:
0225:                // listener to repaint lists on selecting a catalog...
0226:                catComboBox.setSelectedItem(dbConnUtil.getDbConnection()
0227:                        .getUsername().toUpperCase());
0228:                updateLists();
0229:                catComboBox
0230:                        .addItemListener(new SchemaFrame_catComboBox_itemAdapter(
0231:                                this ));
0232:
0233:                graph.addKeyListener(new KeyAdapter() {
0234:
0235:                    public void keyTyped(KeyEvent e) {
0236:                        if (e.getKeyChar() == '\b') {
0237:                            Object[] objs = view.getCells(false, true, false,
0238:                                    false);
0239:                            objs = graph.getSelectionCells(objs);
0240:                            if (objs.length == 0)
0241:                                return;
0242:                            graph.getGraphLayoutCache().remove(objs);
0243:                            EntityPanel panel = null;
0244:                            for (int i = 0; i < objs.length; i++)
0245:                                if (objs[i] instanceof  DefaultGraphCell) {
0246:                                    panel = (EntityPanel) ((DefaultGraphCell) objs[i])
0247:                                            .getUserObject();
0248:                                    entitiesAlreadyInserted.remove(panel
0249:                                            .getEntityName());
0250:                                }
0251:                            objs = view.getCells(false, false, true, true);
0252:                            objs = graph.getSelectionCells(objs);
0253:                            graph.getGraphLayoutCache().remove(objs);
0254:                        }
0255:
0256:                    }
0257:                });
0258:
0259:                graph.addMouseListener(new MouseAdapter() {
0260:
0261:                    public void mouseClicked(MouseEvent e) {
0262:                        if (e.getClickCount() == 1) {
0263:                            Object[] objs = view.getCells(false, true, false,
0264:                                    false);
0265:                            objs = graph.getSelectionCells(objs);
0266:                            if (objs.length > 0)
0267:                                return;
0268:
0269:                            Object[] entities = null;
0270:                            if (tableTabbedPane.getSelectedIndex() == 0)
0271:                                entities = tablesList.getSelectedValues();
0272:                            else if (tableTabbedPane.getSelectedIndex() == 1)
0273:                                entities = viewList.getSelectedValues();
0274:                            else if (tableTabbedPane.getSelectedIndex() == 2)
0275:                                entities = sinList.getSelectedValues();
0276:                            //          if (entities.length==1 && !entitiesAlreadyInserted.containsKey(entities[0].toString())) {
0277:                            //            // add the selected entity to the graph...
0278:                            //            EntityPanel panel = new EntityPanel(dbConnUtil,entities[0].toString());
0279:                            //            DefaultGraphCell cell = new DefaultGraphCell(panel);
0280:                            //            GraphConstants.setEditable(cell.getAttributes(),false);
0281:                            //            GraphConstants.setBounds(cell.getAttributes(), new Rectangle2D.Double(
0282:                            //                e.getX(),e.getY(),panel.getSize().width,panel.getSize().height
0283:                            //            ));
0284:                            //            Object insertCells[] = new Object[] { cell };
0285:                            //            model.insert(insertCells, null, null, null, null);
0286:                            //            entitiesAlreadyInserted.put(entities[0].toString(),cell);
0287:                            //            addFKs(insertCells);
0288:                            //          }
0289:                            //          else if (entities.length>1) {
0290:                            if (entities.length > 0) {
0291:                                // add all selected entities to the graph...
0292:                                addEntities(entities, e.getX(), e.getY());
0293:                            }
0294:                        }
0295:                    }
0296:
0297:                });
0298:
0299:                // enable drag 'n drop onto the three entity lists...
0300:                dragSource1.createDefaultDragGestureRecognizer(tablesList,
0301:                        DnDConstants.ACTION_MOVE, new DragGestureAdapter(this ));
0302:                dragSource2.createDefaultDragGestureRecognizer(viewList,
0303:                        DnDConstants.ACTION_MOVE, new DragGestureAdapter(this ));
0304:                dragSource3.createDefaultDragGestureRecognizer(sinList,
0305:                        DnDConstants.ACTION_MOVE, new DragGestureAdapter(this ));
0306:
0307:            }
0308:
0309:            /**
0310:             * Add tables/vies/synonims to the graph.
0311:             * @param entities entities to add
0312:             */
0313:            private void addEntities(final Object[] entities, final int x,
0314:                    final int y) {
0315:                ProgressDialog.getInstance().startProgressNoClose();
0316:
0317:                // execute adding entities in another thread to allow viewing a waiting dialog...
0318:                new Thread() {
0319:                    public void run() {
0320:                        try {
0321:                            EntityPanel panel = null;
0322:                            DefaultGraphCell cell = null;
0323:                            ArrayList cells = new ArrayList();
0324:                            int deltaX = 0;
0325:                            int deltaY = 0;
0326:                            int maxH = 0;
0327:                            for (int i = 0; i < entities.length; i++) {
0328:                                if (!entitiesAlreadyInserted
0329:                                        .containsKey(entities[i].toString())) {
0330:                                    panel = new EntityPanel(dbConnUtil,
0331:                                            entities[i].toString());
0332:
0333:                                    cell = new DefaultGraphCell(panel);
0334:                                    GraphConstants.setEditable(cell
0335:                                            .getAttributes(), false);
0336:                                    GraphConstants.setBounds(cell
0337:                                            .getAttributes(),
0338:                                            new Rectangle2D.Double(x + deltaX,
0339:                                                    y + deltaY,
0340:                                                    panel.getSize().width,
0341:                                                    panel.getSize().height));
0342:                                    //                GraphConstants.setOpaque(cell.getAttributes(), true);
0343:                                    //            GraphConstants.setBorder(cell.getAttributes(),BorderFactory.createMatteBorder(2,2,2,2,Color.red));
0344:                                    //                graph.getGraphLayoutCache().insert(cell);
0345:                                    cells.add(cell);
0346:                                    entitiesAlreadyInserted.put(entities[i]
0347:                                            .toString(), cell);
0348:
0349:                                    if (panel.getSize().height > maxH)
0350:                                        maxH = panel.getSize().height;
0351:                                    if (deltaX > graph.getWidth()) {
0352:                                        deltaX = 0;
0353:                                        deltaY = maxH + 20;
0354:                                    } else
0355:                                        deltaX += panel.getSize().width + 40;
0356:
0357:                                }
0358:
0359:                            }
0360:                            model.insert(cells.toArray(), null, null, null,
0361:                                    null);
0362:                            addFKs(cells.toArray());
0363:                        } catch (Exception ex) {
0364:                            ex.printStackTrace();
0365:                        }
0366:                        ProgressDialog.getInstance().forceStopProgress();
0367:                    }
0368:                }.start();
0369:
0370:            }
0371:
0372:            /**
0373:             * Method called by LoadFileDialog class:
0374:             * load the specified profile file.
0375:             * @param fileName profile file name
0376:             */
0377:            public final void loadProfile(String fileName) {
0378:                try {
0379:                    // remove existing schema objects...
0380:                    Object[] objs = view.getCells(true, true, true, true);
0381:                    graph.getGraphLayoutCache().remove(objs);
0382:                    EntityPanel panel = null;
0383:                    for (int i = 0; i < objs.length; i++)
0384:                        if (objs[i] instanceof  DefaultGraphCell) {
0385:                            panel = (EntityPanel) ((DefaultGraphCell) objs[i])
0386:                                    .getUserObject();
0387:                            if (panel != null)
0388:                                entitiesAlreadyInserted.remove(panel
0389:                                        .getEntityName());
0390:                        }
0391:
0392:                    // load schema objects...
0393:                    BufferedReader br = new BufferedReader(
0394:                            new InputStreamReader(new FileInputStream(fileName)));
0395:                    String line = null;
0396:                    StringTokenizer st = null;
0397:                    String tableName = null;
0398:                    double x, y, w, h;
0399:                    DefaultGraphCell cell = null;
0400:                    Object insertCells[] = null;
0401:                    while ((line = br.readLine()) != null) {
0402:                        if (line.trim().length() > 0) {
0403:                            st = new StringTokenizer(line, ",");
0404:                            while (st.hasMoreTokens()) {
0405:                                // add an entity to the schema...
0406:                                tableName = st.nextToken();
0407:                                x = Double.parseDouble(st.nextToken());
0408:                                y = Double.parseDouble(st.nextToken());
0409:                                w = Double.parseDouble(st.nextToken());
0410:                                h = Double.parseDouble(st.nextToken());
0411:
0412:                                panel = new EntityPanel(dbConnUtil, tableName);
0413:                                cell = new DefaultGraphCell(panel);
0414:                                GraphConstants.setBounds(cell.getAttributes(),
0415:                                        new Rectangle2D.Double(x, y, w, h));
0416:                                insertCells = new Object[] { cell };
0417:                                model.insert(insertCells, null, null, null,
0418:                                        null);
0419:                                entitiesAlreadyInserted.put(tableName, cell);
0420:                                addFKs(insertCells);
0421:                            }
0422:                        }
0423:                    }
0424:                    br.close();
0425:                    graph.setSelectionCells(new Object[0]);
0426:                } catch (Exception ex) {
0427:                    ex.printStackTrace();
0428:                    JOptionPane.showMessageDialog(parent, ex.getMessage(),
0429:                            Options.getInstance().getResource(
0430:                                    "error on loading"),
0431:                            JOptionPane.ERROR_MESSAGE);
0432:                }
0433:            }
0434:
0435:            private void addFKs(Object[] insertCells) {
0436:                // determine fks...
0437:                String tableName = null;
0438:                TableModel fks = null;
0439:                String fkTName = null;
0440:                DefaultPort port0, port1;
0441:                DefaultGraphCell node0, node1;
0442:                DefaultEdge edge = null;
0443:                ArrayList cells = new ArrayList();
0444:                EntityPanel panel = null;
0445:                for (int j = 0; j < insertCells.length; j++) {
0446:                    panel = (EntityPanel) ((DefaultGraphCell) insertCells[j])
0447:                            .getUserObject();
0448:                    tableName = panel.getEntityName();
0449:                    node0 = (DefaultGraphCell) entitiesAlreadyInserted
0450:                            .get(tableName);
0451:                    port0 = new DefaultPort();
0452:                    node0.add(port0);
0453:
0454:                    fks = dbConnUtil.getCrossReference(tableName);
0455:                    /*
0456:                          PKTABLE_CAT String => primary key table catalog (may be null)
0457:                          PKTABLE_SCHEM String => primary key table schema (may be null)
0458:                          PKTABLE_NAME String => primary key table name
0459:                          PKCOLUMN_NAME String => primary key column name
0460:                          FKTABLE_CAT String => foreign key table catalog (may be null) being exported (may be null)
0461:                          FKTABLE_SCHEM String => foreign key table schema (may be null) being exported (may be null)
0462:                          FKTABLE_NAME String => foreign key table name being exported
0463:                          FKCOLUMN_NAME String => foreign key column name being exported
0464:                          KEY_SEQ short => sequence number within foreign key
0465:                          UPDATE_RULE short => What happens to foreign key when primary is updated: importedNoAction - do not allow update of primary key if it has been imported importedKeyCascade - change imported key to agree with primary key update importedKeySetNull - change imported key to NULL if its primary key has been updated importedKeySetDefault - change imported key to default values if its primary key has been updated importedKeyRestrict - same as importedKeyNoAction (for ODBC 2.x compatibility)
0466:                          DELETE_RULE short => What happens to the foreign key when primary is deleted. importedKeyNoAction - do not allow delete of primary key if it has been imported importedKeyCascade - delete rows that import a deleted key importedKeySetNull - change imported key to NULL if its primary key has been deleted importedKeyRestrict - same as importedKeyNoAction (for ODBC 2.x compatibility) importedKeySetDefault - change imported key to default if its primary key has been deleted
0467:                          FK_NAME String => foreign key name (may be null)
0468:                          PK_NAME String => primary key name (may be null)
0469:                          DEFERRABILITY short => can the evaluation of foreign key constraints be deferred until commit importedKeyInitiallyDeferred - see SQL92 for definition importedKeyInitiallyImmediate - see SQL92 for definition importedKeyNotDeferrable - see SQL92 for definition
0470:                     */
0471:
0472:                    for (int i = 0; i < fks.getRowCount(); i++) {
0473:                        fkTName = fks.getValueAt(i, 2).toString();
0474:                        if (entitiesAlreadyInserted.containsKey(fkTName)) {
0475:                            // add an edge...
0476:
0477:                            node1 = (DefaultGraphCell) entitiesAlreadyInserted
0478:                                    .get(fkTName);
0479:                            port1 = new DefaultPort();
0480:                            node1.add(port1);
0481:
0482:                            edge = new DefaultEdge();
0483:                            edge.setSource(port0);
0484:                            edge.setTarget(port1);
0485:
0486:                            //          edge.setSource(node0.getChildAt(0));
0487:                            //          edge.setTarget(node1.getChildAt(0));
0488:
0489:                            //          GraphConstants.setLineBegin(edge.getAttributes(), GraphConstants.ARROW_DIAMOND);
0490:                            GraphConstants.setLineEnd(edge.getAttributes(),
0491:                                    GraphConstants.ARROW_SIMPLE);
0492:                            //          GraphConstants.setEndFill(edge.getAttributes(), true);
0493:                            cells.add(edge);
0494:                        }
0495:                    }
0496:                    graph.getGraphLayoutCache().insert(cells.toArray());
0497:
0498:                }
0499:            }
0500:
0501:            public void updateLists() {
0502:                if (tableTabbedPane.getSelectedIndex() == 0) {
0503:                    new Thread() {
0504:                        public void run() {
0505:                            loadTables();
0506:                            loadViews();
0507:                            loadSyns();
0508:                            tablesList.requestFocus();
0509:                        }
0510:                    }.start();
0511:                } else if (tableTabbedPane.getSelectedIndex() == 1) {
0512:                    new Thread() {
0513:                        public void run() {
0514:                            loadViews();
0515:                            loadTables();
0516:                            loadSyns();
0517:                            viewList.requestFocus();
0518:                        }
0519:                    }.start();
0520:                } else if (tableTabbedPane.getSelectedIndex() == 2) {
0521:                    new Thread() {
0522:                        public void run() {
0523:                            loadSyns();
0524:                            loadTables();
0525:                            loadViews();
0526:                            sinList.requestFocus();
0527:                        }
0528:                    }.start();
0529:                }
0530:
0531:            }
0532:
0533:            /**
0534:             * Load tables.
0535:             */
0536:            private void loadTables() {
0537:                java.util.List tables = dbConnUtil.getTables(catComboBox
0538:                        .getSelectedItem().toString(), "TABLE");
0539:                DefaultListModel model = new DefaultListModel();
0540:                String name = null;
0541:                boolean ok = true;
0542:                for (int i = 0; i < tables.size(); i++) {
0543:                    name = tables.get(i).toString();
0544:                    ok = true;
0545:                    for (int j = 0; j < tableFilterListPanel.getFilterPattern()
0546:                            .length(); j++)
0547:                        if (name.indexOf(tableFilterListPanel
0548:                                .getFilterPattern().charAt(j)) != -1) {
0549:                            ok = false;
0550:                            break;
0551:                        }
0552:                    if (ok)
0553:                        model.addElement(name);
0554:                }
0555:                tablesList.setModel(model);
0556:                tablesList.revalidate();
0557:                tablesList.requestFocus();
0558:            }
0559:
0560:            /**
0561:             * Load views.
0562:             */
0563:            private void loadViews() {
0564:                java.util.List views = dbConnUtil.getTables(catComboBox
0565:                        .getSelectedItem().toString(), "VIEW");
0566:                DefaultListModel model = new DefaultListModel();
0567:                String name = null;
0568:                boolean ok = true;
0569:                for (int i = 0; i < views.size(); i++) {
0570:                    name = views.get(i).toString();
0571:                    ok = true;
0572:                    for (int j = 0; j < viewFilterListPanel.getFilterPattern()
0573:                            .length(); j++)
0574:                        if (name.indexOf(viewFilterListPanel.getFilterPattern()
0575:                                .charAt(j)) != -1) {
0576:                            ok = false;
0577:                            break;
0578:                        }
0579:                    if (ok)
0580:                        model.addElement(name);
0581:                }
0582:                viewList.setModel(model);
0583:                viewList.revalidate();
0584:                viewList.requestFocus();
0585:            }
0586:
0587:            /**
0588:             * Load synonyms.
0589:             */
0590:            private void loadSyns() {
0591:                java.util.List sin = dbConnUtil.getTables(catComboBox
0592:                        .getSelectedItem().toString(), "SYNONYM");
0593:                DefaultListModel model = new DefaultListModel();
0594:                String name = null;
0595:                boolean ok = true;
0596:                for (int i = 0; i < sin.size(); i++) {
0597:                    name = sin.get(i).toString();
0598:                    ok = true;
0599:                    for (int j = 0; j < synFilterListPanel.getFilterPattern()
0600:                            .length(); j++)
0601:                        if (name.indexOf(synFilterListPanel.getFilterPattern()
0602:                                .charAt(j)) != -1) {
0603:                            ok = false;
0604:                            break;
0605:                        }
0606:                    if (ok)
0607:                        model.addElement(name);
0608:                }
0609:                sinList.setModel(model);
0610:                sinList.revalidate();
0611:                sinList.requestFocus();
0612:            }
0613:
0614:            void loadButton_actionPerformed(ActionEvent e) {
0615:                LoadFileDialog d = new LoadFileDialog(parent, this , dbConnUtil
0616:                        .getDbConnection().getName());
0617:            }
0618:
0619:            void saveButton_actionPerformed(ActionEvent e) {
0620:                // view an input dialog to specifiy a profile file name...
0621:                String fileName = JOptionPane.showInputDialog(parent, Options
0622:                        .getInstance().getResource(
0623:                                "please specify schema profile file name: "),
0624:                        Options.getInstance().getResource(
0625:                                "save database schema"),
0626:                        JOptionPane.QUESTION_MESSAGE);
0627:                if (fileName == null || fileName.trim().length() == 0) {
0628:                    return;
0629:                }
0630:                // create the profile file...
0631:                fileName = fileName.trim().replace(' ', '_');
0632:
0633:                File fileToSave = new File("profile/"
0634:                        + dbConnUtil.getDbConnection().getName() + "_"
0635:                        + fileName + ".sch");
0636:                if (fileToSave.exists()) {
0637:                    int answer = JOptionPane
0638:                            .showConfirmDialog(
0639:                                    parent,
0640:                                    Options
0641:                                            .getInstance()
0642:                                            .getResource(
0643:                                                    "the specified file already exists.\noverwrite it?"),
0644:                                    Options.getInstance().getResource(
0645:                                            "save not allowed"),
0646:                                    JOptionPane.YES_NO_OPTION);
0647:                    if (answer == JOptionPane.NO_OPTION)
0648:                        return;
0649:                    else
0650:                        fileToSave.delete();
0651:                }
0652:
0653:                try {
0654:                    Object[] objs = view.getCells(false, true, false, false);
0655:
0656:                    // save database schema in the profile file...
0657:                    PrintWriter pw = new PrintWriter(new FileOutputStream(
0658:                            fileToSave));
0659:
0660:                    EntityPanel panel = null;
0661:                    DefaultGraphCell cell = null;
0662:                    Rectangle2D rect = null;
0663:                    for (int j = 0; j < objs.length; j++) {
0664:                        cell = (DefaultGraphCell) objs[j];
0665:                        panel = (EntityPanel) cell.getUserObject();
0666:                        rect = GraphConstants.getBounds(cell.getAttributes());
0667:                        pw.println(panel.getEntityName() + "," + rect.getX()
0668:                                + "," + rect.getY() + "," + rect.getWidth()
0669:                                + "," + rect.getHeight());
0670:                    }
0671:
0672:                    pw.close();
0673:                } catch (Exception ex) {
0674:                    ex.printStackTrace();
0675:                    JOptionPane.showMessageDialog(parent, ex.getMessage(),
0676:                            Options.getInstance()
0677:                                    .getResource("error on saving"),
0678:                            JOptionPane.ERROR_MESSAGE);
0679:                }
0680:
0681:            }
0682:
0683:            void expButton_actionPerformed(ActionEvent e) {
0684:                final JFileChooser f = new JFileChooser();
0685:                int res = f.showSaveDialog(parent);
0686:                if (res == f.CANCEL_OPTION || f.getSelectedFile() == null)
0687:                    return;
0688:
0689:                try {
0690:                    ProgressDialog.getInstance().startProgress();
0691:                } catch (Throwable ex5) {
0692:                }
0693:                new Thread() {
0694:                    public void run() {
0695:
0696:                        try {
0697:                            f.getSelectedFile().delete();
0698:
0699:                            int w = graph.getPreferredSize().width;
0700:                            int h = graph.getPreferredSize().height;
0701:                            Document document = new Document();
0702:                            document
0703:                                    .setPageSize(new com.lowagie.text.Rectangle(
0704:                                            0, 0, w + 30, h + 30));
0705:                            PdfWriter writer = PdfWriter.getInstance(document,
0706:                                    new FileOutputStream(f.getSelectedFile()));
0707:                            document.open();
0708:                            DefaultFontMapper mapper = new DefaultFontMapper();
0709:                            FontFactory.registerDirectories();
0710:                            PdfContentByte cb = writer.getDirectContent();
0711:                            PdfTemplate tp = cb.createTemplate(w, h);
0712:                            Graphics2D g2 = tp.createGraphics(w, h, mapper);
0713:                            tp.setWidth(w);
0714:                            tp.setHeight(h);
0715:                            graph.paint(g2);
0716:
0717:                            g2.dispose();
0718:                            cb.addTemplate(tp, 0, 30);
0719:                            document.close();
0720:
0721:                        } catch (Throwable ex) {
0722:                            ex.printStackTrace();
0723:                            JOptionPane
0724:                                    .showMessageDialog(
0725:                                            parent,
0726:                                            Options
0727:                                                    .getInstance()
0728:                                                    .getResource(
0729:                                                            "error while exporting schema diagram")
0730:                                                    + ":\n"
0731:                                                    + (ex.getMessage() == null ? ex
0732:                                                            .toString()
0733:                                                            : ex.getMessage()),
0734:                                            Options.getInstance().getResource(
0735:                                                    "error"),
0736:                                            JOptionPane.ERROR_MESSAGE);
0737:                        }
0738:                        try {
0739:                            ProgressDialog.getInstance().stopProgress();
0740:                        } catch (Throwable ex5) {
0741:                        }
0742:
0743:                    }
0744:                }.start();
0745:
0746:            }
0747:
0748:            void printFitButton_actionPerformed(ActionEvent e) {
0749:                new Thread() {
0750:                    public void run() {
0751:                        print(true);
0752:                    }
0753:                }.start();
0754:
0755:            }
0756:
0757:            void printButton_actionPerformed(ActionEvent e) {
0758:                new Thread() {
0759:                    public void run() {
0760:                        print(false);
0761:                    }
0762:                }.start();
0763:            }
0764:
0765:            private void print(final boolean fitToPage) {
0766:                graph.setSelectionCells(new Object[0]);
0767:
0768:                Printable printable = new Printable() {
0769:
0770:                    public int print(Graphics g, PageFormat printFormat,
0771:                            int page) {
0772:                        if (!fitToPage) {
0773:                            // print all pages...
0774:                            double pageScale = 1.0d;
0775:                            Dimension pSize = graph.getPreferredSize(); // graph is a JGraph
0776:                            int w = (int) (printFormat.getWidth() * pageScale);
0777:                            int h = (int) (printFormat.getHeight() * pageScale);
0778:                            int cols = (int) Math.max(Math
0779:                                    .ceil((double) (pSize.width - 5)
0780:                                            / (double) w), 1);
0781:                            int rows = (int) Math.max(Math
0782:                                    .ceil((double) (pSize.height - 5)
0783:                                            / (double) h), 1);
0784:                            if (page < cols * rows) {
0785:                                // Configures graph for printing
0786:                                RepaintManager currentManager = RepaintManager
0787:                                        .currentManager(graph);
0788:                                currentManager.setDoubleBufferingEnabled(false);
0789:                                double oldScale = graph.getScale();
0790:                                graph.setScale(1 / pageScale);
0791:                                int dx = (int) ((page % cols) * printFormat
0792:                                        .getWidth());
0793:                                int dy = (int) ((page % rows) * printFormat
0794:                                        .getHeight());
0795:                                g.translate(-dx, -dy);
0796:                                g.setClip(dx, dy, (int) (dx + printFormat
0797:                                        .getWidth()), (int) (dy + printFormat
0798:                                        .getHeight()));
0799:                                // Prints the graph on the graphics.
0800:                                graph.paint(g);
0801:                                // Restores graph
0802:                                g.translate(dx, dy);
0803:                                graph.setScale(oldScale);
0804:                                currentManager.setDoubleBufferingEnabled(true);
0805:                                return PAGE_EXISTS;
0806:                            } else {
0807:                                return NO_SUCH_PAGE;
0808:                            }
0809:                        } else {
0810:                            if (page > 0)
0811:                                return NO_SUCH_PAGE;
0812:                            Dimension pSize = graph.getPreferredSize(); // graph is a JGraph
0813:                            RepaintManager currentManager = RepaintManager
0814:                                    .currentManager(graph);
0815:                            currentManager.setDoubleBufferingEnabled(false);
0816:                            double oldScale = graph.getScale();
0817:                            double w = printFormat.getWidth();
0818:                            graph.setScale(w / (pSize.width + 50));
0819:
0820:                            g.setClip(0, 0, graph.getPreferredSize().width,
0821:                                    graph.getPreferredSize().height);
0822:                            graph.paint(g);
0823:                            graph.setScale(oldScale);
0824:                            currentManager.setDoubleBufferingEnabled(true);
0825:                            return PAGE_EXISTS;
0826:                        }
0827:                    }
0828:
0829:                };
0830:
0831:                PrinterJob printJob = PrinterJob.getPrinterJob();
0832:                printJob.setPrintable(printable);
0833:                if (printJob.printDialog()) {
0834:                    try {
0835:                        // start progress bar...
0836:                        try {
0837:                            ProgressDialog.getInstance().startProgress();
0838:                        } catch (Throwable ex5) {
0839:                        }
0840:                        printJob.print();
0841:                    } catch (PrinterException ex) {
0842:                        ex.printStackTrace();
0843:                        JOptionPane.showMessageDialog(this , Options
0844:                                .getInstance().getResource(
0845:                                        "error while printing schema")
0846:                                + ":\n" + ex.getMessage(), Options
0847:                                .getInstance().getResource("error"),
0848:                                JOptionPane.ERROR_MESSAGE);
0849:                    }
0850:                }
0851:
0852:                // start progress bar...
0853:                try {
0854:                    ProgressDialog.getInstance().stopProgress();
0855:                } catch (Throwable ex5) {
0856:                }
0857:
0858:            }
0859:
0860:            private void jbInit() throws Exception {
0861:                toolbarPanel.setLayout(flowLayout1);
0862:                flowLayout1.setAlignment(FlowLayout.LEFT);
0863:
0864:                loadImage = ImageLoader.getInstance().getIcon("load.gif");
0865:                loadButton.setBorder(null);
0866:                loadButton.setMaximumSize(new Dimension(24, 24));
0867:                loadButton.setPreferredSize(new Dimension(24, 24));
0868:                loadButton.setIcon(loadImage);
0869:                loadButton
0870:                        .addActionListener(new SchemaFrame_loadButton_actionAdapter(
0871:                                this ));
0872:                loadButton.setToolTipText(Options.getInstance().getResource(
0873:                        "loadbutton.tooltip"));
0874:                zoomComboBox
0875:                        .addItemListener(new SchemaFrame_zoomComboBox_itemAdapter(
0876:                                this ));
0877:                toolbarPanel.add(loadButton, null);
0878:
0879:                saveImage = ImageLoader.getInstance().getIcon("save.gif");
0880:                saveButton.setBorder(null);
0881:                saveButton.setMaximumSize(new Dimension(24, 24));
0882:                saveButton.setPreferredSize(new Dimension(24, 24));
0883:                saveButton.setIcon(saveImage);
0884:                saveButton
0885:                        .addActionListener(new SchemaFrame_saveButton_actionAdapter(
0886:                                this ));
0887:                saveButton.setToolTipText(Options.getInstance().getResource(
0888:                        "savebutton.tooltip"));
0889:                toolbarPanel.add(saveButton, null);
0890:
0891:                printImage = ImageLoader.getInstance().getIcon("print.gif");
0892:                printButton.setBorder(null);
0893:                printButton.setMaximumSize(new Dimension(24, 24));
0894:                printButton.setPreferredSize(new Dimension(24, 24));
0895:                printButton.setIcon(printImage);
0896:                printButton
0897:                        .addActionListener(new SchemaFrame_printButton_actionAdapter(
0898:                                this ));
0899:                printButton.setToolTipText(Options.getInstance().getResource(
0900:                        "printbutton.tooltip"));
0901:                toolbarPanel.add(printButton, null);
0902:
0903:                printFitImage = ImageLoader.getInstance().getIcon(
0904:                        "printfit.gif");
0905:                printFitButton.setBorder(null);
0906:                printFitButton.setMaximumSize(new Dimension(24, 24));
0907:                printFitButton.setPreferredSize(new Dimension(24, 24));
0908:                printFitButton.setIcon(printFitImage);
0909:                printFitButton
0910:                        .addActionListener(new SchemaFrame_printFitButton_actionAdapter(
0911:                                this ));
0912:                printFitButton.setToolTipText(Options.getInstance()
0913:                        .getResource("printfitbutton.tooltip"));
0914:                toolbarPanel.add(printFitButton, null);
0915:
0916:                expImage = ImageLoader.getInstance().getIcon("export.gif");
0917:                expButton.setBorder(null);
0918:                expButton.setMaximumSize(new Dimension(24, 24));
0919:                expButton.setPreferredSize(new Dimension(24, 24));
0920:                expButton.setIcon(expImage);
0921:                expButton
0922:                        .addActionListener(new SchemaFrame_expButton_actionAdapter(
0923:                                this ));
0924:                expButton.setToolTipText(Options.getInstance().getResource(
0925:                        "expbutton.tooltip"));
0926:                toolbarPanel.add(expButton, null);
0927:                toolbarPanel.add(zoomComboBox, null);
0928:
0929:                mainPanel.setLayout(borderLayout1);
0930:                splitPane.setDebugGraphicsOptions(0);
0931:                tableScrollPane.setToolTipText(Options.getInstance()
0932:                        .getResource("tables list"));
0933:                viewScrollPane.setRowHeader(null);
0934:                viewScrollPane.setToolTipText(Options.getInstance()
0935:                        .getResource("views list"));
0936:                sinScrollPane.setToolTipText(Options.getInstance().getResource(
0937:                        "synonyms list"));
0938:                tablesPanel.setLayout(borderLayout2);
0939:                catLabel.setText(Options.getInstance().getResource("catalog"));
0940:                catPanel.setLayout(gridBagLayout1);
0941:
0942:                tablesList
0943:                        .setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
0944:                viewList
0945:                        .setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
0946:                sinList
0947:                        .setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
0948:                this .getContentPane().add(mainPanel, BorderLayout.CENTER);
0949:                mainPanel.add(splitPane, BorderLayout.CENTER);
0950:                splitPane.add(schemaPanel, JSplitPane.RIGHT);
0951:                schemaPanel.setLayout(borderLayout6);
0952:                schemaPanel.add(toolbarPanel, BorderLayout.NORTH);
0953:                schemaPanel.add(schemaScrollPane, BorderLayout.CENTER);
0954:                schemaScrollPane.getViewport().add(graph, null);
0955:                splitPane.add(tablesPanel, JSplitPane.LEFT);
0956:                tablePanel.setLayout(borderLayout3);
0957:                viewPanel.setLayout(borderLayout4);
0958:                synPanel.setLayout(borderLayout5);
0959:                tablePanel.add(tableFilterListPanel, BorderLayout.NORTH);
0960:                tablePanel.add(tableScrollPane, BorderLayout.CENTER);
0961:                viewPanel.add(viewFilterListPanel, BorderLayout.NORTH);
0962:                viewPanel.add(viewScrollPane, BorderLayout.CENTER);
0963:                synPanel.add(synFilterListPanel, BorderLayout.NORTH);
0964:                synPanel.add(sinScrollPane, BorderLayout.CENTER);
0965:
0966:                tableTabbedPane.add(tablePanel, "tablePanel");
0967:                tableTabbedPane.add(viewPanel, "viewPanel");
0968:                tableTabbedPane.add(synPanel, "synPanel");
0969:                tablesPanel.add(catPanel, BorderLayout.NORTH);
0970:                tableScrollPane.getViewport().add(tablesList, null);
0971:                viewScrollPane.getViewport().add(viewList, null);
0972:                sinScrollPane.getViewport().add(sinList, null);
0973:                splitPane.setDividerLocation(200);
0974:                tablesPanel.add(tableTabbedPane, BorderLayout.CENTER);
0975:                catPanel.add(catLabel, new GridBagConstraints(0, 0, 1, 1, 0.0,
0976:                        0.0, GridBagConstraints.WEST, GridBagConstraints.NONE,
0977:                        new Insets(5, 5, 5, 5), 0, 0));
0978:                catPanel.add(catComboBox, new GridBagConstraints(1, 0, 1, 1,
0979:                        1.0, 0.0, GridBagConstraints.CENTER,
0980:                        GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5),
0981:                        0, 0));
0982:            }
0983:
0984:            public DbConnectionUtil getDbConnectionUtil() {
0985:                return dbConnUtil;
0986:            }
0987:
0988:            void catComboBox_itemStateChanged(ItemEvent e) {
0989:                if (e.getStateChange() == e.SELECTED) {
0990:                    if (catComboBox.getSelectedItem() != null
0991:                            && !catComboBox.getSelectedItem().equals(""))
0992:                        schemaName = catComboBox.getSelectedItem() + ".";
0993:                    else
0994:                        schemaName = "";
0995:
0996:                    new Thread() {
0997:                        public void run() {
0998:                            ProgressDialog.getInstance().startProgress();
0999:                            try {
1000:                                // update lists...
1001:                                updateLists();
1002:                            } catch (Throwable ex) {
1003:                            } finally {
1004:                                ProgressDialog.getInstance().stopProgress();
1005:                            }
1006:                        }
1007:                    }.start();
1008:                }
1009:            }
1010:
1011:            /**
1012:             * <p>Description: Inner class which manages filter events on tables.</p>
1013:             */
1014:            class TableFilterController implements  FilterListController {
1015:
1016:                /**
1017:                 * Reload the list, which will be filtered by the specified pattern
1018:                 */
1019:                public void reloadList() {
1020:                    loadTables();
1021:                }
1022:
1023:            }
1024:
1025:            /**
1026:             * <p>Description: Inner class which manages filter events on views.</p>
1027:             */
1028:            class ViewFilterController implements  FilterListController {
1029:
1030:                /**
1031:                 * Reload the list, which will be filtered by the specified pattern
1032:                 */
1033:                public void reloadList() {
1034:                    loadViews();
1035:                }
1036:
1037:            }
1038:
1039:            /**
1040:             * <p>Description: Inner class which manages filter events on synonyms.</p>
1041:             */
1042:            class SynFilterController implements  FilterListController {
1043:
1044:                /**
1045:                 * Reload the list, which will be filtered by the specified pattern
1046:                 */
1047:                public void reloadList() {
1048:                    loadSyns();
1049:                }
1050:
1051:            }
1052:
1053:            void zoomComboBox_itemStateChanged(ItemEvent e) {
1054:                if (e.getStateChange() == e.SELECTED) {
1055:                    double zoom = 1;
1056:                    if (zoomComboBox.getSelectedItem().equals(ZOOM200))
1057:                        zoom = 2;
1058:                    else if (zoomComboBox.getSelectedItem().equals(ZOOM150))
1059:                        zoom = 1.5;
1060:                    else if (zoomComboBox.getSelectedItem().equals(ZOOM100))
1061:                        zoom = 1;
1062:                    else if (zoomComboBox.getSelectedItem().equals(ZOOM75))
1063:                        zoom = 0.75;
1064:                    else if (zoomComboBox.getSelectedItem().equals(ZOOM50))
1065:                        zoom = 0.5;
1066:                    else if (zoomComboBox.getSelectedItem().equals(ZOOM25))
1067:                        zoom = 0.25;
1068:                    else if (zoomComboBox.getSelectedItem().equals(ZOOM10))
1069:                        zoom = 0.1;
1070:
1071:                    if (graph.getScale() != zoom)
1072:                        graph.setScale(zoom);
1073:                }
1074:            }
1075:
1076:            /********************************************************************
1077:             *
1078:             *             DRAG 'N DROP MANAGEMENTS METHODS
1079:             *
1080:             ********************************************************************/
1081:
1082:            /************************************************************
1083:             * DRAG MANAGEMENT
1084:             ************************************************************/
1085:
1086:            class DragGestureAdapter implements  DragGestureListener {
1087:
1088:                private DragSourceListener dragListener = null;
1089:
1090:                public DragGestureAdapter(DragSourceListener dragListener) {
1091:                    this .dragListener = dragListener;
1092:                }
1093:
1094:                /**
1095:                 * A drag gesture has been initiated.
1096:                 */
1097:                public final void dragGestureRecognized(DragGestureEvent event) {
1098:                    if (tableTabbedPane.getSelectedIndex() == 0
1099:                            && tablesList.getSelectedIndices().length > 0) {
1100:                        try {
1101:                            parent.setCursor(Cursor
1102:                                    .getPredefinedCursor(Cursor.HAND_CURSOR));
1103:                        } catch (Exception ex) {
1104:                        }
1105:                        dragSource1.startDrag(event,
1106:                                DragSource.DefaultMoveDrop,
1107:                                new StringSelection(""), dragListener);
1108:                    } else if (tableTabbedPane.getSelectedIndex() == 1
1109:                            && viewList.getSelectedIndices().length > 0) {
1110:                        try {
1111:                            parent.setCursor(Cursor
1112:                                    .getPredefinedCursor(Cursor.HAND_CURSOR));
1113:                        } catch (Exception ex) {
1114:                        }
1115:                        dragSource2.startDrag(event,
1116:                                DragSource.DefaultMoveDrop,
1117:                                new StringSelection(""), dragListener);
1118:                    } else if (tableTabbedPane.getSelectedIndex() == 2
1119:                            && sinList.getSelectedIndices().length > 0) {
1120:                        try {
1121:                            parent.setCursor(Cursor
1122:                                    .getPredefinedCursor(Cursor.HAND_CURSOR));
1123:                        } catch (Exception ex) {
1124:                        }
1125:                        dragSource3.startDrag(event,
1126:                                DragSource.DefaultMoveDrop,
1127:                                new StringSelection(""), dragListener);
1128:                    }
1129:                }
1130:
1131:            } // end inner-class...
1132:
1133:            /**
1134:             * This message goes to DragSourceListener, informing it that the dragging has entered the DropSite
1135:             */
1136:            public final void dragEnter(DragSourceDragEvent event) {
1137:            }
1138:
1139:            /**
1140:             * This message goes to DragSourceListener, informing it that the dragging has exited the DropSite.
1141:             */
1142:            public final void dragExit(DragSourceEvent event) {
1143:            }
1144:
1145:            /**
1146:             * This message goes to DragSourceListener, informing it that the dragging is currently ocurring over the DropSite.
1147:             */
1148:            public final void dragOver(DragSourceDragEvent event) {
1149:            }
1150:
1151:            /**
1152:             * This method is invoked when the user changes the dropAction.
1153:             */
1154:            public final void dropActionChanged(DragSourceDragEvent event) {
1155:            }
1156:
1157:            /**
1158:             * This message goes to DragSourceListener, informing it that the dragging has ended.
1159:             */
1160:            public final void dragDropEnd(DragSourceDropEvent event) {
1161:            }
1162:
1163:            /************************************************************
1164:             * DROP MANAGEMENT
1165:             ************************************************************/
1166:
1167:            /**
1168:             * This method is invoked when you are dragging over the DropSite.
1169:             */
1170:            public final void dragEnter(DropTargetDragEvent event) {
1171:                event.acceptDrag(DnDConstants.ACTION_MOVE);
1172:            }
1173:
1174:            /**
1175:             * This method is invoked when you are exit the DropSite without dropping.
1176:             */
1177:            public final void dragExit(DropTargetEvent event) {
1178:            }
1179:
1180:            /**
1181:             * This method is invoked when a drag operation is going on.
1182:             */
1183:            public final void dragOver(DropTargetDragEvent event) {
1184:            }
1185:
1186:            /**
1187:             * This method is invoked when a drop event has occurred.
1188:             */
1189:            public final void drop(DropTargetDropEvent event) {
1190:                try {
1191:                    Transferable transferable = event.getTransferable();
1192:                    if (transferable
1193:                            .isDataFlavorSupported(DataFlavor.stringFlavor)) {
1194:                        event.acceptDrop(DnDConstants.ACTION_MOVE);
1195:                        event.getDropTargetContext().dropComplete(true);
1196:
1197:                        // add entities to the graph...
1198:                        Object[] entities = null;
1199:                        if (tableTabbedPane.getSelectedIndex() == 0)
1200:                            entities = tablesList.getSelectedValues();
1201:                        else if (tableTabbedPane.getSelectedIndex() == 1)
1202:                            entities = viewList.getSelectedValues();
1203:                        else if (tableTabbedPane.getSelectedIndex() == 2)
1204:                            entities = sinList.getSelectedValues();
1205:
1206:                        addEntities(entities, event.getLocation().x, event
1207:                                .getLocation().y);
1208:
1209:                    } else {
1210:                        event.rejectDrop();
1211:                    }
1212:                } catch (Exception ex) {
1213:                    ex.printStackTrace();
1214:                    event.rejectDrop();
1215:                } finally {
1216:                    try {
1217:                        parent.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
1218:                    } catch (Exception ex) {
1219:                    }
1220:
1221:                }
1222:            }
1223:
1224:            /**
1225:             * This method is invoked if the use modifies the current drop gesture.
1226:             */
1227:            public final void dropActionChanged(DropTargetDragEvent event) {
1228:            }
1229:
1230:        }
1231:
1232:        class SchemaFrame_catComboBox_itemAdapter implements 
1233:                java.awt.event.ItemListener {
1234:            SchemaFrame adaptee;
1235:
1236:            SchemaFrame_catComboBox_itemAdapter(SchemaFrame adaptee) {
1237:                this .adaptee = adaptee;
1238:            }
1239:
1240:            public void itemStateChanged(ItemEvent e) {
1241:                adaptee.catComboBox_itemStateChanged(e);
1242:            }
1243:        }
1244:
1245:        class SchemaFrame_printButton_actionAdapter implements 
1246:                java.awt.event.ActionListener {
1247:            SchemaFrame adaptee;
1248:
1249:            SchemaFrame_printButton_actionAdapter(SchemaFrame adaptee) {
1250:                this .adaptee = adaptee;
1251:            }
1252:
1253:            public void actionPerformed(ActionEvent e) {
1254:                adaptee.printButton_actionPerformed(e);
1255:            }
1256:        }
1257:
1258:        class SchemaFrame_printFitButton_actionAdapter implements 
1259:                java.awt.event.ActionListener {
1260:            SchemaFrame adaptee;
1261:
1262:            SchemaFrame_printFitButton_actionAdapter(SchemaFrame adaptee) {
1263:                this .adaptee = adaptee;
1264:            }
1265:
1266:            public void actionPerformed(ActionEvent e) {
1267:                adaptee.printFitButton_actionPerformed(e);
1268:            }
1269:        }
1270:
1271:        class SchemaFrame_loadButton_actionAdapter implements 
1272:                java.awt.event.ActionListener {
1273:            SchemaFrame adaptee;
1274:
1275:            SchemaFrame_loadButton_actionAdapter(SchemaFrame adaptee) {
1276:                this .adaptee = adaptee;
1277:            }
1278:
1279:            public void actionPerformed(ActionEvent e) {
1280:                adaptee.loadButton_actionPerformed(e);
1281:            }
1282:        }
1283:
1284:        class SchemaFrame_saveButton_actionAdapter implements 
1285:                java.awt.event.ActionListener {
1286:            SchemaFrame adaptee;
1287:
1288:            SchemaFrame_saveButton_actionAdapter(SchemaFrame adaptee) {
1289:                this .adaptee = adaptee;
1290:            }
1291:
1292:            public void actionPerformed(ActionEvent e) {
1293:                adaptee.saveButton_actionPerformed(e);
1294:            }
1295:        }
1296:
1297:        class SchemaFrame_expButton_actionAdapter implements 
1298:                java.awt.event.ActionListener {
1299:            SchemaFrame adaptee;
1300:
1301:            SchemaFrame_expButton_actionAdapter(SchemaFrame adaptee) {
1302:                this .adaptee = adaptee;
1303:            }
1304:
1305:            public void actionPerformed(ActionEvent e) {
1306:                adaptee.expButton_actionPerformed(e);
1307:            }
1308:        }
1309:
1310:        class SchemaFrame_zoomComboBox_itemAdapter implements 
1311:                java.awt.event.ItemListener {
1312:            SchemaFrame adaptee;
1313:
1314:            SchemaFrame_zoomComboBox_itemAdapter(SchemaFrame adaptee) {
1315:                this .adaptee = adaptee;
1316:            }
1317:
1318:            public void itemStateChanged(ItemEvent e) {
1319:                adaptee.zoomComboBox_itemStateChanged(e);
1320:            }
1321:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.