Source Code Cross Referenced for BasicSQLGraphController.java in  » IDE-Netbeans » etl.project » org » netbeans » modules » sql » framework » ui » view » graph » 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 » IDE Netbeans » etl.project » org.netbeans.modules.sql.framework.ui.view.graph 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003:         *
0004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005:         *
0006:         * The contents of this file are subject to the terms of either the GNU
0007:         * General Public License Version 2 only ("GPL") or the Common
0008:         * Development and Distribution License("CDDL") (collectively, the
0009:         * "License"). You may not use this file except in compliance with the
0010:         * License. You can obtain a copy of the License at
0011:         * http://www.netbeans.org/cddl-gplv2.html
0012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
0013:         * specific language governing permissions and limitations under the
0014:         * License.  When distributing the software, include this License Header
0015:         * Notice in each file and include the License file at
0016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
0017:         * particular file as subject to the "Classpath" exception as provided
0018:         * by Sun in the GPL Version 2 section of the License file that
0019:         * accompanied this code. If applicable, add the following below the
0020:         * License Header, with the fields enclosed by brackets [] replaced by
0021:         * your own identifying information:
0022:         * "Portions Copyrighted [year] [name of copyright owner]"
0023:         *
0024:         * Contributor(s):
0025:         *
0026:         * The Original Software is NetBeans. The Initial Developer of the Original
0027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
0028:         * Microsystems, Inc. All Rights Reserved.
0029:         *
0030:         * If you wish your version of this file to be governed by only the CDDL
0031:         * or only the GPL Version 2, indicate your decision by adding
0032:         * "[Contributor] elects to include this software in this distribution
0033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
0034:         * single choice of license, a recipient has the option to distribute
0035:         * your version of this file under either the CDDL, the GPL Version 2 or
0036:         * to extend the choice of license to its licensees as provided above.
0037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
0038:         * Version 2 license, then the option applies only if the new code is
0039:         * made subject to such option by the copyright holder.
0040:         */
0041:        package org.netbeans.modules.sql.framework.ui.view.graph;
0042:
0043:        import java.awt.BorderLayout;
0044:        import java.awt.Dialog;
0045:        import java.awt.Point;
0046:        import java.awt.datatransfer.DataFlavor;
0047:        import java.awt.datatransfer.Transferable;
0048:        import java.awt.datatransfer.UnsupportedFlavorException;
0049:        import java.awt.dnd.DnDConstants;
0050:        import java.io.IOException;
0051:        import java.sql.Connection;
0052:        import java.sql.Types;
0053:        import java.util.ArrayList;
0054:        import java.util.Iterator;
0055:        import java.util.List;
0056:        import java.util.MissingResourceException;
0057:        import javax.swing.BorderFactory;
0058:        import javax.swing.BoxLayout;
0059:        import javax.swing.ButtonGroup;
0060:        import javax.swing.JLabel;
0061:        import javax.swing.JPanel;
0062:        import javax.swing.JRadioButton;
0063:        import javax.swing.SwingUtilities;
0064:        import org.openide.DialogDescriptor;
0065:        import org.openide.DialogDisplayer;
0066:        import org.openide.NotifyDescriptor;
0067:        import org.openide.windows.WindowManager;
0068:        import org.netbeans.api.db.explorer.DatabaseConnection;
0069:        import org.netbeans.api.db.explorer.DatabaseMetaDataTransfer;
0070:        import org.netbeans.modules.etl.ui.DataObjectProvider;
0071:        import org.netbeans.modules.etl.ui.ETLDataObject;
0072:        import org.netbeans.modules.etl.ui.ETLEditorSupport;
0073:        import org.netbeans.modules.sql.framework.model.DBMetaDataFactory;
0074:        import org.netbeans.modules.sql.framework.common.utils.TagParserUtility;
0075:        import org.netbeans.modules.sql.framework.model.GUIInfo;
0076:        import org.netbeans.modules.sql.framework.model.RuntimeDatabaseModel;
0077:        import org.netbeans.modules.sql.framework.model.RuntimeInput;
0078:        import org.netbeans.modules.sql.framework.model.RuntimeOutput;
0079:        import org.netbeans.modules.sql.framework.model.SQLCanvasObject;
0080:        import org.netbeans.modules.sql.framework.model.SQLCastOperator;
0081:        import org.netbeans.modules.sql.framework.model.SQLConnectableObject;
0082:        import org.netbeans.modules.sql.framework.model.SQLConstants;
0083:        import org.netbeans.modules.sql.framework.model.SQLDBColumn;
0084:        import org.netbeans.modules.sql.framework.model.SQLDBModel;
0085:        import org.netbeans.modules.sql.framework.model.SQLDBTable;
0086:        import org.netbeans.modules.sql.framework.model.SQLInputObject;
0087:        import org.netbeans.modules.sql.framework.model.SQLJoinView;
0088:        import org.netbeans.modules.sql.framework.model.SQLModelObjectFactory;
0089:        import org.netbeans.modules.sql.framework.model.SQLObject;
0090:        import org.netbeans.modules.sql.framework.model.SQLOperator;
0091:        import org.netbeans.modules.sql.framework.model.SQLOperatorArg;
0092:        import org.netbeans.modules.sql.framework.model.SQLPredicate;
0093:        import org.netbeans.modules.sql.framework.model.SourceColumn;
0094:        import org.netbeans.modules.sql.framework.model.SourceTable;
0095:        import org.netbeans.modules.sql.framework.model.TargetColumn;
0096:        import org.netbeans.modules.sql.framework.model.TargetTable;
0097:        import org.netbeans.modules.sql.framework.model.VisibleSQLLiteral;
0098:        import org.netbeans.modules.sql.framework.model.impl.RuntimeDatabaseModelImpl;
0099:        import org.netbeans.modules.sql.framework.model.impl.RuntimeOutputImpl;
0100:        import org.netbeans.modules.sql.framework.model.impl.SQLCustomOperatorImpl;
0101:        import org.netbeans.modules.sql.framework.model.impl.SourceTableImpl;
0102:        import org.netbeans.modules.sql.framework.model.impl.TargetTableImpl;
0103:        import org.netbeans.modules.sql.framework.model.utils.SQLObjectUtil;
0104:        import org.netbeans.modules.sql.framework.ui.event.SQLDataEvent;
0105:        import org.netbeans.modules.sql.framework.ui.graph.IGraphController;
0106:        import org.netbeans.modules.sql.framework.ui.graph.IGraphLink;
0107:        import org.netbeans.modules.sql.framework.ui.graph.IGraphNode;
0108:        import org.netbeans.modules.sql.framework.ui.graph.IGraphPort;
0109:        import org.netbeans.modules.sql.framework.ui.graph.IGraphView;
0110:        import org.netbeans.modules.sql.framework.ui.graph.IOperatorXmlInfo;
0111:        import org.netbeans.modules.sql.framework.ui.graph.impl.CustomOperatorNode;
0112:        import org.netbeans.modules.sql.framework.ui.model.CollabSQLUIModel;
0113:        import org.netbeans.modules.sql.framework.ui.model.SQLUIModel;
0114:        import org.netbeans.modules.sql.framework.ui.view.join.JoinMainDialog;
0115:        import org.netbeans.modules.sql.framework.ui.view.join.JoinUtility;
0116:        import com.sun.sql.framework.exception.BaseException;
0117:        import net.java.hulp.i18n.Logger;
0118:        import org.netbeans.modules.etl.logger.Localizer;
0119:        import org.netbeans.modules.etl.logger.LogUtil;
0120:        import org.netbeans.modules.sql.framework.model.DBConnectionDefinition;
0121:        import org.netbeans.modules.sql.framework.model.DBTable;
0122:
0123:        /**
0124:         * @author Ritesh Adval
0125:         * @version $Revision$
0126:         */
0127:        public class BasicSQLGraphController implements  IGraphController {
0128:
0129:            private static final String NETBEANS_DBTABLE_MIMETYPE = "application/x-java-netbeans-dbexplorer-table;class=org.netbeans.api.db.explorer.DatabaseMetaDataTransfer$Table";
0130:            private static final String LOG_CATEGORY = BasicSQLGraphController.class
0131:                    .getName();
0132:            private static transient final Logger mLogger = LogUtil
0133:                    .getLogger(BasicSQLGraphController.class.getName());
0134:            private static transient final Localizer mLoc = Localizer.get();
0135:            private static DataFlavor[] mDataFlavorArray = new DataFlavor[1];
0136:
0137:            static {
0138:                try {
0139:                    mDataFlavorArray[0] = new DataFlavor(
0140:                            NETBEANS_DBTABLE_MIMETYPE);
0141:                } catch (ClassNotFoundException ex) {
0142:                    ex.printStackTrace();
0143:                }
0144:            }
0145:            protected SQLUIModel collabModel;
0146:            protected IGraphView viewC;
0147:            private String srcParam = null;
0148:            private String destParam = null;
0149:            private transient int tableTypeSelected = SQLConstants.SOURCE_TABLE;
0150:
0151:            /**
0152:             * Handle drop.
0153:             *
0154:             * @param e DropTargetDropEvent
0155:             */
0156:            public void handleDrop(java.awt.dnd.DropTargetDropEvent e) {
0157:                if (!isEditAllowed()) {
0158:                    return;
0159:                }
0160:
0161:                boolean dropStatus = false;
0162:                Point loc = e.getLocation();
0163:                if (e.isDataFlavorSupported(mDataFlavorArray[0])) {
0164:                    Connection conn = null;
0165:                    try {
0166:                        Transferable t = e.getTransferable();
0167:                        Object o = t.getTransferData(mDataFlavorArray[0]);
0168:                        if (o instanceof  DatabaseMetaDataTransfer.Table) {
0169:                            DatabaseMetaDataTransfer.Table tbl = (DatabaseMetaDataTransfer.Table) o;
0170:                            DatabaseConnection dbConn = tbl
0171:                                    .getDatabaseConnection();
0172:                            conn = dbConn.getJDBCConnection();
0173:                            String tableName = tbl.getTableName();
0174:                            String schema = tbl.getDatabaseConnection()
0175:                                    .getSchema();
0176:                            String url = dbConn.getDatabaseURL();
0177:                            String catalog = null;
0178:                            try {
0179:                                catalog = conn.getCatalog();
0180:                            } catch (Exception ex) {
0181:                            }
0182:
0183:                            String dlgTitle = null;
0184:                            try {
0185:                                String nbBundle1 = mLoc
0186:                                        .t("PRSR001: Add a table");
0187:                                dlgTitle = Localizer.parse(nbBundle1);
0188:                            } catch (MissingResourceException mre) {
0189:                                dlgTitle = "Add a table";
0190:                            }
0191:
0192:                            CollabSQLUIModel sqlModel = (CollabSQLUIModel) collabModel;
0193:                            TypeSelectorPanel selectorPnl = new TypeSelectorPanel(
0194:                                    tableTypeSelected);
0195:                            DialogDescriptor dlgDesc = null;
0196:                            DBMetaDataFactory dbMeta = new DBMetaDataFactory();
0197:                            dlgDesc = new DialogDescriptor(selectorPnl,
0198:                                    dlgTitle, true,
0199:                                    NotifyDescriptor.OK_CANCEL_OPTION,
0200:                                    NotifyDescriptor.OK_OPTION,
0201:                                    DialogDescriptor.DEFAULT_ALIGN, null, null);
0202:
0203:                            Dialog dlg = DialogDisplayer.getDefault()
0204:                                    .createDialog(dlgDesc);
0205:                            dlg
0206:                                    .getAccessibleContext()
0207:                                    .setAccessibleDescription(
0208:                                            "This dialog helps user to add a table");
0209:                            dlg.setVisible(true);
0210:                            SQLDBTable sTable = null;
0211:                            if (NotifyDescriptor.OK_OPTION == dlgDesc
0212:                                    .getValue()) {
0213:                                e.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
0214:                                tableTypeSelected = selectorPnl
0215:                                        .getSelectedType();
0216:                                boolean isSource = false;
0217:                                if (SQLConstants.SOURCE_TABLE == tableTypeSelected) {
0218:                                    isSource = true;
0219:                                }
0220:                                String[][] tableList = null;
0221:                                try {
0222:                                    dbMeta.connectDB(conn);
0223:                                    schema = (schema == null) ? "" : schema;
0224:                                    catalog = (catalog == null) ? "" : catalog;
0225:                                    tableList = dbMeta.getTablesAndViews(
0226:                                            catalog, schema, "", false);
0227:                                } catch (Exception ex) {
0228:                                }
0229:                                Object dbTable = createTable(tableList,
0230:                                        tableName, isSource);
0231:                                List tbls = null;
0232:                                if (isSource) {
0233:                                    tbls = sqlModel.getSQLDefinition()
0234:                                            .getSourceTables();
0235:                                } else {
0236:                                    tbls = sqlModel.getSQLDefinition()
0237:                                            .getTargetTables();
0238:                                }
0239:                                ((SQLDBTable) dbTable).setAliasUsed(true);
0240:                                ((SQLDBTable) dbTable)
0241:                                        .setAliasName(generateTableAliasName(
0242:                                                isSource, tbls));
0243:                                DBConnectionDefinition def = null;
0244:                                try {
0245:                                    def = SQLModelObjectFactory.getInstance()
0246:                                            .createDBConnectionDefinition(
0247:                                                    dbConn.getDisplayName(),
0248:                                                    dbMeta.getDBType(),
0249:                                                    dbConn.getDriverClass(),
0250:                                                    dbConn.getDatabaseURL(),
0251:                                                    dbConn.getUser(),
0252:                                                    dbConn.getPassword(),
0253:                                                    "Descriptive info here");
0254:                                } catch (Exception ex) {
0255:                                    //ignore
0256:                                }
0257:                                SQLDBModel model = null;
0258:                                if (isSource) {
0259:                                    model = SQLModelObjectFactory
0260:                                            .getInstance()
0261:                                            .createDBModel(
0262:                                                    SQLConstants.SOURCE_DBMODEL);
0263:                                } else {
0264:                                    model = SQLModelObjectFactory
0265:                                            .getInstance()
0266:                                            .createDBModel(
0267:                                                    SQLConstants.TARGET_DBMODEL);
0268:                                }
0269:                                model.setModelName(dbConn.getDisplayName());
0270:                                model.setConnectionDefinition(def);
0271:                                dbMeta.populateColumns((SQLDBTable) dbTable);
0272:                                ((SQLDBTable) dbTable).setEditable(true);
0273:                                ((SQLDBTable) dbTable).setSelected(true);
0274:                                model.addTable((SQLDBTable) dbTable);
0275:
0276:                                if (isSource) {
0277:                                    sTable = (SQLDBTable) collabModel
0278:                                            .addSourceTable(
0279:                                                    (SQLDBTable) dbTable, loc);
0280:                                } else {
0281:                                    sTable = (SQLDBTable) collabModel
0282:                                            .addTargetTable(
0283:                                                    (SQLDBTable) dbTable, loc);
0284:                                    RuntimeDatabaseModel rtModel = sqlModel
0285:                                            .getSQLDefinition()
0286:                                            .getRuntimeDbModel();
0287:                                    if (rtModel == null) {
0288:                                        rtModel = new RuntimeDatabaseModelImpl();
0289:                                    }
0290:                                    RuntimeOutput rtOut = rtModel
0291:                                            .getRuntimeOutput();
0292:                                    SQLDBColumn column = null;
0293:                                    if (rtOut == null) {
0294:                                        rtOut = new RuntimeOutputImpl();
0295:                                        // add STATUS
0296:                                        column = SQLModelObjectFactory
0297:                                                .getInstance()
0298:                                                .createTargetColumn("STATUS",
0299:                                                        Types.VARCHAR, 0, 0,
0300:                                                        true);
0301:                                        column.setEditable(false);
0302:                                        rtOut.addColumn(column);
0303:
0304:                                        // add STARTTIME
0305:                                        column = SQLModelObjectFactory
0306:                                                .getInstance()
0307:                                                .createTargetColumn(
0308:                                                        "STARTTIME",
0309:                                                        Types.TIMESTAMP, 0, 0,
0310:                                                        true);
0311:                                        column.setEditable(false);
0312:                                        rtOut.addColumn(column);
0313:
0314:                                        // add ENDTIME
0315:                                        column = SQLModelObjectFactory
0316:                                                .getInstance()
0317:                                                .createTargetColumn("ENDTIME",
0318:                                                        Types.TIMESTAMP, 0, 0,
0319:                                                        true);
0320:                                        column.setEditable(false);
0321:                                        rtOut.addColumn(column);
0322:                                    }
0323:                                    String argName = SQLObjectUtil
0324:                                            .getTargetTableCountRuntimeOutput((TargetTable) sTable);
0325:                                    column = SQLModelObjectFactory
0326:                                            .getInstance().createTargetColumn(
0327:                                                    argName, Types.INTEGER, 0,
0328:                                                    0, true);
0329:                                    column.setEditable(false);
0330:                                    rtOut.addColumn(column);
0331:                                    rtModel.addTable(rtOut);
0332:                                    sqlModel.getSQLDefinition().addObject(
0333:                                            rtModel);
0334:                                }
0335:
0336:                                SourceColumn runtimeArg = SQLObjectUtil
0337:                                        .createRuntimeInput(sTable, sqlModel
0338:                                                .getSQLDefinition());
0339:                                SQLObjectUtil.setOrgProperties(sTable);
0340:
0341:                                if (runtimeArg != null
0342:                                        && (RuntimeInput) runtimeArg
0343:                                                .getParent() != null) {
0344:                                    RuntimeInput runtimeInput = (RuntimeInput) runtimeArg
0345:                                            .getParent();
0346:                                    // if runtime input is not in SQL definition then add it
0347:                                    if ((sqlModel.getSQLDefinition()
0348:                                            .isTableExists(runtimeInput)) == null) {
0349:                                        sqlModel.getSQLDefinition().addObject(
0350:                                                (SQLObject) runtimeInput);
0351:                                        collabModel.addObject(runtimeInput);
0352:                                        SQLDataEvent evt = new SQLDataEvent(
0353:                                                collabModel, runtimeInput,
0354:                                                runtimeArg);
0355:                                        collabModel
0356:                                                .fireChildObjectCreatedEvent(evt);
0357:                                    }
0358:                                }
0359:                                if (sqlModel.getSQLDefinition()
0360:                                        .getSourceTables().size() > 1) {
0361:                                    if (dbTable instanceof  SourceTableImpl) {
0362:                                        NotifyDescriptor d = new NotifyDescriptor.Confirmation(
0363:                                                "Do you want to create a join?",
0364:                                                "Confirm join creation",
0365:                                                NotifyDescriptor.YES_NO_OPTION);
0366:                                        if (DialogDisplayer.getDefault()
0367:                                                .notify(d) == NotifyDescriptor.YES_OPTION) {
0368:                                            JoinMainDialog.showJoinDialog(
0369:                                                    sqlModel.getSQLDefinition()
0370:                                                            .getJoinSources(),
0371:                                                    null, this .viewC, true);
0372:                                            if (JoinMainDialog
0373:                                                    .getClosingButtonState() == JoinMainDialog.OK_BUTTON) {
0374:                                                SQLJoinView joinView = JoinMainDialog
0375:                                                        .getSQLJoinView();
0376:                                                try {
0377:                                                    if (joinView != null) {
0378:                                                        JoinUtility
0379:                                                                .handleNewJoinCreation(
0380:                                                                        joinView,
0381:                                                                        JoinMainDialog
0382:                                                                                .getTableColumnNodes(),
0383:                                                                        this .viewC);
0384:                                                    }
0385:                                                } catch (BaseException ex) {
0386:                                                    DialogDisplayer
0387:                                                            .getDefault()
0388:                                                            .notify(
0389:                                                                    new NotifyDescriptor.Message(
0390:                                                                            "Error adding join view.",
0391:                                                                            NotifyDescriptor.INFORMATION_MESSAGE));
0392:                                                    mLogger
0393:                                                            .errorNoloc(
0394:                                                                    mLoc
0395:                                                                            .t(
0396:                                                                                    "PRSR160: error adding join view{0}",
0397:                                                                                    LOG_CATEGORY),
0398:                                                                    ex);
0399:
0400:                                                }
0401:                                            }
0402:                                        }
0403:                                    }
0404:                                }
0405:                                collabModel.setDirty(true);
0406:                                updateActions(collabModel);
0407:                                dropStatus = true;
0408:                            }
0409:                        } else {
0410:                            e.rejectDrop();
0411:                        }
0412:                    } catch (IOException ex) {
0413:
0414:                        mLogger
0415:                                .errorNoloc(
0416:                                        mLoc
0417:                                                .t(
0418:                                                        "PRSR161: Caught IOException while handling DnD.{0}",
0419:                                                        LOG_CATEGORY), ex);
0420:                        e.rejectDrop();
0421:                    } catch (UnsupportedFlavorException ex) {
0422:
0423:                        mLogger
0424:                                .errorNoloc(
0425:                                        mLoc
0426:                                                .t(
0427:                                                        "PRSR162: Caught IOException while handling DnD.{0}",
0428:                                                        LOG_CATEGORY), ex);
0429:                        e.rejectDrop();
0430:                    } catch (BaseException ex) {
0431:                        DialogDisplayer.getDefault().notify(
0432:                                new NotifyDescriptor.Message(ex
0433:                                        .getLocalizedMessage(),
0434:                                        NotifyDescriptor.WARNING_MESSAGE));
0435:                        mLogger
0436:                                .errorNoloc(
0437:                                        mLoc
0438:                                                .t(
0439:                                                        "PRSR163: Caught IOException while handling DnD.{0}",
0440:                                                        LOG_CATEGORY), ex);
0441:
0442:                        e.rejectDrop();
0443:                    } catch (Exception ex) {
0444:                        mLogger
0445:                                .errorNoloc(
0446:                                        mLoc
0447:                                                .t(
0448:                                                        "PRSR164: Caught IOException while handling DnD.{0}",
0449:                                                        LOG_CATEGORY), ex);
0450:
0451:                        e.rejectDrop();
0452:                    } finally {
0453:                        e.dropComplete(dropStatus);
0454:                        conn = null;
0455:                    }
0456:                } else {
0457:                    e.rejectDrop();
0458:                }
0459:            }
0460:
0461:            /**
0462:             * Handle drop of arbitrary object.
0463:             *
0464:             * @param obj Object dropped onto canvas
0465:             */
0466:            public void handleObjectDrop(Object obj) {
0467:                if (!isEditAllowed()) {
0468:                    return;
0469:                }
0470:            }
0471:
0472:            /**
0473:             * handle new link
0474:             *
0475:             * @param from IGraphPort
0476:             * @param to IGraphPort
0477:             */
0478:            public void handleLinkAdded(IGraphPort from, IGraphPort to) {
0479:                if (!isEditAllowed()) {
0480:                    return;
0481:                }
0482:
0483:                IGraphNode srcGraphNode = null;
0484:                IGraphNode destGraphNode = null;
0485:
0486:                srcGraphNode = from.getDataNode();
0487:                destGraphNode = to.getDataNode();
0488:
0489:                if (srcGraphNode != null && destGraphNode != null
0490:                        && srcGraphNode.equals(destGraphNode)) {
0491:                    return;
0492:                }
0493:
0494:                setParameters(from, to, srcGraphNode, destGraphNode);
0495:
0496:                SQLCanvasObject srcObj = (SQLCanvasObject) srcGraphNode
0497:                        .getDataObject();
0498:                SQLConnectableObject destObj = (SQLConnectableObject) destGraphNode
0499:                        .getDataObject();
0500:
0501:                if (srcObj == null && destObj == null) {
0502:                    return;
0503:                }
0504:
0505:                SQLInputObject inputObj = destObj.getInput(destParam);
0506:                SQLObject existing = (inputObj != null) ? inputObj
0507:                        .getSQLObject() : null;
0508:                if (existing instanceof  TargetColumn) {
0509:                    existing = ((TargetColumn) existing).getValue();
0510:                }
0511:
0512:                if (existing != null) {
0513:                    return;
0514:                }
0515:
0516:                try {
0517:                    // do type checking
0518:                    boolean userResponse = doTypeChecking(srcObj, destObj,
0519:                            srcParam, destParam);
0520:
0521:                    if (!userResponse) {
0522:                        return;
0523:                    }
0524:
0525:                    CollabSQLUIModel sqlModel = (CollabSQLUIModel) this .collabModel;
0526:                    SourceTable s1 = SQLObjectUtil.getInputSourceTable(srcObj,
0527:                            sqlModel.getSQLDefinition().getAllObjects());
0528:                    SourceTable s2 = SQLObjectUtil.getInputSourceTable(destObj,
0529:                            sqlModel.getSQLDefinition().getAllObjects());
0530:
0531:                    TargetTable t1 = SQLObjectUtil.getMappedTargetTable(srcObj,
0532:                            sqlModel.getSQLDefinition().getTargetTables());
0533:                    TargetTable t2 = SQLObjectUtil.getMappedTargetTable(
0534:                            destObj, sqlModel.getSQLDefinition()
0535:                                    .getTargetTables());
0536:
0537:                    if (t1 == null && s1 != null) {
0538:                        t1 = SQLObjectUtil.getMappedTargetTable(s1, sqlModel
0539:                                .getSQLDefinition().getTargetTables());
0540:                    }
0541:
0542:                    if (t2 == null && s2 != null) {
0543:                        t2 = SQLObjectUtil.getMappedTargetTable(s2, sqlModel
0544:                                .getSQLDefinition().getTargetTables());
0545:                    }
0546:
0547:                    SQLJoinView jv1 = sqlModel.getJoinView(s1);
0548:                    SQLJoinView jv2 = sqlModel.getJoinView(s2);
0549:
0550:                    // join view is not null but a source table of join view which is not
0551:                    // directly linked to target is s1 so we need to find target based on join
0552:                    // view
0553:                    if (jv1 != null && t1 == null) {
0554:                        t1 = SQLObjectUtil.getMappedTargetTable(jv1, sqlModel
0555:                                .getSQLDefinition().getTargetTables());
0556:                    }
0557:
0558:                    if (jv2 != null && t2 == null) {
0559:                        t2 = SQLObjectUtil.getMappedTargetTable(jv2, sqlModel
0560:                                .getSQLDefinition().getTargetTables());
0561:                    }
0562:
0563:                    // we have target table but join view is still null, so check target
0564:                    // if it has a join view
0565:                    if (jv1 == null && t1 != null) {
0566:                        jv1 = t1.getJoinView();
0567:                    }
0568:
0569:                    if (jv2 == null && t2 != null) {
0570:                        jv2 = t2.getJoinView();
0571:                    }
0572:
0573:                    // can not map it as both source tables are mapped to different
0574:                    // target tables or can not map if both source tables belong to different
0575:                    // join view
0576:                    if (t1 != null && t2 != null && !t1.equals(t2)) {
0577:                        String nbBundle2 = mLoc
0578:                                .t(
0579:                                        "PRSR001: Link is not allowed. ''{0}'' is already mapped to target table ''{1}''.",
0580:                                        srcObj.getDisplayName(), t1
0581:                                                .getDisplayName());
0582:                        String msg = Localizer.parse(nbBundle2);
0583:
0584:                        if (!(srcObj instanceof  SourceTable) && s1 != null) {
0585:                            String nbBundle3 = mLoc
0586:                                    .t(
0587:                                            "PRSR001: Link is not allowed. ''{0}'' is mapped to source table ''{1}'' which is already mapped to target table ''{2}''.",
0588:                                            srcObj.getDisplayName(), s1
0589:                                                    .getName(), t1
0590:                                                    .getDisplayName());
0591:                            msg = Localizer.parse(nbBundle3);
0592:                        }
0593:
0594:                        NotifyDescriptor d = new NotifyDescriptor.Message(msg,
0595:                                NotifyDescriptor.INFORMATION_MESSAGE);
0596:
0597:                        DialogDisplayer.getDefault().notify(d);
0598:
0599:                        return;
0600:                    } else if (jv1 != null && jv2 != null && !jv1.equals(jv2)) {
0601:                        String nbBundle4 = mLoc
0602:                                .t(
0603:                                        "PRSR001: Link is not allowed between join view ''{0}'' and ''{1}''.",
0604:                                        jv1.getAliasName(), jv2.getAliasName());
0605:                        NotifyDescriptor d = new NotifyDescriptor.Message(
0606:                                Localizer.parse(nbBundle4),
0607:                                NotifyDescriptor.INFORMATION_MESSAGE);
0608:                        DialogDisplayer.getDefault().notify(d);
0609:                        return;
0610:                    }
0611:
0612:                    if (s1 != null && s2 != null && !s1.equals(s2)) {
0613:                        // if both source tables are not part of a join view then prompt user for
0614:                        // a join view
0615:                        if (jv1 == null && jv2 == null) {
0616:                            ArrayList<DBTable> sTables = new ArrayList<DBTable>();
0617:                            sTables.add(s1);
0618:                            sTables.add(s2);
0619:                            this .promptForNewJoinView(srcObj, destObj, sTables);
0620:                            return;
0621:                        } else if (jv1 == null && jv2 != null) {
0622:                            this .promptForAddToExistingJoinView(srcObj,
0623:                                    destObj, s1, jv2);
0624:                            return;
0625:                        } else if (jv1 != null && jv2 == null) {
0626:                            this .promptForAddToExistingJoinView(srcObj,
0627:                                    destObj, s2, jv1);
0628:                            return;
0629:                        }
0630:                    }
0631:
0632:                    // create actual link
0633:                    createLink(srcObj, destObj);
0634:
0635:                    if (destObj instanceof  TargetTable) {
0636:                        SQLTargetTableArea tt = (SQLTargetTableArea) destGraphNode;
0637:                        TargetColumn tCol = (TargetColumn) inputObj
0638:                                .getSQLObject();
0639:                        if ((tCol != null) && (tCol.isPrimaryKey())) {
0640:                            tt.setConditionIcons();
0641:                        }
0642:                    }
0643:                    updateActions(collabModel);
0644:                } catch (Exception sqle) {
0645:                    NotifyDescriptor d = new NotifyDescriptor.Message(sqle
0646:                            .toString(), NotifyDescriptor.INFORMATION_MESSAGE);
0647:                    DialogDisplayer.getDefault().notify(d);
0648:                }
0649:            }
0650:
0651:            private void createLink(SQLCanvasObject srcObj,
0652:                    SQLConnectableObject destObj) throws BaseException {
0653:                if (srcObj != null && destObj != null) {
0654:                    collabModel
0655:                            .createLink(srcObj, srcParam, destObj, destParam);
0656:                }
0657:            }
0658:
0659:            private void promptForNewJoinView(final SQLCanvasObject srcObj,
0660:                    final SQLConnectableObject destObj,
0661:                    final List<DBTable> sTables) {
0662:
0663:                Runnable runDialog = new Runnable() {
0664:
0665:                    public void run() {
0666:                        try {
0667:                            if (promptForNewJoinView(sTables)) {
0668:                                // create actual link
0669:                                createLink(srcObj, destObj);
0670:                            }
0671:                        } catch (Exception ex) {
0672:                            NotifyDescriptor d = new NotifyDescriptor.Message(
0673:                                    ex.toString(),
0674:                                    NotifyDescriptor.ERROR_MESSAGE);
0675:                            DialogDisplayer.getDefault().notify(d);
0676:                        }
0677:                    }
0678:                };
0679:
0680:                SwingUtilities.invokeLater(runDialog);
0681:            }
0682:
0683:            private boolean promptForNewJoinView(List<DBTable> sTables)
0684:                    throws BaseException {
0685:                boolean userResponse = false;
0686:                String nbBundle5 = mLoc
0687:                        .t("PRSR001: You need to create a join view if you want to map columns of two or more tables.  Create a join view?");
0688:                NotifyDescriptor d = new NotifyDescriptor.Confirmation(
0689:                        Localizer.parse(nbBundle5),
0690:                        NotifyDescriptor.WARNING_MESSAGE);
0691:                Object response = DialogDisplayer.getDefault().notify(d);
0692:
0693:                if (response.equals(NotifyDescriptor.OK_OPTION)) {
0694:                    CollabSQLUIModel sqlModel = (CollabSQLUIModel) this .collabModel;
0695:                    List<DBTable> joinSources = sqlModel.getSQLDefinition()
0696:                            .getJoinSources();
0697:
0698:                    joinSources.removeAll(sTables);
0699:                    JoinMainDialog.showJoinDialog(joinSources, sTables,
0700:                            this .viewC, false);
0701:
0702:                    if (JoinMainDialog.getClosingButtonState() == JoinMainDialog.OK_BUTTON) {
0703:                        SQLJoinView joinView = JoinMainDialog.getSQLJoinView();
0704:                        if (joinView != null) {
0705:                            sqlModel.setDirty(true);
0706:                            JoinUtility.handleNewJoinCreation(joinView,
0707:                                    JoinMainDialog.getTableColumnNodes(),
0708:                                    this .viewC);
0709:                            userResponse = true;
0710:                        }
0711:                    }
0712:                }
0713:
0714:                return userResponse;
0715:            }
0716:
0717:            private void promptForAddToExistingJoinView(
0718:                    final SQLCanvasObject srcObj,
0719:                    final SQLConnectableObject destObj,
0720:                    final SourceTable sTable, final SQLJoinView initJoinView) {
0721:                Runnable runDialog = new Runnable() {
0722:
0723:                    public void run() {
0724:                        try {
0725:                            if (promptForAddToExistingJoinView(sTable,
0726:                                    initJoinView)) {
0727:                                // create actual link
0728:                                createLink(srcObj, destObj);
0729:                            }
0730:                        } catch (Exception ex) {
0731:                            NotifyDescriptor d = new NotifyDescriptor.Message(
0732:                                    ex.toString(),
0733:                                    NotifyDescriptor.ERROR_MESSAGE);
0734:                            DialogDisplayer.getDefault().notify(d);
0735:                        }
0736:                    }
0737:                };
0738:
0739:                SwingUtilities.invokeLater(runDialog);
0740:            }
0741:
0742:            private boolean promptForAddToExistingJoinView(SourceTable sTable,
0743:                    SQLJoinView initJoinView) throws BaseException {
0744:                boolean userResponse = false;
0745:                String nbBundle6 = mLoc
0746:                        .t(
0747:                                "PRSR001: You need to add table ''{0}'' to the already existing join view in order to map columns.  Add table to existing join view?",
0748:                                sTable.getName());
0749:                NotifyDescriptor d = new NotifyDescriptor.Confirmation(
0750:                        Localizer.parse(nbBundle6),
0751:                        NotifyDescriptor.WARNING_MESSAGE);
0752:                Object response = DialogDisplayer.getDefault().notify(d);
0753:
0754:                if (response.equals(NotifyDescriptor.OK_OPTION)) {
0755:                    CollabSQLUIModel sqlModel = (CollabSQLUIModel) this .collabModel;
0756:                    List<DBTable> joinSources = sqlModel.getSQLDefinition()
0757:                            .getJoinSources();
0758:                    joinSources.remove(sTable);
0759:                    JoinMainDialog.showJoinDialog(joinSources, sTable,
0760:                            initJoinView, this .viewC);
0761:                    if (JoinMainDialog.getClosingButtonState() == JoinMainDialog.OK_BUTTON) {
0762:                        SQLJoinView joinView = JoinMainDialog.getSQLJoinView();
0763:
0764:                        if (!initJoinView.equals(joinView)) {
0765:                            sqlModel.setDirty(true);
0766:                        }
0767:                        // join sources
0768:                        List<DBTable> jSources = initJoinView.getSourceTables();
0769:                        jSources.add(sTable);
0770:                        // call this
0771:                        JoinUtility.editJoinView(initJoinView, joinView,
0772:                                jSources, JoinMainDialog.getTableColumnNodes(),
0773:                                this .viewC);
0774:                        userResponse = true;
0775:                    }
0776:                }
0777:
0778:                return userResponse;
0779:            }
0780:
0781:            /** Creates a new instance of SQLGraphController */
0782:            public BasicSQLGraphController() {
0783:            }
0784:
0785:            private boolean doTypeChecking(SQLCanvasObject srcObj,
0786:                    SQLConnectableObject destObj, String srcParam1,
0787:                    String destParam1) throws BaseException {
0788:
0789:                String msg = null;
0790:                SQLObject input = srcObj;
0791:
0792:                // get the specific sub object from srcObj which we are trying to link
0793:                input = srcObj.getOutput(srcParam1);
0794:
0795:                if (!destObj.isInputValid(destParam1, input)) {
0796:                    try {
0797:                        String srcObjType = TagParserUtility
0798:                                .getDisplayStringFor(input.getObjectType());
0799:                        String destObjType = TagParserUtility
0800:                                .getDisplayStringFor(destObj.getObjectType());
0801:                        String srcName = destObj.getDisplayName();
0802:
0803:                        if (srcName != null && destParam1 != null) {
0804:                            String nbBundle7 = mLoc
0805:                                    .t(
0806:                                            "PRSR001: Cannot connect {0} to {1}-{2} at input {3}.",
0807:                                            srcObjType, destObjType, destObj
0808:                                                    .getDisplayName(),
0809:                                            destParam1);
0810:                            msg = Localizer.parse(nbBundle7);
0811:                        } else {
0812:                            String nbBundle8 = mLoc.t(
0813:                                    "PRSR001: Cannot connect {0} to {1}",
0814:                                    srcObjType, destObjType);
0815:                            msg = Localizer.parse(nbBundle8);
0816:                        }
0817:                    } catch (Exception e) {
0818:                        mLogger
0819:                                .errorNoloc(
0820:                                        mLoc
0821:                                                .t(
0822:                                                        "PRSR165: Caught Exception while resolving error message{0}",
0823:                                                        LOG_CATEGORY), e);
0824:
0825:                        msg = "Cannot link these objects together.";
0826:                    }
0827:
0828:                    NotifyDescriptor.Message m = new NotifyDescriptor.Message(
0829:                            msg, NotifyDescriptor.ERROR_MESSAGE);
0830:
0831:                    DialogDisplayer.getDefault().notify(m);
0832:                    return false;
0833:                }
0834:
0835:                switch (destObj.isInputCompatible(destParam1, input)) {
0836:                case SQLConstants.TYPE_CHECK_INCOMPATIBLE:
0837:                    try {
0838:                        String nbBundle9 = mLoc
0839:                                .t("PRSR001: Incompatible source and target datatypes.");
0840:                        msg = Localizer.parse(nbBundle9);
0841:                    } catch (MissingResourceException e) {
0842:                        msg = "Incompatible source and target datatypes.";
0843:                    }
0844:
0845:                    NotifyDescriptor.Message m = new NotifyDescriptor.Message(
0846:                            msg, NotifyDescriptor.ERROR_MESSAGE);
0847:
0848:                    DialogDisplayer.getDefault().notify(m);
0849:                    return false;
0850:                case SQLConstants.TYPE_CHECK_DOWNCAST_WARNING:
0851:                    try {
0852:                        String nbBundle11 = mLoc
0853:                                .t("PRSR001: Connecting these types may result in a loss of precision or data truncation.  Continue?");
0854:                        msg = Localizer.parse(nbBundle11);
0855:                    } catch (MissingResourceException e) {
0856:                        msg = "Connecting these datatypes may result in a loss of "
0857:                                + "precision or data truncation in the target.  Continue?";
0858:                    }
0859:
0860:                    String title = null;
0861:                    try {
0862:                        String nbBundle12 = mLoc
0863:                                .t("PRSR001: Datatype conversion");
0864:                        title = Localizer.parse(nbBundle12);
0865:                    } catch (MissingResourceException e) {
0866:                        title = "Datatype conversion";
0867:                    }
0868:
0869:                    NotifyDescriptor.Confirmation d = new NotifyDescriptor.Confirmation(
0870:                            msg, title, NotifyDescriptor.OK_CANCEL_OPTION,
0871:                            NotifyDescriptor.QUESTION_MESSAGE);
0872:
0873:                    return DialogDisplayer.getDefault().notify(d) == NotifyDescriptor.OK_OPTION;
0874:                case SQLConstants.TYPE_CHECK_COMPATIBLE:
0875:                default:
0876:                    return true;
0877:                }
0878:            }
0879:
0880:            private void setParameters(IGraphPort from, IGraphPort to,
0881:                    IGraphNode srcGraphNode, IGraphNode destGraphNode) {
0882:
0883:                if (srcGraphNode != null && destGraphNode != null) {
0884:                    srcParam = srcGraphNode.getFieldName(from);
0885:                    destParam = destGraphNode.getFieldName(to);
0886:                }
0887:            }
0888:
0889:            /**
0890:             * handle link deletion
0891:             *
0892:             * @param link IGraphLink
0893:             */
0894:            public void handleLinkDeleted(IGraphLink link) {
0895:                if (!isEditAllowed()) {
0896:                    return;
0897:                }
0898:
0899:                IGraphPort from = link.getFromGraphPort();
0900:                IGraphPort to = link.getToGraphPort();
0901:                IGraphNode srcGraphNode = from.getDataNode();
0902:                IGraphNode destGraphNode = to.getDataNode();
0903:
0904:                setParameters(from, to, srcGraphNode, destGraphNode);
0905:
0906:                // source is always canvas object and destination is always expression object
0907:                SQLCanvasObject srcObj = (SQLCanvasObject) srcGraphNode
0908:                        .getDataObject();
0909:                SQLConnectableObject destObj = (SQLConnectableObject) destGraphNode
0910:                        .getDataObject();
0911:
0912:                if (srcObj == null && destObj == null) {
0913:                    return;
0914:                }
0915:
0916:                try {
0917:                    collabModel
0918:                            .removeLink(srcObj, srcParam, destObj, destParam);
0919:
0920:                    if (destObj instanceof  TargetTable) {
0921:                        SQLTargetTableArea tt = (SQLTargetTableArea) destGraphNode;
0922:                        SQLInputObject inputObj = destObj.getInput(destParam);
0923:                        if (inputObj != null) {
0924:                            TargetColumn tCol = (TargetColumn) inputObj
0925:                                    .getSQLObject();
0926:                            if ((tCol != null) && (tCol.isPrimaryKey())) {
0927:                                tt.setConditionIcons();
0928:                            }
0929:                        }
0930:                    }
0931:                } catch (Exception e) {
0932:                    NotifyDescriptor d = new NotifyDescriptor.Message(e
0933:                            .toString(), NotifyDescriptor.INFORMATION_MESSAGE);
0934:                    DialogDisplayer.getDefault().notify(d);
0935:                }
0936:            }
0937:
0938:            /**
0939:             * handle node add
0940:             *
0941:             * @param xmlInfo IOperatorXmlInfo
0942:             * @param dropLocation dropLocation
0943:             */
0944:            @SuppressWarnings(value="fallthrough")
0945:            public void handleNodeAdded(IOperatorXmlInfo xmlInfo,
0946:                    Point dropLocation) {
0947:                if (!isEditAllowed()) {
0948:                    return;
0949:                }
0950:
0951:                // what object type is dropped
0952:                String className = xmlInfo.getObjectClassName();
0953:
0954:                try {
0955:                    // create object
0956:                    SQLCanvasObject sqlObj = collabModel
0957:                            .createObject(className);
0958:                    sqlObj.setDisplayName(xmlInfo.getName());
0959:
0960:                    GUIInfo guiInfo = sqlObj.getGUIInfo();
0961:
0962:                    if (dropLocation.x == 0 && dropLocation.y == 0) {
0963:                        guiInfo.setX(guiInfo.getX());
0964:                        guiInfo.setY(guiInfo.getY());
0965:                    } else {
0966:                        guiInfo.setX(dropLocation.x);
0967:                        guiInfo.setY(dropLocation.y);
0968:                    }
0969:
0970:                    // do special processing for following objects
0971:                    switch (sqlObj.getObjectType()) {
0972:                    case SQLConstants.CAST_OPERATOR:
0973:                        String nbBundle13 = mLoc
0974:                                .t("PRSR001: New Cast-As Operator");
0975:                        CastAsDialog castDlg = new CastAsDialog(WindowManager
0976:                                .getDefault().getMainWindow(), Localizer
0977:                                .parse(nbBundle13), true);
0978:                        castDlg.show();
0979:                        if (castDlg.isCanceled()) {
0980:                            return;
0981:                        }
0982:
0983:                        SQLCastOperator castOp = (SQLCastOperator) sqlObj;
0984:                        castOp.setOperatorXmlInfo(xmlInfo);
0985:
0986:                        castOp.setJdbcType(castDlg.getJdbcType());
0987:
0988:                        int precision = castDlg.getPrecision();
0989:                        castOp.setPrecision(precision);
0990:
0991:                        int scale = castDlg.getScale();
0992:                        castOp.setScale(scale);
0993:
0994:                        break;
0995:                    case SQLConstants.CUSTOM_OPERATOR:
0996:                        CustomOperatorPane customOptPane = new CustomOperatorPane(
0997:                                new ArrayList());
0998:                        String nbBundle14 = mLoc.t("PRSR001: User Function");
0999:                        String title = Localizer.parse(nbBundle14);
1000:                        DialogDescriptor dlgDesc = new DialogDescriptor(
1001:                                customOptPane, title, true,
1002:                                NotifyDescriptor.OK_CANCEL_OPTION,
1003:                                NotifyDescriptor.OK_OPTION,
1004:                                DialogDescriptor.DEFAULT_ALIGN, null, null);
1005:                        Dialog customOptDialog = DialogDisplayer.getDefault()
1006:                                .createDialog(dlgDesc);
1007:                        customOptDialog
1008:                                .getAccessibleContext()
1009:                                .setAccessibleDescription(
1010:                                        "This dialog hepls user configure user-defined functions");
1011:                        customOptDialog.setVisible(true);
1012:                        if (NotifyDescriptor.CANCEL_OPTION == dlgDesc
1013:                                .getValue()) {
1014:                            return;
1015:                        }
1016:                        List inputArgs = customOptPane.getArgList();
1017:                        SQLOperatorArg retType = customOptPane.getReturnType();
1018:                        CustomOperatorNode customOptNode = new CustomOperatorNode(
1019:                                xmlInfo, inputArgs, retType);
1020:                        SQLCustomOperatorImpl custOp = (SQLCustomOperatorImpl) sqlObj;
1021:                        custOp.setOperatorXmlInfo(customOptNode);
1022:                        custOp.setCustomOperatorName(customOptPane
1023:                                .getFunctionName());
1024:                        custOp.getOperatorDefinition().setArgList(inputArgs);
1025:                        custOp.initializeInputs(inputArgs.size());
1026:                        break;
1027:                    case SQLConstants.VISIBLE_PREDICATE:
1028:                        ((SQLPredicate) sqlObj).setOperatorXmlInfo(xmlInfo);
1029:                        // fall through to set XML info (using common SQLOperator interface)
1030:                    case SQLConstants.GENERIC_OPERATOR:
1031:                    case SQLConstants.DATE_ARITHMETIC_OPERATOR:
1032:                        // for operator we need to set the type of operator
1033:                        // ((SQLGenericOperator) sqlObj).setOperatorType(xmlInfo.getName());
1034:                        ((SQLOperator) sqlObj).setOperatorXmlInfo(xmlInfo);
1035:                        sqlObj.setDisplayName(xmlInfo.getDisplayName());
1036:                        break;
1037:                    case SQLConstants.VISIBLE_LITERAL:
1038:                        String nbBundle15 = mLoc
1039:                                .t("PRSR001: New Literal Object");
1040:                        LiteralDialog dlg = new LiteralDialog(WindowManager
1041:                                .getDefault().getMainWindow(), Localizer
1042:                                .parse(nbBundle15), true);
1043:                        dlg.show();
1044:
1045:                        // OK button is not pressed so return
1046:                        if (dlg.isCanceled()) {
1047:                            return;
1048:                        }
1049:
1050:                        String value = dlg.getLiteral();
1051:                        VisibleSQLLiteral lit = (VisibleSQLLiteral) sqlObj;
1052:                        lit.setJdbcType(dlg.getType());
1053:                        lit.setValue(value);
1054:                        lit.setDisplayName(xmlInfo.getDisplayName());
1055:
1056:                        break;
1057:                    }
1058:
1059:                    // now add the object
1060:                    collabModel.addObject(sqlObj);
1061:                } catch (BaseException e) {
1062:                    NotifyDescriptor d = new NotifyDescriptor.Message(e
1063:                            .toString(), NotifyDescriptor.INFORMATION_MESSAGE);
1064:                    DialogDisplayer.getDefault().notify(d);
1065:                }
1066:            }
1067:
1068:            /**
1069:             * handle node deletion
1070:             *
1071:             * @param node IGraphNode
1072:             */
1073:            public void handleNodeRemoved(IGraphNode node) {
1074:                if (!isEditAllowed()) {
1075:                    return;
1076:                }
1077:
1078:                try {
1079:                    IGraphNode pNode = node.getParentGraphNode();
1080:                    // if node has a parent then we should delete it from parent and return
1081:                    // we do not need to go to collaboration as node is contained within
1082:                    // its parent and deleting it from its parent should remove it
1083:                    if (pNode != null) {
1084:                        pNode.removeChildNode(node);
1085:                        return;
1086:                    }
1087:
1088:                    SQLCanvasObject sqlObj = (SQLCanvasObject) node
1089:                            .getDataObject();
1090:                    if (sqlObj != null) {
1091:                        collabModel.removeObject(sqlObj);
1092:                    }
1093:
1094:                    // if a source table is deleted, check if it is flatfile and try to remove
1095:                    // its auto generated runtime input argument for file location
1096:                    if (sqlObj.getObjectType() == SQLConstants.SOURCE_TABLE
1097:                            || sqlObj.getObjectType() == SQLConstants.TARGET_TABLE) {
1098:                        SourceColumn col = SQLObjectUtil.removeRuntimeInput(
1099:                                (SQLDBTable) sqlObj,
1100:                                (CollabSQLUIModel) collabModel);
1101:                        if (col != null) {
1102:                            SQLDataEvent evt = new SQLDataEvent(collabModel,
1103:                                    (RuntimeInput) col.getParent(), col);
1104:                            collabModel.fireChildObjectDeletedEvent(evt);
1105:                        }
1106:                    }
1107:                    updateActions(collabModel);
1108:                } catch (Exception e) {
1109:
1110:                    mLogger
1111:                            .errorNoloc(
1112:                                    mLoc
1113:                                            .t(
1114:                                                    "PRSR166: Caught exception while removing object{0}",
1115:                                                    LOG_CATEGORY), e);
1116:                    NotifyDescriptor d = new NotifyDescriptor.Message(e
1117:                            .toString(), NotifyDescriptor.INFORMATION_MESSAGE);
1118:                    DialogDisplayer.getDefault().notify(d);
1119:                }
1120:            }
1121:
1122:            private String generateTableAliasName(boolean isSource, List sTables) {
1123:                int cnt = 1;
1124:                String aliasPrefix = isSource ? "S" : "T";
1125:                String aName = aliasPrefix + cnt;
1126:                while (isTableAliasNameExist(aName, sTables)) {
1127:                    cnt++;
1128:                    aName = aliasPrefix + cnt;
1129:                }
1130:
1131:                return aName;
1132:            }
1133:
1134:            private boolean isTableAliasNameExist(String aName, List sTables) {
1135:
1136:                Iterator it = sTables.iterator();
1137:
1138:                while (it.hasNext()) {
1139:                    SQLDBTable tTable = (SQLDBTable) it.next();
1140:                    String tAlias = tTable.getAliasName();
1141:                    if (tAlias != null && tAlias.equals(aName)) {
1142:                        return true;
1143:                    }
1144:                }
1145:
1146:                return false;
1147:            }
1148:
1149:            /**
1150:             * Sets the data model which this controller modifies
1151:             *
1152:             * @param newModel new data model
1153:             */
1154:            public void setDataModel(Object newModel) {
1155:                collabModel = (SQLUIModel) newModel;
1156:            }
1157:
1158:            public Object getDataModel() {
1159:                return collabModel;
1160:            }
1161:
1162:            class TypeSelectorPanel extends JPanel {
1163:
1164:                private ButtonGroup bg;
1165:                private JRadioButton source;
1166:                private JRadioButton target;
1167:
1168:                public TypeSelectorPanel() {
1169:                    this (SQLConstants.SOURCE_TABLE);
1170:                }
1171:
1172:                public TypeSelectorPanel(int newType) {
1173:                    super ();
1174:                    setLayout(new BorderLayout());
1175:
1176:                    JPanel insetPanel = new JPanel();
1177:                    insetPanel.setLayout(new BoxLayout(insetPanel,
1178:                            BoxLayout.PAGE_AXIS));
1179:                    insetPanel.setBorder(BorderFactory.createEmptyBorder(10,
1180:                            15, 0, 15));
1181:
1182:                    String title = "";
1183:                    try {
1184:                        String nbBundle16 = mLoc
1185:                                .t("PRSR001: Select table type:");
1186:                        title = Localizer.parse(nbBundle16);
1187:                    } catch (MissingResourceException mre) {
1188:                        title = "Specify table type:";
1189:                    }
1190:
1191:                    insetPanel.add(new JLabel(title));
1192:
1193:                    String sourceLabel = "";
1194:                    try {
1195:                        String nbBundle17 = mLoc.t("PRSR001: Source table");
1196:                        sourceLabel = Localizer.parse(nbBundle17);
1197:                    } catch (MissingResourceException mre) {
1198:                        sourceLabel = "Source table";
1199:                    }
1200:
1201:                    String targetLabel = "";
1202:                    try {
1203:                        String nbBundle18 = mLoc.t("PRSR001: Target table");
1204:                        targetLabel = Localizer.parse(nbBundle18);
1205:                    } catch (MissingResourceException mre) {
1206:                        targetLabel = "Target table";
1207:                    }
1208:
1209:                    source = new JRadioButton(sourceLabel);
1210:                    target = new JRadioButton(targetLabel);
1211:
1212:                    insetPanel.add(source);
1213:                    insetPanel.add(target);
1214:
1215:                    add(insetPanel, BorderLayout.CENTER);
1216:
1217:                    bg = new ButtonGroup();
1218:                    bg.add(source);
1219:                    bg.add(target);
1220:
1221:                    setSelectedType(newType);
1222:                }
1223:
1224:                public void setSelectedType(int type) {
1225:                    switch (type) {
1226:                    case SQLConstants.TARGET_TABLE:
1227:                        bg.setSelected(target.getModel(), true);
1228:                        break;
1229:                    case SQLConstants.SOURCE_TABLE:
1230:                    default:
1231:                        bg.setSelected(source.getModel(), true);
1232:                    }
1233:                }
1234:
1235:                public int getSelectedType() {
1236:                    return target.isSelected() ? SQLConstants.TARGET_TABLE
1237:                            : SQLConstants.SOURCE_TABLE;
1238:                }
1239:
1240:                @Override
1241:                public void addNotify() {
1242:                    super .addNotify();
1243:
1244:                    switch (getSelectedType()) {
1245:                    case SQLConstants.TARGET_TABLE:
1246:                        target.requestFocusInWindow();
1247:                        break;
1248:                    case SQLConstants.SOURCE_TABLE:
1249:                    default:
1250:                        source.requestFocusInWindow();
1251:                        break;
1252:                    }
1253:                }
1254:            }
1255:
1256:            protected boolean isEditAllowed() {
1257:                /*  if (viewC != null) {
1258:                return viewC.canEdit();
1259:                }*/
1260:
1261:                return true;
1262:            }
1263:
1264:            /**
1265:             * set the view from which this controller interacts
1266:             *
1267:             * @param view view
1268:             */
1269:            public void setView(Object view) {
1270:                viewC = (IGraphView) view;
1271:            }
1272:
1273:            private void updateActions(SQLUIModel model) {
1274:                try {
1275:                    ETLDataObject etlDataObject = DataObjectProvider
1276:                            .getProvider().getActiveDataObject();
1277:                    if (model.isDirty()) {
1278:                        ETLEditorSupport editor = etlDataObject
1279:                                .getETLEditorSupport();
1280:                        editor.synchDocument();
1281:                    }
1282:                } catch (Exception e) {
1283:                    //ignore
1284:                }
1285:            }
1286:
1287:            private Object createTable(String[][] tableList, String tableName,
1288:                    boolean isSource) {
1289:                String[] currTable = null;
1290:                Object dbTable = null;
1291:                if (tableList != null) {
1292:                    for (int i = 0; i < tableList.length; i++) {
1293:                        currTable = tableList[i];
1294:                        if (currTable[DBMetaDataFactory.NAME].equals(tableName)) {
1295:                            if (isSource) {
1296:                                dbTable = new SourceTableImpl(
1297:                                        currTable[DBMetaDataFactory.NAME],
1298:                                        currTable[DBMetaDataFactory.SCHEMA],
1299:                                        currTable[DBMetaDataFactory.CATALOG]);
1300:                            } else {
1301:                                dbTable = new TargetTableImpl(
1302:                                        currTable[DBMetaDataFactory.NAME],
1303:                                        currTable[DBMetaDataFactory.SCHEMA],
1304:                                        currTable[DBMetaDataFactory.CATALOG]);
1305:                            }
1306:                            break;
1307:                        }
1308:                    }
1309:                }
1310:                return dbTable;
1311:            }
1312:
1313:            class LinkInfo {
1314:
1315:                private SQLCanvasObject sObj;
1316:                private SQLConnectableObject eObj;
1317:                private String sParam;
1318:                private String dParam;
1319:
1320:                LinkInfo(SQLCanvasObject srcObj, SQLConnectableObject expObj,
1321:                        String srcParam, String destParam) {
1322:                    this .sObj = srcObj;
1323:                    this .eObj = expObj;
1324:                    this .sParam = srcParam;
1325:                    this .dParam = destParam;
1326:                }
1327:
1328:                public SQLCanvasObject getSource() {
1329:                    return this .sObj;
1330:                }
1331:
1332:                public SQLConnectableObject getTarget() {
1333:                    return this .eObj;
1334:                }
1335:
1336:                public String getSourceParam() {
1337:                    return this .sParam;
1338:                }
1339:
1340:                public String getTargetParam() {
1341:                    return this.dParam;
1342:                }
1343:            }
1344:        }
ww___w__.j_av__a___2__s.__c__om___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.