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