Package org.pentaho.reporting.engine.classic.core.modules.gui.html

Source Code of org.pentaho.reporting.engine.classic.core.modules.gui.html.HtmlStreamExportPlugin

/*
* This program is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software
* Foundation.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
* or from the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* Copyright (c) 2001 - 2009 Object Refinery Ltd, Pentaho Corporation and Contributors..  All rights reserved.
*/

package org.pentaho.reporting.engine.classic.core.modules.gui.html;

import java.util.Locale;
import javax.swing.Icon;
import javax.swing.KeyStroke;
import javax.swing.WindowConstants;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.pentaho.reporting.engine.classic.core.ClassicEngineBoot;
import org.pentaho.reporting.engine.classic.core.MasterReport;
import org.pentaho.reporting.engine.classic.core.modules.gui.commonswing.AbstractExportActionPlugin;
import org.pentaho.reporting.engine.classic.core.modules.gui.commonswing.ReportProgressDialog;
import org.pentaho.reporting.engine.classic.core.modules.gui.commonswing.StatusType;
import org.pentaho.reporting.engine.classic.core.modules.gui.commonswing.SwingGuiContext;
import org.pentaho.reporting.engine.classic.core.modules.gui.commonswing.SwingUtil;
import org.pentaho.reporting.libraries.base.util.ObjectUtilities;
import org.pentaho.reporting.libraries.base.util.ResourceBundleSupport;

/**
* Encapsulates the HtmlExportDialog into a separate plugin.
*
* @author Thomas Morgner
*/
public class HtmlStreamExportPlugin extends AbstractExportActionPlugin
{
  private static final Log logger = LogFactory.getLog(HtmlStreamExportPlugin.class);
  /**
   * Localised resources.
   */
  private final ResourceBundleSupport resources;

  /**
   * DefaultConstructor.
   */
  public HtmlStreamExportPlugin()
  {
    resources = new ResourceBundleSupport(Locale.getDefault(), HtmlExportGUIModule.BASE_RESOURCE_CLASS,
            ObjectUtilities.getClassLoader(HtmlExportGUIModule.class));
  }


  public boolean initialize(final SwingGuiContext context)
  {
    if (super.initialize(context) == false)
    {
      return false;
    }
    if (ClassicEngineBoot.getInstance().isModuleAvailable(HtmlExportGUIModule.class.getName()) == false)
    {
      return false;
    }
    return true;
  }

  protected String getConfigurationPrefix()
  {
    return "org.pentaho.reporting.engine.classic.core.modules.gui.html.export.stream."; //$NON-NLS-1$
  }

  /**
   * Creates the progress dialog that monitors the export process.
   *
   * @return the progress monitor dialog.
   */
  protected ReportProgressDialog createProgressDialog()
  {
    final ReportProgressDialog progressDialog = super.createProgressDialog();
    progressDialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    progressDialog.setMessage(resources.getString("html-export.progressdialog.message")); //$NON-NLS-1$
    progressDialog.pack();
    SwingUtil.positionFrameRandomly(progressDialog);
    return progressDialog;
  }

  /**
   * Shows this dialog and (if the dialog is confirmed) saves the complete report into an Excel file.
   *
   * @param report the report being processed.
   * @return true or false.
   */
  public boolean performExport(final MasterReport report)
  {
    final boolean result = performShowExportDialog
        (report, "org.pentaho.reporting.engine.classic.core.modules.gui.html.stream.Dialog"); //$NON-NLS-1$
    if (result == false)
    {
      // user canceled the dialog ...
      return false;
    }

    final ReportProgressDialog progressDialog;
    if (isProgressDialogEnabled(report,
        "org.pentaho.reporting.engine.classic.core.modules.gui.html.stream.ProgressDialogEnabled"))
    {
      progressDialog = createProgressDialog();
      final String title = report.getTitle();
      if (title == null)
      {
        progressDialog.setTitle(getResources().getString("ProgressDialog.EMPTY_TITLE"));
      }
      else
      {
        progressDialog.setTitle(getResources().formatMessage("ProgressDialog.TITLE", title));
      }
    }
    else
    {
      progressDialog = null;
    }

    try
    {
      final HtmlStreamExportTask task = new HtmlStreamExportTask(report, progressDialog, getContext());
      final Thread worker = new Thread(task);
      worker.start();
      return true;
    }
    catch (Exception e)
    {
      HtmlStreamExportPlugin.logger.error("Failure while preparing the HTML export", e); //$NON-NLS-1$
      getContext().getStatusListener().setStatus
          (StatusType.ERROR, getResources().getString("HtmlStreamExportPlugin.USER_FAILED"), e); //$NON-NLS-1$
      return false;
    }
  }

  /**
   * Returns the action display name.
   *
   * @return The display name.
   */
  public String getDisplayName()
  {
    return resources.getString("action.export-to-html.stream.name"); //$NON-NLS-1$
  }

  /**
   * Returns the short description for the action.
   *
   * @return The short description.
   */
  public String getShortDescription()
  {
    return resources.getString("action.export-to-html.stream.description"); //$NON-NLS-1$
  }

  /**
   * Returns the small icon for the action.
   *
   * @return The icon.
   */
  public Icon getSmallIcon()
  {
    final Locale locale = getContext().getLocale();
    return getIconTheme().getSmallIcon(locale, "action.export-to-html.stream.small-icon"); //$NON-NLS-1$
  }

  /**
   * Returns the large icon for the action.
   *
   * @return The icon.
   */
  public Icon getLargeIcon()
  {
    final Locale locale = getContext().getLocale();
    return getIconTheme().getLargeIcon(locale, "action.export-to-html.stream.icon"); //$NON-NLS-1$
  }

  /**
   * Returns the accelerator key for the action.
   *
   * @return The accelerator key.
   */
  public KeyStroke getAcceleratorKey()
  {
    return resources.getOptionalKeyStroke("action.export-to-html.stream.accelerator"); //$NON-NLS-1$
  }

  /**
   * Returns the mnemonic key code for the action.
   *
   * @return The key code.
   */
  public Integer getMnemonicKey()
  {
    return resources.getOptionalMnemonic("action.export-to-html.stream.mnemonic"); //$NON-NLS-1$
  }

  /**
   * Returns the resourcebundle to be used to translate strings into localized content.
   *
   * @return the resourcebundle for the localisation.
   */
  protected ResourceBundleSupport getResources()
  {
    return resources;
  }
}
TOP

Related Classes of org.pentaho.reporting.engine.classic.core.modules.gui.html.HtmlStreamExportPlugin

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.