Source Code Cross Referenced for JoinDialog.java in  » J2EE » Sofia » com » salmonllc » ideTools » 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 » J2EE » Sofia » com.salmonllc.ideTools 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        //** Copyright Statement ***************************************************
002:        //The Salmon Open Framework for Internet Applications (SOFIA)
003:        // Copyright (C) 1999 - 2002, Salmon LLC
004:        //
005:        // This program is free software; you can redistribute it and/or
006:        // modify it under the terms of the GNU General Public License version 2
007:        // as published by the Free Software Foundation;
008:        //
009:        // This program is distributed in the hope that it will be useful,
010:        // but WITHOUT ANY WARRANTY; without even the implied warranty of
011:        // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012:        // GNU General Public License for more details.
013:        //
014:        // You should have received a copy of the GNU General Public License
015:        // along with this program; if not, write to the Free Software
016:        // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
017:        //
018:        // For more information please visit http://www.salmonllc.com
019:        //** End Copyright Statement ***************************************************
020:        package com.salmonllc.ideTools;
021:
022:        /////////////////////////
023:        //$Archive: /SOFIA/SourceCode/com/salmonllc/ideTools/JoinDialog.java $
024:        //$Author: Dan $
025:        //$Revision: 8 $
026:        //$Modtime: 6/11/03 12:52p $
027:        /////////////////////////
028:        import java.awt.*;
029:        import java.awt.event.ActionEvent;
030:        import java.awt.event.ActionListener;
031:        import java.util.Vector;
032:
033:        import javax.swing.*;
034:        import javax.swing.border.EmptyBorder;
035:        import javax.swing.event.ListSelectionEvent;
036:        import javax.swing.event.ListSelectionListener;
037:
038:        import com.salmonllc.sql.ColumnDefinition;
039:        import com.salmonllc.sql.DataDictionary;
040:
041:        public class JoinDialog extends JDialog implements  ActionListener,
042:                ListSelectionListener {
043:
044:            ModelDialog.AliasDef[] _aliases;
045:            JButton _ok, _cancel, _add, _del;
046:            JComboBox _leftTables, _rightTables;
047:            JList _leftColumns, _rightColumns, _joins;
048:            JCheckBox _outer;
049:            DataDictionary _dd;
050:            boolean _clickedCancel = true;
051:
052:            public class JoinTermDef {
053:                String left;
054:                String right;
055:                boolean outer;
056:
057:                public JoinTermDef(String left, String right, boolean outer) {
058:                    this .left = left;
059:                    this .right = right;
060:                    this .outer = outer;
061:                }
062:
063:                public String toString() {
064:                    return left + (outer ? "*=" : "=") + right;
065:                }
066:            }
067:
068:            public JoinDialog(Frame owner, ModelDialog.AliasDef[] aliases,
069:                    DataDictionary dd, int buttonHeight) {
070:                super (owner, "Create a join", true);
071:                _dd = dd;
072:                int width = 620;
073:                int height = 450;
074:                Dimension frameBounds = Toolkit.getDefaultToolkit()
075:                        .getScreenSize();
076:                int x = (frameBounds.width - width) / 2;
077:                int y = (frameBounds.height - height) / 2;
078:
079:                setBounds(x, y, width, height);
080:                setResizable(false);
081:                setModal(true);
082:
083:                //main box
084:                JPanel main = new JPanel();
085:                main.setLayout(new BoxLayout(main, BoxLayout.Y_AXIS));
086:                main.setBorder(new EmptyBorder(10, 10, 10, 10));
087:
088:                //row 1, headings
089:                JPanel box = new JPanel();
090:                box.setLayout(new BoxLayout(box, BoxLayout.X_AXIS));
091:                box.add(DialogComponentFactory.makeLabel(
092:                        "Tables/Columns Left Side:", 300));
093:                box.add(DialogComponentFactory.makeLabel(
094:                        "Tables/Columns Right Side:", 300));
095:                box.add(Box.createHorizontalGlue());
096:                main.add(box);
097:                main.add(Box.createRigidArea(new Dimension(0, 5)));
098:
099:                //row 2, drop downs
100:                box = new JPanel();
101:                box.setLayout(new BoxLayout(box, BoxLayout.X_AXIS));
102:                box.add(_leftTables = DialogComponentFactory.makeComboBox(290));
103:                box.add(Box.createRigidArea(new Dimension(10, 0)));
104:                box
105:                        .add(_rightTables = DialogComponentFactory
106:                                .makeComboBox(290));
107:                box.add(Box.createHorizontalGlue());
108:                main.add(box);
109:                main.add(Box.createRigidArea(new Dimension(0, 5)));
110:
111:                //row3, column lists
112:                box = new JPanel();
113:                box.setLayout(new BoxLayout(box, BoxLayout.X_AXIS));
114:                box.add(_leftColumns = DialogComponentFactory
115:                        .makeList(new LModel()));
116:                box.add(DialogComponentFactory.makeScrollPane(290, 150,
117:                        _leftColumns = DialogComponentFactory
118:                                .makeList(new LModel())));
119:                box.add(Box.createRigidArea(new Dimension(10, 0)));
120:                box.add(DialogComponentFactory.makeScrollPane(290, 150,
121:                        _rightColumns = DialogComponentFactory
122:                                .makeList(new LModel())));
123:                box.add(Box.createHorizontalGlue());
124:                main.add(box);
125:                main.add(Box.createRigidArea(new Dimension(0, 5)));
126:
127:                //row4, Add and Delete Buttons
128:                box = new JPanel();
129:                box.setLayout(new BoxLayout(box, BoxLayout.X_AXIS));
130:                box.add(DialogComponentFactory.makeLabel(
131:                        "Column Pairs in Join:", 370));
132:                box.add(DialogComponentFactory.makeLabel("Outer:", 50));
133:                box.add(_outer = new JCheckBox());
134:                box.add(Box.createRigidArea(new Dimension(30, 0)));
135:                box.add(_add = DialogComponentFactory.makeButton("Add", 60,
136:                        buttonHeight));
137:                box.add(_del = DialogComponentFactory.makeButton("Del", 60,
138:                        buttonHeight));
139:                box.add(Box.createHorizontalGlue());
140:                main.add(box);
141:                main.add(Box.createRigidArea(new Dimension(0, 5)));
142:
143:                //row5, Join Display
144:                box = new JPanel();
145:                box.setLayout(new BoxLayout(box, BoxLayout.X_AXIS));
146:                box
147:                        .add(DialogComponentFactory.makeScrollPane(600, 100,
148:                                _joins = DialogComponentFactory
149:                                        .makeList(new LModel())));
150:                main.add(box);
151:
152:                //button bar
153:                _ok = new JButton("OK");
154:                _ok.addActionListener(this );
155:                _cancel = new JButton("Cancel");
156:                _cancel.addActionListener(this );
157:                JPanel buttonBar = new JPanel();
158:                buttonBar.setLayout(new BoxLayout(buttonBar, BoxLayout.X_AXIS));
159:                buttonBar.add(_ok = new JButton("OK"));
160:                buttonBar.add(_cancel = new JButton("Cancel"));
161:                main.add(buttonBar);
162:
163:                //Add Listeners
164:                _ok.addActionListener(this );
165:                _cancel.addActionListener(this );
166:                _leftTables.addActionListener(this );
167:                _rightTables.addActionListener(this );
168:                _add.addActionListener(this );
169:                _del.addActionListener(this );
170:                _leftColumns.addListSelectionListener(this );
171:                _rightColumns.addListSelectionListener(this );
172:                _joins.addListSelectionListener(this );
173:                _leftColumns
174:                        .setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
175:                _rightColumns
176:                        .setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
177:                //Fill Drop Downs
178:                loadTables(aliases, _leftTables);
179:                loadTables(aliases, _rightTables);
180:
181:                //Add it to the screen
182:                Container cp = getContentPane();
183:                cp.setLayout(new BoxLayout(cp, BoxLayout.Y_AXIS));
184:                cp.add(main);
185:                cp.add(Box.createVerticalGlue());
186:                cp.add(buttonBar);
187:                cp.add(Box.createRigidArea(new Dimension(0, 20)));
188:                enableDisableButtons();
189:                setVisible(true);
190:
191:            }
192:
193:            public void actionPerformed(ActionEvent e) {
194:                if (e.getSource() == _leftTables) {
195:                    ModelDialog.AliasDef d = (ModelDialog.AliasDef) _leftTables
196:                            .getSelectedItem();
197:                    loadColumns(d.table, _leftColumns);
198:                    enableDisableButtons();
199:                } else if (e.getSource() == _rightTables) {
200:                    ModelDialog.AliasDef d = (ModelDialog.AliasDef) _rightTables
201:                            .getSelectedItem();
202:                    loadColumns(d.table, _rightColumns);
203:                    enableDisableButtons();
204:                } else if (e.getSource() == _cancel) {
205:                    _clickedCancel = true;
206:                    setVisible(false);
207:                } else if (e.getSource() == _ok) {
208:                    _clickedCancel = false;
209:                    setVisible(false);
210:                } else if (e.getSource() == _add)
211:                    addJoin();
212:                else if (e.getSource() == _del)
213:                    deleteJoin();
214:
215:            }
216:
217:            public void addJoin() {
218:                ModelDialog.AliasDef leftTable = (ModelDialog.AliasDef) _leftTables
219:                        .getSelectedItem();
220:                ModelDialog.AliasDef rightTable = (ModelDialog.AliasDef) _rightTables
221:                        .getSelectedItem();
222:                ColumnDefinition leftColumn = (ColumnDefinition) _leftColumns
223:                        .getSelectedValue();
224:                ColumnDefinition rightColumn = (ColumnDefinition) _rightColumns
225:                        .getSelectedValue();
226:                boolean outer = _outer.isSelected();
227:                LModel joinModel = (LModel) _joins.getModel();
228:                for (int i = 0; i < joinModel.getSize(); i++)
229:                    ((JoinTermDef) joinModel.getElementAt(i)).outer = outer;
230:                JoinTermDef d = new JoinTermDef(
231:                        (leftTable.alias == null ? leftTable.table
232:                                : leftTable.alias)
233:                                + "." + leftColumn.getColumnName(),
234:                        (rightTable.alias == null ? rightTable.table
235:                                : rightTable.alias)
236:                                + "." + rightColumn.getColumnName(), outer);
237:
238:                joinModel.addElement(d);
239:                enableDisableButtons();
240:            }
241:
242:            private void deleteJoin() {
243:                LModel mod = (LModel) _joins.getModel();
244:                int sel[] = _joins.getSelectedIndices();
245:                for (int i = sel.length - 1; i > -1; i--)
246:                    mod.remove(sel[i]);
247:                _joins.getSelectionModel().clearSelection();
248:                enableDisableButtons();
249:            }
250:
251:            private void enableDisableButtons() {
252:                _ok.setEnabled(_joins.getModel().getSize() > 0);
253:                _del.setEnabled(_joins.getModel().getSize() > 0
254:                        && _joins.getSelectedIndices().length > 0);
255:                _add.setEnabled(_leftColumns.getSelectedIndex() > -1
256:                        && _rightColumns.getSelectedIndex() > -1);
257:            }
258:
259:            /**
260:             * Returns the join terms specified by the user or an empty array if the user clicked cancel
261:             */
262:            public JoinTermDef[] getResult() {
263:                if (_clickedCancel)
264:                    return new JoinTermDef[0];
265:                LModel l = (LModel) _joins.getModel();
266:                JoinTermDef ret[] = new JoinTermDef[l.getSize()];
267:                for (int i = 0; i < l.getSize(); i++)
268:                    ret[i] = (JoinTermDef) l.getElementAt(i);
269:                return ret;
270:            }
271:
272:            private void loadColumns(String tableName, JList list) {
273:                if (tableName != null) {
274:                    Vector v = _dd.getColumns(tableName);
275:                    Vector mod = new Vector(v.size());
276:                    for (int i = 0; i < v.size(); i++) {
277:                        ColumnDefinition def = (ColumnDefinition) v
278:                                .elementAt(i);
279:                        mod.add(def);
280:                    }
281:                    list.setModel(new LModel(mod));
282:                }
283:            }
284:
285:            private void loadTables(ModelDialog.AliasDef[] defs, JComboBox box) {
286:                box.removeAllItems();
287:                for (int i = 0; i < defs.length; i++)
288:                    box.addItem(defs[i]);
289:            }
290:
291:            public void valueChanged(ListSelectionEvent e) {
292:                enableDisableButtons();
293:            }
294:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.