Source Code Cross Referenced for AbstractSaveCommand.java in  » Database-Client » squirrel-sql-2.6.5a » net » sourceforge » squirrel_sql » plugins » exportconfig » action » 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 » squirrel sql 2.6.5a » net.sourceforge.squirrel_sql.plugins.exportconfig.action 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.sourceforge.squirrel_sql.plugins.exportconfig.action;
002:
003:        /*
004:         * Copyright (C) 2003 Colin Bell
005:         * colbell@users.sourceforge.net
006:         *
007:         * This library is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU Lesser General Public
009:         * License as published by the Free Software Foundation; either
010:         * version 2.1 of the License, or (at your option) any later version.
011:         *
012:         * This library is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this library; if not, write to the Free Software
019:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
020:         */
021:        import java.awt.Frame;
022:        import java.io.File;
023:        import java.io.IOException;
024:
025:        import javax.swing.JFileChooser;
026:
027:        import net.sourceforge.squirrel_sql.fw.gui.ChooserPreviewer;
028:        import net.sourceforge.squirrel_sql.fw.gui.Dialogs;
029:        import net.sourceforge.squirrel_sql.fw.util.*;
030:        import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
031:        import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
032:        import net.sourceforge.squirrel_sql.fw.xml.XMLException;
033:
034:        import net.sourceforge.squirrel_sql.client.IApplication;
035:
036:        import net.sourceforge.squirrel_sql.plugins.exportconfig.ExportConfigPlugin;
037:
038:        /**
039:         * Base class for all the "save" commands.
040:         *
041:         * @author <A HREF="mailto:colbell@users.sourceforge.net">Colin Bell</A>
042:         */
043:        abstract class AbstractSaveCommand implements  ICommand {
044:            private static final StringManager s_stringMgr = StringManagerFactory
045:                    .getStringManager(AbstractSaveCommand.class);
046:
047:            /** Logger for this class. */
048:            private final static ILogger s_log = LoggerController
049:                    .createLogger(AbstractSaveCommand.class);
050:
051:            /** The last directory saved to. */
052:            private static File s_lastDir;
053:
054:            /** Parent frame. */
055:            private final Frame _frame;
056:
057:            /** Current plugin. */
058:            private ExportConfigPlugin _plugin;
059:
060:            /**
061:             * Ctor.
062:             *
063:             * @param	frame	Parent frame for dialog.
064:             * @param	plugin	The current plugin.
065:             *
066:             * @throws	IllegalArgumentException
067:             * 			Thrown if a�<TT>null</TT> <TT>ISession</TT>,
068:             * 			<TT>Resources</TT> or <TT>MysqlPlugin</TT> passed.
069:             */
070:            AbstractSaveCommand(Frame frame, ExportConfigPlugin plugin) {
071:                super ();
072:                if (frame == null) {
073:                    throw new IllegalArgumentException("Frame == null");
074:                }
075:                if (plugin == null) {
076:                    throw new IllegalArgumentException(
077:                            "ExportConfigPlugin == null");
078:                }
079:                _frame = frame;
080:                _plugin = plugin;
081:            }
082:
083:            public void execute() throws BaseException {
084:                final JFileChooser chooser = new JFileChooser();
085:                chooser.addChoosableFileFilter(new FileExtensionFilter(
086:                        "XML files", new String[] { ".xml" }));
087:                File file = null;
088:                if (s_lastDir != null) {
089:                    file = new File(s_lastDir, getDefaultFilename());
090:                } else {
091:                    file = new File((File) null, getDefaultFilename());
092:                }
093:                chooser.setSelectedFile(file);
094:                chooser.setAccessory(new ChooserPreviewer());
095:                chooser.setDialogTitle("Save " + getSaveDescription());
096:
097:                for (;;) {
098:                    if (chooser.showSaveDialog(_frame) == JFileChooser.CANCEL_OPTION) {
099:                        break;
100:                    }
101:                    if (saveFile(chooser.getSelectedFile())) {
102:                        break;
103:                    }
104:                }
105:            }
106:
107:            private boolean saveFile(File file) {
108:                if (file.exists()) {
109:                    // i18n[exportconfig.fileExistsReplace={0}\nalready exists. Do you want to replace it?]
110:                    String msg = s_stringMgr.getString(
111:                            "exportconfig.fileExistsReplace", file
112:                                    .getAbsolutePath());
113:
114:                    if (!Dialogs.showYesNo(_frame, msg)) {
115:                        return false;
116:                    }
117:                    if (!file.canWrite()) {
118:                        // i18n[exportconfig.fileExistsButReadOnly={0}\nexists and you cannot write to it.\nPlease use a different name.]
119:                        msg = s_stringMgr.getString(
120:                                "exportconfig.fileExistsButReadOnly", file
121:                                        .getAbsolutePath());
122:
123:                        Dialogs.showOk(_frame, msg);
124:                        return false;
125:                    }
126:                    file.delete();
127:                }
128:
129:                s_lastDir = file.getParentFile();
130:
131:                final IApplication app = _plugin.getApplication();
132:                try {
133:                    writeToFile(file);
134:
135:                    String[] params = new String[] { getSaveDescription(),
136:                            file.getAbsolutePath() };
137:
138:                    // i18n[exportconfig.fileSavedTo={0} saved to {1}]
139:                    String msg = s_stringMgr.getString(
140:                            "exportconfig.fileSavedTo", params);
141:
142:                    Dialogs.showOk(_frame, msg);
143:                } catch (IOException ex) {
144:                    // i18n[exportconfig.ioErrorWritingTo=IO Error writing to\n{0}]
145:                    String msg = s_stringMgr.getString(
146:                            "exportconfig.ioErrorWritingTo", file
147:                                    .getAbsolutePath());
148:                    _plugin.getApplication().showErrorDialog(msg, ex);
149:                } catch (XMLException ex) {
150:                    // i18n[exportconfig.xmlErrorWritingTo=XML Error writing to\n{0}]
151:                    String msg = s_stringMgr.getString(
152:                            "exportconfig.xmlErrorWritingTo", file
153:                                    .getAbsolutePath());
154:                    _plugin.getApplication().showErrorDialog(msg, ex);
155:                }
156:                return true;
157:            }
158:
159:            /**
160:             * Override this to supply the description of the objects being saved.
161:             *
162:             * @return	description of the objects being saved.
163:             */
164:            protected abstract String getSaveDescription();
165:
166:            /**
167:             * Override this to supply the default file name to be used.
168:             *
169:             * @return	The default file name.
170:             */
171:            protected abstract String getDefaultFilename();
172:
173:            /**
174:             * Override this m,ethod to do the actual writing out to the file system.
175:             *
176:             * @param	file	The <TT>File</TT> to be written to.
177:             *
178:             * @throws	IOException		Thrown if an IO error occurs.
179:             * @throws	XMLException	Thrown if an XML error occurs.
180:             */
181:            protected abstract void writeToFile(File file) throws IOException,
182:                    XMLException;
183:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.