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: * CSVTableExportPlugin.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.util.Locale;
032: import javax.swing.Icon;
033: import javax.swing.KeyStroke;
034:
035: import org.jfree.report.JFreeReport;
036: import org.jfree.report.JFreeReportBoot;
037: import org.jfree.report.modules.gui.commonswing.AbstractExportActionPlugin;
038: import org.jfree.report.modules.gui.commonswing.ReportProgressDialog;
039: import org.jfree.report.modules.gui.commonswing.StatusType;
040: import org.jfree.report.modules.gui.commonswing.SwingGuiContext;
041: import org.jfree.ui.RefineryUtilities;
042: import org.jfree.util.Log;
043: import org.jfree.util.ResourceBundleSupport;
044:
045: /**
046: * Encapsulates the CSVDataExportDialog into a separate plugin.
047: *
048: * @author Thomas Morgner
049: */
050: public class CSVTableExportPlugin extends AbstractExportActionPlugin {
051: public static final String BASE_RESOURCE_CLASS = "org.jfree.report.modules.gui.csv.messages.messages"; //$NON-NLS-1$
052:
053: /**
054: * Localised resources.
055: */
056: private final ResourceBundleSupport resources;
057:
058: /**
059: * DefaultConstructor.
060: */
061: public CSVTableExportPlugin() {
062: resources = new ResourceBundleSupport(
063: CSVTableExportPlugin.BASE_RESOURCE_CLASS);
064: }
065:
066: public boolean initialize(final SwingGuiContext context) {
067: if (super .initialize(context) == false) {
068: return false;
069: }
070: if (JFreeReportBoot.getInstance().isModuleAvailable(
071: CSVExportGUIModule.class.getName()) == false) {
072: return false;
073: }
074: return true;
075: }
076:
077: protected String getConfigurationPrefix() {
078: return "org.jfree.report.modules.gui.csv.export.table."; //$NON-NLS-1$
079: }
080:
081: /**
082: * Creates the report progress dialog used to monitor the export.
083: *
084: * @return the created dialog.
085: */
086: protected ReportProgressDialog createProgressDialog() {
087: final ReportProgressDialog progressDialog = super
088: .createProgressDialog();
089: progressDialog
090: .setDefaultCloseOperation(ReportProgressDialog.DO_NOTHING_ON_CLOSE);
091: progressDialog.setMessage(resources
092: .getString("cvs-export.progressdialog.message")); //$NON-NLS-1$
093: progressDialog.pack();
094: RefineryUtilities.positionFrameRandomly(progressDialog);
095: return progressDialog;
096: }
097:
098: /**
099: * Shows this dialog and (if the dialog is confirmed) saves the complete report into an comma separated values file.
100: *
101: * @param report the report being processed.
102: * @return true or false.
103: */
104: public boolean performExport(final JFreeReport report) {
105: if (report == null) {
106: throw new NullPointerException();
107: }
108:
109: final boolean result = performShowExportDialog(report,
110: "org.jfree.report.modules.gui.csv.table.Dialog"); //$NON-NLS-1$
111: if (result == false) {
112: // user canceled the dialog ...
113: return false;
114: }
115:
116: final ReportProgressDialog progressDialog;
117: if (isProgressDialogEnabled(report,
118: "org.jfree.report.modules.gui.csv.table.ProgressDialogEnabled")) {
119: progressDialog = createProgressDialog();
120: if (report.getName() == null) {
121: progressDialog.setTitle(getResources().getString(
122: "ProgressDialog.EMPTY_TITLE"));
123: } else {
124: progressDialog.setTitle(getResources().formatMessage(
125: "ProgressDialog.TITLE", report.getName()));
126: }
127: } else {
128: progressDialog = null;
129: }
130:
131: try {
132: final Runnable task = new CSVTableExportTask(report,
133: progressDialog, getContext());
134: final Thread worker = new Thread(task);
135: worker.start();
136: return true;
137: } catch (Exception e) {
138: Log.error("Failure while preparing the CSV export", e); //$NON-NLS-1$
139: getContext().getStatusListener().setStatus(
140: StatusType.ERROR,
141: getResources().getString(
142: "CVSExportPlugin.ERROR_0001_FAILED")); //$NON-NLS-1$
143: return false;
144: }
145: }
146:
147: /**
148: * Returns the resourcebundle to be used to translate strings into localized content.
149: *
150: * @return the resourcebundle for the localisation.
151: */
152: protected ResourceBundleSupport getResources() {
153: return resources;
154: }
155:
156: /**
157: * Returns the display name for the CSV dialog.
158: *
159: * @return The name.
160: */
161: public String getDisplayName() {
162: return resources.getString("action.export-to-csv.table.name"); //$NON-NLS-1$
163: }
164:
165: /**
166: * Returns a short description for the CSV dialog.
167: *
168: * @return The description.
169: */
170: public String getShortDescription() {
171: return resources
172: .getString("action.export-to-csv.table.description"); //$NON-NLS-1$
173: }
174:
175: /**
176: * Returns the small icon for the dialog.
177: *
178: * @return The icon.
179: */
180: public Icon getSmallIcon() {
181: final Locale locale = getContext().getLocale();
182: return getIconTheme().getSmallIcon(locale,
183: "action.export-to-csv.table.small-icon"); //$NON-NLS-1$
184: }
185:
186: /**
187: * Returns the large icon for the dialog.
188: *
189: * @return The icon.
190: */
191: public Icon getLargeIcon() {
192: final Locale locale = getContext().getLocale();
193: return getIconTheme().getLargeIcon(locale,
194: "action.export-to-csv.table.icon"); //$NON-NLS-1$
195: }
196:
197: /**
198: * Returns the accelerator key for the action associated with the dialog.
199: *
200: * @return The key stroke.
201: */
202: public KeyStroke getAcceleratorKey() {
203: return resources
204: .getKeyStroke("action.export-to-csv.table.accelerator"); //$NON-NLS-1$
205: }
206:
207: /**
208: * Returns the mnemonic key code for the action associated with the dialog.
209: *
210: * @return The key code.
211: */
212: public Integer getMnemonicKey() {
213: return resources
214: .getMnemonic("action.export-to-csv.table.mnemonic"); //$NON-NLS-1$
215: }
216: }
|