Source Code Cross Referenced for ConfigController.java in  » Database-Client » ViennaSQL » uk » co » whisperingwind » vienna » 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 » ViennaSQL » uk.co.whisperingwind.vienna 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         ** $Id: ConfigController.java,v 1.12 2000/10/26 08:34:15 mrw Exp $
003:         **
004:         ** Controller for the configuration view.
005:         **
006:         ** Mike Wilson, July 2000, mrw@whisperingwind.co.uk
007:         **
008:         ** (C) Copyright 2000, Mike Wilson, Reading, Berkshire, UK
009:         **
010:         ** This program is free software; you can redistribute it and/or modify
011:         ** it under the terms of the GNU General Public License as published by
012:         ** the Free Software Foundation; either version 2 of the License, or
013:         ** (at your option) any later version.
014:         ** 
015:         ** This program is distributed in the hope that it will be useful,
016:         ** but WITHOUT ANY WARRANTY; without even the implied warranty of
017:         ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
018:         ** GNU General Public License for more details.
019:         ** 
020:         ** You should have received a copy of the GNU Library General
021:         ** Public License along with this library; if not, write to the
022:         ** Free Software Foundation, Inc., 59 Temple Place - Suite 330,
023:         ** Boston, MA  02111-1307  USA.
024:         */
025:
026:        package uk.co.whisperingwind.vienna;
027:
028:        import java.awt.Font;
029:        import java.io.FileNotFoundException;
030:        import java.io.IOException;
031:        import java.util.Enumeration;
032:        import java.util.Vector;
033:        import javax.swing.JFrame;
034:        import uk.co.whisperingwind.framework.Controller;
035:        import uk.co.whisperingwind.framework.Dialogs;
036:        import uk.co.whisperingwind.framework.ExceptionDialog;
037:        import uk.co.whisperingwind.framework.FontChooser;
038:        import uk.co.whisperingwind.framework.ModelEvent;
039:        import uk.co.whisperingwind.framework.ViewEvent;
040:
041:        class ConfigController extends Controller {
042:            private static ConfigController instance = null;
043:            private ConfigModel configModel = null;
044:            private ConfigView configView = null;
045:            private ConfigConnectionView connectionView = null;
046:            private ConfigModel originalConfigModel = null;
047:            private FontChooser fontChooser = null;
048:            private Vector testViewList = new Vector();
049:
050:            public static ConfigController singleton(JFrame parent,
051:                    ConfigModel theConfigModel) {
052:                ConfigController result = null;
053:
054:                if (instance == null) {
055:                    instance = new ConfigController(parent, theConfigModel);
056:                    result = instance;
057:                }
058:
059:                return result;
060:            }
061:
062:            public ConfigController(JFrame parent, ConfigModel theConfigModel) {
063:                originalConfigModel = theConfigModel;
064:                configModel = new ConfigModel(theConfigModel);
065:
066:                configView = new ConfigView(parent, configModel, false);
067:                configView.addObserver(this );
068:
069:                connectionView = new ConfigConnectionView(parent, false);
070:                connectionView.addObserver(this );
071:            }
072:
073:            public void modelEvent(ModelEvent event) {
074:            }
075:
076:            /*
077:             **
078:             */
079:
080:            public void viewEvent(ViewEvent event) {
081:                if (event.getInitiator() == configView)
082:                    handleViewEvent(event);
083:                else if (event.getInitiator() == connectionView)
084:                    handleConnectionEvent(event);
085:                else if (event.getInitiator() instanceof  TestView)
086:                    handleTestEvent(event);
087:            }
088:
089:            private void handleViewEvent(ViewEvent event) {
090:                String action = event.getArg1();
091:
092:                if (action.equals("ok")) {
093:                    configModel.setSavePasswords(configView.getSavePasswords());
094:
095:                    try {
096:                        String maxRows = configView.getMaxRows();
097:                        configModel.setMaxRows(Integer.decode(maxRows)
098:                                .intValue());
099:
100:                        configView.closeDialog();
101:                        configView.deleteObserver(this );
102:                        configView = null;
103:
104:                        connectionView.closeDialog();
105:                        instance = null;
106:
107:                        originalConfigModel.assign(configModel);
108:                        originalConfigModel.save();
109:                    } catch (NumberFormatException ex) {
110:                        Dialogs.showError("Invalid configuration",
111:                                "Maximum rows must be an integer");
112:                    } catch (FileNotFoundException ex) {
113:                        Dialogs.showError(
114:                                "Unexpected 'File not found' problem", ex
115:                                        .getMessage());
116:                        new ExceptionDialog(ex);
117:                    } catch (IOException ex) {
118:                        Dialogs.showError("Unexpected I/O problem", ex
119:                                .getMessage());
120:                        new ExceptionDialog(ex);
121:                    }
122:                } else if (action.equals("cancel")) {
123:                    configView.closeDialog();
124:                    connectionView.closeDialog();
125:                    configView.deleteObserver(this );
126:                    configView = null;
127:                    instance = null;
128:
129:                    Enumeration i = testViewList.elements();
130:
131:                    while (i.hasMoreElements()) {
132:                        ((TestView) i.nextElement()).closeDialog();
133:                    }
134:                } else if (action.equals("textfont")) {
135:                    Font font = FontChooser.chooseFont(null, configModel
136:                            .getTextFont());
137:
138:                    if (font != null) {
139:                        configModel.setTextFont(font);
140:                        configView.setTextFont(font);
141:                    }
142:                } else if (action.equals("tablefont")) {
143:                    Font font = FontChooser.chooseFont(null, configModel
144:                            .getTableFont());
145:
146:                    if (font != null)
147:                        configModel.setTableFont(font);
148:                } else if (action.equals("new")) {
149:                    newConnection();
150:                } else if (action.equals("edit")) {
151:                    editConnection(configView.getSelectedConnection());
152:                } else if (action.equals("delete")) {
153:                    deleteConnection(configView.getSelectedConnection());
154:                }
155:            }
156:
157:            private void handleConnectionEvent(ViewEvent event) {
158:                String action = event.getArg1();
159:
160:                if (action.equals("ok")) {
161:                    String originalName = connectionView.getOriginalName();
162:                    String newName = connectionView.getName();
163:                    String url = connectionView.getUrl();
164:                    String driverClass = connectionView.getDriverClass();
165:                    String userName = connectionView.getUserName();
166:                    String password = connectionView.getPassword();
167:
168:                    try {
169:                        if (originalName == null) {
170:                            configModel.addConnection(newName, url,
171:                                    driverClass, userName, password);
172:                        } else {
173:                            configModel.amendConnection(originalName, newName,
174:                                    url, driverClass, userName, password);
175:                        }
176:
177:                        connectionView.setVisible(false);
178:                    } catch (ConfigException ex) {
179:                        Dialogs.showError("Invalid configuration", ex
180:                                .getMessage());
181:                    }
182:                } else if (action.equals("cancel")) {
183:                    connectionView.setVisible(false);
184:                } else if (action.equals("test")) {
185:                    String url = connectionView.getUrl();
186:                    String driverClass = connectionView.getDriverClass();
187:                    String userName = connectionView.getUserName();
188:                    String password = connectionView.getPassword();
189:                    TestView testView = new TestView(url, driverClass,
190:                            userName, password);
191:                    testView.addObserver(this );
192:                    testView.startTest();
193:                    testViewList.add(testView);
194:                }
195:            }
196:
197:            private void handleTestEvent(ViewEvent event) {
198:                String action = event.getArg1();
199:
200:                if (action.equals("dismiss")) {
201:                    TestView view = (TestView) event.getInitiator();
202:                    view.closeDialog();
203:                }
204:            }
205:
206:            private void editConnection(String name) {
207:                if (!connectionView.isVisible()) {
208:                    connectionView.setOriginalName(name);
209:                    connectionView.setName(name);
210:                    connectionView.setDriverClass(configModel
211:                            .getConnectionDriverClass(name));
212:                    connectionView.setUrl(configModel.getConnectionUrl(name));
213:                    connectionView.setUserName(configModel
214:                            .getConnectionUserName(name));
215:                    connectionView.setPassword(configModel
216:                            .getConnectionPassword(name));
217:                }
218:
219:                connectionView.setVisible(true);
220:            }
221:
222:            private void newConnection() {
223:                if (!connectionView.isVisible()) {
224:                    connectionView.setOriginalName(null);
225:                }
226:
227:                connectionView.setVisible(true);
228:            }
229:
230:            private void deleteConnection(String name) {
231:                configModel.removeConnection(name);
232:            }
233:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.