Source Code Cross Referenced for ExportCSVWizard.java in  » Database-Client » QuantumDB » com » quantum » csv » wizard » 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 » QuantumDB » com.quantum.csv.wizard 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.quantum.csv.wizard;
002:
003:        import java.beans.PropertyChangeEvent;
004:        import java.beans.PropertyChangeListener;
005:        import java.io.File;
006:        import java.io.FileOutputStream;
007:        import java.io.FileWriter;
008:        import java.io.IOException;
009:        import java.lang.reflect.InvocationTargetException;
010:        import java.sql.SQLException;
011:        import java.util.zip.Deflater;
012:        import java.util.zip.ZipEntry;
013:        import java.util.zip.ZipOutputStream;
014:
015:        import org.eclipse.core.runtime.IPath;
016:        import org.eclipse.core.runtime.IProgressMonitor;
017:        import org.eclipse.core.runtime.Path;
018:        import org.eclipse.jface.dialogs.MessageDialog;
019:        import org.eclipse.jface.operation.IRunnableWithProgress;
020:        import org.eclipse.jface.preference.IPreferenceStore;
021:        import org.eclipse.jface.viewers.IStructuredSelection;
022:        import org.eclipse.jface.wizard.Wizard;
023:        import org.eclipse.ui.IExportWizard;
024:        import org.eclipse.ui.IWorkbench;
025:        import org.eclipse.ui.PlatformUI;
026:        import org.eclipse.ui.progress.IProgressService;
027:
028:        import com.quantum.ImageStore;
029:        import com.quantum.PluginPreferences;
030:        import com.quantum.QuantumPlugin;
031:        import com.quantum.flatfiles.ImageStoreKeys;
032:        import com.quantum.flatfiles.MessageUtil;
033:        import com.quantum.flatfiles.QuantumFlatFilesPlugin;
034:        import com.quantum.model.Entity;
035:        import com.quantum.ui.dialog.ExceptionDisplayDialog;
036:        import com.quantum.util.connection.NotConnectedException;
037:        import com.quantum.view.bookmark.BookmarkView;
038:        import com.quantum.view.bookmark.EntityNode;
039:
040:        /**
041:         * @author BC Holmes
042:         * @author Julen
043:         */
044:        public class ExportCSVWizard extends Wizard implements  IExportWizard,
045:                PropertyChangeListener {
046:
047:            private ExportCSVDetailsPage page1;
048:
049:            public ExportCSVWizard() {
050:                setWindowTitle(MessageUtil.getString(getClass(), "windowTitle"));
051:                setDefaultPageImageDescriptor(ImageStore.getImageDescriptor(
052:                        ImageStoreKeys.EXPORT_CSV, QuantumFlatFilesPlugin
053:                                .getDefault()));
054:            }
055:
056:            public boolean performFinish() {
057:                IProgressService progressService = PlatformUI.getWorkbench()
058:                        .getProgressService();
059:                File file = new File(this .page1.getFileName());
060:
061:                // Check if the given file exists, and if it does, if it should be overwritten
062:                // Quantum has a preference that we should check about this
063:                IPreferenceStore store = QuantumPlugin.getDefault()
064:                        .getPreferenceStore();
065:                boolean confirmOverwrite = store
066:                        .getBoolean(com.quantum.PluginPreferences.EXPORT_CONFIRM_OVERWRITE);
067:
068:                if (!(new File(file.getParent()).isDirectory())) {
069:                    MessageDialog.openInformation(getShell(), "Cannot export",
070:                            "Your selected export file directory doesn't seem to exist:\n"
071:                                    + file.getParent());
072:                    return false;
073:                }
074:
075:                if (!file.exists()
076:                        || !confirmOverwrite
077:                        || (file.exists() && MessageDialog.openConfirm(
078:                                getShell(), MessageUtil.getString(getClass(),
079:                                        "overwriteTitle"), MessageUtil
080:                                        .getString(getClass(),
081:                                                "confirmOverwrite",
082:                                                new Object[] { file
083:                                                        .getAbsoluteFile() })))) {
084:                    try {
085:                        progressService
086:                                .busyCursorWhile(new IRunnableWithProgress() {
087:                                    public void run(IProgressMonitor monitor) {
088:                                        doExport();
089:                                    }
090:                                });
091:                    } catch (InvocationTargetException e) {
092:                        e.printStackTrace();
093:                        return false;
094:                    } catch (InterruptedException e) {
095:                        e.printStackTrace();
096:                        return false;
097:                    }
098:                    return true;
099:                }
100:                return false;
101:            }
102:
103:            /**
104:             * @return
105:             */
106:            private boolean doExport() {
107:                boolean successful = false;
108:                try {
109:                    // Get the entities from the wizard data
110:                    Entity[] entities = this .page1.getEntities();
111:                    // If more than one entity, then will be a zip file
112:                    if (entities.length > 1) {
113:                        ZipOutputStream out = new ZipOutputStream(
114:                                new FileOutputStream(this .page1.getFileName()));
115:                        ConverterCSV converter = new ConverterCSV();
116:                        out.setLevel(Deflater.DEFAULT_COMPRESSION);
117:                        for (int i = 0; i < entities.length; i++) {
118:                            Entity entity = entities[i];
119:                            out.putNextEntry(new ZipEntry(entity.getName()
120:                                    + ".csv"));
121:                            // convert() will do all the work
122:                            converter.convert(out, entity, this .page1
123:                                    .isWriteHeaderRow(), this .page1
124:                                    .getColumnSeparator());
125:                            out.closeEntry();
126:                        }
127:                        out.close();
128:                    }
129:                    // If only one entity, a regular file will do
130:                    else {
131:                        File outputFile = new File(this .page1.getFileName());
132:                        FileWriter writer = new FileWriter(outputFile);
133:                        ConverterCSV converter = new ConverterCSV();
134:                        //	 convert() will do all the work
135:                        converter.convert(writer, entities[0], this .page1
136:                                .isWriteHeaderRow(), this .page1
137:                                .getColumnSeparator());
138:                        writer.close();
139:                    }
140:                    successful = true;
141:                } catch (IOException e) {
142:                    ExceptionDisplayDialog.openError(getShell(), null, null, e);
143:                } catch (NotConnectedException e) {
144:                    e.printStackTrace();
145:                } catch (SQLException e) {
146:                    e.printStackTrace();
147:                } catch (Exception e) {
148:                    // TODO Auto-generated catch block
149:                    e.printStackTrace();
150:                }
151:
152:                return successful;
153:            }
154:
155:            public void init(IWorkbench workbench,
156:                    IStructuredSelection selection) {
157:                Object[] nodes = BookmarkView.getInstance().getSelection()
158:                        .toArray();
159:                if (nodes.length == 0) {
160:                    MessageDialog
161:                            .openInformation(getShell(), "Invalid selection",
162:                                    "Please select some tables and views in the Quantum Bookmark View");
163:                    return;
164:                }
165:                for (int i = 0; i < nodes.length; i++) {
166:                    Object node = nodes[i];
167:                    if (!(node instanceof  EntityNode)
168:                            || (!((EntityNode) node).isTable() && !((EntityNode) node)
169:                                    .isView())) {
170:                        MessageDialog
171:                                .openInformation(getShell(),
172:                                        "Invalid selection",
173:                                        "Please select ONLY tables and/or views in the Quantum Bookmark View");
174:                        return;
175:                    }
176:                }
177:                this .page1 = new ExportCSVDetailsPage("page1");
178:
179:            }
180:
181:            public void dispose() {
182:                super .dispose();
183:            }
184:
185:            /**
186:             * @see org.eclipse.jface.wizard.IWizard#addPages()
187:             */
188:            public void addPages() {
189:                if (this .page1 != null)
190:                    addPage(this .page1);
191:            }
192:
193:            /* (non-Javadoc)
194:             * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
195:             */
196:            public void propertyChange(PropertyChangeEvent arg0) {
197:            }
198:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.