Source Code Cross Referenced for JoinPreviewGraphNode.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.Insets;
045:        import java.awt.Point;
046:        import java.awt.Rectangle;
047:        import java.awt.event.ItemEvent;
048:        import java.awt.event.ItemListener;
049:        import java.net.URL;
050:        import java.util.ArrayList;
051:        import java.util.Iterator;
052:        import java.util.List;
053:        import java.util.Vector;
054:
055:        import javax.swing.Icon;
056:        import javax.swing.ImageIcon;
057:
058:        import org.netbeans.modules.sql.framework.model.SQLCondition;
059:        import org.netbeans.modules.sql.framework.model.SQLConstants;
060:        import org.netbeans.modules.sql.framework.model.SQLJoinOperator;
061:        import org.netbeans.modules.sql.framework.ui.graph.IGraphPort;
062:        import org.netbeans.modules.sql.framework.ui.graph.IGraphView;
063:        import org.netbeans.modules.sql.framework.ui.graph.IOperatorXmlInfoModel;
064:        import org.netbeans.modules.sql.framework.ui.graph.impl.BasicCanvasArea;
065:        import org.netbeans.modules.sql.framework.ui.graph.impl.BasicCellArea;
066:        import org.netbeans.modules.sql.framework.ui.graph.impl.BasicComboBoxArea;
067:        import org.netbeans.modules.sql.framework.ui.graph.impl.CanvasArea;
068:        import org.netbeans.modules.sql.framework.ui.graph.impl.CellArea;
069:        import org.netbeans.modules.sql.framework.ui.graph.impl.ColumnPortArea;
070:        import org.netbeans.modules.sql.framework.ui.graph.impl.GraphPort;
071:        import org.netbeans.modules.sql.framework.ui.graph.impl.TitleArea;
072:        import org.netbeans.modules.sql.framework.ui.view.IGraphViewContainer;
073:        import org.netbeans.modules.sql.framework.ui.view.conditionbuilder.ConditionBuilderView;
074:        import org.openide.DialogDescriptor;
075:        import org.openide.DialogDisplayer;
076:        import org.openide.NotifyDescriptor;
077:
078:        import com.nwoods.jgo.JGoArea;
079:        import com.nwoods.jgo.JGoBrush;
080:        import com.nwoods.jgo.JGoImage;
081:        import com.nwoods.jgo.JGoLink;
082:        import com.nwoods.jgo.JGoObject;
083:        import com.nwoods.jgo.JGoPen;
084:        import com.nwoods.jgo.JGoPort;
085:        import com.nwoods.jgo.JGoRectangle;
086:        import com.nwoods.jgo.JGoView;
087:
088:        /**
089:         * This is the join representation in preview panel.
090:         * 
091:         * @author Ritesh Adval
092:         */
093:        public class JoinPreviewGraphNode extends BasicCanvasArea {
094:
095:            private JoinBottomArea bottomArea;
096:
097:            private ColumnPortArea outputArea;
098:
099:            private boolean showOutput = false;
100:
101:            private int cbAreaHeight;
102:
103:            private Vector<JoinType> joinTypes;
104:
105:            private BasicComboBoxArea cbArea;
106:
107:            private IGraphView mainSQLGraphView;
108:
109:            private static URL no_condition_url = JoinPreviewGraphNode.class
110:                    .getResource("/org/netbeans/modules/sql/framework/ui/resources/images/no_condition.png");
111:
112:            private static URL no_condition_hover_url = JoinPreviewGraphNode.class
113:                    .getResource("/org/netbeans/modules/sql/framework/ui/resources/images/no_condition_hover.png");
114:
115:            private static URL system_condition_url = JoinPreviewGraphNode.class
116:                    .getResource("/org/netbeans/modules/sql/framework/ui/resources/images/system_condition.png");
117:
118:            private static URL system_condition_hover_url = JoinPreviewGraphNode.class
119:                    .getResource("/org/netbeans/modules/sql/framework/ui/resources/images/system_condition_hover.png");
120:
121:            private static URL modified_condition_url = JoinPreviewGraphNode.class
122:                    .getResource("/org/netbeans/modules/sql/framework/ui/resources/images/modified_condition.png");
123:
124:            private static URL modified_condition_hover_url = JoinPreviewGraphNode.class
125:                    .getResource("/org/netbeans/modules/sql/framework/ui/resources/images/modified_condition_hover.png");
126:
127:            /** Creates a new instance of JoinPreviewGraphNode */
128:            public JoinPreviewGraphNode() {
129:                initGUI();
130:            }
131:
132:            private void initGUI() {
133:                this .setSelectable(true);
134:                this .setResizable(false);
135:                this .setPickableBackground(false);
136:                this .setUpdateGuiInfo(false);
137:
138:                //add bounding rectangle
139:                //rect = new JGoRectangle();
140:
141:                //add title
142:                titleArea = new TitleArea("join");
143:                titleArea.setInsets(new Insets(1, 3, 0, 3));
144:
145:                URL url = JoinPreviewGraphNode.class
146:                        .getResource("/org/netbeans/modules/sql/framework/ui/resources/images/Join.png");
147:
148:                ImageIcon joinTitleIcon = new ImageIcon(url);
149:                titleArea.setTitleImage(joinTitleIcon);
150:                titleArea.showExpansionImage(false);
151:                addObjectAtTail(titleArea);
152:
153:                //add join bottom area
154:                bottomArea = new JoinBottomArea();
155:                bottomArea.setSelectable(false);
156:                bottomArea.setResizable(false);
157:                addObjectAtHead(bottomArea);
158:
159:                //add output port if any
160:                outputArea = new ColumnPortArea(ColumnPortArea.RIGHT_PORT_AREA,
161:                        1);
162:                outputArea.setVisible(false);
163:                outputArea.setInsets(new Insets(0, 0, 0, 0));
164:                addObjectAtTail(outputArea);
165:
166:                this .setSize(this .getMaximumWidth(), this .getMaximumHeight());
167:            }
168:
169:            @Override
170:            public void setDataObject(Object obj) {
171:                super .setDataObject(obj);
172:                SQLJoinOperator op = (SQLJoinOperator) obj;
173:                int jConditionType = op.getJoinConditionType();
174:
175:                if (jConditionType == SQLJoinOperator.SYSTEM_DEFINED_CONDITION) {
176:                    this .bottomArea
177:                            .setImage(new ImageIcon(system_condition_url));
178:                    this .bottomArea
179:                            .setConditionToolTip("Click To Edit System Discovered Condition");
180:                } else if (jConditionType == SQLJoinOperator.USER_DEFINED_CONDITION) {
181:                    this .bottomArea.setImage(new ImageIcon(
182:                            modified_condition_url));
183:                    this .bottomArea
184:                            .setConditionToolTip("Click To Edit User Modified Condition");
185:                } else {
186:                    this .bottomArea.setImage(new ImageIcon(no_condition_url));
187:                    this .bottomArea
188:                            .setConditionToolTip("Click To Edit Condition");
189:                }
190:
191:                if (cbArea != null) {
192:                    //set join type in combo box
193:                    setJoinType(op.getJoinType());
194:                }
195:            }
196:
197:            public void setModifiable(boolean b) {
198:                this .cbArea.setComboBoxEnabled(b);
199:            }
200:
201:            private void setJoinType(int joinType) {
202:                Iterator it = joinTypes.iterator();
203:                while (it.hasNext()) {
204:                    JoinType jt = (JoinType) it.next();
205:                    if (jt.getJoinType() == joinType) {
206:                        cbArea.setSelectedItem(jt);
207:                    }
208:                }
209:            }
210:
211:            /**
212:             * layout the children of this cell area
213:             */
214:            @Override
215:            public void layoutChildren() {
216:                int rectleft = getLeft();
217:                int recttop = getTop();
218:                int rectwidth = getWidth();
219:
220:                int left = rectleft + insets.left;
221:                int top = recttop + insets.top;
222:                int width = rectwidth - insets.left - insets.right;
223:
224:                titleArea.setBoundingRect(left, top, width, titleArea
225:                        .getMinimumHeight());
226:
227:                if (cbArea != null) {
228:                    cbArea.setBoundingRect(left, top + titleArea.getHeight(),
229:                            width, cbAreaHeight);
230:
231:                    cbAreaHeight = cbArea.getHeight();
232:                }
233:
234:                if (cbArea != null) {
235:                    bottomArea.setSpotLocation(JGoObject.TopLeft, cbArea,
236:                            JGoObject.BottomLeft);
237:                } else {
238:                    bottomArea.setSpotLocation(JGoObject.TopLeft, titleArea,
239:                            JGoObject.BottomLeft);
240:                }
241:
242:                if (showOutput) {
243:                    this .outputArea.setVisible(true);
244:                    this .outputArea.setSpotLocation(JGoObject.TopRight,
245:                            bottomArea, JGoObject.BottomRight);
246:                } else {
247:                    this .outputArea.setVisible(false);
248:                }
249:            }
250:
251:            /**
252:             * get the minimum height of the area
253:             * 
254:             * @return minimum height
255:             */
256:            @Override
257:            public int getMaximumHeight() {
258:                int minHeight = 0;
259:
260:                minHeight = getInsets().top + getInsets().bottom;
261:
262:                minHeight += titleArea.getMinimumHeight();
263:                if (cbArea != null) {
264:                    minHeight += cbArea.getMinimumHeight();
265:                }
266:                minHeight += bottomArea.getHeight();
267:                if (showOutput) {
268:                    minHeight += outputArea.getMinimumHeight();
269:                }
270:                return minHeight;
271:            }
272:
273:            @Override
274:            public int getMaximumWidth() {
275:                int maxWidth = 0;
276:
277:                maxWidth = getInsets().left + getInsets().right;
278:
279:                int width = 0;
280:
281:                if (titleArea.getMinimumWidth() > width) {
282:                    width = titleArea.getMinimumWidth();
283:                }
284:
285:                if (bottomArea.getWidth() > width) {
286:                    width = bottomArea.getWidth();
287:                }
288:
289:                maxWidth += width;
290:
291:                return maxWidth;
292:            }
293:
294:            class JoinBottomArea extends JGoArea {
295:
296:                private JoinCellArea leftArea;
297:                private JoinCellArea rightArea;
298:                private JoinConditionArea conditionArea;
299:
300:                JoinBottomArea() {
301:                    leftArea = new JoinCellArea("(L)");
302:                    rightArea = new JoinCellArea("(R)");
303:                    JGoArea leftRightArea = new JGoArea();
304:                    leftRightArea.setSelectable(false);
305:                    leftRightArea.setResizable(false);
306:
307:                    leftArea.setSpotLocation(JGoObject.Left, leftRightArea,
308:                            JGoObject.Left);
309:                    rightArea.setSpotLocation(JGoObject.TopLeft, leftArea,
310:                            JGoObject.BottomLeft);
311:
312:                    leftRightArea.addObjectAtTail(leftArea);
313:                    leftRightArea.addObjectAtTail(rightArea);
314:
315:                    addObjectAtTail(leftRightArea);
316:
317:                    //add condition Area
318:                    conditionArea = new JoinConditionArea();
319:                    conditionArea.setSpotLocation(JGoObject.TopLeft,
320:                            leftRightArea, JGoObject.TopRight);
321:                    conditionArea.setHeight(40);
322:
323:                    addObjectAtHead(conditionArea);
324:                }
325:
326:                public IGraphPort getLeftGraphPort() {
327:                    return leftArea.getGraphPort();
328:                }
329:
330:                public IGraphPort getRightGraphPort() {
331:                    return rightArea.getGraphPort();
332:                }
333:
334:                public void setImage(Icon icon) {
335:                    this .conditionArea.setImage(icon);
336:                }
337:
338:                public void setConditionToolTip(String tTip) {
339:                    this .conditionArea.setConditionToolTip(tTip);
340:                }
341:            }
342:
343:            class JoinConditionArea extends CanvasArea {
344:                private JGoRectangle rect;
345:
346:                //this area has one image also
347:                private ImageArea imageArea;
348:
349:                private CellArea cell;
350:
351:                JoinConditionArea() {
352:                    this .setSelectable(true);
353:                    this .setResizable(false);
354:                    this .setDraggable(true);
355:                    this .setPickableBackground(false);
356:
357:                    rect = new JGoRectangle();
358:                    rect.setPen(JGoPen.makeStockPen(Color.lightGray));
359:                    rect.setBrush(JGoBrush.makeStockBrush(Color.white));
360:                    rect.setSelectable(false);
361:                    rect.setResizable(false);
362:                    addObjectAtHead(rect);
363:
364:                    //add image area
365:                    imageArea = new ImageArea();
366:                    addObjectAtTail(imageArea);
367:
368:                    //add condition cell
369:                    cell = new CellArea(" Condition");
370:                    this .addObjectAtTail(cell);
371:
372:                    //add image for testing
373:                    this .setImage(new ImageIcon(no_condition_url));
374:                }
375:
376:                public void setImage(Icon icon) {
377:                    this .imageArea.setImage(icon);
378:                    this .layoutChildren();
379:                }
380:
381:                public void setConditionToolTip(String tTip) {
382:                    this .setToolTipText(tTip);
383:                }
384:
385:                /**
386:                 * layout the children of this cell area
387:                 */
388:                @Override
389:                public void layoutChildren() {
390:                    Rectangle rectangle = this .getBoundingRect();
391:                    rect.setBoundingRect(rectangle);
392:                    cell.setBoundingRect(rectangle.x, rectangle.y,
393:                            rectangle.width, rectangle.height / 3);
394:                    imageArea.setBoundingRect(rectangle.x, rectangle.y,
395:                            rectangle.width, (rectangle.height * 2) / 3);
396:                    cell.setSpotLocation(JGoObject.TopLeft, imageArea,
397:                            JGoObject.BottomLeft);
398:                }
399:
400:                @Override
401:                public boolean doMouseClick(int modifiers, java.awt.Point dc,
402:                        java.awt.Point vc, JGoView aView) {
403:                    return doMouseDblClick(modifiers, dc, vc, aView);
404:                }
405:
406:                @Override
407:                public boolean doMouseDblClick(int modifiers,
408:                        java.awt.Point dc, java.awt.Point vc, JGoView aView) {
409:                    SQLJoinOperator join = (SQLJoinOperator) JoinPreviewGraphNode.this 
410:                            .getDataObject();
411:                    if (join != null && mainSQLGraphView != null) {
412:                        ConditionBuilderView conditionView = new ConditionBuilderView(
413:                                (IGraphViewContainer) mainSQLGraphView
414:                                        .getGraphViewContainer(), join
415:                                        .getAllSourceTables(), join
416:                                        .getJoinCondition(),
417:                                IOperatorXmlInfoModel.CATEGORY_FILTER);
418:                        DialogDescriptor dd = new DialogDescriptor(
419:                                conditionView, "Edit Join Condition", true,
420:                                NotifyDescriptor.OK_CANCEL_OPTION, null, null);
421:
422:                        if (DialogDisplayer.getDefault().notify(dd) == NotifyDescriptor.OK_OPTION) {
423:                            SQLCondition cond = (SQLCondition) conditionView
424:                                    .getPropertyValue();
425:                            if (cond != null) {
426:                                SQLCondition oldCondition = join
427:                                        .getJoinCondition();
428:                                if (join != null && !cond.equals(oldCondition)) {
429:                                    join.setJoinCondition(cond);
430:                                    join
431:                                            .setJoinConditionType(SQLJoinOperator.USER_DEFINED_CONDITION);
432:                                    this .setImage(new ImageIcon(
433:                                            modified_condition_url));
434:                                }
435:                            }
436:                        }
437:                        return true;
438:                    }
439:
440:                    return false;
441:                }
442:
443:                public boolean doMouseEntered(int modifiers, Point dc,
444:                        Point vc, JGoView aView) {
445:                    SQLJoinOperator join = (SQLJoinOperator) JoinPreviewGraphNode.this 
446:                            .getDataObject();
447:                    if (join != null) {
448:                        int conditonType = join.getJoinConditionType();
449:                        ImageIcon imageIcon = null;
450:                        switch (conditonType) {
451:                        case SQLJoinOperator.SYSTEM_DEFINED_CONDITION:
452:                            imageIcon = new ImageIcon(
453:                                    JoinPreviewGraphNode.system_condition_hover_url);
454:                            this .setImage(imageIcon);
455:                            break;
456:                        case SQLJoinOperator.USER_DEFINED_CONDITION:
457:                            imageIcon = new ImageIcon(
458:                                    JoinPreviewGraphNode.modified_condition_hover_url);
459:                            this .setImage(imageIcon);
460:                            break;
461:                        case SQLJoinOperator.NO_CONDITION:
462:                            imageIcon = new ImageIcon(
463:                                    JoinPreviewGraphNode.no_condition_hover_url);
464:                            this .setImage(imageIcon);
465:                            break;
466:                        }
467:
468:                        return true;
469:                    }
470:
471:                    return false;
472:                }
473:
474:                public boolean doMouseExited(int modifiers, Point dc, Point vc,
475:                        JGoView aView) {
476:                    SQLJoinOperator join = (SQLJoinOperator) JoinPreviewGraphNode.this 
477:                            .getDataObject();
478:                    if (join != null) {
479:                        int conditonType = join.getJoinConditionType();
480:                        ImageIcon imageIcon = null;
481:                        switch (conditonType) {
482:                        case SQLJoinOperator.SYSTEM_DEFINED_CONDITION:
483:                            imageIcon = new ImageIcon(
484:                                    JoinPreviewGraphNode.system_condition_url);
485:                            this .setImage(imageIcon);
486:                            break;
487:                        case SQLJoinOperator.USER_DEFINED_CONDITION:
488:                            imageIcon = new ImageIcon(
489:                                    JoinPreviewGraphNode.modified_condition_url);
490:                            this .setImage(imageIcon);
491:                            break;
492:                        case SQLJoinOperator.NO_CONDITION:
493:                            imageIcon = new ImageIcon(
494:                                    JoinPreviewGraphNode.no_condition_url);
495:                            this .setImage(imageIcon);
496:                            break;
497:                        }
498:                        return true;
499:                    }
500:
501:                    return false;
502:                }
503:            }
504:
505:            class ImageArea extends CanvasArea {
506:                //image
507:                private JGoImage img;
508:
509:                ImageArea() {
510:                    this .setSelectable(false);
511:                    this .setResizable(false);
512:
513:                    img = new JGoImage();
514:                    img.setSelectable(false);
515:                    img.setResizable(false);
516:                    addObjectAtTail(img);
517:                }
518:
519:                /**
520:                 * set he image in this cell area
521:                 * 
522:                 * @param icon icon
523:                 */
524:                public void setImage(Icon icon) {
525:                    if (icon != null) {
526:                        img.setVisible(true);
527:                        ImageIcon imgIcon = (ImageIcon) icon;
528:                        img.loadImage(imgIcon.getImage(), false);
529:                        img.setSize(imgIcon.getImage().getWidth(null), imgIcon
530:                                .getImage().getHeight(null));
531:
532:                        layoutChildren();
533:                    } else {
534:                        img.setVisible(false);
535:                    }
536:
537:                }
538:
539:                /**
540:                 * layout the children of this cell area
541:                 */
542:                @Override
543:                public void layoutChildren() {
544:                    Rectangle rectangle = this .getBoundingRect();
545:                    img.setSpotLocation(JGoObject.Center, this ,
546:                            JGoObject.Center);
547:                    img.setTop(rectangle.y + 2);
548:                }
549:            }
550:
551:            //this class is used to render left and right port areas
552:            class JoinCellArea extends CanvasArea {
553:
554:                private GraphPort port;
555:                private BasicCellArea cell;
556:
557:                JoinCellArea(String text) {
558:                    this .setSelectable(false);
559:                    this .setResizable(false);
560:                    this .setDraggable(true);
561:
562:                    //add port which will be hidden
563:                    port = new GraphPort();
564:                    port.setStyle(JGoPort.StyleHidden);
565:
566:                    //default port can be a source and destination of a link
567:                    port.setValidSource(true);
568:                    port.setValidDestination(true);
569:                    this .addObjectAtTail(port);
570:
571:                    cell = new BasicCellArea(text);
572:                    cell.setLeftGap(3);
573:                    cell.setIconTextGap(0);
574:                    cell.setInsets(new Insets(1, 0, 1, 0));
575:                    cell.drawBoundingRect(true);
576:                    cell.setBackGroundColor(new Color(254, 253, 235));
577:
578:                    this .addObjectAtTail(cell);
579:
580:                    this .setSize(22, 20);
581:                }
582:
583:                /**
584:                 * layout the children of this cell area
585:                 */
586:                @Override
587:                public void layoutChildren() {
588:                    Rectangle rectangle = this .getBoundingRect();
589:                    //rect.setBoundingRect(rectangle);
590:                    port.setBoundingRect(rectangle);
591:                    cell.setBoundingRect(rectangle);
592:                }
593:
594:                public IGraphPort getGraphPort() {
595:                    return this .port;
596:                }
597:            }
598:
599:            /**
600:             * get the field name for a port
601:             * 
602:             * @param iGraphPort port
603:             * @return field name
604:             */
605:            @Override
606:            public String getFieldName(IGraphPort iGraphPort) {
607:                IGraphPort graphPort;
608:                String fieldName = null;
609:
610:                //check at left area
611:                graphPort = this .bottomArea.getLeftGraphPort();
612:                if (iGraphPort.equals(graphPort)) {
613:                    fieldName = SQLJoinOperator.LEFT;
614:                }
615:
616:                //check at right area of join
617:                graphPort = this .bottomArea.getRightGraphPort();
618:                if (iGraphPort.equals(graphPort)) {
619:                    fieldName = SQLJoinOperator.RIGHT;
620:                }
621:
622:                //check result area of join
623:                if (this .showOutput) {
624:                    graphPort = outputArea.getPortAreaAt(0).getGraphPort();
625:                    if (iGraphPort.equals(graphPort)) {
626:                        SQLJoinOperator join = (SQLJoinOperator) this 
627:                                .getDataObject();
628:                        if (join != null) {
629:                            fieldName = join.getDisplayName();
630:                        }
631:                    }
632:                }
633:
634:                return fieldName;
635:            }
636:
637:            /**
638:             * get the input port for a field name
639:             * 
640:             * @param str name of the field name
641:             * @return port
642:             */
643:            @Override
644:            public IGraphPort getInputGraphPort(String str) {
645:                IGraphPort graphPort = null;
646:
647:                if (SQLJoinOperator.LEFT.equals(str)) {
648:                    graphPort = this .bottomArea.getLeftGraphPort();
649:                } else if (SQLJoinOperator.RIGHT.equals(str)) {
650:                    graphPort = this .bottomArea.getRightGraphPort();
651:                }
652:
653:                return graphPort;
654:            }
655:
656:            /**
657:             * get the output port for a field name
658:             * 
659:             * @param str field name
660:             * @return port
661:             */
662:            @Override
663:            public IGraphPort getOutputGraphPort(String str) {
664:                IGraphPort graphPort = null;
665:                //there is only one output graph port so no need to look on str
666:                graphPort = outputArea.getPortAreaAt(0).getGraphPort();
667:
668:                return graphPort;
669:            }
670:
671:            /**
672:             * get a list of all input and output links
673:             * 
674:             * @return list of input links
675:             */
676:            @Override
677:            public List getAllLinks() {
678:                ArrayList<JGoLink> list = new ArrayList<JGoLink>();
679:                IGraphPort port = null;
680:                port = this .bottomArea.getLeftGraphPort();
681:                addLinks(port, list);
682:                port = this .bottomArea.getRightGraphPort();
683:                addLinks(port, list);
684:                port = outputArea.getPortAreaAt(0).getGraphPort();
685:                addLinks(port, list);
686:
687:                return list;
688:            }
689:
690:            public void showOutputPort(boolean show) {
691:                this .showOutput = show;
692:                this .setSize(this .getMaximumWidth(), this .getMaximumHeight());
693:            }
694:
695:            private class JoinType {
696:                int joinType;
697:                String strJoinType;
698:
699:                public JoinType(int jType, String strJType) {
700:                    this .joinType = jType;
701:                    this .strJoinType = strJType;
702:                }
703:
704:                public int getJoinType() {
705:                    return this .joinType;
706:                }
707:
708:                @Override
709:                public String toString() {
710:                    return this .strJoinType;
711:                }
712:            }
713:
714:            class CBItemListener implements  ItemListener {
715:
716:                /**
717:                 * Invoked when an item has been selected or deselected by the user. The code
718:                 * written for this method performs the operations that need to occur when an item
719:                 * is selected (or deselected).
720:                 */
721:                public void itemStateChanged(ItemEvent e) {
722:                    JoinType jt = (JoinType) e.getItem();
723:                    SQLJoinOperator join = (SQLJoinOperator) JoinPreviewGraphNode.this 
724:                            .getDataObject();
725:                    if (join != null) {
726:                        join.setJoinType(jt.getJoinType());
727:                    }
728:                }
729:
730:            }
731:
732:            public void addJoinTypeComboBox() {
733:                //add join type
734:                joinTypes = new Vector<JoinType>();
735:                JoinType jt1 = new JoinType(SQLConstants.INNER_JOIN, "Inner");
736:                joinTypes.add(jt1);
737:                JoinType jt2 = new JoinType(SQLConstants.LEFT_OUTER_JOIN,
738:                        "Left Outer");
739:                joinTypes.add(jt2);
740:                JoinType jt3 = new JoinType(SQLConstants.RIGHT_OUTER_JOIN,
741:                        "Right Outer");
742:                joinTypes.add(jt3);
743:                JoinType jt4 = new JoinType(SQLConstants.FULL_OUTER_JOIN,
744:                        "Full Outer");
745:                joinTypes.add(jt4);
746:
747:                cbArea = new BasicComboBoxArea(null, joinTypes);
748:                cbArea.addItemListener(new CBItemListener());
749:                this .addObjectAtTail(cbArea);
750:                cbAreaHeight = cbArea.getMinimumHeight();
751:                this .setSize(this .getMaximumWidth(), this .getMaximumHeight());
752:            }
753:
754:            public void setMainSQLGraphView(IGraphView gView) {
755:                this.mainSQLGraphView = gView;
756:            }
757:
758:        }
w___w__w.__j_av___a_2___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.