Source Code Cross Referenced for ImportFileDialog.java in  » Database-Client » SQL-Workbench » workbench » gui » dialogs » dataimport » 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 » SQL Workbench » workbench.gui.dialogs.dataimport 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * ImportFileDialog.java
003:         *
004:         * This file is part of SQL Workbench/J, http://www.sql-workbench.net
005:         *
006:         * Copyright 2002-2008, Thomas Kellerer
007:         * No part of this code maybe reused without the permission of the author
008:         *
009:         * To contact the author please send an email to: support@sql-workbench.net
010:         *
011:         */
012:        package workbench.gui.dialogs.dataimport;
013:
014:        import java.awt.Component;
015:        import java.awt.Window;
016:        import java.beans.PropertyChangeEvent;
017:        import java.beans.PropertyChangeListener;
018:        import java.io.File;
019:
020:        import javax.swing.JFileChooser;
021:        import javax.swing.SwingUtilities;
022:        import javax.swing.filechooser.FileFilter;
023:        import workbench.db.importer.ProducerFactory;
024:
025:        import workbench.gui.components.ExtensionFileFilter;
026:        import workbench.log.LogMgr;
027:        import workbench.resource.Settings;
028:        import workbench.util.StringUtil;
029:
030:        /**
031:         * @author support@sql-workbench.net
032:         */
033:        public class ImportFileDialog implements  PropertyChangeListener {
034:            private int importType = -1;
035:            private File selectedFile = null;
036:            private boolean isCancelled = false;
037:            private Settings settings = Settings.getInstance();
038:            private ImportOptionsPanel importOptions;
039:            private JFileChooser chooser;
040:            private boolean filterChange = false;
041:            private String lastDirConfigKey = "workbench.import.lastdir";
042:            private Component parentComponent;
043:
044:            public ImportFileDialog(Component caller) {
045:                this .importOptions = new ImportOptionsPanel();
046:                this .parentComponent = caller;
047:            }
048:
049:            public void allowImportModeSelection(boolean flag) {
050:                this .importOptions.allowImportModeSelection(flag);
051:            }
052:
053:            public void saveSettings() {
054:                importOptions.saveSettings();
055:            }
056:
057:            public void restoreSettings() {
058:                importOptions.restoreSettings();
059:            }
060:
061:            public XmlImportOptions getXmlOptions() {
062:                return importOptions.getXmlOptions();
063:            }
064:
065:            public TextImportOptions getTextOptions() {
066:                return importOptions.getTextOptions();
067:            }
068:
069:            public ImportOptions getGeneralOptions() {
070:                return importOptions.getGeneralOptions();
071:            }
072:
073:            public File getSelectedFile() {
074:                return this .selectedFile;
075:            }
076:
077:            public int getImportType() {
078:                return this .importType;
079:            }
080:
081:            public boolean isCancelled() {
082:                return this .isCancelled;
083:            }
084:
085:            /**
086:             *	Set the config key for the Settings object
087:             *  where the selected directory should be stored
088:             */
089:            public void setConfigKey(String key) {
090:                this .lastDirConfigKey = key;
091:            }
092:
093:            public boolean selectInput() {
094:                return this .selectInput(null);
095:            }
096:
097:            public boolean selectInput(String title) {
098:                this .importType = -1;
099:                this .selectedFile = null;
100:                boolean result = false;
101:
102:                String lastDir = settings.getProperty(lastDirConfigKey, null);
103:                this .chooser = new JFileChooser(lastDir);
104:                if (title != null)
105:                    this .chooser.setDialogTitle(title);
106:
107:                chooser.addChoosableFileFilter(ExtensionFileFilter
108:                        .getTextFileFilter());
109:                chooser.addChoosableFileFilter(ExtensionFileFilter
110:                        .getXmlFileFilter());
111:                chooser.addPropertyChangeListener("fileFilterChanged", this );
112:                chooser.setFileFilter(ExtensionFileFilter.getTextFileFilter());
113:                this .importOptions
114:                        .addPropertyChangeListener("exportType", this );
115:                this .restoreSettings();
116:                this .importOptions.setTypeText();
117:
118:                chooser.setAccessory(this .importOptions);
119:
120:                Window parentWindow = SwingUtilities
121:                        .getWindowAncestor(this .parentComponent);
122:
123:                int answer = chooser.showOpenDialog(parentWindow);
124:                if (answer == JFileChooser.APPROVE_OPTION) {
125:                    String filename = null;
126:                    this .isCancelled = false;
127:                    File fl = chooser.getSelectedFile();
128:
129:                    FileFilter ff = chooser.getFileFilter();
130:                    if (ff instanceof  ExtensionFileFilter) {
131:                        ExtensionFileFilter eff = (ExtensionFileFilter) ff;
132:                        filename = fl.getAbsolutePath();
133:
134:                        String ext = ExtensionFileFilter.getExtension(fl);
135:                        if (StringUtil.isEmptyString(ext)) {
136:                            if (!filename.endsWith("."))
137:                                filename = filename + ".";
138:                            filename = filename + eff.getDefaultExtension();
139:                        }
140:                        this .importType = this .getImportType(ff);
141:                    } else {
142:                        filename = fl.getAbsolutePath();
143:                        this .importType = this .importOptions.getImportType();
144:                    }
145:                    lastDir = chooser.getCurrentDirectory().getAbsolutePath();
146:
147:                    settings.setProperty(this .lastDirConfigKey, lastDir);
148:                    this .saveSettings();
149:                    this .selectedFile = new File(filename);
150:                    result = true;
151:                } else {
152:                    this .isCancelled = true;
153:                    result = false;
154:                }
155:                return result;
156:            }
157:
158:            private int getImportType(FileFilter ff) {
159:                if (ff == ExtensionFileFilter.getXmlFileFilter()) {
160:                    return ProducerFactory.IMPORT_XML;
161:                } else if (ff == ExtensionFileFilter.getTextFileFilter()) {
162:                    return ProducerFactory.IMPORT_TEXT;
163:                }
164:                return -1;
165:            }
166:
167:            public void propertyChange(PropertyChangeEvent evt) {
168:                if (this .importOptions == null)
169:                    return;
170:
171:                if (evt.getSource() instanceof  JFileChooser && !filterChange) {
172:                    JFileChooser fc = (JFileChooser) evt.getSource();
173:                    FileFilter ff = fc.getFileFilter();
174:                    if (ff instanceof  ExtensionFileFilter) {
175:                        ExtensionFileFilter eff = (ExtensionFileFilter) ff;
176:                        int type = this .getImportType(eff);
177:                        this .importOptions.setImportType(type);
178:                    }
179:                } else if (evt.getSource() == this .importOptions
180:                        && this .chooser != null) {
181:                    try {
182:                        FileFilter ff = this .chooser.getFileFilter();
183:                        // check for All file (*.*) filter. In that
184:                        // case we do not change the current filter.
185:                        if (!(ff instanceof  ExtensionFileFilter))
186:                            return;
187:
188:                        Integer newvalue = (Integer) evt.getNewValue();
189:                        int type = (newvalue == null ? -1 : newvalue.intValue());
190:                        this .filterChange = true;
191:
192:                        switch (type) {
193:                        case ProducerFactory.IMPORT_XML:
194:                            this .chooser.setFileFilter(ExtensionFileFilter
195:                                    .getXmlFileFilter());
196:                            break;
197:                        case ProducerFactory.IMPORT_TEXT:
198:                            this .chooser.setFileFilter(ExtensionFileFilter
199:                                    .getTextFileFilter());
200:                            break;
201:                        }
202:                    } catch (Throwable th) {
203:                        LogMgr.logError("ImportFileDialog.propertyChange",
204:                                "Error: ", th);
205:                    } finally {
206:                        this .filterChange = false;
207:                    }
208:                }
209:            }
210:
211:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.