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


001:        package com.salmonllc.examples.example2;
002:
003:        //The Salmon Open Framework for Internet Applications (SOFIA)
004:        //Copyright (C) 1999 - 2002, Salmon LLC
005:        //
006:        //This program is free software; you can redistribute it and/or
007:        //modify it under the terms of the GNU General Public License version 2
008:        //as published by the Free Software Foundation; 
009:        //
010:        //This program is distributed in the hope that it will be useful,
011:        //but WITHOUT ANY WARRANTY; without even the implied warranty of
012:        //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013:        //GNU General Public License for more details.
014:        //
015:        //You should have received a copy of the GNU General Public License
016:        //along with this program; if not, write to the Free Software
017:        //Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
018:        //
019:        //For more information please visit http://www.salmonllc.com
020:
021:        import com.salmonllc.html.*;
022:        import com.salmonllc.html.events.PageListener;
023:        import com.salmonllc.html.events.PageEvent;
024:        import com.salmonllc.sql.DataDictionary;
025:        import com.salmonllc.sql.ColumnDefinition;
026:
027:        import java.util.Vector;
028:
029:        /**
030:         * This class implements a combination component.
031:         * It's a drop down list of database tables and a list box of columns in a table.
032:         * When the user chooses a table, it automatically submits the page. The component
033:         * figures out which table the user selected and populates the list box with the
034:         * appropriate columns.
035:         *
036:         * This component uses the com.salmonllc.sql.DataDictionary component to query the database engine for the tables and columns.
037:         */
038:        public class DBSelector extends HtmlTable implements  PageListener {
039:            DataDictionary _dd;
040:            HtmlDropDownList _tables;
041:            HtmlListBox _columns;
042:            HtmlHiddenField _hidden;
043:
044:            /**
045:             * Create a new DBSelector component
046:             */
047:            public DBSelector(String name, com.salmonllc.html.HtmlPage p) {
048:                super (name, p);
049:
050:                //set some properties of the table
051:                setBorder(0);
052:                setCellSpacing(1);
053:                setCellPadding(1);
054:
055:                //create the components to display on the screen
056:                _tables = new HtmlDropDownList("tables", p);
057:                _columns = new HtmlListBox("columns", p);
058:                setComponentAt(0, 0, _tables);
059:                setComponentAt(1, 0, _columns);
060:
061:                //populate the tables component
062:                _dd = new DataDictionary(p.getApplicationName());
063:                Vector v = _dd.getTableNames();
064:                for (int i = 0; i < v.size(); i++)
065:                    _tables.addOption((String) v.elementAt(i), (String) v
066:                            .elementAt(i));
067:                if (v.size() > 0) {
068:                    _tables.setSelectedIndex(0);
069:                    populateColumns();
070:                }
071:
072:                //add a hidden field and some javascript to the component
073:                //so it submits the page when the user changes it.
074:                //This hidden field is used so the submit performed event can test to
075:                //make sure that it was this component that submitted the page and not
076:                //a different one.
077:                _hidden = new HtmlHiddenField("hidden", "0", p);
078:                setComponentAt(2, 0, _hidden);
079:
080:                //add a page listener so this page will get notified when the page containing the component is submitted
081:                p.addPageListener(this );
082:            }
083:
084:            /**
085:             * This method is populates the column list box, based on what the user selected in the table drop down
086:             */
087:            private void populateColumns() {
088:                String table = _tables.getValue();
089:                _columns.resetOptions();
090:                if (table == null)
091:                    return;
092:                Vector v = _dd.getColumns(table);
093:                for (int i = 0; i < v.size(); i++) {
094:                    ColumnDefinition colDef = (ColumnDefinition) v.elementAt(i);
095:                    _columns.addOption(colDef.getColumnName(), colDef
096:                            .getColumnName(), true);
097:                }
098:            }
099:
100:            /**
101:             * This method occurs each time a page is submitted.
102:             * The hidden field in this component is checked to see if this is the comp that submitted the page.
103:             */
104:            public void pageSubmitEnd(PageEvent p) {
105:                //if the hidden field has a value of one, then this component submitted the page
106:                if (_hidden.getValue() != null
107:                        && _hidden.getValue().equals("1")) {
108:                    populateColumns();
109:                    _hidden.setValue("0");
110:                }
111:            }
112:
113:            /**
114:             * This method returns an array of column definition objects, one for each column selected in the list box.
115:             */
116:            public ColumnDefinition[] getSelectedColumns() {
117:                Vector v = new Vector();
118:                String tableName = _tables.getValue() + ".";
119:                for (int i = 0; i < _columns.getOptionCount(); i++) {
120:                    if (_columns.getOptionSelected(i)) {
121:                        ColumnDefinition def = _dd.getColumnDefintion(tableName
122:                                + _columns.getOptionKey(i));
123:                        v.add(def);
124:                    }
125:                }
126:                ColumnDefinition ret[] = new ColumnDefinition[v.size()];
127:                v.copyInto(ret);
128:                return ret;
129:            }
130:
131:            /**
132:             * This event is part of the PageListener interface. It is only implemented here to fill out the interface, but the component doesn't use it.
133:             */
134:            public void pageRequested(PageEvent p) throws Exception {
135:            }
136:
137:            /**
138:             * This event is part of the PageListener interface. It is only implemented here to fill out the interface, but the component doesn't use it.
139:             */
140:            public void pageRequestEnd(PageEvent p) throws Exception {
141:            }
142:
143:            /**
144:             * This event is part of the PageListener interface. It is only implemented here to fill out the interface, but the component doesn't use it.
145:             */
146:            public void pageSubmitted(PageEvent p) {
147:            }
148:
149:            /**
150:             * We can't set the submit javascript until we know what form this component is in and we don't know that until the component is added to the container. So we can override setParent and set the data there
151:             */
152:            public void setParent(HtmlComponent parent) {
153:                super .setParent(parent);
154:                _tables.setOnChange(getFormString() + _hidden.getFullName()
155:                        + ".value=1;" + getFormString() + "submit();");
156:            }
157:
158:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.