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