Implemented grid data export extension for swing client.

This commit is contained in:
Heng Sin Low 2010-11-24 11:03:19 +08:00
parent 993c687788
commit 95fdfa0208
5 changed files with 234 additions and 23 deletions

View File

@ -11,6 +11,7 @@
<extension-point id="org.compiere.interfaces.Status" name="Status interface" schema="schema/org.compiere.interfaces.Status.exsd"/>
<extension-point id="org.adempiere.base.IModelFactory" name="Model Factory" schema="schema/org.adempiere.base.IModelFactory.exsd"/>
<extension-point id="org.adempiere.base.IDocFactory" name="Financial Document Factory" schema="schema/org.adempiere.base.IDocFactory.exsd"/>
<extension-point id="org.adempiere.base.IGridTabExporter" name="Grid data export extension" schema="schema/org.adempiere.base.IGridTabExporter.exsd"/>
<extension
id="org.adempiere.base.DefaultModelFactory"
name="Default model factory"
@ -30,5 +31,14 @@
priority="0">
</factory>
</extension>
<extension
id="org.adempiere.impexp.GridTabXlsExporter"
name="Grid data excel exporter"
point="org.adempiere.base.IGridTabExporter">
<exporter
class="org.adempiere.impexp.GridTabExcelExporter"
priority="0">
</exporter>
</extension>
</plugin>

View File

@ -0,0 +1,109 @@
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
<schema targetNamespace="org.adempiere.base" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appinfo>
<meta.schema plugin="org.adempiere.base" id="org.adempiere.base.IGridTabExporter" name="Grid data export extension"/>
</appinfo>
<documentation>
[Enter description of this extension point.]
</documentation>
</annotation>
<element name="extension">
<annotation>
<appinfo>
<meta.element />
</appinfo>
</annotation>
<complexType>
<choice>
<element ref="exporter"/>
</choice>
<attribute name="point" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="id" type="string">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="name" type="string">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute translatable="true"/>
</appinfo>
</annotation>
</attribute>
</complexType>
</element>
<element name="exporter">
<complexType>
<attribute name="priority" type="string" use="required">
<annotation>
<documentation>
numeric priority value, higher value is of higher priority.
</documentation>
</annotation>
</attribute>
<attribute name="class" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute kind="java" basedOn=":org.adempiere.base.IGridTabExporter"/>
</appinfo>
</annotation>
</attribute>
</complexType>
</element>
<annotation>
<appinfo>
<meta.section type="since"/>
</appinfo>
<documentation>
[Enter the first release in which this extension point appears.]
</documentation>
</annotation>
<annotation>
<appinfo>
<meta.section type="examples"/>
</appinfo>
<documentation>
[Enter extension point usage example here.]
</documentation>
</annotation>
<annotation>
<appinfo>
<meta.section type="apiinfo"/>
</appinfo>
<documentation>
[Enter API information here.]
</documentation>
</annotation>
<annotation>
<appinfo>
<meta.section type="implementation"/>
</appinfo>
<documentation>
[Enter information about supplied implementation of this extension point.]
</documentation>
</annotation>
</schema>

View File

@ -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();
}

View File

@ -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
* <li>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<String, MLookup> m_buttonLookups = new HashMap<String, MLookup>();
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";
}
}

View File

@ -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<String, IGridTabExporter> exporterMap = null;
private Map<String, String> extensionMap = null;
public AExport(APanel parent)
{
m_ctx = Env.getCtx();
m_WindowNo = parent.getWindowNo();
//
exporterMap = new HashMap<String, IGridTabExporter>();
extensionMap = new HashMap<String, String>();
List<IGridTabExporter> 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<String, String> 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);
}
}