Source Code Cross Referenced for ConfigureServiceResources.java in  » Database-Client » iSQL-Viewer » org » isqlviewer » ui » wizards » service » 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 » Database Client » iSQL Viewer » org.isqlviewer.ui.wizards.service 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * The contents of this file are subject to the Mozilla Public License
003:         * Version 1.1 (the "License"); you may not use this file except in
004:         * compliance with the License. You may obtain a copy of the License at
005:         * http://www.mozilla.org/MPL/
006:         *
007:         * Software distributed under the License is distributed on an "AS IS"
008:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
009:         * License for the specific language governing rights and limitations
010:         * under the License.
011:         * 
012:         * The Original Code is iSQL-Viewer, A Mutli-Platform Database Tool.
013:         *
014:         * The Initial Developer of the Original Code is iSQL-Viewer, A Mutli-Platform Database Tool.
015:         * Portions created by Mark A. Kobold are Copyright (C) 2000-2007. All Rights Reserved.
016:         *
017:         * Contributor(s): 
018:         *  Mark A. Kobold [mkobold <at> isqlviewer <dot> com].
019:         *  
020:         * If you didn't download this code from the following link, you should check
021:         * if you aren't using an obsolete version: http://www.isqlviewer.com
022:         */
023:        package org.isqlviewer.ui.wizards.service;
024:
025:        import java.awt.Component;
026:        import java.awt.GridBagConstraints;
027:        import java.awt.GridBagLayout;
028:        import java.awt.event.ActionEvent;
029:        import java.awt.event.ActionListener;
030:        import java.io.File;
031:        import java.net.MalformedURLException;
032:        import java.net.URL;
033:        import java.net.URLClassLoader;
034:        import java.util.ArrayList;
035:        import java.util.Enumeration;
036:
037:        import javax.swing.Box;
038:        import javax.swing.DefaultListModel;
039:        import javax.swing.JButton;
040:        import javax.swing.JComponent;
041:        import javax.swing.JFileChooser;
042:        import javax.swing.JList;
043:        import javax.swing.JPanel;
044:        import javax.swing.JScrollPane;
045:        import javax.swing.JToolBar;
046:
047:        import org.isqlviewer.sql.ConnectionProfile;
048:        import org.isqlviewer.sql.JdbcService;
049:        import org.isqlviewer.swing.SwingUtilities;
050:        import org.isqlviewer.ui.renderer.FileListCellRenderer;
051:        import org.isqlviewer.ui.wizards.AbstractWizardStep;
052:        import org.isqlviewer.ui.wizards.WizardContext;
053:        import org.isqlviewer.util.LocalMessages;
054:
055:        public class ConfigureServiceResources extends AbstractWizardStep
056:                implements  ActionListener {
057:
058:            private LocalMessages messages = new LocalMessages(
059:                    ServiceWizard.BUNDLE_NAME);
060:            private DefaultListModel fileListModel = new DefaultListModel();
061:            private JList fileList = new JList(fileListModel);
062:            private static final int ACTION_ADD_FILE = 0;
063:            private static final int ACTION_REMOVE_FILE = 1;
064:
065:            public void actionPerformed(ActionEvent event) {
066:
067:                String command = event.getActionCommand();
068:                Component source = (Component) event.getSource();
069:                int action = -1;
070:                try {
071:                    action = Integer.parseInt(command);
072:                } catch (Exception error) {
073:                    error.printStackTrace();
074:                }
075:                switch (action) {
076:                case ACTION_REMOVE_FILE:
077:                    int[] idxs = fileList.getSelectedIndices();
078:                    for (int i = idxs.length - 1; i >= 0; i--) {
079:                        fileListModel.removeElementAt(idxs[i]);
080:                    }
081:                    break;
082:                case ACTION_ADD_FILE:
083:                    File[] f = SwingUtilities.getSystemFiles(source,
084:                            JFileChooser.FILES_AND_DIRECTORIES);
085:                    if (f != null) {
086:                        for (int i = 0; i < f.length; i++) {
087:                            fileListModel.addElement(f[i]);
088:                        }
089:                    }
090:                    break;
091:                default:
092:                    break;
093:                }
094:            }
095:
096:            public boolean isFirst() {
097:
098:                return false;
099:            }
100:
101:            public boolean isLast() {
102:
103:                return false;
104:            }
105:
106:            public boolean isValid(WizardContext context) {
107:
108:                JdbcService service = (JdbcService) context
109:                        .getAttribute(ServiceWizard.ATTRIBUTE_SERVICE);
110:                ArrayList<URL> classPath = new ArrayList<URL>();
111:                int count = fileListModel.getSize();
112:                for (int i = 0; i < count; i++) {
113:                    File file = (File) fileListModel.get(i);
114:                    try {
115:                        classPath.add(file.toURL());
116:                    } catch (MalformedURLException e) {
117:                        context.error("file.toURL()", e);
118:                    }
119:                }
120:
121:                URLClassLoader classLoader = new URLClassLoader(classPath
122:                        .toArray(new URL[count]));
123:                ClassLoader contextClassLoader = Thread.currentThread()
124:                        .getContextClassLoader();
125:                Thread.currentThread().setContextClassLoader(classLoader);
126:                try {
127:                    Class.forName(service.getDriverClass(), false, classLoader);
128:                } catch (ClassNotFoundException error) {
129:                    String localMessage = messages.format(
130:                            "newservicewizard.class-not-found", service
131:                                    .getDriverClass());
132:                    context.showErrorDialog(null, localMessage);
133:                    return false;
134:                } catch (Error error) {
135:                    String localMessage = messages.format(
136:                            "newservicewizard.class-init-error", service
137:                                    .getDriverClass());
138:                    context.showErrorDialog(null, localMessage);
139:                    return false;
140:                } finally {
141:                    Thread.currentThread().setContextClassLoader(
142:                            contextClassLoader);
143:                    classLoader = null;
144:                    System.gc();
145:                }
146:
147:                ConnectionProfile profile = service.getProfile();
148:                if (profile != null) {
149:                    Enumeration<File> existingElements = profile
150:                            .resourceElements();
151:                    while (existingElements.hasMoreElements()) {
152:                        profile.removeResource(existingElements.nextElement());
153:                    }
154:                } else {
155:                    profile = new ConnectionProfile();
156:                    service.setProfile(profile);
157:                }
158:                for (int i = 0; i < count; i++) {
159:                    profile.addResource((File) fileListModel.get(i));
160:                }
161:                return true;
162:            }
163:
164:            @Override
165:            public void init(WizardContext context) {
166:
167:                setTitle(messages
168:                        .getMessage("newservicewizard.configure-resources.title"));
169:                setComment(messages
170:                        .getMessage("newservicewizard.configure-resources.tip"));
171:                setImage(SwingUtilities.loadIconResource(ServiceWizard.class,
172:                        "database", 22));
173:
174:                GridBagConstraints constraint = null;
175:                String tip = null;
176:
177:                JPanel panel = new JPanel(new GridBagLayout());
178:                setView(panel);
179:
180:                JComponent component = new JToolBar(JToolBar.VERTICAL);
181:                ((JToolBar) component).setFloatable(false);
182:                constraint = ServiceWizard.constrain(0, 0, 1, 1, 0.0, 1.0,
183:                        GridBagConstraints.NORTHWEST, GridBagConstraints.NONE);
184:                panel.add(component, constraint);
185:
186:                tip = messages.format("newservicewizard.jdbcurlexample.tip");
187:                fileList.setToolTipText(tip);
188:                fileList.setCellRenderer(new FileListCellRenderer());
189:                // fileList.setDropTarget(null);
190:                constraint = ServiceWizard.constrain(1, 0, 1, 1, 1.0, 1.0,
191:                        GridBagConstraints.CENTER, GridBagConstraints.BOTH);
192:                panel.add(new JScrollPane(fileList), constraint);
193:
194:                JButton actionButton = null;
195:
196:                actionButton = new JButton(SwingUtilities.loadIconResource(
197:                        ServiceWizard.class, "add", 16));
198:                actionButton.addActionListener(this );
199:                actionButton
200:                        .setActionCommand(Integer.toString(ACTION_ADD_FILE));
201:                actionButton.setToolTipText(messages
202:                        .getMessage("newservicewizard.add-resources.tip"));
203:                component.add(actionButton);
204:
205:                actionButton = new JButton(SwingUtilities.loadIconResource(
206:                        ServiceWizard.class, "delete", 16));
207:                actionButton.addActionListener(this );
208:                actionButton.setActionCommand(Integer
209:                        .toString(ACTION_REMOVE_FILE));
210:                actionButton.setToolTipText(messages
211:                        .getMessage("newservicewizard.delete-resources.tip"));
212:                component.add(actionButton);
213:
214:                component = (JComponent) Box.createVerticalGlue();
215:                component.setName("GLUE");
216:                component.setToolTipText(tip);
217:                constraint = ServiceWizard.constrain(0, 7, 2, 1, 0.0, 1.0,
218:                        GridBagConstraints.CENTER, GridBagConstraints.VERTICAL);
219:                panel.add(component, constraint);
220:            }
221:
222:            @Override
223:            public void activate(WizardContext context) {
224:
225:                super .activate(context);
226:                JdbcService service = (JdbcService) context
227:                        .getAttribute(ServiceWizard.ATTRIBUTE_SERVICE);
228:                if (fileListModel.isEmpty()) {
229:                    ConnectionProfile profile = service.getProfile();
230:                    Enumeration<File> files = profile.resourceElements();
231:                    while (files.hasMoreElements()) {
232:                        fileListModel.addElement(files.nextElement());
233:                    }
234:                }
235:            }
236:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.