001 /**
002 * ========================================
003 * JFreeReport : a free Java report library
004 * ========================================
005 *
006 * Project Info: http://reporting.pentaho.org/
007 *
008 * (C) Copyright 2000-2007, by Object Refinery Limited, 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 * $Id: AbstractExportActionPlugin.java,v 1.6 2007/04/01 18:49:30 taqua Exp $
027 * ------------
028 * (C) Copyright 2000-2005, by Object Refinery Limited.
029 * (C) Copyright 2005-2007, by Pentaho Corporation.
030 */
031
032 package org.jfree.report.modules.gui.swing.common;
033
034 import java.awt.Dialog;
035 import java.awt.Frame;
036 import java.awt.Window;
037 import java.lang.reflect.Constructor;
038
039 import org.jfree.report.flow.ReportJob;
040 import org.jfree.util.Configuration;
041 import org.jfree.util.Log;
042 import org.jfree.util.ObjectUtilities;
043
044 /**
045 * Creation-Date: 02.12.2006, 14:21:07
046 *
047 * @author Thomas Morgner
048 */
049 public abstract class AbstractExportActionPlugin extends AbstractActionPlugin
050 implements ExportActionPlugin
051 {
052
053 public AbstractExportActionPlugin()
054 {
055 }
056
057
058 /**
059 * Creates a progress dialog, and tries to assign a parent based on the given
060 * preview proxy.
061 *
062 * @return the progress dialog.
063 */
064 protected ExportDialog createExportDialog(final String className)
065 throws InstantiationException
066 {
067 final Window proxy = getContext().getWindow();
068 if (proxy instanceof Frame)
069 {
070 final ClassLoader classLoader =
071 ObjectUtilities.getClassLoader(AbstractActionPlugin.class);
072 try
073 {
074 final Class aClass = classLoader.loadClass(className);
075 final Constructor constructor =
076 aClass.getConstructor(new Class[]{Frame.class});
077 return (ExportDialog) constructor.newInstance(new Object[]{proxy});
078 }
079 catch (Exception e)
080 {
081 Log.error("Failed to instantiate Export-Dialog with a 'Frame'-parent: " + className);
082 }
083 }
084 else if (proxy instanceof Dialog)
085 {
086 final ClassLoader classLoader =
087 ObjectUtilities.getClassLoader(AbstractActionPlugin.class);
088 try
089 {
090 final Class aClass = classLoader.loadClass(className);
091 final Constructor constructor =
092 aClass.getConstructor(new Class[]{Dialog.class});
093 return (ExportDialog) constructor.newInstance(new Object[]{proxy});
094 }
095 catch (Exception e)
096 {
097 Log.error("Failed to instantiate Export-Dialog with a 'Dialog'-parent: " + className, e);
098 }
099 }
100
101 final Object fallBack = ObjectUtilities.loadAndInstantiate
102 (className, AbstractActionPlugin.class, ExportDialog.class);
103 if (fallBack != null)
104 {
105 return (ExportDialog) fallBack;
106 }
107
108 Log.error ("Failed to instantiate Export-Dialog without a parent: " + className);
109 throw new InstantiationException("Failed to instantiate Export-Dialog");
110 }
111
112
113 /**
114 * Exports a report.
115 *
116 * @param report the report.
117 * @return A boolean.
118 */
119 public boolean performShowExportDialog(ReportJob job, String configKey)
120 {
121 try
122 {
123 final Configuration configuration = job.getConfiguration();
124 final String dialogClassName = configuration.getConfigProperty(configKey);
125 final ExportDialog dialog = createExportDialog(dialogClassName);
126 final boolean dialogResult = dialog.performQueryForExport(job, getContext());
127 return dialogResult;
128 }
129 catch (InstantiationException e)
130 {
131 Log.error ("Unable to configure the report job.");
132 setStatusText("Unable to configure the report job.");
133 return false;
134 }
135 }
136
137 }