Source Code Cross Referenced for VisTableWin.java in  » Report » datavision-1.1.0 » jimm » datavision » gui » sql » 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 » Report » datavision 1.1.0 » jimm.datavision.gui.sql 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package jimm.datavision.gui.sql;
002:
003:        import jimm.datavision.*;
004:        import jimm.datavision.gui.Designer;
005:        import jimm.datavision.gui.EditWin;
006:        import jimm.datavision.source.*;
007:        import jimm.datavision.gui.cmd.TableJoinCommand;
008:        import jimm.util.I18N;
009:        import java.awt.BorderLayout;
010:        import java.awt.event.ActionListener;
011:        import java.awt.event.ActionEvent;
012:        import java.util.*;
013:        import javax.swing.*;
014:
015:        /**
016:         * The dialog used for defining joins between database tables. Eventually,
017:         * this will be nice and graphical.
018:         * <p>
019:         * This dialog should only be created if the report uses more than one table.
020:         * The method {@link Designer#enableMenuItems} makes sure this is true.
021:         *
022:         * @author Jim Menard, <a href="mailto:jimm@io.com">jimm@io.com</a>
023:         */
024:        public class VisTableWin extends EditWin implements  ActionListener {
025:
026:            /* ================================================================ */
027:            static class RevertInfo {
028:                ArrayList joins;
029:
030:                RevertInfo(Query q) {
031:                    joins = new ArrayList();
032:                    for (Iterator iter = q.joins(); iter.hasNext();) {
033:                        Join j = (Join) iter.next();
034:                        joins.add(j.clone());
035:                    }
036:                }
037:            }
038:
039:            /* ================================================================ */
040:            static class JoinFields {
041:
042:                Join join; // If null, it's a newly created join
043:                JCheckBox del;
044:                JComboBox from;
045:                JComboBox relation;
046:                JComboBox to;
047:
048:                JoinFields(Join j, DataSource db) {
049:                    join = j;
050:                    del = new JCheckBox();
051:                    from = buildColDropdown((j == null) ? null : j.getFrom(),
052:                            db);
053:                    relation = buildRelDropdown((j == null) ? null : j
054:                            .getRelation());
055:                    to = buildColDropdown((j == null) ? null : j.getTo(), db);
056:                }
057:
058:                protected JComboBox buildColDropdown(Column col, DataSource db) {
059:                    JComboBox cb = new JComboBox();
060:
061:                    // Get iterator over tables actually used by the report. Will be
062:                    // null if the data source does not have tables.
063:                    for (Iterator iter = db.columnsInTablesUsedInReport(); iter
064:                            .hasNext();) {
065:                        Column c = (Column) iter.next();
066:                        cb.addItem(c.fullName());
067:                        if (col != null && col.equals(c))
068:                            cb.setSelectedItem(c.fullName());
069:                    }
070:
071:                    return cb;
072:                }
073:
074:                protected JComboBox buildRelDropdown(String rel) {
075:                    JComboBox cb = new JComboBox(Join.RELATIONS);
076:                    if (rel != null)
077:                        cb.setSelectedItem(rel);
078:                    return cb;
079:                }
080:            }
081:
082:            /* ================================================================ */
083:
084:            protected Report report;
085:            protected Query query;
086:            protected ArrayList joinFieldsList;
087:            protected JPanel joinsPanel;
088:            protected Box delCheckBoxPanel;
089:            protected Box fromPanel;
090:            protected Box relationPanel;
091:            protected Box toPanel;
092:            protected JButton deleteButton;
093:
094:            /**
095:             * Constructor.
096:             *
097:             * @param designer the window to which this dialog belongs
098:             * @param report the...um...I forgot
099:             */
100:            public VisTableWin(Designer designer, Report report) {
101:                this (designer, report, report.getDataSource().getQuery());
102:            }
103:
104:            /**
105:             * Constructor.
106:             *
107:             * @param designer the window to which this dialog belongs
108:             * @param report the...um...I forgot
109:             * @param query a query
110:             */
111:            public VisTableWin(Designer designer, Report report, Query query) {
112:                super (designer, I18N.get("VisTableWin.title"),
113:                        "TableJoinCommand.name");
114:                this .report = report;
115:                this .query = query;
116:
117:                buildWindow();
118:                pack();
119:                setVisible(true);
120:            }
121:
122:            /**
123:             * Builds the window contents.
124:             */
125:            protected void buildWindow() {
126:                // Joins
127:                buildJoinsPanel();
128:
129:                // Add/Delete buttons
130:                JPanel addDelButtons = new JPanel();
131:                JButton button = new JButton(I18N.get("VisTableWin.add"));
132:                button.addActionListener(this );
133:                addDelButtons.add(button);
134:
135:                deleteButton = new JButton(I18N
136:                        .get("VisTableWin.delete_selected"));
137:                deleteButton.addActionListener(this );
138:                addDelButtons.add(deleteButton);
139:
140:                // Panel containing joins and add/delete buttons
141:                JPanel centerPanel = new JPanel();
142:                centerPanel.setLayout(new BorderLayout());
143:                centerPanel.add(joinsPanel, BorderLayout.CENTER);
144:                centerPanel.add(addDelButtons, BorderLayout.SOUTH);
145:
146:                // OK, Apply, Revert, and Cancel Buttons
147:                JPanel buttonPanel = closeButtonPanel();
148:
149:                // Add tables and buttons to window
150:                getContentPane().add(centerPanel, BorderLayout.CENTER);
151:                getContentPane().add(buttonPanel, BorderLayout.SOUTH);
152:            }
153:
154:            protected void buildJoinsPanel() {
155:                joinsPanel = new JPanel();
156:                joinsPanel.setBorder(BorderFactory.createEmptyBorder(20, 20,
157:                        20, 20));
158:
159:                Box panel = Box.createHorizontalBox();
160:                joinsPanel.add(panel);
161:
162:                delCheckBoxPanel = Box.createVerticalBox();
163:                fromPanel = Box.createVerticalBox();
164:                relationPanel = Box.createVerticalBox();
165:                toPanel = Box.createVerticalBox();
166:
167:                fillJoinsPanel();
168:
169:                panel.add(delCheckBoxPanel);
170:                panel.add(fromPanel);
171:                panel.add(relationPanel);
172:                panel.add(toPanel);
173:            }
174:
175:            protected void fillJoinsPanel() {
176:                joinFieldsList = new ArrayList();
177:                for (Iterator iter = query.joins(); iter.hasNext();) {
178:                    Join j = (Join) iter.next();
179:                    joinFieldsList
180:                            .add(new JoinFields(j, report.getDataSource()));
181:                }
182:
183:                for (Iterator iter = joinFieldsList.iterator(); iter.hasNext();) {
184:                    JoinFields jf = (JoinFields) iter.next();
185:                    delCheckBoxPanel.add(jf.del);
186:                    fromPanel.add(jf.from);
187:                    relationPanel.add(jf.relation);
188:                    toPanel.add(jf.to);
189:                }
190:            }
191:
192:            protected void emptyJoinsPanel() {
193:                delCheckBoxPanel.removeAll();
194:                fromPanel.removeAll();
195:                relationPanel.removeAll();
196:                toPanel.removeAll();
197:            }
198:
199:            /**
200:             * Handles add and delete buttons.
201:             */
202:            public void actionPerformed(ActionEvent e) {
203:                String cmd = e.getActionCommand();
204:                if (cmd.equals(I18N.get("VisTableWin.add")))
205:                    addNewJoin();
206:                else if (cmd.equals(I18N.get("VisTableWin.delete_selected")))
207:                    deleteSelectedJoins();
208:                else
209:                    super .actionPerformed(e);
210:            }
211:
212:            protected void addNewJoin() {
213:                JoinFields jf = new JoinFields(null, report.getDataSource());
214:                joinFieldsList.add(jf);
215:
216:                delCheckBoxPanel.add(jf.del);
217:                fromPanel.add(jf.from);
218:                relationPanel.add(jf.relation);
219:                toPanel.add(jf.to);
220:
221:                joinsPanel.invalidate();
222:                pack();
223:            }
224:
225:            protected void deleteSelectedJoins() {
226:                ArrayList copy = (ArrayList) joinFieldsList.clone();
227:                for (Iterator iter = copy.iterator(); iter.hasNext();) {
228:                    JoinFields jf = (JoinFields) iter.next();
229:                    if (jf.del.isSelected()) {
230:                        joinFieldsList.remove(jf);
231:
232:                        delCheckBoxPanel.remove(jf.del);
233:                        fromPanel.remove(jf.from);
234:                        relationPanel.remove(jf.relation);
235:                        toPanel.remove(jf.to);
236:                    }
237:                }
238:                joinsPanel.invalidate();
239:                pack();
240:            }
241:
242:            protected void doSave() {
243:                ArrayList newJoins = new ArrayList();
244:                for (Iterator iter = joinFieldsList.iterator(); iter.hasNext();) {
245:                    JoinFields jf = (JoinFields) iter.next();
246:                    Column from = columnFromDropdown(jf.from);
247:                    String relation = (String) jf.relation.getSelectedItem();
248:                    Column to = columnFromDropdown(jf.to);
249:
250:                    newJoins.add(new Join(from, relation, to));
251:                }
252:
253:                TableJoinCommand cmd = new TableJoinCommand(query, newJoins);
254:                cmd.perform();
255:                commands.add(cmd);
256:            }
257:
258:            protected Column columnFromDropdown(JComboBox cb) {
259:                String sel = (String) cb.getSelectedItem();
260:                return report.findColumn(sel);
261:            }
262:
263:            protected void doRevert() {
264:                // Rebuild widgets
265:                emptyJoinsPanel();
266:                fillJoinsPanel();
267:                joinsPanel.invalidate();
268:                pack();
269:            }
270:
271:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.