Source Code Cross Referenced for Databases.java in  » XML-UI » xui32 » com » xoetrope » carousel » catalog » 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 » XML UI » xui32 » com.xoetrope.carousel.catalog 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.xoetrope.carousel.catalog;
002:
003:        import com.xoetrope.carousel.build.BuildProperties;
004:        import java.io.File;
005:        import java.net.MalformedURLException;
006:        import java.net.URL;
007:        import java.net.URLClassLoader;
008:        import java.sql.Connection;
009:        import java.sql.DriverManager;
010:
011:        import java.awt.Font;
012:        import java.awt.Rectangle;
013:        import java.awt.event.ActionEvent;
014:        import java.awt.event.ActionListener;
015:        import java.net.URLClassLoader;
016:        import javax.swing.BorderFactory;
017:        import javax.swing.JButton;
018:        import javax.swing.JCheckBox;
019:        import javax.swing.JComboBox;
020:        import javax.swing.JLabel;
021:        import javax.swing.JOptionPane;
022:        import javax.swing.JPanel;
023:        import javax.swing.JPasswordField;
024:        import javax.swing.JTextArea;
025:        import javax.swing.JTextField;
026:
027:        import net.xoetrope.swing.XImage;
028:        import com.xoetrope.carousel.wizard.XWizardPanel;
029:        import net.xoetrope.editor.project.XEditorProject;
030:        import net.xoetrope.editor.project.XEditorProjectManager;
031:
032:        /**
033:         * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
034:         * the GNU Public License (GPL), please see license.txt for more details. If
035:         * you make commercial use of this software you must purchase a commercial
036:         * license from Xoetrope.</p>
037:         * <p> $Revision: 1.5 $</p>
038:         */
039:        public class Databases extends XWizardPanel {
040:            private boolean isStandalone = false;
041:            private XCatalogueWizardDialog wizard;
042:            private XImage imageControl1 = new XImage();
043:            private JTextArea jTextArea1 = new JTextArea();
044:            private JPanel jPanel1 = new JPanel();
045:            private JLabel jLabel1 = new JLabel();
046:            private JButton jButton1 = new JButton();
047:            private JLabel jLabel2 = new JLabel();
048:            private JLabel jLabel3 = new JLabel();
049:            private XEditorProject currentProject;
050:            private JComboBox driverList;;
051:            private JComboBox urlList;
052:            private JLabel jLabel4 = new JLabel();
053:            private JLabel jLabel5 = new JLabel();
054:            private JTextField userNameField = new JTextField();
055:            private JPasswordField passwordField = new JPasswordField();
056:            private JPanel jPanel2 = new JPanel();
057:            private JCheckBox dummyDataCB = new javax.swing.JCheckBox();
058:            private JCheckBox newTablesCB = new javax.swing.JCheckBox();
059:            private JCheckBox ejbsCB = new javax.swing.JCheckBox();
060:            private JLabel jLabel6 = new JLabel();
061:            private JTextField ejbServerField = new JTextField();
062:            private JCheckBox logConnsCB = new javax.swing.JCheckBox();
063:            private JCheckBox profileCB = new javax.swing.JCheckBox();
064:            private Connection connection;
065:
066:            /**
067:             * Constructor which takes an instance of the <CODE>XCatalogueWizardDialog</CODE> and 
068:             * a String specifying the super class name.
069:             * @param wiz the <CODE>XCatalogueWizardDialog</CODE> instance passed to this class.
070:             * @param name the <CODE>String</CODE> instance passed to this class specifying the super class name.
071:             */
072:            public Databases(XCatalogueWizardDialog wiz,
073:                    XEditorProject project, String name) {
074:                super (name);
075:                wizard = wiz;
076:                currentProject = project;
077:
078:                try {
079:                    jbInit();
080:                } catch (Exception ex) {
081:                    ex.printStackTrace();
082:                }
083:            }
084:
085:            /**
086:             * Method responsible for initialising the components used in this wizard panel. 
087:             */
088:            void jbInit() throws Exception {
089:                Font font = new java.awt.Font("SansSerif", 0, 11);
090:                setLayout(null);
091:
092:                dummyDataCB.setFocusable(false);
093:                newTablesCB.setFocusable(false);
094:                jButton1.setFocusable(false);
095:
096:                imageControl1.setBackground(getBackground());
097:                imageControl1.setBounds(new Rectangle(5, 9, 179, 366));
098:                imageControl1.setImage(((XEditorProject) (XEditorProjectManager
099:                        .getCurrentProject())).getImage(getClass(),
100:                        "com/xoetrope/carousel/catalog/books.jpg"));
101:                imageControl1.setBorder(BorderFactory.createEtchedBorder());
102:
103:                jTextArea1.setBackground(getBackground());
104:                jTextArea1
105:                        .setText("Step 9: Enter the settings for your database so that the wizard can "
106:                                + "access the database, setup tables and configure servers.");
107:                jTextArea1.setLineWrap(true);
108:                jTextArea1.setEditable(false);
109:                jTextArea1.setWrapStyleWord(true);
110:                jTextArea1.setBounds(new Rectangle(190, 10, 400, 39));
111:
112:                jPanel1.setBorder(BorderFactory.createEtchedBorder());
113:                jPanel1.setBounds(new Rectangle(191, 73, 397, 106));
114:                jPanel1.setLayout(null);
115:
116:                jLabel1.setText("Connection");
117:                jLabel1.setBounds(new Rectangle(191, 55, 88, 17));
118:
119:                jButton1.setToolTipText("Attempt to connect to the database");
120:                jButton1.setText("Test Connection");
121:                jButton1.setBounds(new Rectangle(271, 71, 115, 25));
122:
123:                jButton1.addActionListener(new java.awt.event.ActionListener() {
124:                    public void actionPerformed(ActionEvent e) {
125:                        testConnection(e);
126:                    }
127:                });
128:
129:                jLabel2.setText("Driver");
130:                jLabel2.setBounds(new Rectangle(9, 13, 41, 17));
131:                jLabel3.setText("URL");
132:                jLabel3.setBounds(new Rectangle(9, 35, 41, 17));
133:
134:                String[] drivers = { "sun.jdbc.odbc.JdbcOdbcDriver",
135:                        "org.hsqldb.jdbcDriver",
136:                        "org.apache.derby.jdbc.ClientDriver", "<Other>" };
137:
138:                driverList = new JComboBox(drivers);
139:                driverList.setEnabled(true);
140:                driverList.setDoubleBuffered(true);
141:                driverList
142:                        .setToolTipText("Choose a driver from the list below or type the class name for the required driver");
143:                driverList.setEditable(true);
144:                driverList.setBounds(new Rectangle(72, 12, 316, 18));
145:
146:                driverList
147:                        .addActionListener(new java.awt.event.ActionListener() {
148:                            public void actionPerformed(ActionEvent e) {
149:                                driverList_actionPerformed(e);
150:                            }
151:                        });
152:
153:                String projectPath = currentProject.getPath();
154:                projectPath = projectPath.replaceAll("\\\\", "/");
155:                projectPath = "file://" + projectPath + "/resources/mydb";
156:
157:                String[] connectStrings = { "jdbc:odbc:odbcDataSource",
158:                        "jdbc:hsqldb:<<DataBase URL>>",
159:                        "jdbc:derby:<<DataBase URL>>",
160:                        "jdbc:<protocol>:<subprotocol>://<url>:<port>/" };
161:
162:                urlList = new JComboBox(connectStrings);
163:                urlList.setDoubleBuffered(true);
164:                urlList
165:                        .setToolTipText("Complete the URL connection string for the database or replace as necessary");
166:                urlList.setEditable(true);
167:                urlList.setBounds(new Rectangle(72, 33, 316, 18));
168:
169:                urlList.addActionListener(new java.awt.event.ActionListener() {
170:                    public void actionPerformed(ActionEvent e) {
171:                        urlList_actionPerformed(e);
172:                    }
173:                });
174:
175:                jLabel4.setText("User Name");
176:                jLabel4.setBounds(new Rectangle(9, 55, 63, 17));
177:                jLabel5.setText("Password");
178:                jLabel5.setBounds(new Rectangle(9, 75, 66, 17));
179:
180:                userNameField
181:                        .setToolTipText("Enter your database user name here");
182:                userNameField.setText("SYSDBA");
183:                userNameField.setBounds(new Rectangle(72, 54, 129, 18));
184:
185:                passwordField.setText("Admin");
186:                passwordField
187:                        .setToolTipText("Enter the corresponding database password");
188:                passwordField.setBounds(new Rectangle(72, 76, 129, 18));
189:
190:                jPanel2.setBorder(BorderFactory.createEtchedBorder());
191:                jPanel2.setBounds(new Rectangle(192, 185, 395, 53));
192:                jPanel2.setLayout(null);
193:
194:                dummyDataCB
195:                        .setToolTipText("Initialize the database with data from the sample database");
196:                dummyDataCB.setText("Use dummy data");
197:                dummyDataCB.setEnabled(false);
198:                dummyDataCB.setBounds(new Rectangle(8, 2, 141, 25));
199:
200:                newTablesCB
201:                        .setToolTipText("Add any required tables to the database");
202:                newTablesCB.setSelected(false);
203:                newTablesCB.setText("Create new tables");
204:                newTablesCB.setEnabled(false);
205:                newTablesCB.setBounds(new Rectangle(8, 23, 168, 25));
206:
207:                profileCB.setText("Profile users");
208:                profileCB.setBounds(new Rectangle(26, 112, 235, 25));
209:                profileCB
210:                        .setToolTipText("Build a profile of how each user accesses the catalogue and the underlying databases");
211:                profileCB.setEnabled(false);
212:
213:                add(imageControl1);
214:                add(jTextArea1);
215:                add(jPanel1);
216:
217:                jPanel1.add(driverList);
218:                jPanel1.add(urlList);
219:                jPanel1.add(jLabel3);
220:                jPanel1.add(jLabel2);
221:                jPanel1.add(jLabel4);
222:                jPanel1.add(userNameField);
223:                jPanel1.add(passwordField);
224:                jPanel1.add(jButton1);
225:                jPanel1.add(jLabel5);
226:
227:                add(jLabel1);
228:                add(jPanel2);
229:
230:                jPanel2.add(dummyDataCB);
231:                jPanel2.add(newTablesCB);
232:            }
233:
234:            /**
235:             * Used to test the database connection parameters the user has entered.
236:             * @param evt the passed <CODE>ActionEvent</CODE> instance.
237:             */
238:            private void testConnection(ActionEvent evt) {
239:                try {
240:                    Class.forName(driverList.getSelectedItem().toString()
241:                            .trim());
242:                } catch (Exception e) {
243:                    JOptionPane.showMessageDialog(this ,
244:                            "Unable to load the class: "
245:                                    + driverList.getSelectedItem().toString(),
246:                            "Driver Error", JOptionPane.ERROR_MESSAGE);
247:                    return;
248:                }
249:
250:                try {
251:                    connection = DriverManager.getConnection(urlList
252:                            .getSelectedItem().toString(), userNameField
253:                            .getText(), passwordField.getPassword().toString());
254:                } catch (Exception e) {
255:                    JOptionPane.showMessageDialog(this ,
256:                            "Unable to open the connection to: "
257:                                    + urlList.getSelectedItem().toString(),
258:                            "URL Error", JOptionPane.ERROR_MESSAGE);
259:                    return;
260:                }
261:
262:                JOptionPane.showMessageDialog(this ,
263:                        "Driver loaded and connection opened successfully",
264:                        "Success", JOptionPane.INFORMATION_MESSAGE);
265:            }
266:
267:            /**
268:             * Called when an action occurs on the driver list to update the url list
269:             * @param e the <CODE>ActionEvent</CODE> instance passed to this method
270:             */
271:            public void driverList_actionPerformed(ActionEvent e) {
272:                int selIdx = driverList.getSelectedIndex();
273:                urlList.setSelectedIndex(selIdx);
274:
275:                if (selIdx == 2) {
276:                    dummyDataCB.setEnabled(true);
277:                    newTablesCB.setEnabled(true);
278:                } else {
279:                    dummyDataCB.setEnabled(false);
280:                    newTablesCB.setEnabled(false);
281:                }
282:            }
283:
284:            /**
285:             * Called when an action occurs on the url list to update the driver list
286:             * @param e the <CODE>ActionEvent</CODE> instance passed to this method
287:             */
288:            public void urlList_actionPerformed(ActionEvent e) {
289:                int selIdx = urlList.getSelectedIndex();
290:                driverList.setSelectedIndex(selIdx);
291:
292:                if (selIdx == 2) {
293:                    dummyDataCB.setEnabled(true);
294:                    newTablesCB.setEnabled(true);
295:                } else {
296:                    dummyDataCB.setEnabled(false);
297:                    newTablesCB.setEnabled(false);
298:                }
299:            }
300:
301:            /**
302:             * Returns which database type is to be used
303:             * @return <CODE>int</CODE> specifying which database type is to be used
304:             */
305:            public int useDataBase() {
306:                return driverList.getSelectedIndex();
307:            }
308:
309:            /**
310:             * Returns the created connection instance
311:             * @return the returned <CODE>Connection</CODE> instance
312:             */
313:            public Connection getConnection() {
314:                if (connection == null) {
315:                    try {
316:                        Class.forName(driverList.getSelectedItem().toString()
317:                                .trim());
318:                        connection = DriverManager.getConnection(urlList
319:                                .getSelectedItem().toString(), userNameField
320:                                .getText(), passwordField.getText());
321:                    } catch (Exception ex) {
322:                        if (BuildProperties.DEBUG)
323:                            ex.printStackTrace();
324:                    }
325:                }
326:
327:                return connection;
328:            }
329:
330:            /**
331:             * Returns whether dummy data is to be added to the database or not
332:             * @return <CODE>boolean</CODE> specifying whether to include dummy data or not
333:             */
334:            public boolean wantsDummyData() {
335:                return dummyDataCB.isSelected();
336:            }
337:
338:            /**
339:             * Returns whether new tables are to be added to the database or not
340:             * @return <CODE>boolean</CODE> specifying whether to include new tables or not
341:             */
342:            public boolean wantsNewTables() {
343:                return newTablesCB.isSelected();
344:            }
345:
346:            /**
347:             * Returns the selected database driver
348:             * @return <CODE>String</CODE> specifying the selected database driver
349:             */
350:            public String getDriver() {
351:                return driverList.getSelectedItem().toString();
352:            }
353:
354:            /**
355:             * Returns the selected url
356:             * @return <CODE>String</CODE> specifying the selected url
357:             */
358:            public String getUrl() {
359:                return urlList.getSelectedItem().toString();
360:            }
361:
362:            /**
363:             * Returns the entered database user name
364:             * @return <CODE>String</CODE> specifying the entered database user name
365:             */
366:            public String getUserName() {
367:                return userNameField.getText();
368:            }
369:
370:            /**
371:             * Returns the entered password
372:             * @return <CODE>String</CODE> specifying the entered password
373:             */
374:            public String getPassword() {
375:                return passwordField.getText();
376:            }
377:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.