Source Code Cross Referenced for CSVTableExportDialog.java in  » Report » pentaho-report » org » jfree » report » modules » gui » csv » 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 » Report » pentaho report » org.jfree.report.modules.gui.csv 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * ===========================================
003:         * JFreeReport : a free Java reporting library
004:         * ===========================================
005:         *
006:         * Project Info:  http://reporting.pentaho.org/
007:         *
008:         * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
009:         *
010:         * This library is free software; you can redistribute it and/or modify it under the terms
011:         * of the GNU Lesser General Public License as published by the Free Software Foundation;
012:         * either version 2.1 of the License, or (at your option) any later version.
013:         *
014:         * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
015:         * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016:         * See the GNU Lesser General Public License for more details.
017:         *
018:         * You should have received a copy of the GNU Lesser General Public License along with this
019:         * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020:         * Boston, MA 02111-1307, USA.
021:         *
022:         * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
023:         * in the United States and other countries.]
024:         *
025:         * ------------
026:         * CSVTableExportDialog.java
027:         * ------------
028:         * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029:         */package org.jfree.report.modules.gui.csv;
030:
031:        import java.awt.Dialog;
032:        import java.awt.Frame;
033:        import java.awt.GridBagConstraints;
034:        import java.awt.GridBagLayout;
035:        import java.awt.Insets;
036:        import java.awt.event.ActionEvent;
037:        import java.io.File;
038:        import java.text.MessageFormat;
039:        import java.util.Locale;
040:        import java.util.ResourceBundle;
041:        import javax.swing.AbstractAction;
042:        import javax.swing.Action;
043:        import javax.swing.BorderFactory;
044:        import javax.swing.ButtonGroup;
045:        import javax.swing.JButton;
046:        import javax.swing.JCheckBox;
047:        import javax.swing.JComboBox;
048:        import javax.swing.JFileChooser;
049:        import javax.swing.JLabel;
050:        import javax.swing.JOptionPane;
051:        import javax.swing.JPanel;
052:        import javax.swing.JRadioButton;
053:        import javax.swing.JTabbedPane;
054:        import javax.swing.JTextField;
055:        import javax.swing.border.TitledBorder;
056:
057:        import org.jfree.base.config.ModifiableConfiguration;
058:        import org.jfree.fonts.encoding.EncodingRegistry;
059:        import org.jfree.report.JFreeReportBoot;
060:        import org.jfree.report.modules.gui.commonswing.AbstractExportDialog;
061:        import org.jfree.report.modules.gui.commonswing.EncodingComboBoxModel;
062:        import org.jfree.report.modules.gui.commonswing.JStatusBar;
063:        import org.jfree.report.modules.gui.commonswing.StatusType;
064:        import org.jfree.report.modules.output.csv.CSVProcessor;
065:        import org.jfree.report.modules.output.table.csv.CSVTableModule;
066:        import org.jfree.ui.ExtensionFileFilter;
067:        import org.jfree.ui.LengthLimitingDocument;
068:        import org.jfree.ui.action.ActionButton;
069:        import org.jfree.util.Configuration;
070:        import org.jfree.util.DefaultConfiguration;
071:        import org.jfree.util.StringUtils;
072:
073:        /**
074:         * A dialog for exporting a report to CSV format.
075:         *
076:         * @author Thomas Morgner.
077:         */
078:        public class CSVTableExportDialog extends AbstractExportDialog {
079:            /**
080:             * The 'CSV encoding' property key.
081:             */
082:            public static final String CSV_OUTPUT_ENCODING = "org.jfree.report.modules.gui.csv.Encoding"; //$NON-NLS-1$
083:            /**
084:             * A default value of the 'CSV encoding' property key.
085:             */
086:            public static final String CSV_OUTPUT_ENCODING_DEFAULT = EncodingRegistry
087:                    .getPlatformDefaultEncoding();
088:
089:            /**
090:             * Internal action class to confirm the dialog and to validate the input.
091:             */
092:            private class ActionSelectSeparator extends AbstractAction {
093:                /**
094:                 * Default constructor.
095:                 */
096:                protected ActionSelectSeparator() {
097:                }
098:
099:                /**
100:                 * Receives notification that the action has occurred.
101:                 *
102:                 * @param e the action event.
103:                 */
104:                public void actionPerformed(final ActionEvent e) {
105:                    performSeparatorSelection();
106:                }
107:            }
108:
109:            /**
110:             * Internal action class to select a target file.
111:             */
112:            private class ActionSelectFile extends AbstractAction {
113:                /**
114:                 * Default constructor.
115:                 */
116:                protected ActionSelectFile(final ResourceBundle resources) {
117:                    putValue(Action.NAME, resources
118:                            .getString("csvexportdialog.selectFile")); //$NON-NLS-1$
119:                }
120:
121:                /**
122:                 * Receives notification that the action has occurred.
123:                 *
124:                 * @param e the action event.
125:                 */
126:                public void actionPerformed(final ActionEvent e) {
127:                    performSelectFile();
128:                }
129:            }
130:
131:            /**
132:             * Filename text field.
133:             */
134:            private JTextField txFilename;
135:
136:            /**
137:             * The encoding combo-box.
138:             */
139:            private JComboBox cbEncoding;
140:
141:            /**
142:             * The encoding model.
143:             */
144:            private EncodingComboBoxModel encodingModel;
145:
146:            /**
147:             * The strict layout check-box.
148:             */
149:            private JCheckBox cbxStrictLayout;
150:
151:            /**
152:             * A radio button for tab separators.
153:             */
154:            private JRadioButton rbSeparatorTab;
155:
156:            /**
157:             * A radio button for colon separators.
158:             */
159:            private JRadioButton rbSeparatorColon;
160:
161:            /**
162:             * A radio button for semi-colon separators.
163:             */
164:            private JRadioButton rbSeparatorSemicolon;
165:
166:            /**
167:             * A radio button for other separators.
168:             */
169:            private JRadioButton rbSeparatorOther;
170:
171:            /**
172:             * A text field for the 'other' separator.
173:             */
174:            private JTextField txSeparatorOther;
175:
176:            private JStatusBar statusBar;
177:
178:            /**
179:             * A file chooser.
180:             */
181:            private JFileChooser fileChooser;
182:
183:            private static final String COMMA_SEPARATOR = ","; //$NON-NLS-1$
184:            private static final String SEMICOLON_SEPARATOR = ";"; //$NON-NLS-1$
185:            private static final String TAB_SEPARATOR = "\t"; //$NON-NLS-1$
186:            private static final String CSV_FILE_EXTENSION = ".csv"; //$NON-NLS-1$
187:
188:            /**
189:             * Creates a new CSV export dialog.
190:             *
191:             * @param owner the dialog owner.
192:             */
193:            public CSVTableExportDialog(final Frame owner) {
194:                super (owner);
195:                initConstructor();
196:            }
197:
198:            /**
199:             * Creates a new CSV export dialog.
200:             *
201:             * @param owner the dialog owner.
202:             */
203:            public CSVTableExportDialog(final Dialog owner) {
204:                super (owner);
205:                initConstructor();
206:            }
207:
208:            /**
209:             * Creates a new CSV export dialog.  The created dialog is modal.
210:             */
211:            public CSVTableExportDialog() {
212:                initConstructor();
213:            }
214:
215:            /**
216:             * Initialisation.
217:             */
218:            private void initConstructor() {
219:                statusBar = new JStatusBar();
220:                setTitle(getResources()
221:                        .getString("csvexportdialog.dialogtitle")); //$NON-NLS-1$
222:                initialize();
223:                clear();
224:                getFormValidator().setEnabled(true);
225:            }
226:
227:            public JStatusBar getStatusBar() {
228:                return statusBar;
229:            }
230:
231:            protected String getResourceBaseName() {
232:                return CSVDataExportPlugin.BASE_RESOURCE_CLASS;
233:            }
234:
235:            /**
236:             * Initializes the Swing components of this dialog.
237:             */
238:            private void initialize() {
239:
240:                rbSeparatorTab = new JRadioButton(getResources().getString(
241:                        "csvexportdialog.separator.tab")); //$NON-NLS-1$
242:                rbSeparatorColon = new JRadioButton(getResources().getString(
243:                        "csvexportdialog.separator.colon")); //$NON-NLS-1$
244:                rbSeparatorSemicolon = new JRadioButton(getResources()
245:                        .getString("csvexportdialog.separator.semicolon")); //$NON-NLS-1$
246:                rbSeparatorOther = new JRadioButton(getResources().getString(
247:                        "csvexportdialog.separator.other")); //$NON-NLS-1$
248:
249:                getFormValidator().registerButton(rbSeparatorColon);
250:                getFormValidator().registerButton(rbSeparatorOther);
251:                getFormValidator().registerButton(rbSeparatorSemicolon);
252:                getFormValidator().registerButton(rbSeparatorTab);
253:
254:                final ButtonGroup btg = new ButtonGroup();
255:                btg.add(rbSeparatorTab);
256:                btg.add(rbSeparatorColon);
257:                btg.add(rbSeparatorSemicolon);
258:                btg.add(rbSeparatorOther);
259:
260:                final Action selectAction = new CSVTableExportDialog.ActionSelectSeparator();
261:                rbSeparatorTab.addActionListener(selectAction);
262:                rbSeparatorColon.addActionListener(selectAction);
263:                rbSeparatorSemicolon.addActionListener(selectAction);
264:                rbSeparatorOther.addActionListener(selectAction);
265:
266:                txSeparatorOther = new JTextField();
267:                txSeparatorOther.setDocument(new LengthLimitingDocument(1));
268:                txSeparatorOther.setColumns(5);
269:                getFormValidator().registerTextField(txSeparatorOther);
270:
271:                cbxStrictLayout = new JCheckBox(getResources().getString(
272:                        "csvexportdialog.strict-layout")); //$NON-NLS-1$
273:                getFormValidator().registerButton(cbxStrictLayout);
274:
275:                txFilename = new JTextField();
276:                txFilename.setColumns(30);
277:                encodingModel = EncodingComboBoxModel.createDefaultModel(Locale
278:                        .getDefault());
279:                encodingModel.sort();
280:                cbEncoding = new JComboBox(encodingModel);
281:
282:                final JPanel exportPane = createExportPane();
283:
284:                // button panel
285:                final Configuration config = JFreeReportBoot.getInstance()
286:                        .getGlobalConfig();
287:                if ("true"
288:                        .equals(config
289:                                .getConfigProperty("org.jfree.report.modules.gui.csv.table.AdvancedSettingsAvailable"))) {
290:                    final JTabbedPane tabbedPane = new JTabbedPane();
291:                    final JPanel advancedOptionsPane = createAdvancedOptionsPanel();
292:
293:                    tabbedPane.add(getResources().getString(
294:                            "csvexportdialog.export-settings"), exportPane); //$NON-NLS-1$
295:                    tabbedPane
296:                            .add(
297:                                    getResources()
298:                                            .getString(
299:                                                    "csvexportdialog.advanced-settings"), advancedOptionsPane); //$NON-NLS-1$
300:
301:                    setContentPane(createContentPane(tabbedPane));
302:                } else {
303:                    setContentPane(createContentPane(exportPane));
304:                }
305:
306:                getFormValidator().registerTextField(txFilename);
307:                getFormValidator().registerComboBox(cbEncoding);
308:            }
309:
310:            private JPanel createExportPane() {
311:                final JLabel lblFileName = new JLabel(getResources().getString(
312:                        "csvexportdialog.filename")); //$NON-NLS-1$
313:                final JButton btnSelect = new ActionButton(
314:                        new CSVTableExportDialog.ActionSelectFile(
315:                                getResources()));
316:                final JPanel exportPane = new JPanel();
317:                exportPane.setLayout(new GridBagLayout());
318:                exportPane.setBorder(BorderFactory
319:                        .createEmptyBorder(3, 3, 3, 3));
320:
321:                GridBagConstraints gbc = new GridBagConstraints();
322:                gbc.gridx = 0;
323:                gbc.gridy = 0;
324:                gbc.anchor = GridBagConstraints.WEST;
325:                gbc.insets = new Insets(3, 1, 1, 5);
326:                exportPane.add(lblFileName, gbc);
327:
328:                gbc = new GridBagConstraints();
329:                gbc.fill = GridBagConstraints.HORIZONTAL;
330:                gbc.weightx = 1;
331:                gbc.gridx = 1;
332:                gbc.gridy = 0;
333:                gbc.gridwidth = 1;
334:                gbc.insets = new Insets(3, 1, 5, 1);
335:                exportPane.add(txFilename, gbc);
336:
337:                gbc = new GridBagConstraints();
338:                gbc.anchor = GridBagConstraints.NORTHWEST;
339:                gbc.gridx = 2;
340:                gbc.gridy = 0;
341:                gbc.gridheight = 2;
342:                gbc.insets = new Insets(1, 5, 5, 1);
343:                exportPane.add(btnSelect, gbc);
344:
345:                gbc = new GridBagConstraints();
346:                gbc.weightx = 1;
347:                gbc.gridx = 1;
348:                gbc.gridy = 4;
349:                gbc.weighty = 1;
350:                gbc.fill = GridBagConstraints.REMAINDER;
351:                gbc.insets = new Insets(10, 1, 1, 1);
352:                exportPane.add(new JPanel(), gbc);
353:
354:                return exportPane;
355:            }
356:
357:            private JPanel createAdvancedOptionsPanel() {
358:                final JPanel advancedOptionsPane = new JPanel();
359:                advancedOptionsPane.setLayout(new GridBagLayout());
360:
361:                GridBagConstraints gbc = new GridBagConstraints();
362:                gbc.fill = GridBagConstraints.BOTH;
363:                gbc.weighty = 1;
364:                gbc.weightx = 1;
365:                gbc.gridx = 0;
366:                gbc.gridy = 0;
367:                gbc.gridwidth = 3;
368:                gbc.insets = new Insets(10, 1, 1, 1);
369:                advancedOptionsPane.add(createExportOptionsPanel(), gbc);
370:
371:                gbc = new GridBagConstraints();
372:                gbc.fill = GridBagConstraints.BOTH;
373:                gbc.weighty = 1;
374:                gbc.weightx = 1;
375:                gbc.gridx = 0;
376:                gbc.gridy = 1;
377:                gbc.gridwidth = 3;
378:                gbc.insets = new Insets(10, 1, 1, 1);
379:                advancedOptionsPane.add(createSeparatorPanel(), gbc);
380:                return advancedOptionsPane;
381:            }
382:
383:            /**
384:             * Creates a panel for the export type.
385:             *
386:             * @return The panel.
387:             */
388:            private JPanel createExportOptionsPanel() {
389:                // separator panel
390:                final JPanel exportTypePanel = new JPanel();
391:                exportTypePanel.setLayout(new GridBagLayout());
392:                final JLabel lblEncoding = new JLabel(getResources().getString(
393:                        "csvexportdialog.encoding")); //$NON-NLS-1$
394:
395:                final TitledBorder tb = new TitledBorder(getResources()
396:                        .getString("csvexportdialog.export-options")); //$NON-NLS-1$
397:                exportTypePanel.setBorder(tb);
398:
399:                GridBagConstraints gbc = new GridBagConstraints();
400:                gbc.anchor = GridBagConstraints.WEST;
401:                gbc.gridx = 0;
402:                gbc.gridy = 0;
403:                gbc.insets = new Insets(1, 1, 1, 5);
404:                exportTypePanel.add(lblEncoding, gbc);
405:
406:                gbc = new GridBagConstraints();
407:                gbc.fill = GridBagConstraints.HORIZONTAL;
408:                gbc.weightx = 0;
409:                gbc.gridx = 1;
410:                gbc.gridy = 0;
411:                gbc.gridwidth = 1;
412:                gbc.insets = new Insets(5, 1, 1, 1);
413:                exportTypePanel.add(cbEncoding, gbc);
414:
415:                gbc = new GridBagConstraints();
416:                gbc.fill = GridBagConstraints.HORIZONTAL;
417:                gbc.anchor = GridBagConstraints.WEST;
418:                gbc.weightx = 0;
419:                gbc.gridx = 1;
420:                gbc.gridy = 1;
421:                gbc.gridwidth = 1;
422:                gbc.insets = new Insets(5, 1, 1, 1);
423:                exportTypePanel.add(cbxStrictLayout, gbc);
424:
425:                return exportTypePanel;
426:            }
427:
428:            /**
429:             * Creates a separator panel.
430:             *
431:             * @return The panel.
432:             */
433:            private JPanel createSeparatorPanel() {
434:                // separator panel
435:                final JPanel separatorPanel = new JPanel();
436:                separatorPanel.setLayout(new GridBagLayout());
437:
438:                final TitledBorder tb = new TitledBorder(getResources()
439:                        .getString("csvexportdialog.separatorchar")); //$NON-NLS-1$
440:                separatorPanel.setBorder(tb);
441:
442:                GridBagConstraints gbc = new GridBagConstraints();
443:                gbc.anchor = GridBagConstraints.WEST;
444:                gbc.fill = GridBagConstraints.HORIZONTAL;
445:                gbc.gridx = 0;
446:                gbc.gridy = 0;
447:                gbc.insets = new Insets(1, 1, 1, 1);
448:                separatorPanel.add(rbSeparatorTab, gbc);
449:
450:                gbc = new GridBagConstraints();
451:                gbc.anchor = GridBagConstraints.WEST;
452:                gbc.fill = GridBagConstraints.HORIZONTAL;
453:                gbc.gridx = 0;
454:                gbc.gridy = 1;
455:                gbc.insets = new Insets(1, 1, 1, 1);
456:                separatorPanel.add(rbSeparatorColon, gbc);
457:
458:                gbc = new GridBagConstraints();
459:                gbc.anchor = GridBagConstraints.WEST;
460:                gbc.fill = GridBagConstraints.HORIZONTAL;
461:                gbc.gridx = 0;
462:                gbc.gridy = 2;
463:                gbc.insets = new Insets(1, 1, 1, 1);
464:                separatorPanel.add(rbSeparatorSemicolon, gbc);
465:
466:                gbc = new GridBagConstraints();
467:                gbc.anchor = GridBagConstraints.WEST;
468:                gbc.fill = GridBagConstraints.NONE;
469:                gbc.weightx = 0;
470:                gbc.gridx = 0;
471:                gbc.gridy = 3;
472:                gbc.insets = new Insets(1, 1, 1, 1);
473:                separatorPanel.add(rbSeparatorOther, gbc);
474:
475:                gbc = new GridBagConstraints();
476:                gbc.anchor = GridBagConstraints.WEST;
477:                gbc.fill = GridBagConstraints.NONE;
478:                gbc.weighty = 1;
479:                gbc.gridx = 1;
480:                gbc.gridy = 3;
481:                gbc.insets = new Insets(1, 1, 1, 1);
482:                gbc.ipadx = 20;
483:                separatorPanel.add(txSeparatorOther, gbc);
484:
485:                gbc = new GridBagConstraints();
486:                gbc.gridx = 1;
487:                gbc.gridy = 4;
488:                gbc.weighty = 1;
489:                gbc.weightx = 1;
490:                gbc.gridwidth = 2;
491:                gbc.fill = GridBagConstraints.BOTH;
492:                separatorPanel.add(new JPanel(), gbc);
493:
494:                return separatorPanel;
495:            }
496:
497:            /**
498:             * Returns the export file name.
499:             *
500:             * @return The file name.
501:             */
502:            public String getFilename() {
503:                return txFilename.getText();
504:            }
505:
506:            /**
507:             * Sets the export file name.
508:             *
509:             * @param filename the file name.
510:             */
511:            public void setFilename(final String filename) {
512:                this .txFilename.setText(filename);
513:            }
514:
515:            /**
516:             * Clears all selections, input fields and sets the selected encryption level
517:             * to none.
518:             */
519:            public void clear() {
520:                txFilename.setText(""); //$NON-NLS-1$
521:                cbEncoding
522:                        .setSelectedIndex(encodingModel
523:                                .indexOf(EncodingRegistry
524:                                        .getPlatformDefaultEncoding()));
525:                rbSeparatorColon.setSelected(true);
526:                cbxStrictLayout.setSelected(false);
527:                performSeparatorSelection();
528:            }
529:
530:            /**
531:             * Returns a new (and not connected to the default config from the job)
532:             * configuration containing all properties from the dialog.
533:             *
534:             * @param full
535:             * @return
536:             */
537:            protected Configuration grabDialogContents(final boolean full) {
538:                final ModifiableConfiguration config = new DefaultConfiguration();
539:                config.setConfigProperty(CSVProcessor.CSV_SEPARATOR,
540:                        getSeparatorString());
541:                config.setConfigProperty(CSVTableModule.CONFIGURATION_PREFIX
542:                        + '.' + CSVTableModule.SEPARATOR_KEY,
543:                        getSeparatorString());
544:                config.setConfigProperty(CSVTableModule.CONFIGURATION_PREFIX
545:                        + ".StrictLayout", //$NON-NLS-1$
546:                        String.valueOf(isStrictLayout()));
547:                config
548:                        .setConfigProperty(
549:                                CSVTableExportDialog.CSV_OUTPUT_ENCODING,
550:                                getEncoding());
551:
552:                config
553:                        .setConfigProperty(
554:                                "org.jfree.report.modules.gui.csv.FileName", getFilename()); //$NON-NLS-1$
555:                config.setConfigProperty(CSVProcessor.CSV_WRITE_STATECOLUMNS,
556:                        "false"); //$NON-NLS-1$
557:
558:                return config;
559:            }
560:
561:            /**
562:             * Initialises the CSV export dialog from the settings in the report
563:             * configuration.
564:             *
565:             * @param config the report configuration.
566:             */
567:            protected void setDialogContents(final Configuration config) {
568:                // the CSV separator has two sources, either the data CSV or the
569:                // table CSV. As we have only one input field for that property,
570:                // we use a cascading schema to resolve this. The data oriented
571:                // separator is preferred ...
572:                final String tableCSVSeparator = config.getConfigProperty(
573:                        CSVTableModule.CONFIGURATION_PREFIX + '.'
574:                                + CSVTableModule.SEPARATOR_KEY,
575:                        CSVTableExportDialog.COMMA_SEPARATOR);
576:                setSeparatorString(config.getConfigProperty(
577:                        CSVProcessor.CSV_SEPARATOR, tableCSVSeparator));
578:
579:                final String strict = config
580:                        .getConfigProperty(CSVTableModule.CONFIGURATION_PREFIX
581:                                + ".StrictLayout"); //$NON-NLS-1$
582:                setStrictLayout("true".equals(strict)); //$NON-NLS-1$
583:
584:                final String encoding = config.getConfigProperty(
585:                        CSVTableExportDialog.CSV_OUTPUT_ENCODING,
586:                        CSVTableExportDialog.CSV_OUTPUT_ENCODING_DEFAULT);
587:                encodingModel.ensureEncodingAvailable(encoding);
588:                setEncoding(encoding);
589:
590:                final String defaultFileName = config
591:                        .getConfigProperty("org.jfree.report.modules.gui.csv.FileName"); //$NON-NLS-1$
592:                if (defaultFileName != null) {
593:                    setFilename(resolvePath(defaultFileName).getAbsolutePath());
594:                } else {
595:                    setFilename(""); //$NON-NLS-1$
596:                }
597:            }
598:
599:            /**
600:             * Returns the separator string, which is controlled by the selection of radio
601:             * buttons.
602:             *
603:             * @return The separator string.
604:             */
605:            public String getSeparatorString() {
606:                if (rbSeparatorColon.isSelected()) {
607:                    return CSVTableExportDialog.COMMA_SEPARATOR;
608:                }
609:                if (rbSeparatorSemicolon.isSelected()) {
610:                    return CSVTableExportDialog.SEMICOLON_SEPARATOR;
611:                }
612:                if (rbSeparatorTab.isSelected()) {
613:                    return CSVTableExportDialog.TAB_SEPARATOR;
614:                }
615:                if (rbSeparatorOther.isSelected()) {
616:                    return txSeparatorOther.getText();
617:                }
618:                return ""; //$NON-NLS-1$
619:            }
620:
621:            /**
622:             * Sets the separator string.
623:             *
624:             * @param s the separator.
625:             */
626:            public void setSeparatorString(final String s) {
627:                if (s == null) {
628:                    rbSeparatorOther.setSelected(true);
629:                    txSeparatorOther.setText(""); //$NON-NLS-1$
630:                } else if (s.equals(CSVTableExportDialog.COMMA_SEPARATOR)) {
631:                    rbSeparatorColon.setSelected(true);
632:                } else if (s.equals(CSVTableExportDialog.SEMICOLON_SEPARATOR)) {
633:                    rbSeparatorSemicolon.setSelected(true);
634:                } else if (s.equals(CSVTableExportDialog.TAB_SEPARATOR)) {
635:                    rbSeparatorTab.setSelected(true);
636:                } else {
637:                    rbSeparatorOther.setSelected(true);
638:                    txSeparatorOther.setText(s);
639:                }
640:                performSeparatorSelection();
641:            }
642:
643:            /**
644:             * Returns the encoding.
645:             *
646:             * @return The encoding.
647:             */
648:            public String getEncoding() {
649:                if (cbEncoding.getSelectedIndex() == -1) {
650:                    return EncodingRegistry.getPlatformDefaultEncoding();
651:                } else {
652:                    return encodingModel.getEncoding(cbEncoding
653:                            .getSelectedIndex());
654:                }
655:            }
656:
657:            /**
658:             * Sets the encoding.
659:             *
660:             * @param encoding the encoding.
661:             */
662:            public void setEncoding(final String encoding) {
663:                cbEncoding.setSelectedIndex(encodingModel.indexOf(encoding));
664:            }
665:
666:            /**
667:             * Selects a file to use as target for the report processing.
668:             */
669:            protected void performSelectFile() {
670:                if (fileChooser == null) {
671:                    fileChooser = new JFileChooser();
672:                    final ExtensionFileFilter filter = new ExtensionFileFilter(
673:                            getResources().getString(
674:                                    "csvexportdialog.csv-file-description"), CSVTableExportDialog.CSV_FILE_EXTENSION); //$NON-NLS-1$
675:                    fileChooser.addChoosableFileFilter(filter);
676:                    fileChooser.setMultiSelectionEnabled(false);
677:                }
678:
679:                fileChooser.setSelectedFile(new File(getFilename()));
680:                final int option = fileChooser.showSaveDialog(this );
681:                if (option == JFileChooser.APPROVE_OPTION) {
682:                    final File selFile = fileChooser.getSelectedFile();
683:                    String selFileName = selFile.getAbsolutePath();
684:
685:                    // Test if ends on csv
686:                    if (StringUtils.endsWithIgnoreCase(selFileName,
687:                            CSVTableExportDialog.CSV_FILE_EXTENSION) == false) {
688:                        selFileName = selFileName
689:                                + CSVTableExportDialog.CSV_FILE_EXTENSION;
690:                    }
691:                    setFilename(selFileName);
692:                }
693:            }
694:
695:            /**
696:             * Validates the contents of the dialog's input fields. If the selected file
697:             * exists, it is also checked for validity.
698:             *
699:             * @return <code>true</code> if the input is valid, <code>false</code>
700:             *         otherwise
701:             */
702:            protected boolean performValidate() {
703:                getStatusBar().clear();
704:
705:                final String filename = getFilename();
706:                if (filename.trim().length() == 0) {
707:                    getStatusBar().setStatus(
708:                            StatusType.ERROR,
709:                            getResources().getString(
710:                                    "csvexportdialog.targetIsEmpty")); //$NON-NLS-1$
711:                    return false;
712:                }
713:                final File f = new File(filename);
714:                if (f.exists()) {
715:                    if (f.isFile() == false) {
716:                        getStatusBar().setStatus(
717:                                StatusType.ERROR,
718:                                getResources().getString(
719:                                        "csvexportdialog.targetIsNoFile")); //$NON-NLS-1$
720:                        return false;
721:                    }
722:                    if (f.canWrite() == false) {
723:                        getStatusBar().setStatus(
724:                                StatusType.ERROR,
725:                                getResources().getString(
726:                                        "csvexportdialog.targetIsNotWritable")); //$NON-NLS-1$
727:                        return false;
728:                    }
729:
730:                    final String message = MessageFormat.format(getResources()
731:                            .getString("csvexportdialog.targetExistsWarning"), //$NON-NLS-1$
732:                            new Object[] { filename });
733:                    getStatusBar().setStatus(StatusType.WARNING, message);
734:
735:                }
736:                return true;
737:            }
738:
739:            protected boolean performConfirm() {
740:                final File f = new File(getFilename());
741:                if (f.exists()) {
742:                    final String key1 = "csvexportdialog.targetOverwriteConfirmation"; //$NON-NLS-1$
743:                    final String key2 = "csvexportdialog.targetOverwriteTitle"; //$NON-NLS-1$
744:                    if (JOptionPane.showConfirmDialog(this , MessageFormat
745:                            .format(getResources().getString(key1),
746:                                    new Object[] { getFilename() }),
747:                            getResources().getString(key2),
748:                            JOptionPane.YES_NO_OPTION,
749:                            JOptionPane.QUESTION_MESSAGE) == JOptionPane.NO_OPTION) {
750:                        return false;
751:                    }
752:                }
753:                return true;
754:            }
755:
756:            /**
757:             * Enables or disables the 'other' separator text field.
758:             */
759:            protected void performSeparatorSelection() {
760:                if (rbSeparatorOther.isSelected()) {
761:                    txSeparatorOther.setEnabled(true);
762:                } else {
763:                    txSeparatorOther.setEnabled(false);
764:                }
765:            }
766:
767:            /**
768:             * Returns the current setting of the 'strict layout' combo-box.
769:             *
770:             * @return A boolean.
771:             */
772:            public boolean isStrictLayout() {
773:                return cbxStrictLayout.isSelected();
774:            }
775:
776:            /**
777:             * Sets the 'strict layout' combo-box setting.
778:             *
779:             * @param strictLayout the new setting.
780:             */
781:            public void setStrictLayout(final boolean strictLayout) {
782:                cbxStrictLayout.setSelected(strictLayout);
783:            }
784:
785:            protected String getConfigurationSuffix() {
786:                return "_csvexport"; //$NON-NLS-1$
787:            }
788:
789:            protected String getConfigurationPrefix() {
790:                return "org.jfree.report.modules.gui.csv."; //$NON-NLS-1$
791:            }
792:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.