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


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:        package org.netbeans.modules.sql.framework.ui.view.join;
042:
043:        import java.awt.Color;
044:        import java.awt.Font;
045:        import java.awt.GridBagConstraints;
046:        import java.awt.GridBagLayout;
047:        import java.awt.event.ActionEvent;
048:        import java.awt.event.ActionListener;
049:        import java.net.URL;
050:        import java.util.ArrayList;
051:        import java.util.Collection;
052:        import java.util.HashMap;
053:        import java.util.Iterator;
054:        import java.util.List;
055:        import java.util.Map;
056:        import javax.swing.ImageIcon;
057:        import javax.swing.JLabel;
058:        import javax.swing.JMenuItem;
059:        import javax.swing.JOptionPane;
060:        import javax.swing.JPanel;
061:        import javax.swing.JPopupMenu;
062:        import javax.swing.JSeparator;
063:        import org.netbeans.modules.sql.framework.model.SQLDBColumn;
064:        import org.netbeans.modules.sql.framework.model.SQLDBTable;
065:        import org.netbeans.modules.sql.framework.model.SQLJoinOperator;
066:        import org.netbeans.modules.sql.framework.model.SQLJoinTable;
067:        import org.netbeans.modules.sql.framework.model.SQLJoinView;
068:        import org.netbeans.modules.sql.framework.model.SourceTable;
069:        import org.netbeans.modules.sql.framework.ui.graph.ICommand;
070:        import org.netbeans.modules.sql.framework.ui.graph.IGraphNode;
071:        import org.netbeans.modules.sql.framework.ui.graph.IGraphView;
072:        import org.netbeans.modules.sql.framework.ui.graph.impl.BasicCanvasArea;
073:        import org.netbeans.modules.sql.framework.ui.graph.impl.TableArea;
074:        import org.netbeans.modules.sql.framework.ui.graph.impl.TitleArea;
075:        import org.netbeans.modules.sql.framework.ui.model.CollabSQLUIModel;
076:        import org.netbeans.modules.sql.framework.ui.model.JoinBuilderSQLUIModel;
077:        import org.netbeans.modules.sql.framework.ui.model.SQLUIModel;
078:        import org.netbeans.modules.sql.framework.ui.model.impl.JoinBuilderSQLUIModelImpl;
079:        import org.netbeans.modules.sql.framework.ui.view.TableColumnNode;
080:        import org.netbeans.modules.sql.framework.ui.view.TableColumnTreePanel;
081:        import org.netbeans.modules.sql.framework.ui.view.graph.MetaTableModel;
082:        import org.netbeans.modules.sql.framework.ui.view.graph.SQLBasicTableArea;
083:        import org.netbeans.modules.sql.framework.ui.view.graph.SQLTableArea;
084:        import org.openide.DialogDisplayer;
085:        import org.openide.NotifyDescriptor;
086:        import org.openide.windows.WindowManager;
087:        import com.nwoods.jgo.JGoBrush;
088:        import com.nwoods.jgo.JGoLink;
089:        import com.sun.sql.framework.exception.BaseException;
090:        import net.java.hulp.i18n.Logger;
091:        import javax.swing.table.TableModel;
092:        import org.netbeans.modules.etl.logger.Localizer;
093:        import org.netbeans.modules.etl.logger.LogUtil;
094:        import org.netbeans.modules.sql.framework.model.DBColumn;
095:        import org.netbeans.modules.sql.framework.model.DBTable;
096:        import org.netbeans.modules.sql.framework.ui.graph.impl.GradientBrush;
097:
098:        /**
099:         * @author Ritesh Adval
100:         * @version $Revision$
101:         */
102:        public class JoinViewGraphNode extends BasicCanvasArea {
103:
104:            /* log4j logger category */
105:            private static final String LOG_CATEGORY = JoinViewGraphNode.class
106:                    .getName();
107:            private static URL showSqlUrl = JoinViewGraphNode.class
108:                    .getResource("/org/netbeans/modules/sql/framework/ui/resources/images/Show_Sql.png");
109:            private static URL joinViewUrl = JoinViewGraphNode.class
110:                    .getResource("/org/netbeans/modules/sql/framework/ui/resources/images/join_view.png");
111:            private static URL editJoinViewUrl = JoinViewGraphNode.class
112:                    .getResource("/org/netbeans/modules/sql/framework/ui/resources/images/edit_join.png");
113:            protected static URL selectColumnsUrl = JoinViewGraphNode.class
114:                    .getResource("/org/netbeans/modules/sql/framework/ui/resources/images/ColumnSelection.png");
115:            private static URL removeUrl = JoinViewGraphNode.class
116:                    .getResource("/org/netbeans/modules/sql/framework/ui/resources/images/remove.png");
117:            private static URL showJoinDataUrl = JoinViewGraphNode.class
118:                    .getResource("/org/netbeans/modules/sql/framework/ui/resources/images/showOutput.png");
119:            //private static final Color DEFAULT_TITLE_COLOR = new Color(221, 235, 246);
120:            private static final Color DEFAULT_BG_COLOR = new Color(204, 213,
121:                    241);
122:            private static final Color DEFAULT_BG_COLOR_DARK = new Color(165,
123:                    193, 249);
124:            private static final JGoBrush DEFAULT_TITLE_BRUSH = new GradientBrush(
125:                    DEFAULT_BG_COLOR_DARK, DEFAULT_BG_COLOR);
126:            private JMenuItem showSqlItem;
127:            private JMenuItem editItem;
128:            private JMenuItem showDataItem;
129:            private JMenuItem selectColumnsItem;
130:            protected JMenuItem removeItem;
131:            private JoinViewActionListener aListener;
132:            private ArrayList<SQLJoinTableArea> tableAreas = new ArrayList<SQLJoinTableArea>();
133:            private static final int PREFERRED_JOIN_VIEW_WIDTH = 140;
134:            private static transient final Logger mLogger = LogUtil
135:                    .getLogger(JoinViewGraphNode.class.getName());
136:            private static transient final Localizer mLoc = Localizer.get();
137:
138:            /** Creates a new instance of JoinViewGraphNode */
139:            public JoinViewGraphNode(SQLJoinView jView) {
140:                initGUI(jView);
141:            }
142:
143:            private void initGUI(SQLJoinView jView) {
144:                this .setSelectable(true);
145:                this .setResizable(true);
146:                this .setPickableBackground(false);
147:
148:                //add join view title
149:                String lblTitleArea = jView.getQualifiedName();
150:                titleArea = new TitleArea(lblTitleArea);
151:                titleArea.setBrush(DEFAULT_TITLE_BRUSH);
152:
153:                ImageIcon joinTitleIcon = new ImageIcon(joinViewUrl);
154:                titleArea.setTitleImage(joinTitleIcon);
155:                addObjectAtTail(titleArea);
156:
157:                //go through each table in join view and add table header and
158:                //all table columns
159:                Collection joinTables = jView.getSQLJoinTables();
160:
161:                Iterator it = joinTables.iterator();
162:                while (it.hasNext()) {
163:                    SQLJoinTable jTable = (SQLJoinTable) it.next();
164:                    SourceTable sTable = jTable.getSourceTable();
165:                    addTable(sTable);
166:                }
167:
168:                if (this .getSize().getWidth() == PREFERRED_JOIN_VIEW_WIDTH) {
169:                    // Force layoutChildren().
170:                    this .setSize(PREFERRED_JOIN_VIEW_WIDTH - 1, this 
171:                            .getMaximumHeight());
172:                } else {
173:                    this .setSize(PREFERRED_JOIN_VIEW_WIDTH, this 
174:                            .getMaximumHeight());
175:                }
176:
177:                initializePopUpMenu();
178:            }
179:
180:            private void initializePopUpMenu() {
181:                this .popUpMenu = new JPopupMenu();
182:                aListener = new JoinViewActionListener();
183:
184:                // edit join
185:                String nbBundle1 = mLoc.t("PRSR001: Edit JoinView...");
186:                String lblEditJoin = Localizer.parse(nbBundle1);
187:                editItem = new JMenuItem(lblEditJoin, new ImageIcon(
188:                        editJoinViewUrl));
189:                editItem.addActionListener(aListener);
190:                popUpMenu.add(editItem);
191:
192:                // show sql
193:                // NOTE: Use SQLBasicTableArea.class as superclass Bundle already contains this
194:                // resource
195:                String nbBundle2 = mLoc.t("PRSR001: Show SQL");
196:                String lblShowSql = Localizer.parse(nbBundle2);
197:                showSqlItem = new JMenuItem(lblShowSql, new ImageIcon(
198:                        showSqlUrl));
199:                showSqlItem.addActionListener(aListener);
200:                popUpMenu.add(showSqlItem);
201:
202:                // show join data
203:                String nbBundle3 = mLoc.t("PRSR001: Show Data");
204:                String lblShowData = Localizer.parse(nbBundle3);
205:                showDataItem = new JMenuItem(lblShowData, new ImageIcon(
206:                        showJoinDataUrl));
207:                showDataItem.addActionListener(aListener);
208:                popUpMenu.add(showDataItem);
209:
210:                // select visible columns
211:                // NOTE: Use SQLBasicTableArea.class as superclass Bundle already contains this
212:                // resource
213:                String nbBundle4 = mLoc.t("PRSR001: Select Columns...");
214:                String lblSelectColumns = Localizer.parse(nbBundle4);
215:                selectColumnsItem = new JMenuItem(lblSelectColumns,
216:                        new ImageIcon(selectColumnsUrl));
217:                selectColumnsItem.addActionListener(aListener);
218:                popUpMenu.add(selectColumnsItem);
219:
220:                popUpMenu.addSeparator();
221:                // NOTE: Use SQLBasicTableArea.class as superclass Bundle already contains this
222:                // resource
223:                String nbBundle5 = mLoc.t("PRSR001: Remove");
224:                String lbl = Localizer.parse(nbBundle5);
225:                removeItem = new JMenuItem(lbl, new ImageIcon(removeUrl));
226:                removeItem.addActionListener(aListener);
227:                popUpMenu.add(removeItem);
228:            }
229:
230:            @Override
231:            public void setGraphView(IGraphView view) {
232:                super .setGraphView(view);
233:                Iterator it = tableAreas.iterator();
234:
235:                while (it.hasNext()) {
236:                    SQLBasicTableArea tableArea = (SQLBasicTableArea) it.next();
237:                    tableArea.setGraphView(view);
238:                }
239:            }
240:
241:            /**
242:             * Gets the minimum height of the area.
243:             *
244:             * @return minimum height
245:             */
246:            @Override
247:            public int getMaximumHeight() {
248:                int maxHeight = 0;
249:
250:                maxHeight = getInsets().top + getInsets().bottom;
251:
252:                maxHeight += titleArea.getMinimumHeight();
253:
254:                Iterator it = tableAreas.iterator();
255:                while (it.hasNext()) {
256:                    SQLBasicTableArea tableArea = (SQLBasicTableArea) it.next();
257:                    maxHeight += tableArea.getMaximumHeight();
258:                }
259:
260:                return maxHeight;
261:            }
262:
263:            /**
264:             * Gets the minimum width of the area.
265:             *
266:             * @return minimum width
267:             */
268:            @Override
269:            public int getMaximumWidth() {
270:                int maxWidth = 0;
271:
272:                maxWidth = getInsets().left + getInsets().right;
273:
274:                int width = 0;
275:
276:                if (titleArea.getMinimumWidth() > width) {
277:                    width = titleArea.getMinimumWidth();
278:                }
279:
280:                Iterator it = tableAreas.iterator();
281:                while (it.hasNext()) {
282:                    SQLBasicTableArea tableArea = (SQLBasicTableArea) it.next();
283:                    if (tableArea.getMaximumWidth() > width) {
284:                        width = tableArea.getMaximumWidth();
285:                    }
286:                }
287:
288:                maxWidth += width;
289:
290:                return maxWidth;
291:            }
292:
293:            /**
294:             * Gets the minimum height.
295:             *
296:             * @return minimum height
297:             */
298:            @Override
299:            public int getMinimumHeight() {
300:                int minHeight = getInsets().top + getInsets().bottom;
301:
302:                //take min height of title into account this much height
303:                //we want to show always
304:                if (titleArea != null) {
305:                    minHeight += titleArea.getMinimumHeight();
306:                }
307:
308:                return minHeight;
309:            }
310:
311:            /**
312:             * Gets the minimum width.
313:             *
314:             * @return minimum width
315:             */
316:            @Override
317:            public int getMinimumWidth() {
318:                int minWidth = 0;
319:
320:                //take min width of title into account this much
321:                //wide we want to show always
322:                if (titleArea != null) {
323:                    minWidth = titleArea.getMinimumWidth();
324:                }
325:
326:                // Account for width of all table areas - use maximum width to allow for
327:                // visibility of all column names.
328:                Iterator it = tableAreas.iterator();
329:                while (it.hasNext()) {
330:                    SQLBasicTableArea tableArea = (SQLBasicTableArea) it.next();
331:                    minWidth = Math.max(tableArea.getMaximumWidth(), minWidth);
332:                }
333:
334:                // Always account for horizontal insets.
335:                minWidth += getInsets().left + getInsets().right;
336:                return minWidth;
337:            }
338:
339:            /**
340:             * Lays out the children of this cell area.
341:             */
342:            @Override
343:            public void layoutChildren() {
344:                int rectleft = getLeft();
345:                int recttop = getTop();
346:                int rectwidth = getWidth();
347:                int rectheight = getHeight();
348:
349:                int left = rectleft + insets.left;
350:                int top = recttop + insets.top;
351:                int width = rectwidth - insets.left - insets.right;
352:                int height = rectheight - insets.top - insets.bottom;
353:
354:                titleArea.setBoundingRect(left, top, width, titleArea
355:                        .getMinimumHeight());
356:
357:                Iterator it = tableAreas.iterator();
358:
359:                int topSoFar = top + titleArea.getHeight();
360:
361:                while (it.hasNext()) {
362:                    SQLBasicTableArea tableArea = (SQLBasicTableArea) it.next();
363:                    if (height - titleArea.getHeight() > 0) {
364:                        tableArea.setVisible(true);
365:                        tableArea.setBoundingRect(left, topSoFar, width,
366:                                tableArea.getMaximumHeight());
367:                        topSoFar += tableArea.getHeight();
368:                    } else {
369:                        tableArea.setVisible(false);
370:                        tableArea.setBoundingRect(titleArea.getBoundingRect());
371:                    }
372:                }
373:            }
374:
375:            private class JoinViewActionListener implements  ActionListener {
376:
377:                /**
378:                 * Invoked when an action occurs.
379:                 */
380:                public void actionPerformed(ActionEvent e) {
381:                    Object source = e.getSource();
382:                    if (source == editItem) {
383:                        edit_ActionPerformed(e);
384:                    } else if (source == showSqlItem) {
385:                        ShowSql_ActionPerformed(e);
386:                    } else if (source == selectColumnsItem) {
387:                        selectVisibleColumnsActionPerformed(e);
388:                    } else if (source == removeItem) {
389:                        Remove_ActionPerformed(e);
390:                    } else if (source == showDataItem) {
391:                        showJoinData_ActionPerformed(e);
392:                    }
393:                }
394:            }
395:
396:            private void edit_ActionPerformed(ActionEvent e) {
397:                SQLJoinView joinView = (SQLJoinView) JoinViewGraphNode.this 
398:                        .getDataObject();
399:                Object[] args = new Object[] { joinView };
400:                this .getGraphView().execute(ICommand.EDIT_JOINVIEW, args);
401:            }
402:
403:            private void ShowSql_ActionPerformed(ActionEvent e) {
404:                SQLJoinView joinView = (SQLJoinView) JoinViewGraphNode.this 
405:                        .getDataObject();
406:                SQLJoinOperator op = joinView.getRootJoin();
407:                op.setDisplayName(joinView.getAliasName());
408:                Object[] args = new Object[] { op };
409:                this .getGraphView().execute(ICommand.SHOW_SQL_CMD, args);
410:            }
411:
412:            private void showJoinData_ActionPerformed(ActionEvent e) {
413:                SQLJoinView joinView = (SQLJoinView) JoinViewGraphNode.this 
414:                        .getDataObject();
415:                Object[] args = new Object[] { joinView };
416:                this .getGraphView().execute(ICommand.SHOW_DATA_CMD, args);
417:            }
418:
419:            private void selectVisibleColumnsActionPerformed(ActionEvent e) {
420:                List<SourceTable> tables = new ArrayList<SourceTable>(
421:                        tableAreas.size());
422:                List<DBColumn> columns = new ArrayList<DBColumn>(tableAreas
423:                        .size() * 5);
424:                Map<SourceTable, TableModel> tableToModelMap = new HashMap<SourceTable, TableModel>();
425:
426:                Iterator tableIter = tableAreas.iterator();
427:                if (tableIter.hasNext()) {
428:                    do {
429:                        SQLJoinTableArea joinTblArea = (SQLJoinTableArea) tableIter
430:                                .next();
431:                        TableArea tblArea = joinTblArea.getTableArea();
432:                        SourceTable srcTable = (SourceTable) joinTblArea
433:                                .getDataObject();
434:
435:                        if (tblArea instanceof  SQLTableArea && srcTable != null) {
436:                            tableToModelMap.put(srcTable,
437:                                    ((SQLTableArea) tblArea).getModel());
438:                            tables.add(srcTable);
439:                            columns.addAll(srcTable.getColumnList());
440:                        }
441:                    } while (tableIter.hasNext());
442:                }
443:
444:                if (tables.isEmpty()) {
445:                    return;
446:                }
447:
448:                TableColumnTreePanel columnPanel = new TableColumnTreePanel(
449:                        tables, true);
450:                JPanel panel = new JPanel();
451:                panel.setLayout(new GridBagLayout());
452:
453:                GridBagConstraints gbc = new GridBagConstraints();
454:                gbc.gridx = 0;
455:                gbc.gridy = 0;
456:                gbc.anchor = GridBagConstraints.FIRST_LINE_START;
457:                gbc.fill = GridBagConstraints.HORIZONTAL;
458:                gbc.weightx = 1.0;
459:                gbc.weighty = 0.0;
460:
461:                // NOTE: Use SQLBasicTableArea.class as superclass Bundle already contains this
462:                // resource
463:                String nbBundle6 = mLoc
464:                        .t("PRSR001: Select columns to display for this table.");
465:                String dlgLabel = Localizer.parse(nbBundle6);
466:                JLabel lbl = new JLabel(dlgLabel);
467:                lbl.getAccessibleContext().setAccessibleName(dlgLabel);
468:                lbl.setFont(lbl.getFont().deriveFont(Font.BOLD));
469:                panel.add(lbl, gbc);
470:
471:                gbc = new GridBagConstraints();
472:                gbc.gridx = 0;
473:                gbc.gridy = GridBagConstraints.RELATIVE;
474:                gbc.anchor = GridBagConstraints.CENTER;
475:                gbc.fill = GridBagConstraints.HORIZONTAL;
476:                gbc.insets.bottom = 2;
477:                gbc.weightx = 1.0;
478:                gbc.weighty = 0.0;
479:                panel.add(new JSeparator(), gbc);
480:
481:                gbc = new GridBagConstraints();
482:                gbc.gridx = 0;
483:                gbc.gridy = GridBagConstraints.RELATIVE;
484:                gbc.anchor = GridBagConstraints.PAGE_START;
485:                gbc.fill = GridBagConstraints.BOTH;
486:                gbc.weightx = 1.0;
487:                gbc.weighty = 1.0;
488:                panel.add(columnPanel, gbc);
489:
490:                // NOTE: Use SQLBasicTableArea.class as superclass Bundle already contains this
491:                // resource
492:                String nbBundle7 = mLoc.t("PRSR001: Select Columns");
493:                String dlgTitle = Localizer.parse(nbBundle7);
494:                int response = JOptionPane
495:                        .showConfirmDialog(WindowManager.getDefault()
496:                                .getMainWindow(), panel, dlgTitle,
497:                                JOptionPane.OK_CANCEL_OPTION,
498:                                JOptionPane.PLAIN_MESSAGE);
499:
500:                if (JOptionPane.OK_OPTION == response) {
501:                    List tableNodes = columnPanel.getTableColumnNodes();
502:
503:                    // Toggle visibility of columns as directed by user.
504:                    Iterator iter = columns.iterator();
505:                    while (iter.hasNext()) {
506:                        SQLDBColumn column = (SQLDBColumn) iter.next();
507:                        boolean userWantsVisible = TableColumnNode
508:                                .isColumnVisible(column, tableNodes);
509:                        if (column.isVisible() && !userWantsVisible) {
510:                            column.setVisible(false);
511:                            try {
512:                                removeColumn(column);
513:                            } catch (BaseException ex) {
514:                            }
515:                        } else if (!column.isVisible() && userWantsVisible) {
516:                            column.setVisible(true);
517:                            MetaTableModel model = (MetaTableModel) tableToModelMap
518:                                    .get(column.getParentObject());
519:
520:                            if ((model != null)
521:                                    && !model.containsColumn(column)) {
522:                                model.addColumn(column);
523:                            } else {
524:                                makeColumnVisible(column);
525:                            }
526:                        }
527:                    }
528:
529:                    // Trigger repaint of all affected GUI objects.
530:                    iter = tableAreas.iterator();
531:                    while (iter.hasNext()) {
532:                        SQLJoinTableArea tblArea = (SQLJoinTableArea) iter
533:                                .next();
534:                        tblArea.setHeight(tblArea.getMaximumHeight());
535:                        tblArea.layoutChildren();
536:                    }
537:
538:                    setHeight(getMaximumHeight());
539:                    layoutChildren();
540:
541:                    // Mark collab as needing to be persisted.
542:                    Object graphModel = getGraphView().getGraphModel();
543:                    if (graphModel instanceof  CollabSQLUIModel) {
544:                        ((CollabSQLUIModel) graphModel).setDirty(true);
545:                    }
546:                }
547:            }
548:
549:            private void Remove_ActionPerformed(ActionEvent e) {
550:                this .getGraphView().deleteNode(this );
551:            }
552:
553:            /**
554:             * get a list of all input and output links
555:             *
556:             * @return list of input links
557:             */
558:            @Override
559:            public List getAllLinks() {
560:                ArrayList<JGoLink> links = new ArrayList<JGoLink>();
561:
562:                Iterator it = this .tableAreas.iterator();
563:
564:                while (it.hasNext()) {
565:                    SQLBasicTableArea tableArea = (SQLBasicTableArea) it.next();
566:                    links.addAll(tableArea.getAllLinks());
567:                }
568:
569:                return links;
570:            }
571:
572:            /**
573:             * get a list of all table areas in this join view
574:             *
575:             * @return list of input links
576:             */
577:            public List getAllTableAreas() {
578:                return this .tableAreas;
579:            }
580:
581:            public boolean isColumnMapped(SQLDBColumn column) {
582:                Iterator it = this .tableAreas.iterator();
583:
584:                while (it.hasNext()) {
585:                    SQLBasicTableArea tableArea = (SQLBasicTableArea) it.next();
586:                    if (tableArea.isColumnMapped(column)) {
587:                        return true;
588:                    }
589:                }
590:
591:                return false;
592:            }
593:
594:            public void removeColumnReference(SQLDBColumn column)
595:                    throws BaseException {
596:                DBTable table = column.getParent();
597:
598:                Iterator it = this .tableAreas.iterator();
599:
600:                while (it.hasNext()) {
601:                    SQLBasicTableArea tableArea = (SQLBasicTableArea) it.next();
602:                    Object tableObj = tableArea.getDataObject();
603:                    if (tableObj.equals(table)) {
604:                        tableArea.removeColumnReference(column);
605:                        return;
606:                    }
607:                }
608:            }
609:
610:            public void removeColumn(SQLDBColumn column) throws BaseException {
611:                DBTable table = column.getParent();
612:
613:                Iterator it = this .tableAreas.iterator();
614:
615:                while (it.hasNext()) {
616:                    SQLBasicTableArea tableArea = (SQLBasicTableArea) it.next();
617:                    Object tableObj = tableArea.getDataObject();
618:                    if (tableObj.equals(table)) {
619:                        tableArea.removeColumn(column);
620:                        this .layoutChildren();
621:                        return;
622:                    }
623:                }
624:            }
625:
626:            public void makeColumnInVisible(SQLDBColumn column)
627:                    throws BaseException {
628:                DBTable table = column.getParent();
629:
630:                Iterator it = this .tableAreas.iterator();
631:
632:                while (it.hasNext()) {
633:                    SQLBasicTableArea tableArea = (SQLBasicTableArea) it.next();
634:                    Object tableObj = tableArea.getDataObject();
635:                    if (tableObj.equals(table)) {
636:                        tableArea.makeColumnInVisible(column);
637:                        return;
638:                    }
639:                }
640:            }
641:
642:            public void makeColumnVisible(SQLDBColumn column) {
643:                DBTable table = column.getParent();
644:
645:                Iterator it = this .tableAreas.iterator();
646:
647:                while (it.hasNext()) {
648:                    SQLBasicTableArea tableArea = (SQLBasicTableArea) it.next();
649:                    Object tableObj = tableArea.getDataObject();
650:                    if (tableObj.equals(table)) {
651:                        tableArea.makeColumnVisible(column);
652:                        return;
653:                    }
654:                }
655:            }
656:
657:            public void addColumn(SQLDBColumn column) {
658:                SQLDBTable table = (SQLDBTable) column.getParent();
659:
660:                Iterator it = this .tableAreas.iterator();
661:
662:                while (it.hasNext()) {
663:                    SQLBasicTableArea tableArea = (SQLBasicTableArea) it.next();
664:                    SQLDBTable tableObj = (SQLDBTable) tableArea
665:                            .getDataObject();
666:                    if (tableObj.getParent().getFullyQualifiedTableName(
667:                            tableObj)
668:                            .equals(
669:                                    table.getParent()
670:                                            .getFullyQualifiedTableName(table))) {
671:                        ArrayList<SQLDBColumn> columns = new ArrayList<SQLDBColumn>();
672:                        columns.add(column);
673:                        tableArea.addColumns(columns);
674:                        this .layoutChildren();
675:                        return;
676:                    }
677:                }
678:            }
679:
680:            /**
681:             * set the bounding rectangle and make it not resize beyond a certain wisth
682:             *
683:             * @param left left
684:             * @param top top
685:             * @param width width
686:             * @param height
687:             */
688:            @Override
689:            public void setBoundingRect(int left, int top, int width, int height) {
690:                if (this .isExpandedState()) {
691:                    super .setBoundingRect(left, top, Math.max(width, 100), this 
692:                            .getMaximumHeight());
693:                } else {
694:                    super .setBoundingRect(left, top, Math.max(width, 100),
695:                            height);
696:                }
697:            }
698:
699:            //
700:            //    public void removeColumnReference(SQLDBTable table, SQLDBColumn column) {
701:            //        Iterator it = this.tableAreas.iterator();
702:            //        while(it.hasNext()) {
703:            //            SQLJoinTableArea tableArea = (SQLJoinTableArea) it.next();
704:            //            if(tableArea.getDataObject().equals(table)) {
705:            //                tableArea.removeColumnReference(column);
706:            //            }
707:            //        }
708:            //    }
709:            public void addTable(SourceTable sTable) {
710:                SQLJoinTableArea tableArea = new SQLJoinTableArea(sTable);
711:                tableArea.setDataObject(sTable);
712:                tableArea.setGraphView(this .getGraphView());
713:                tableArea.setSelectable(true);
714:                tableArea.setResizable(false);
715:                tableArea.setPickableBackground(false);
716:                tableArea.showExpansionImage(false);
717:                //tableArea.setShowHeader(false);
718:                addObjectAtTail(tableArea);
719:                tableAreas.add(tableArea);
720:            }
721:
722:            public boolean containsTable(SourceTable sTable) {
723:                Iterator it = tableAreas.iterator();
724:
725:                while (it.hasNext()) {
726:                    SQLJoinTableArea tableArea = (SQLJoinTableArea) it.next();
727:                    if (sTable.equals(tableArea.getDataObject())) {
728:                        return true;
729:                    }
730:                }
731:
732:                return false;
733:            }
734:
735:            public void removeTable(SourceTable sTable) throws BaseException {
736:                try {
737:                    SQLJoinView joinView = (SQLJoinView) this .getDataObject();
738:                    SQLJoinTable jTable = joinView.getJoinTable(sTable);
739:
740:                    NotifyDescriptor nd = new NotifyDescriptor.Confirmation(
741:                            "You may lose some user defined conditions in some joins, Do you really want to remove the table?",
742:                            NotifyDescriptor.WARNING_MESSAGE);
743:
744:                    Object response = DialogDisplayer.getDefault().notify(nd);
745:                    if (response.equals(NotifyDescriptor.CANCEL_OPTION)) {
746:                        return;
747:                    }
748:
749:                    SQLUIModel model = (SQLUIModel) this .getGraphView()
750:                            .getGraphModel();
751:                    if (model == null) {
752:                        throw new BaseException("can not delete table "
753:                                + sTable.getName()
754:                                + " from join view, graph model is null");
755:                    }
756:
757:                    Iterator it = tableAreas.iterator();
758:
759:                    while (it.hasNext()) {
760:                        SQLJoinTableArea tableArea = (SQLJoinTableArea) it
761:                                .next();
762:                        if (sTable.equals(tableArea.getDataObject())) {
763:                            SQLJoinOperator op = joinView.getRootJoin();
764:                            List joinTableList = null;
765:                            if (op != null) {
766:                                joinTableList = JoinUtility.getJoinTables(op);
767:                            }
768:
769:                            if (joinTableList == null) {
770:                                return;
771:                            }
772:
773:                            //remove table from join view this will also remove
774:                            //dangling references to jTable
775:                            joinView.removeObject(jTable);
776:
777:                            JoinBuilderSQLUIModel joinModel = new JoinBuilderSQLUIModelImpl(
778:                                    joinView);
779:                            int index = joinTableList.indexOf(jTable);
780:
781:                            if (index != 0) {
782:                                for (int i = index + 1; i < joinTableList
783:                                        .size(); i++) {
784:                                    JoinUtility
785:                                            .handleAutoJoins(
786:                                                    (SQLJoinTable) joinTableList
787:                                                            .get(i), false,
788:                                                    joinModel);
789:                                }
790:                            } else {
791:                                //now once table is remove join relationship will be in disorder
792:                                //so we need to create auto joins again, for this create JoinBuilderSQLUIModelImpl
793:                                //first get the list of join tables
794:                                ArrayList<SQLJoinTable> joinTables = new ArrayList<SQLJoinTable>(
795:                                        joinView.getSQLJoinTables());
796:                                //now remove all objects from join view
797:                                joinModel.removeAll();
798:                                //populate join view again with auto joins
799:                                JoinUtility.handleAutoJoins(joinTables,
800:                                        joinModel);
801:                            }
802:
803:                            removeColumnReference(sTable);
804:                            model.removeObject(sTable);
805:                            tableAreas.remove(tableArea);
806:                            this .removeObject(tableArea);
807:
808:                            break;
809:                        }
810:                    }
811:
812:                    this .setSize(140, this .getMaximumHeight());
813:                    //set size is not calling layoutChildren so need to call it again
814:                    //so that join view can refresh
815:                    this .layoutChildren();
816:                } catch (BaseException ex) {
817:                    mLogger
818:                            .errorNoloc(
819:                                    mLoc
820:                                            .t(
821:                                                    "PRSR188: Error removing source table {0}from join view",
822:                                                    sTable.getName()), ex);
823:                    throw ex;
824:                }
825:            }
826:
827:            //remove a table without re adjusting joins in join view
828:            public void removeJoinTable(SourceTable sTable)
829:                    throws BaseException {
830:                SQLJoinView joinView = (SQLJoinView) this .getDataObject();
831:                SQLJoinTable jTable = joinView.getJoinTable(sTable);
832:
833:                SQLUIModel model = (SQLUIModel) this .getGraphView()
834:                        .getGraphModel();
835:                if (model == null) {
836:                    throw new BaseException("can not delete table "
837:                            + sTable.getName()
838:                            + " from join view, graph model is null");
839:                }
840:
841:                Iterator it = tableAreas.iterator();
842:
843:                while (it.hasNext()) {
844:                    SQLJoinTableArea tableArea = (SQLJoinTableArea) it.next();
845:                    if (sTable.equals(tableArea.getDataObject())) {
846:
847:                        //remove table from join view this will also remove
848:                        //dangling references to jTable
849:                        joinView.removeObject(jTable);
850:
851:                        removeColumnReference(sTable);
852:                        model.removeObject(sTable);
853:                        tableAreas.remove(tableArea);
854:                        this .removeObject(tableArea);
855:                        break;
856:                    }
857:                }
858:
859:                this .setSize(140, this .getMaximumHeight());
860:                //set size is not calling layoutChildren so need to call it again
861:                //so that join view can refresh
862:                this .layoutChildren();
863:            }
864:
865:            public boolean isTableColumnMapped(SourceTable sTable) {
866:                Iterator it = sTable.getColumnList().iterator();
867:                while (it.hasNext()) {
868:                    SQLDBColumn column = (SQLDBColumn) it.next();
869:                    if (this .isColumnMapped(column)) {
870:                        return true;
871:                    }
872:                }
873:
874:                return false;
875:            }
876:
877:            private void removeColumnReference(SourceTable sTable)
878:                    throws BaseException {
879:                Iterator it = sTable.getColumnList().iterator();
880:                while (it.hasNext()) {
881:                    SQLDBColumn column = (SQLDBColumn) it.next();
882:                    this .removeColumnReference(column);
883:                }
884:            }
885:
886:            @Override
887:            public void removeChildNode(IGraphNode child) {
888:                SourceTable sTable = (SourceTable) child.getDataObject();
889:                SQLJoinView joinView = (SQLJoinView) this .getDataObject();
890:
891:                SQLJoinTable jTable = joinView.getJoinTable(sTable);
892:
893:                try {
894:                    SQLUIModel model = (SQLUIModel) this .getGraphView()
895:                            .getGraphModel();
896:                    if (model == null) {
897:                        throw new BaseException("Cannot delete table "
898:                                + sTable.getName()
899:                                + " from join view, graph model is null");
900:                    }
901:
902:                    if (joinView.getSourceTables().size() <= 2) {
903:                        NotifyDescriptor d = new NotifyDescriptor.Message(
904:                                "Cannot remove table "
905:                                        + sTable.getName()
906:                                        + " from join view, join view always requires atleast two tables",
907:                                NotifyDescriptor.INFORMATION_MESSAGE);
908:                        DialogDisplayer.getDefault().notify(d);
909:                        return;
910:                    }
911:
912:                    this .removeTable(jTable.getSourceTable());
913:                } catch (BaseException ex) {
914:                    mLogger
915:                            .errorNoloc(
916:                                    mLoc
917:                                            .t(
918:                                                    "PRSR189: Error removing source table {0}from join view",
919:                                                    sTable.getName()), ex);
920:                }
921:            }
922:
923:            /**
924:             * set the state
925:             *
926:             * @param sExpanded whether table is expanded
927:             */
928:            @Override
929:            public void setExpanded(boolean sExpanded) {
930:                //make this table resizeable only in expanded mode
931:                this .setResizable(sExpanded);
932:                Iterator it = tableAreas.iterator();
933:                while (it.hasNext()) {
934:                    SQLJoinTableArea tableArea = (SQLJoinTableArea) it.next();
935:                    tableArea.setExpandedState(sExpanded);
936:                }
937:                super.setExpanded(sExpanded);
938:            }
939:        }
w___w_w___.__j_a_v___a2_s__.__c___om__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.