From 95fdfa0208ed9d2f8a914ca4df8ee781d75fbbc9 Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Wed, 24 Nov 2010 11:03:19 +0800 Subject: [PATCH] Implemented grid data export extension for swing client. --- org.adempiere.base/plugin.xml | 10 ++ .../org.adempiere.base.IGridTabExporter.exsd | 109 ++++++++++++++++++ .../org/adempiere/base/IGridTabExporter.java | 48 ++++++++ .../impexp/GridTabExcelExporter.java | 43 +++++-- .../src/org/compiere/apps/AExport.java | 47 +++++--- 5 files changed, 234 insertions(+), 23 deletions(-) create mode 100644 org.adempiere.base/schema/org.adempiere.base.IGridTabExporter.exsd create mode 100644 org.adempiere.base/src/org/adempiere/base/IGridTabExporter.java diff --git a/org.adempiere.base/plugin.xml b/org.adempiere.base/plugin.xml index bc7589db6e..ac78b9d74b 100644 --- a/org.adempiere.base/plugin.xml +++ b/org.adempiere.base/plugin.xml @@ -11,6 +11,7 @@ + + + + + diff --git a/org.adempiere.base/schema/org.adempiere.base.IGridTabExporter.exsd b/org.adempiere.base/schema/org.adempiere.base.IGridTabExporter.exsd new file mode 100644 index 0000000000..1c9c373565 --- /dev/null +++ b/org.adempiere.base/schema/org.adempiere.base.IGridTabExporter.exsd @@ -0,0 +1,109 @@ + + + + + + + + + [Enter description of this extension point.] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + numeric priority value, higher value is of higher priority. + + + + + + + + + + + + + + + + + + + + + + [Enter the first release in which this extension point appears.] + + + + + + + + + [Enter extension point usage example here.] + + + + + + + + + [Enter API information here.] + + + + + + + + + [Enter information about supplied implementation of this extension point.] + + + + + diff --git a/org.adempiere.base/src/org/adempiere/base/IGridTabExporter.java b/org.adempiere.base/src/org/adempiere/base/IGridTabExporter.java new file mode 100644 index 0000000000..887742180a --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/IGridTabExporter.java @@ -0,0 +1,48 @@ +/****************************************************************************** + * Product: Adempiere ERP & CRM Smart Business Solution * + * Copyright (C) 2010 Heng Sin Low * + * This program is free software; you can redistribute it and/or modify it * + * under the terms version 2 of the GNU General Public License as published * + * by the Free Software Foundation. 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 General Public License for more details. * + * You should have received a copy of the GNU General Public License along * + * with this program; if not, write to the Free Software Foundation, Inc., * + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * + *****************************************************************************/ +package org.adempiere.base; + +import java.io.File; + +import org.compiere.model.GridTab; + +/** + * + * @author hengsin + * + */ +public interface IGridTabExporter { + + /** + * export gridTab data to file + * @param gridTab + * @param file + */ + public void export(GridTab gridTab, File file); + + /** + * @return file extension + */ + public String getFileExtension(); + + /** + * @return description for file extension + */ + public String getFileExtensionLabel(); + + /** + * @return mime type + */ + public String getContentType(); +} diff --git a/org.adempiere.base/src/org/adempiere/impexp/GridTabExcelExporter.java b/org.adempiere.base/src/org/adempiere/impexp/GridTabExcelExporter.java index d24e5f71b9..923f0bcb1c 100644 --- a/org.adempiere.base/src/org/adempiere/impexp/GridTabExcelExporter.java +++ b/org.adempiere.base/src/org/adempiere/impexp/GridTabExcelExporter.java @@ -13,9 +13,11 @@ *****************************************************************************/ package org.adempiere.impexp; +import java.io.File; import java.util.HashMap; -import java.util.Properties; +import org.adempiere.base.IGridTabExporter; +import org.adempiere.exceptions.AdempiereException; import org.compiere.model.GridField; import org.compiere.model.GridTab; import org.compiere.model.Lookup; @@ -23,22 +25,22 @@ import org.compiere.model.MLookup; import org.compiere.model.MLookupFactory; import org.compiere.util.DisplayType; import org.compiere.util.Env; +import org.compiere.util.Msg; /** * Excel Exporter Adapter for GridTab * @author Teo Sarca, www.arhipac.ro *
  • FR [ 1943731 ] Window data export functionality */ -public class GridTabExcelExporter extends AbstractExcelExporter +public class GridTabExcelExporter extends AbstractExcelExporter implements IGridTabExporter { private GridTab m_tab = null; - - public GridTabExcelExporter(Properties ctx, GridTab tab) + + public GridTabExcelExporter() { - m_tab = tab; setFreezePane(0, 1); } - + @Override public int getColumnCount() { @@ -119,9 +121,9 @@ public class GridTabExcelExporter extends AbstractExcelExporter { ; // nothing } - + private HashMap m_buttonLookups = new HashMap(); - + private MLookup getButtonLookup(GridField mField) { MLookup lookup = m_buttonLookups.get(mField.getColumnName()); @@ -143,4 +145,29 @@ public class GridTabExcelExporter extends AbstractExcelExporter m_buttonLookups.put(mField.getColumnName(), lookup); return lookup; } + + @Override + public void export(GridTab gridTab, File file) { + m_tab = gridTab; + try { + export(file, null); + } catch (Exception e) { + throw new AdempiereException(e); + } + } + + @Override + public String getFileExtension() { + return "xls"; + } + + @Override + public String getFileExtensionLabel() { + return Msg.getMsg(Env.getCtx(), "FileXLS"); + } + + @Override + public String getContentType() { + return "application/vnd.ms-excel"; + } } diff --git a/org.adempiere.ui.swing/src/org/compiere/apps/AExport.java b/org.adempiere.ui.swing/src/org/compiere/apps/AExport.java index 12cabe545e..0624912ba2 100644 --- a/org.adempiere.ui.swing/src/org/compiere/apps/AExport.java +++ b/org.adempiere.ui.swing/src/org/compiere/apps/AExport.java @@ -16,18 +16,19 @@ package org.compiere.apps; import java.awt.Cursor; import java.io.File; import java.io.IOException; -import java.util.Properties; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.logging.Level; import javax.swing.JFileChooser; -import org.adempiere.impexp.GridTabExcelExporter; +import org.adempiere.base.IGridTabExporter; +import org.adempiere.base.Service; import org.compiere.model.GridTab; import org.compiere.util.CLogMgt; import org.compiere.util.CLogger; -import org.compiere.util.Env; import org.compiere.util.ExtensionFileFilter; -import org.compiere.util.Msg; /** * Export button consequences @@ -36,17 +37,33 @@ import org.compiere.util.Msg; */ public class AExport { - private CLogger log = CLogger.getCLogger(getClass()); - private Properties m_ctx = null; + private CLogger log = CLogger.getCLogger(getClass()); private int m_WindowNo = 0; - + private Map exporterMap = null; + private Map extensionMap = null; + public AExport(APanel parent) { - m_ctx = Env.getCtx(); m_WindowNo = parent.getWindowNo(); // + exporterMap = new HashMap(); + extensionMap = new HashMap(); + List exporterList = Service.list(IGridTabExporter.class); + for(IGridTabExporter exporter : exporterList) + { + String extension = exporter.getFileExtension(); + if (!extensionMap.containsKey(extension)) + { + extensionMap.put(extension, exporter.getFileExtensionLabel()); + exporterMap.put(extension, exporter); + } + } JFileChooser chooser = new JFileChooser(); - chooser.addChoosableFileFilter(new ExtensionFileFilter("xls", Msg.getMsg(m_ctx, "FileXLS"))); + for(Map.Entry entry : extensionMap.entrySet()) + { + chooser.addChoosableFileFilter(new ExtensionFileFilter(entry.getKey(), entry.getValue())); + } + if (chooser.showSaveDialog(parent) != JFileChooser.APPROVE_OPTION) return; @@ -76,9 +93,9 @@ public class AExport parent.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); try { - if (ext.equals("xls")) + if (extensionMap.containsKey(ext)) { - createXLS(outFile, parent.getCurrentTab()); + export(outFile, parent.getCurrentTab(), ext); } else { @@ -96,11 +113,11 @@ public class AExport parent.setCursor(Cursor.getDefaultCursor()); } } - - private void createXLS(File outFile, GridTab tab) + + private void export(File outFile, GridTab tab, String extension) throws Exception { - GridTabExcelExporter exporter = new GridTabExcelExporter(m_ctx, tab); - exporter.export(outFile, null); + IGridTabExporter exporter = exporterMap.get(extension); + exporter.export(tab, outFile); } }