Source Code Cross Referenced for SQLBasicTableArea.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.Color;
0044:        import java.awt.Dimension;
0045:        import java.awt.Font;
0046:        import java.awt.GridBagConstraints;
0047:        import java.awt.GridBagLayout;
0048:        import java.awt.event.ActionEvent;
0049:        import java.awt.event.ActionListener;
0050:        import java.net.URL;
0051:        import java.util.ArrayList;
0052:        import java.util.Collections;
0053:        import java.util.Iterator;
0054:        import java.util.List;
0055:        import java.util.Set;
0056:        import java.util.Vector;
0057:
0058:        import javax.swing.Icon;
0059:        import javax.swing.ImageIcon;
0060:        import javax.swing.JLabel;
0061:        import javax.swing.JMenuItem;
0062:        import javax.swing.JOptionPane;
0063:        import javax.swing.JPanel;
0064:        import javax.swing.JPopupMenu;
0065:        import javax.swing.JSeparator;
0066:
0067:        import org.netbeans.modules.sql.framework.model.DBColumn;
0068:        import org.netbeans.modules.sql.framework.common.utils.XmlUtil;
0069:        import org.netbeans.modules.sql.framework.model.SQLCondition;
0070:        import org.netbeans.modules.sql.framework.model.SQLConstants;
0071:        import org.netbeans.modules.sql.framework.model.SQLDBColumn;
0072:        import org.netbeans.modules.sql.framework.model.SQLDBTable;
0073:        import org.netbeans.modules.sql.framework.model.SQLPredicate;
0074:        import org.netbeans.modules.sql.framework.model.SourceColumn;
0075:        import org.netbeans.modules.sql.framework.model.visitors.ColumnsUsedInSQLOperatorVisitor;
0076:        import org.netbeans.modules.sql.framework.ui.graph.IGraphNode;
0077:        import org.netbeans.modules.sql.framework.ui.graph.IGraphPort;
0078:        import org.netbeans.modules.sql.framework.ui.graph.impl.BasicCellArea;
0079:        import org.netbeans.modules.sql.framework.ui.graph.impl.BasicImageArea;
0080:        import org.netbeans.modules.sql.framework.ui.graph.impl.BasicTableArea;
0081:        import org.netbeans.modules.sql.framework.ui.graph.impl.ColumnArea;
0082:        import org.netbeans.modules.sql.framework.ui.graph.impl.ColumnPortArea;
0083:        import org.netbeans.modules.sql.framework.ui.graph.impl.PortArea;
0084:        import org.netbeans.modules.sql.framework.ui.graph.impl.TableConstants;
0085:        import org.netbeans.modules.sql.framework.ui.graph.impl.TitleArea;
0086:        import org.netbeans.modules.sql.framework.ui.model.CollabSQLUIModel;
0087:        import org.netbeans.modules.sql.framework.ui.utils.UIUtil;
0088:        import org.netbeans.modules.sql.framework.ui.view.TableColumnNode;
0089:        import org.netbeans.modules.sql.framework.ui.view.TableColumnTreePanel;
0090:        import org.openide.windows.WindowManager;
0091:        import net.java.hulp.i18n.Logger;
0092:        import com.nwoods.jgo.JGoBrush;
0093:        import com.nwoods.jgo.JGoLink;
0094:        import com.nwoods.jgo.JGoPort;
0095:        import com.sun.sql.framework.exception.BaseException;
0096:        import com.sun.sql.framework.utils.StringUtil;
0097:        import java.awt.event.InputEvent;
0098:        import javax.swing.KeyStroke;
0099:        import org.netbeans.modules.etl.logger.Localizer;
0100:        import org.netbeans.modules.etl.logger.LogUtil;
0101:        import org.netbeans.modules.sql.framework.model.DBTable;
0102:        import org.netbeans.modules.sql.framework.model.ForeignKey;
0103:
0104:        /**
0105:         * This class represents the table rendered on the canvas. It implements custom rendering
0106:         * of a table similar to swing's JTable
0107:         *
0108:         * @author Ritesh Adval
0109:         * @author Jonathan Giron
0110:         */
0111:        public abstract class SQLBasicTableArea extends BasicTableArea
0112:                implements  IGraphNode {
0113:
0114:            /* log4j logger category */
0115:            private static final String LOG_CATEGORY = SQLBasicTableArea.class
0116:                    .getName();
0117:            protected SQLDBTable table;
0118:            private static URL filterUrl = SQLBasicTableArea.class
0119:                    .getResource("/org/netbeans/modules/sql/framework/ui/resources/images/filter16.gif");
0120:            private static URL columnValidationIconUrl = SQLBasicTableArea.class
0121:                    .getResource("/org/netbeans/modules/sql/framework/ui/resources/images/validateField.png");
0122:            private static URL selectColumnsUrl = SQLBasicTableArea.class
0123:                    .getResource("/org/netbeans/modules/sql/framework/ui/resources/images/ColumnSelection.png");
0124:            private static URL removeUrl = SQLBasicTableArea.class
0125:                    .getResource("/org/netbeans/modules/sql/framework/ui/resources/images/remove.png");
0126:            private int tableType;
0127:            private JMenuItem selectColumnsItem;
0128:            private JMenuItem removeItem;
0129:            private static transient final Logger mLogger = LogUtil
0130:                    .getLogger(SQLBasicTableArea.class.getName());
0131:            private static transient final Localizer mLoc = Localizer.get();
0132:
0133:            public SQLBasicTableArea() {
0134:                super ();
0135:                this .setSelectable(true);
0136:                this .setResizable(true);
0137:                this .setPickableBackground(true);
0138:                setTitleToolBarGap(0);
0139:                setToolBarTableGap(0);
0140:            }
0141:
0142:            /**
0143:             * Creates a new instance of SQLBasicTableArea
0144:             *
0145:             * @param table the table to render
0146:             * @param icon icon for this table
0147:             * @param tableType type of this table (input, output, both)
0148:             */
0149:            public SQLBasicTableArea(SQLDBTable table) {
0150:                this ();
0151:                initialize(table);
0152:            }
0153:
0154:            public void initialize(Object obj) {
0155:                this .table = (SQLDBTable) obj;
0156:
0157:                init();
0158:
0159:                this .tableType = table.getObjectType();
0160:
0161:                String title = table.getQualifiedName();
0162:
0163:                titleArea = new TableTitleArea(title);
0164:                Icon icon = createIcon();
0165:                titleArea.setTitleImage(icon);
0166:                titleArea.setBrush(getDefaultTitleBrush());
0167:
0168:                this .addObjectAtTail(titleArea);
0169:
0170:                initializeTable();
0171:
0172:                // Set initialized size to ensure everything is visible in this area.
0173:                setSize(new Dimension(getMaximumWidth(), this 
0174:                        .getMaximumHeight()));
0175:            }
0176:
0177:            abstract Icon createIcon();
0178:
0179:            abstract void initializePopUpMenu();
0180:
0181:            protected abstract JGoBrush getDefaultTitleBrush();
0182:
0183:            protected abstract Color getDefaultBackgroundColor();
0184:
0185:            /**
0186:             * Sets the condition filter icon in the graph table.
0187:             */
0188:            public abstract void setConditionIcons();
0189:
0190:            /**
0191:             * set the table title icon
0192:             *
0193:             * @param tableIcon table title icon
0194:             */
0195:            public void setTableIcon(Icon tableIcon) {
0196:                titleArea.setTitleImage(tableIcon);
0197:            }
0198:
0199:            private void init() {
0200:                popUpMenu = new JPopupMenu();
0201:                initializePopUpMenu();
0202:                initializeProperties();
0203:            }
0204:
0205:            protected void addSelectVisibleColumnsPopUpMenu(
0206:                    ActionListener aListener) {
0207:                String nbBundle1 = mLoc.t("PRSR001: Select Columns...");
0208:                String lbl = Localizer.parse(nbBundle1);
0209:                selectColumnsItem = new JMenuItem(lbl, new ImageIcon(
0210:                        selectColumnsUrl));
0211:                selectColumnsItem.setAccelerator(KeyStroke.getKeyStroke('C',
0212:                        InputEvent.CTRL_MASK));
0213:                selectColumnsItem.addActionListener(aListener);
0214:                popUpMenu.add(selectColumnsItem);
0215:            }
0216:
0217:            protected void addRemovePopUpMenu(ActionListener aListener) {
0218:                //remove menu
0219:                String nbBundle2 = mLoc.t("PRSR001: Remove");
0220:                String lbl = Localizer.parse(nbBundle2);
0221:                removeItem = new JMenuItem(lbl, new ImageIcon(removeUrl));
0222:                removeItem.setAccelerator(KeyStroke.getKeyStroke('O',
0223:                        InputEvent.CTRL_MASK));
0224:                removeItem.addActionListener(aListener);
0225:                popUpMenu.add(removeItem);
0226:            }
0227:
0228:            private void initializeTable() {
0229:                int tType = TableConstants.INPUT_TABLE;
0230:
0231:                if (this .tableType == SQLConstants.TARGET_TABLE) {
0232:                    tType = TableConstants.OUTPUT_TABLE;
0233:                } else if (this .tableType == SQLConstants.RUNTIME_OUTPUT) {
0234:                    tType = TableConstants.NO_PORT_TABLE;
0235:                }
0236:
0237:                SQLTableArea sqlTableArea = new SQLTableArea(tType, table);
0238:                sqlTableArea.setShowHeader(false);
0239:                ColumnArea columnArea = sqlTableArea.getColumnArea(0);
0240:                if (columnArea != null) {
0241:                    columnArea.setPreferredWidth(25);
0242:                }
0243:
0244:                columnArea = sqlTableArea.getColumnArea(2);
0245:                columnArea = sqlTableArea.getColumnArea(3);
0246:
0247:                tableArea = sqlTableArea;
0248:                this .addObjectAtTail(tableArea);
0249:
0250:                setBackgroundColor(getDefaultBackgroundColor());
0251:            }
0252:
0253:            void setFilterIcon(String toolTip) {
0254:                SQLTableArea tabArea = (SQLTableArea) this .getTableArea();
0255:                MetaTableModel model = (MetaTableModel) tabArea.getModel();
0256:                int rowCount = model.getRowCount();
0257:                ColumnArea column = tabArea.getColumnArea(0);
0258:
0259:                for (int i = 0; i < rowCount; i++) {
0260:                    BasicCellArea cell = column.getCellAt(i);
0261:
0262:                    if (model.isFiltered(i)) {
0263:                        String columnToolTip = toolTip;
0264:                        ImageIcon icon = new ImageIcon(filterUrl);
0265:                        SQLDBColumn col = (SQLDBColumn) model.getColumn(i);
0266:                        String columnName = col.toString();
0267:                        if (toolTip != null && columnName != null) {
0268:                            int idx = toolTip.indexOf(columnName);
0269:                            if (idx == -1) {
0270:                                columnName = columnName.toLowerCase();
0271:                            }
0272:                            columnToolTip = columnToolTip.replaceAll(
0273:                                    columnName, "<b> " + columnName + "</b>");
0274:                        }
0275:                        cell.setDataExtractionImageIcon(icon, columnToolTip);
0276:                    } else {
0277:                        cell.setDataExtractionImageIcon(null);
0278:                    }
0279:                }
0280:            }
0281:
0282:            /**
0283:             * Sets Validation icons for each of the columns names which are part of Validation
0284:             * condition.
0285:             *
0286:             * @param condition
0287:             */
0288:            void setValidationIcon(String toolTip) {
0289:                SQLTableArea tabArea = (SQLTableArea) this .getTableArea();
0290:                MetaTableModel model = (MetaTableModel) tabArea.getModel();
0291:                int rowCount = model.getRowCount();
0292:                ColumnArea column = tabArea.getColumnArea(0);
0293:
0294:                for (int i = 0; i < rowCount; i++) {
0295:                    BasicCellArea cell = column.getCellAt(i);
0296:
0297:                    if (model.isValidationPresent(i)) {
0298:                        String columnToolTip = toolTip;
0299:                        ImageIcon icon = new ImageIcon(columnValidationIconUrl);
0300:                        SQLDBColumn col = (SQLDBColumn) model.getColumn(i);
0301:                        String columnName = col.toString();
0302:                        if (toolTip != null && columnName != null) {
0303:                            int idx = toolTip.indexOf(columnName);
0304:                            if (idx == -1) {
0305:                                columnName = columnName.toLowerCase();
0306:                            }
0307:                            columnToolTip = columnToolTip.replaceAll(
0308:                                    columnName, "<b> " + columnName + "</b>");
0309:                        }
0310:                        cell.setImageIcon(BasicCellArea.IMAGE_VALIDATION, icon,
0311:                                columnToolTip);
0312:                    } else {
0313:                        cell.setImageIcon(BasicCellArea.IMAGE_VALIDATION, null);
0314:                    }
0315:                }
0316:            }
0317:
0318:            private String getFilterToolTip(SQLCondition condition) {
0319:                SQLPredicate rootPredicate = condition.getRootPredicate();
0320:
0321:                String toolTip = null;
0322:                StringBuilder tBuffer = new StringBuilder(
0323:                        "<html> <table border=0 cellspacing=0 cellpadding=0><tr><td>");
0324:
0325:                if (rootPredicate != null) {
0326:                    toolTip = rootPredicate.toString();
0327:                    if (toolTip != null) {
0328:                        //TODO we should pass locale when we have to convert to upper case.
0329:                        toolTip = XmlUtil.escapeHTML(toolTip);
0330:                        String upperCaseToolTip = toolTip.toUpperCase();
0331:                        tBuffer
0332:                                .append(StringUtil
0333:                                        .insertStringBeforeLogicalOperators(
0334:                                                upperCaseToolTip,
0335:                                                "</td></tr><tr><td>"));
0336:                    }
0337:                }
0338:
0339:                tBuffer.append("</td></tr></table> </html>");
0340:
0341:                toolTip = tBuffer.toString();
0342:
0343:                return toolTip;
0344:
0345:            }
0346:
0347:            /**
0348:             * Sets the bounding rectangle and ensure it does not resize below a certain width and
0349:             * beyond a fixed height, depending on expanded state.
0350:             *
0351:             * @param left new x-location of upper-left-hand corner of object
0352:             * @param top new y-location of upper-left-hand corner of object
0353:             * @param width width of object
0354:             * @param height height of object
0355:             */
0356:            @Override
0357:            public void setBoundingRect(int left, int top, int width, int height) {
0358:                super .setBoundingRect(left, top, Math.max(width, 100),
0359:                        (isExpandedState() ? getMaximumHeight() : height));
0360:            }
0361:
0362:            /**
0363:             * Lays out the children of this area.
0364:             */
0365:            @Override
0366:            public void layoutChildren() {
0367:                super .layoutChildren();
0368:            }
0369:
0370:            private DBColumn getColumn(JGoPort port) {
0371:                PortArea ptArea = (PortArea) port.getParent();
0372:                ColumnPortArea pAreaGroup = (ColumnPortArea) ptArea.getParent();
0373:                int row = pAreaGroup.getIndexOf(ptArea);
0374:
0375:                if (row == -1) {
0376:                    return null;
0377:                }
0378:
0379:                SQLTableArea tabArea = (SQLTableArea) this .getTableArea();
0380:                MetaTableModel model = (MetaTableModel) tabArea.getModel();
0381:                return model.getColumn(row);
0382:
0383:            }
0384:
0385:            /**
0386:             * Gets the name for a given port.
0387:             *
0388:             * @param iGraphPort port
0389:             * @return name which has a port iGraphPort attach to it
0390:             */
0391:            @Override
0392:            public String getFieldName(IGraphPort iGraphPort) {
0393:                DBColumn column = getColumn((JGoPort) iGraphPort);
0394:                return column.getName();
0395:            }
0396:
0397:            /**
0398:             * Gets column port group based on the column name.
0399:             *
0400:             * @param columnName name of the column
0401:             * @return column port group
0402:             */
0403:            @Override
0404:            public IGraphPort getInputGraphPort(String columnName) {
0405:                SQLTableArea tabArea = (SQLTableArea) this .getTableArea();
0406:                MetaTableModel model = (MetaTableModel) tabArea.getModel();
0407:                int index = -1;
0408:
0409:                for (int i = 0; i < model.getRowCount(); i++) {
0410:                    DBColumn column = model.getColumn(i);
0411:                    if (column != null && column.getName().equals(columnName)) {
0412:                        index = i;
0413:                        break;
0414:
0415:                    }
0416:                }
0417:
0418:                if (index != -1) {
0419:                    ColumnPortArea inputPortArea = tabArea.getInputPortArea();
0420:                    if (inputPortArea != null) {
0421:                        PortArea ptArea = inputPortArea.getPortAreaAt(index);
0422:                        return ptArea.getGraphPort();
0423:                    }
0424:
0425:                }
0426:
0427:                return null;
0428:            }
0429:
0430:            /**
0431:             * Gets the output port which represents the field columnName.
0432:             *
0433:             * @param columnName name of the column
0434:             * @return port which represents columnName
0435:             */
0436:            @Override
0437:            public IGraphPort getOutputGraphPort(String columnName) {
0438:                SQLTableArea tabArea = (SQLTableArea) this .getTableArea();
0439:                MetaTableModel model = (MetaTableModel) tabArea.getModel();
0440:                int index = -1;
0441:
0442:                for (int i = 0; i < model.getRowCount(); i++) {
0443:                    DBColumn column = model.getColumn(i);
0444:                    if (column != null && column.getName().equals(columnName)) {
0445:                        index = i;
0446:                        break;
0447:
0448:                    }
0449:                }
0450:
0451:                if (index != -1) {
0452:                    ColumnPortArea outputPortArea = tabArea.getOutputPortArea();
0453:                    if (outputPortArea != null) {
0454:                        PortArea ptArea = outputPortArea.getPortAreaAt(index);
0455:                        return ptArea.getGraphPort();
0456:                    }
0457:                }
0458:
0459:                return null;
0460:
0461:            }
0462:
0463:            /**
0464:             * Sets the data object
0465:             *
0466:             * @param obj - then object to be represented by this node
0467:             */
0468:            @Override
0469:            public void setDataObject(Object obj) {
0470:                table = (SQLDBTable) obj;
0471:            }
0472:
0473:            public void refreshDataObject(Object obj) {
0474:                SQLTableArea tableArea1 = (SQLTableArea) this .getTableArea();
0475:                tableArea1.setTableObject((DBTable) obj);
0476:                SQLBasicTableArea.this .setHeight(this .getMaximumHeight());
0477:                setDataObject(obj);
0478:            }
0479:
0480:            public void addColumns(List<SQLDBColumn> columnList) {
0481:                boolean added = false;
0482:
0483:                SQLTableArea tableArea1 = (SQLTableArea) this .getTableArea();
0484:                MetaTableModel model = (MetaTableModel) tableArea1.getModel();
0485:
0486:                Iterator<SQLDBColumn> it = columnList.iterator();
0487:                while (it.hasNext()) {
0488:                    SQLDBColumn column = it.next();
0489:                    if (!model.containsColumn(column)) {
0490:                        model.addColumn(column);
0491:                        added = true;
0492:                    } else {
0493:                        makeColumnVisible(column);
0494:                    }
0495:                }
0496:
0497:                if (added) {
0498:                    SQLBasicTableArea.this .setHeight(this .getMaximumHeight());
0499:                }
0500:            }
0501:
0502:            public void makeColumnVisible(SQLDBColumn column) {
0503:                SQLTableArea tableArea1 = (SQLTableArea) this .getTableArea();
0504:                tableArea1.makeColumnVisible(column);
0505:            }
0506:
0507:            public void makeColumnInVisible(SQLDBColumn column)
0508:                    throws BaseException {
0509:                SQLTableArea tableArea1 = (SQLTableArea) this .getTableArea();
0510:                tableArea1.makeColumnInVisible(column);
0511:            }
0512:
0513:            public void removeColumns(List columnList) {
0514:                boolean removed = false;
0515:
0516:                SQLTableArea tableArea1 = (SQLTableArea) this .getTableArea();
0517:                MetaTableModel model = (MetaTableModel) tableArea1.getModel();
0518:
0519:                Iterator it = columnList.iterator();
0520:                while (it.hasNext()) {
0521:                    SQLDBColumn column = (SQLDBColumn) it.next();
0522:                    model.removeColumn(column);
0523:                    removed = true;
0524:                }
0525:
0526:                if (removed) {
0527:                    SQLBasicTableArea.this .setHeight(this .getMaximumHeight());
0528:                }
0529:            }
0530:
0531:            /**
0532:             * If column is visible then we remove the model.removeColumn actually remove the
0533:             * column from its parent table otherwise it just make it invisible in the table node
0534:             * so that later it can be made visible at the same position in the table graph node
0535:             * if you just want to hide table in graph node make sure to set the visible attr in
0536:             * column to false before calling this method otherwise that column will actually be
0537:             * removed permanently from table
0538:             */
0539:            public void removeColumn(SQLDBColumn column) throws BaseException {
0540:
0541:                SQLTableArea tableArea1 = (SQLTableArea) this .getTableArea();
0542:                MetaTableModel model = (MetaTableModel) tableArea1.getModel();
0543:                if (column instanceof  SourceColumn) {
0544:                    removeColumnReference(column);
0545:                }
0546:                model.removeColumn(column);
0547:            }
0548:
0549:            public void updateColumn(DBColumn column) {
0550:                SQLTableArea tableArea1 = (SQLTableArea) this .getTableArea();
0551:                MetaTableModel model = (MetaTableModel) tableArea1.getModel();
0552:                model.updateColumn(column);
0553:            }
0554:
0555:            /**
0556:             * get the data object stored in this object
0557:             *
0558:             * @return data object
0559:             */
0560:            @Override
0561:            public Object getDataObject() {
0562:                return this .table;
0563:            }
0564:
0565:            protected void handleCommonActions(ActionEvent e) {
0566:                Object source = e.getSource();
0567:                if (source == selectColumnsItem) {
0568:                    selectVisibleColumnsActionPerformed(e);
0569:                } else if (source == removeItem) {
0570:                    Remove_ActionPerformed(e);
0571:                }
0572:            }
0573:
0574:            //keep it protected as some subclass overrides it
0575:            protected boolean selectVisibleColumnsActionPerformed(ActionEvent e) {
0576:                SQLDBTable dbTable = (SQLDBTable) SQLBasicTableArea.this 
0577:                        .getDataObject();
0578:                if (dbTable == null) {
0579:                    return false;
0580:                }
0581:
0582:                List tableList = new ArrayList();
0583:                tableList.add(dbTable);
0584:
0585:                TableColumnTreePanel columnPanel = new TableColumnTreePanel(
0586:                        tableList, true);
0587:                JPanel panel = new JPanel();
0588:                panel.setLayout(new GridBagLayout());
0589:
0590:                GridBagConstraints gbc = new GridBagConstraints();
0591:                gbc.gridx = 0;
0592:                gbc.gridy = 0;
0593:                gbc.anchor = GridBagConstraints.FIRST_LINE_START;
0594:                gbc.fill = GridBagConstraints.HORIZONTAL;
0595:                gbc.weightx = 1.0;
0596:                gbc.weighty = 0.0;
0597:                String nbBundle3 = mLoc
0598:                        .t("PRSR001: Select columns to display for this table.");
0599:                String dlgLabel = Localizer.parse(nbBundle3);
0600:                JLabel lbl = new JLabel(dlgLabel);
0601:                lbl.getAccessibleContext().setAccessibleName(dlgLabel);
0602:                lbl.setFont(lbl.getFont().deriveFont(Font.BOLD));
0603:                panel.add(lbl, gbc);
0604:
0605:                gbc = new GridBagConstraints();
0606:                gbc.gridx = 0;
0607:                gbc.gridy = GridBagConstraints.RELATIVE;
0608:                gbc.anchor = GridBagConstraints.CENTER;
0609:                gbc.fill = GridBagConstraints.HORIZONTAL;
0610:                gbc.insets.bottom = 2;
0611:                gbc.weightx = 1.0;
0612:                gbc.weighty = 0.0;
0613:                panel.add(new JSeparator(), gbc);
0614:
0615:                gbc = new GridBagConstraints();
0616:                gbc.gridx = 0;
0617:                gbc.gridy = GridBagConstraints.RELATIVE;
0618:                gbc.anchor = GridBagConstraints.PAGE_START;
0619:                gbc.fill = GridBagConstraints.BOTH;
0620:                gbc.weightx = 1.0;
0621:                gbc.weighty = 1.0;
0622:                panel.add(columnPanel, gbc);
0623:
0624:                String nbBundle4 = mLoc.t("PRSR001: Select Columns");
0625:                String dlgTitle = Localizer.parse(nbBundle4);
0626:                int response = JOptionPane
0627:                        .showConfirmDialog(WindowManager.getDefault()
0628:                                .getMainWindow(), panel, dlgTitle,
0629:                                JOptionPane.OK_CANCEL_OPTION,
0630:                                JOptionPane.PLAIN_MESSAGE);
0631:
0632:                boolean userClickedOk = (JOptionPane.OK_OPTION == response);
0633:                if (userClickedOk) {
0634:                    List columns = dbTable.getColumnList();
0635:                    List tableNodes = columnPanel.getTableColumnNodes();
0636:
0637:                    Iterator iter = columns.iterator();
0638:                    while (iter.hasNext()) {
0639:                        SQLDBColumn column = (SQLDBColumn) iter.next();
0640:                        boolean userWantsVisible = TableColumnNode
0641:                                .isColumnVisible(column, tableNodes);
0642:                        if (column.isVisible() && !userWantsVisible) {
0643:                            column.setVisible(false);
0644:                            try {
0645:                                removeColumn(column);
0646:                            } catch (BaseException ex) {
0647:                            }
0648:                        } else if (!column.isVisible() && userWantsVisible) {
0649:                            column.setVisible(true);
0650:
0651:                            MetaTableModel model = (MetaTableModel) (((SQLTableArea) getTableArea())
0652:                                    .getModel());
0653:                            if (!model.containsColumn(column)) {
0654:                                model.addColumn(column);
0655:                            } else {
0656:                                makeColumnVisible(column);
0657:                            }
0658:                        }
0659:                    }
0660:                    setHeight(getMaximumHeight());
0661:                    layoutChildren();
0662:
0663:                    // Mark collab as needing to be persisted.
0664:                    Object graphModel = getGraphView().getGraphModel();
0665:                    if (graphModel instanceof  CollabSQLUIModel) {
0666:                        ((CollabSQLUIModel) graphModel).setDirty(true);
0667:                    }
0668:                    setConditionIcons();
0669:                }
0670:
0671:                return userClickedOk;
0672:            }
0673:
0674:            //keep it protected as some subclass overrides it
0675:            protected void Remove_ActionPerformed(ActionEvent e) {
0676:                this .getGraphView().deleteNode(this );
0677:            }
0678:
0679:            /**
0680:             * Sets the Extraction condition icons.
0681:             *
0682:             * @param condition
0683:             */
0684:            protected void setTableConditionIcons(SQLCondition condition) {
0685:                if (condition == null) {
0686:                    return;
0687:                }
0688:                setTableConditionIcons(condition, null);
0689:            }
0690:
0691:            /**
0692:             * Sets the Extraction and Validation condition icons.
0693:             *
0694:             * @param extractionCondition
0695:             * @param validationCondition
0696:             */
0697:            protected void setTableConditionIcons(
0698:                    SQLCondition extractionCondition,
0699:                    SQLCondition validationCondition) {
0700:                if ((extractionCondition == null)
0701:                        && (validationCondition == null)) {
0702:                    return;
0703:                }
0704:
0705:                SQLTableArea tableArea1 = (SQLTableArea) SQLBasicTableArea.this 
0706:                        .getTableArea();
0707:                MetaTableModel metTabMod = (MetaTableModel) tableArea1
0708:                        .getModel();
0709:                metTabMod.resetFilters();
0710:                metTabMod.resetValidationFlag();
0711:
0712:                SQLPredicate extractionPredicate = null;
0713:                if (extractionCondition != null) {
0714:                    extractionPredicate = extractionCondition
0715:                            .getRootPredicate();
0716:                }
0717:
0718:                //Set extraction flag on model
0719:                if (extractionPredicate != null) {
0720:                    try {
0721:                        setConditionFlag(BasicCellArea.IMAGE_EXTRACTION,
0722:                                metTabMod, extractionPredicate);
0723:                    } catch (BaseException ex) {
0724:                        mLogger.errorNoloc(mLoc.t(
0725:                                "PRSR168: Error setting filter icon for ({0})",
0726:                                table.getDisplayName()), ex);
0727:
0728:                        return;
0729:                    }
0730:                }
0731:
0732:                SQLPredicate validationPredicate = null;
0733:                if (validationCondition != null) {
0734:                    validationPredicate = validationCondition
0735:                            .getRootPredicate();
0736:                }
0737:
0738:                //Set validation flag on model
0739:                if (validationPredicate != null) {
0740:                    try {
0741:                        setConditionFlag(BasicCellArea.IMAGE_VALIDATION,
0742:                                metTabMod, validationPredicate);
0743:                    } catch (BaseException ex) {
0744:                        mLogger
0745:                                .errorNoloc(
0746:                                        mLoc
0747:                                                .t(
0748:                                                        "PRSR169: Error setting validation icon for ({0})",
0749:                                                        table.getDisplayName()),
0750:                                        ex);
0751:
0752:                        return;
0753:                    }
0754:                }
0755:
0756:                if (extractionCondition != null) {
0757:                    setFilterIcon(getFilterToolTip(extractionCondition));
0758:                }
0759:
0760:                if (validationCondition != null) {
0761:                    setValidationIcon(getFilterToolTip(validationCondition));
0762:                }
0763:                layoutChildren();
0764:            }
0765:
0766:            /**
0767:             * Sets data extraction flag on table model.
0768:             *
0769:             * @param metTabMod
0770:             * @param predicate
0771:             * @throws BaseException
0772:             */
0773:            private void setConditionFlag(int flagType,
0774:                    MetaTableModel metTabMod, SQLPredicate predicate)
0775:                    throws BaseException {
0776:
0777:                Set columnNames = ColumnsUsedInSQLOperatorVisitor
0778:                        .visit(predicate);
0779:                if (columnNames != null) {
0780:                    Iterator cNamesItr = columnNames.iterator();
0781:                    while (cNamesItr.hasNext()) {
0782:                        String rowName = (String) cNamesItr.next();
0783:                        if (rowName != null) {
0784:                            if (flagType == BasicCellArea.IMAGE_EXTRACTION) {
0785:                                metTabMod.setFilter(rowName, true);
0786:                            } else if (flagType == BasicCellArea.IMAGE_VALIDATION) {
0787:                                metTabMod.setValidationFlag(rowName, true);
0788:                            }
0789:                        }
0790:                    }
0791:                }
0792:            }
0793:
0794:            /**
0795:             * Gets a list of all input and output links.
0796:             *
0797:             * @return list of input links
0798:             */
0799:            @Override
0800:            public List<JGoLink> getAllLinks() {
0801:                ArrayList<JGoLink> list = new ArrayList<JGoLink>();
0802:                IGraphPort port = null;
0803:                SQLTableArea tabArea = (SQLTableArea) this .getTableArea();
0804:                MetaTableModel model = (MetaTableModel) tabArea.getModel();
0805:
0806:                for (int i = 0; i < model.getRowCount(); i++) {
0807:                    ColumnPortArea inputPortArea = tabArea.getInputPortArea();
0808:                    if (inputPortArea != null) {
0809:                        PortArea ptArea = inputPortArea.getPortAreaAt(i);
0810:                        if (ptArea != null) {
0811:                            port = ptArea.getGraphPort();
0812:                            addLinks(port, list);
0813:                        }
0814:                    }
0815:
0816:                    ColumnPortArea outputPortArea = tabArea.getOutputPortArea();
0817:                    if (outputPortArea != null) {
0818:                        PortArea ptArea = outputPortArea.getPortAreaAt(i);
0819:                        if (ptArea != null) {
0820:                            port = ptArea.getGraphPort();
0821:                            addLinks(port, list);
0822:                        }
0823:                    }
0824:                }
0825:
0826:                return list;
0827:            }
0828:
0829:            private List getForeignKeyList(DBColumn column) {
0830:                ArrayList optionList = new ArrayList();
0831:                String nbBundle5 = mLoc.t("PRSR001: -->");
0832:                String refString = column.getName()
0833:                        + Localizer.parse(nbBundle5);
0834:
0835:                List list = table.getForeignKeys();
0836:                Iterator it = list.iterator();
0837:                while (it.hasNext()) {
0838:                    ForeignKey fk = (ForeignKey) it.next();
0839:                    if (fk.contains(column)) {
0840:                        List pkColumnList = fk.getPKColumnNames();
0841:                        Iterator it1 = pkColumnList.iterator();
0842:                        while (it1.hasNext()) {
0843:                            String pkColName = (String) it1.next();
0844:                            String optStr = refString.toString() + pkColName;
0845:                            optionList.add(optStr);
0846:                        }
0847:                    }
0848:                }
0849:
0850:                return optionList;
0851:            }
0852:
0853:            private void initializeProperties() {
0854:                ArrayList pkList = new ArrayList();
0855:                ArrayList fkList = new ArrayList();
0856:                ArrayList idxList = new ArrayList();
0857:
0858:                List columnList = table.getColumnList();
0859:                Iterator it = columnList.iterator();
0860:                while (it.hasNext()) {
0861:                    DBColumn column = (DBColumn) it.next();
0862:                    boolean pk = column.isPrimaryKey();
0863:                    boolean fk = column.isForeignKey();
0864:                    boolean indexed = column.isIndexed();
0865:
0866:                    //create pk option
0867:                    if (pk) {
0868:                        pkList.add(column.getName());
0869:                    }
0870:
0871:                    //get fk options
0872:                    if (fk) {
0873:                        List fkListForColumn = getForeignKeyList(column);
0874:                        if (fkListForColumn.size() > 0) {
0875:                            fkList.addAll(fkListForColumn);
0876:                        }
0877:                    }
0878:
0879:                    //create idx option
0880:                    if (indexed) {
0881:                        idxList.add(column.getName());
0882:                    }
0883:                }
0884:
0885:                //sort options
0886:                Collections.sort(pkList);
0887:                Collections.sort(fkList);
0888:                Collections.sort(idxList);
0889:            }
0890:
0891:            class ColumnPropertySupport {
0892:
0893:                private Vector pkVec;
0894:
0895:                ColumnPropertySupport(List list) {
0896:                    pkVec = new Vector(list);
0897:                }
0898:
0899:                public void add(String pk) {
0900:                    pkVec.add(pk);
0901:                }
0902:
0903:                public Vector getDisplayVector() {
0904:                    return pkVec;
0905:                }
0906:
0907:                public String getDisplayString() {
0908:                    if (pkVec.isEmpty()) {
0909:                        String nbBundle6 = mLoc.t("PRSR001: None");
0910:                        return Localizer.parse(nbBundle6);
0911:                    }
0912:
0913:                    StringBuilder strBuf = null;
0914:                    Iterator it = pkVec.iterator();
0915:                    while (it.hasNext()) {
0916:                        String str = (String) it.next();
0917:                        if (strBuf == null) {
0918:                            strBuf = new StringBuilder(str);
0919:                        } else {
0920:                            strBuf.append(str);
0921:                        }
0922:                    }
0923:
0924:                    return strBuf.toString();
0925:                }
0926:            }
0927:
0928:            /**
0929:             * Updates this node with changes in data object.
0930:             */
0931:            @Override
0932:            public void updateUI() {
0933:                SQLBasicTableArea.this .setHeight(this .getMaximumHeight());
0934:            }
0935:
0936:            /**
0937:             * Removes the child data object.
0938:             *
0939:             * @param obj child data object
0940:             */
0941:            @Override
0942:            public void removeChildObject(Object obj) {
0943:                if (obj instanceof  DBColumn) {
0944:                    ArrayList list = new ArrayList();
0945:                    list.add(obj);
0946:                    this .addColumns(list);
0947:                }
0948:            }
0949:
0950:            /**
0951:             * Adds a new child data object.
0952:             *
0953:             * @param obj child data object
0954:             */
0955:            @Override
0956:            public void addChildObject(Object obj) {
0957:                if (obj instanceof  DBColumn) {
0958:                    ArrayList list = new ArrayList();
0959:                    list.add(obj);
0960:                    this .removeColumns(list);
0961:                }
0962:            }
0963:
0964:            public void showExpansionImage(boolean show) {
0965:                this .titleArea.showExpansionImage(show);
0966:            }
0967:
0968:            public boolean isColumnMapped(SQLDBColumn column) {
0969:                SQLTableArea tblArea = (SQLTableArea) this .tableArea;
0970:                return tblArea.isColumnMapped(column);
0971:            }
0972:
0973:            public void removeColumnReference(SQLDBColumn column)
0974:                    throws BaseException {
0975:                SQLTableArea tblArea = (SQLTableArea) this .tableArea;
0976:                tblArea.removeColumnReference(column);
0977:            }
0978:
0979:            class TableTitleArea extends TitleArea {
0980:
0981:                TableTitleArea(String titleStr) {
0982:                    super (titleStr);
0983:                }
0984:
0985:                @Override
0986:                public String getToolTipText() {
0987:                    return UIUtil
0988:                            .getTableToolTip((SQLDBTable) SQLBasicTableArea.this 
0989:                                    .getDataObject());
0990:                }
0991:            }
0992:
0993:            class FilterImage extends BasicImageArea {
0994:
0995:                private SQLCondition condition;
0996:
0997:                FilterImage(SQLCondition cond) {
0998:                    super ();
0999:                    this .condition = cond;
1000:                }
1001:
1002:                @Override
1003:                public String getToolTipText() {
1004:                    if (condition == null) {
1005:                        return null;
1006:                    }
1007:
1008:                    SQLPredicate rootPredicate = condition.getRootPredicate();
1009:
1010:                    if (rootPredicate == null) {
1011:                        return null;
1012:                    }
1013:
1014:                    String filterStr = rootPredicate.toString();
1015:
1016:                    return filterStr;
1017:                }
1018:            }
1019:        }
w___ww__.__j__a_v___a2___s.__c__o__m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.