Source Code Cross Referenced for ImportExportExcelPanel.java in  » Database-Client » executequery » org » executequery » gui » importexport » 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 » executequery » org.executequery.gui.importexport 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * ImportExportExcelPanel.java
003:         *
004:         * Copyright (C) 2002, 2003, 2004, 2005, 2006 Takis Diakoumis
005:         *
006:         * This program is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU General Public License
008:         * as published by the Free Software Foundation; either version 2
009:         * of the License, or any later version.
010:         *
011:         * This program is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014:         * GNU General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU General Public License
017:         * along with this program; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
019:         *
020:         */
021:
022:        package org.executequery.gui.importexport;
023:
024:        import java.awt.Dimension;
025:
026:        import java.util.Vector;
027:        import javax.swing.JDialog;
028:        import javax.swing.JPanel;
029:        import org.executequery.ActiveComponent;
030:
031:        import org.executequery.GUIUtilities;
032:        import org.underworldlabs.swing.wizard.DefaultWizardProcessModel;
033:        import org.underworldlabs.swing.wizard.WizardProcessPanel;
034:        import org.executequery.databasemediators.DatabaseConnection;
035:        import org.executequery.databasemediators.MetaDataValues;
036:        import org.executequery.gui.*;
037:        import org.executequery.util.Log;
038:        import org.underworldlabs.swing.actions.ActionBuilder;
039:
040:        /* ----------------------------------------------------------
041:         * CVS NOTE: Changes to the CVS repository prior to the 
042:         *           release of version 3.0.0beta1 has meant a 
043:         *           resetting of CVS revision numbers.
044:         * ----------------------------------------------------------
045:         */
046:
047:        /**
048:         *
049:         * @author   Takis Diakoumis
050:         * @version  $Revision: 1.8 $
051:         * @date     $Date: 2006/09/13 15:15:09 $
052:         */
053:        public class ImportExportExcelPanel extends WizardProcessPanel
054:                implements  ImportExportProcess, ActiveComponent {
055:
056:            /** The dimension of each child panel */
057:            private Dimension childDim;
058:
059:            /** The object to retrieve table details */
060:            private MetaDataValues metaData;
061:
062:            /** The worker that will run the process */
063:            private ImportExportWorker worker;
064:
065:            /** The first panel displayed */
066:            private ImportExportExcelPanel_1 firstPanel;
067:
068:            /** The second panel displayed */
069:            private ImportExportPanel_2 secondPanel;
070:
071:            /** The third panel displayed */
072:            private ImportExportPanel_3 thirdPanel;
073:
074:            /** The fourth panel displayed - export */
075:            private ImportExportExcelPanel_4 fourthPanel;
076:
077:            /** The fourth panel displayed - import */
078:            private ImportXMLPanel_4 fourthPanel_im;
079:
080:            /** The fifth panel displayed */
081:            private ImportExportExcelPanel_5 fifthPanel;
082:
083:            /** The sixth panel displayed */
084:            //  private ImportExportXMLPanel_6 sixthPanel;
085:            /** The progress panel */
086:            private ImportExportProgressPanel progressPanel;
087:
088:            /** The type of transfer - import/export */
089:            private int transferType;
090:
091:            /** Whether the process was cancelled */
092:            private boolean processCancelled;
093:
094:            /** Whether a transfer is currently underway */
095:            private boolean processing;
096:
097:            /** the parent container */
098:            private ActionContainer parent;
099:
100:            /** the wizard model */
101:            private TransferExcelWizardModel model;
102:
103:            public ImportExportExcelPanel(ActionContainer parent,
104:                    int transferType) {
105:                this (parent, transferType, null, null, null);
106:            }
107:
108:            public ImportExportExcelPanel(ActionContainer parent,
109:                    int transferType, DatabaseConnection databaseConnection,
110:                    String schemaName, String tableName) {
111:
112:                this .transferType = transferType;
113:                model = new TransferExcelWizardModel();
114:                setModel(model);
115:
116:                this .parent = parent;
117:
118:                try {
119:                    jbInit();
120:                } catch (Exception e) {
121:                    e.printStackTrace();
122:                }
123:
124:                if (databaseConnection != null) {
125:                    firstPanel.setDatabaseConnection(databaseConnection);
126:                    next();
127:
128:                    if (schemaName != null) {
129:                        secondPanel.setSelectedSchema(schemaName);
130:                        if (tableName != null) {
131:                            secondPanel.setSelectedTable(tableName);
132:                            secondPanel.selectAllAvailable();
133:                        }
134:
135:                    }
136:
137:                }
138:
139:            }
140:
141:            private void jbInit() throws Exception {
142:                metaData = new MetaDataValues();
143:                childDim = new Dimension(525, 340);
144:
145:                // set the help action
146:                setHelpAction(ActionBuilder.get("help-command"), "export-excel");
147:
148:                firstPanel = new ImportExportExcelPanel_1(this );
149:                model.addPanel(firstPanel);
150:                prepare();
151:            }
152:
153:            /**
154:             * Returns the transfer format - XML, CSV etc.
155:             */
156:            public int getTransferFormat() {
157:                return EXCEL;
158:            }
159:
160:            /**
161:             * Releases database resources before closing.
162:             */
163:            public void cleanup() {
164:                metaData.closeConnection();
165:            }
166:
167:            public String getSchemaName() {
168:                return secondPanel.getSelectedSchema();
169:            }
170:
171:            /** <p>Cancels the current in-process transfer */
172:            public void cancelTransfer() {
173:                processCancelled = true;
174:            }
175:
176:            /** <p>Return whether this process is an
177:             *  import or export process.
178:             *
179:             *  @return <code>ImportExportProcess.IMPORT |
180:             *          ImportExportProcess.EXPORT</code>
181:             */
182:            public int getTransferType() {
183:                return transferType;
184:            }
185:
186:            /** <p>Retrieves the selected rollback size for
187:             *  the transfer.
188:             *
189:             *  @return the rollback size
190:             */
191:            public int getRollbackSize() {
192:                return fifthPanel.getRollbackSize();
193:            }
194:
195:            /** <p>Retrieves the action on an error occuring
196:             *  during the import/export process.
197:             *
198:             *  @return the action on error -<br>either:
199:             *          <code>ImportExportProcess.LOG_AND_CONTINUE</code> or
200:             *          <code>ImportExportProcess.STOP_TRANSFER</code>
201:             */
202:            public int getOnError() {
203:                return fifthPanel.getOnError();
204:            }
205:
206:            /** <p>Retrieves the date format for date fields
207:             *  contained within the data file/database table.
208:             *
209:             *  @return the date format (ie. ddMMyyy)
210:             */
211:            public String getDateFormat() {
212:                return fifthPanel.getDateFormat();
213:            }
214:
215:            /**
216:             * Returns whether to parse date values.
217:             *
218:             * @return true | false
219:             */
220:            public boolean parseDateValues() {
221:                return false;
222:            }
223:
224:            /** 
225:             * Retrieves the selected type of delimiter within
226:             * the file to be used with this process.
227:             *
228:             * @return the selected delimiter
229:             */
230:            public char getDelimiter() {
231:                return 0;
232:            }
233:
234:            public void setProcessComplete(boolean success) {
235:                setButtonsEnabled(true);
236:                setNextButtonEnabled(false);
237:                setBackButtonEnabled(true);
238:                setCancelButtonEnabled(true);
239:
240:                if (success) {
241:                    setCancelButtonText("Finish");
242:                }
243:                processing = false;
244:            }
245:
246:            public JDialog getDialog() {
247:                if (parent.isDialog()) {
248:                    return (JDialog) parent;
249:                }
250:                return null;
251:            }
252:
253:            public void doImport() {
254:            }
255:
256:            /** <p>Begins an export process. */
257:            public void doExport() {
258:                Log.info("Beginning data export process");
259:                processCancelled = false;
260:                setNextButtonEnabled(false);
261:                setCancelButtonEnabled(false);
262:                setBackButtonEnabled(false);
263:                worker = new ExportExcelWorker(this , progressPanel);
264:            }
265:
266:            /** <p>Retrieves the selected tables for this process.
267:             *
268:             *  @return the selected table names
269:             */
270:            public String[] getSelectedTables() {
271:                return secondPanel.getSelectedTables();
272:            }
273:
274:            /** <p>Retrieves the table name for this process in
275:             *  the case of a single table import/export.
276:             *
277:             *  @return the table name
278:             */
279:            public String getTableName() {
280:                return secondPanel.getSelectedTables()[0];
281:            }
282:
283:            /** <p>Retrieves the column names for this process.
284:             *
285:             *  @return the column names
286:             */
287:            public Vector getSelectedColumns() {
288:                return secondPanel.getSelectedColumns();
289:            }
290:
291:            /** <p>Returns a <code>Vector</code> of <code>
292:             *  DataTransferObject</code> objects containing
293:             *  all relevant data for the process.
294:             *
295:             *  @return a <code>Vector</code> of
296:             *          <code>DataTransferObject</code> objects
297:             */
298:            public Vector getDataFileVector() {
299:                return thirdPanel.getDataFileVector();
300:            }
301:
302:            public String[][] getSheetNameValues() {
303:                return fourthPanel.getSheetNameValues();
304:            }
305:
306:            public boolean mapDataTypesToCells() {
307:                return fourthPanel.mapDataTypesToCells();
308:            }
309:
310:            /**
311:             * Returns whether to include column names as the
312:             * first row of a delimited export process.
313:             *
314:             * @return true | false
315:             */
316:            public boolean includeColumnNames() {
317:                return fourthPanel.includeColumnNamesRowOne();
318:            }
319:
320:            /**
321:             * Returns whether to trim whitespace on column data values.
322:             *
323:             * @return true | false
324:             */
325:            public boolean trimWhitespace() {
326:                return false;
327:            }
328:
329:            // returns single or multiple table export
330:            public int getTableTransferType() {
331:                return firstPanel.getTableTransferType();
332:            }
333:
334:            /** <p>Returns the type of multiple table
335:             *  transfer - single or multiple file.
336:             *
337:             *  @return the type of multiple table transfer
338:             */
339:            public int getMutlipleTableTransferType() {
340:                return firstPanel.getMutlipleTableTransferType();
341:            }
342:
343:            /** <p>Indicates whether the process (import only)
344:             *  should be run as a batch process.
345:             *
346:             *  @return whether to run as a batch process
347:             */
348:            public boolean runAsBatchProcess() {
349:                return fifthPanel.runAsBatchProcess();
350:            }
351:
352:            public int getXMLFormat() {
353:                return -1;
354:            }
355:
356:            private boolean doNext() {
357:                JPanel nextPanel = null;
358:                int index = model.getSelectedIndex();
359:                switch (index) {
360:
361:                case 0:
362:                    DatabaseConnection dc = getDatabaseConnection();
363:                    if (dc != null) {
364:                        metaData.setDatabaseConnection(dc);
365:                    }
366:
367:                    if (secondPanel == null) {
368:                        secondPanel = new ImportExportPanel_2(this );
369:                    }
370:                    nextPanel = secondPanel;
371:
372:                    secondPanel.setListData(getTableTransferType());
373:                    break;
374:
375:                case 1:
376:
377:                    if (!secondPanel.hasSelections()) {
378:                        if (getTableTransferType() == ImportExportProcess.MULTIPLE_TABLE) {
379:                            GUIUtilities
380:                                    .displayErrorMessage("You must select at least one table");
381:                        } else if (getTableTransferType() == ImportExportProcess.SINGLE_TABLE) {
382:                            GUIUtilities
383:                                    .displayErrorMessage("You must select at least one column");
384:                        }
385:                        return false;
386:                    }
387:
388:                    if (thirdPanel == null) {
389:                        thirdPanel = new ImportExportPanel_3(this );
390:                    } else {
391:                        thirdPanel.buildTable();
392:                    }
393:                    nextPanel = thirdPanel;
394:                    break;
395:
396:                case 2:
397:
398:                    if (!thirdPanel.transferObjectsComplete()) {
399:                        return false;
400:                    }
401:
402:                    if (fourthPanel == null) {
403:                        fourthPanel = new ImportExportExcelPanel_4(this );
404:                    }
405:                    nextPanel = fourthPanel;
406:
407:                    fourthPanel.reset(getSelectedTables());
408:                    break;
409:
410:                case 3:
411:
412:                    if (!fourthPanel.entriesComplete()) {
413:                        GUIUtilities
414:                                .displayErrorMessage("Please ensure all required fields been entered correctly.");
415:                        return false;
416:                    }
417:
418:                    if (fifthPanel == null) {
419:                        fifthPanel = new ImportExportExcelPanel_5(this );
420:                    }
421:                    nextPanel = fifthPanel;
422:                    break;
423:
424:                case 4:
425:
426:                    if (progressPanel == null) {
427:                        progressPanel = new ImportExportProgressPanel(this );
428:                    }
429:                    processing = true;
430:                    model.addPanel(progressPanel);
431:
432:                    if (transferType == EXPORT) {
433:                        doExport();
434:                    } else if (transferType == IMPORT) {
435:                        doImport();
436:                    }
437:                    setButtonsEnabled(false);
438:                    return true;
439:
440:                }
441:
442:                model.addPanel(nextPanel);
443:                return true;
444:            }
445:
446:            /**
447:             * Defines the action for the BACK button.
448:             */
449:            private boolean doPrevious() {
450:                // make sure the cancel button says cancel
451:                setCancelButtonText("Cancel");
452:                return true;
453:            }
454:
455:            /** 
456:             * Stops the current process. 
457:             */
458:            public void stopTransfer() {
459:                setButtonsEnabled(true);
460:                if (processing) {
461:                    worker.cancelTransfer();
462:                    setBackButtonEnabled(true);
463:                    processCancelled = true;
464:                }
465:            }
466:
467:            /** 
468:             * Defines the action for the CANCEL button.
469:             */
470:            public void cancel() {
471:                setButtonsEnabled(true);
472:                if (processing) {
473:                    worker.cancelTransfer();
474:                    setBackButtonEnabled(true);
475:                    processCancelled = true;
476:                } else {
477:                    worker = null;
478:                    parent.finished();
479:                }
480:            }
481:
482:            /**
483:             * Returns the selected database connection properties object.
484:             *
485:             * @return the connection properties object
486:             */
487:            public DatabaseConnection getDatabaseConnection() {
488:                return firstPanel.getDatabaseConnection();
489:            }
490:
491:            public Dimension getChildDimension() {
492:                return childDim;
493:            }
494:
495:            public MetaDataValues getMetaDataUtility() {
496:                return metaData;
497:            }
498:
499:            private class TransferExcelWizardModel extends
500:                    DefaultWizardProcessModel {
501:
502:                public TransferExcelWizardModel() {
503:                    int type = getTransferType();
504:                    String firstTitle = "Database Connection and Export Type";
505:                    String lastTitle = "Exporting Data...";
506:                    if (type == ImportExportProcess.IMPORT) {
507:                        firstTitle = "Database Connection and Import Type";
508:                        lastTitle = "Importing Data...";
509:                    }
510:
511:                    String[] titles = { firstTitle, "Table Selection",
512:                            "Data File Selection", "Spreadsheet Options",
513:                            "Options", lastTitle };
514:                    setTitles(titles);
515:
516:                    String[] steps = {
517:                            "Select database connection and transfer type",
518:                            "Select the tables/columns",
519:                            type == ImportExportProcess.IMPORT ? "Select the data file(s) to import from"
520:                                    : "Select the data file(s) to export to",
521:                            "Set any spreadsheet specific options",
522:                            "Set any further transfer options",
523:                            type == ImportExportProcess.IMPORT ? "Import the data"
524:                                    : "Export the data" };
525:                    setSteps(steps);
526:                }
527:
528:                public boolean previous() {
529:                    if (doPrevious()) {
530:                        return super .previous();
531:                    }
532:                    return false;
533:                }
534:
535:                public boolean next() {
536:                    if (doNext()) {
537:                        return super .next();
538:                    }
539:                    return false;
540:                }
541:
542:            }
543:
544:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.