Change "CreateFrom" factory to use OSGi service

This commit is contained in:
Elaine Tan 2013-01-18 19:14:02 +08:00
parent 78d846ccad
commit 7bc1e373c9
11 changed files with 212 additions and 224 deletions

View File

@ -87,5 +87,5 @@ Import-Package: javax.net.ssl,
org.restlet.security,
org.restlet.service,
org.restlet.util
Service-Component: OSGI-INF/defaultpaymentformfactory.xml, OSGI-INF/serverinterface.xml, OSGI-INF/statusinterface.xml, OSGI-INF/defaultprintshippinglabel.xml
Service-Component: OSGI-INF/defaultpaymentformfactory.xml, OSGI-INF/serverinterface.xml, OSGI-INF/statusinterface.xml, OSGI-INF/defaultprintshippinglabel.xml, OSGI-INF/defaultcreatefromfactory.xml
Bundle-ActivationPolicy: lazy

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.adempiere.ui.swing.createfrom.factory">
<implementation class="org.compiere.grid.DefaultCreateFromFactory"/>
<service>
<provide interface="org.compiere.grid.ICreateFromFactory"/>
</service>
</scr:component>

View File

@ -7,6 +7,7 @@ bin.includes = META-INF/,\
jpedal.jar,\
OSGI-INF/,\
OSGI-INF/defaultpaymentformfactory.xml,\
OSGI-INF/defaultprintshippinglabel.xml
OSGI-INF/defaultprintshippinglabel.xml,\
OSGI-INF/defaultcreatefromfactory.xml
source.client.jar = src/
output.client.jar = build/

View File

@ -0,0 +1,46 @@
/******************************************************************************
* Copyright (C) 2013 Elaine Tan *
* Copyright (C) 2013 Trek Global
* 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.compiere.grid;
import org.compiere.model.GridTab;
import org.compiere.model.I_C_BankStatement;
import org.compiere.model.I_C_Invoice;
import org.compiere.model.I_M_InOut;
import org.compiere.model.I_M_PackageMPS;
import org.compiere.model.I_M_RMA;
/**
*
* @author Elaine
*
*/
public class DefaultCreateFromFactory implements ICreateFromFactory {
@Override
public ICreateFrom create(GridTab mTab) {
String tableName = mTab.getTableName();
if (tableName.equals(I_C_Invoice.Table_Name))
return new VCreateFromInvoiceUI(mTab);
else if (tableName.equals(I_C_BankStatement.Table_Name))
return new VCreateFromStatementUI(mTab);
else if (tableName.equals(I_M_InOut.Table_Name))
return new VCreateFromShipmentUI(mTab);
else if (tableName.equals(I_M_RMA.Table_Name))
return new VCreateFromRMAUI(mTab);
else if (tableName.equals(I_M_PackageMPS.Table_Name))
return new VCreateFromPackageShipmentUI(mTab);
return null;
}
}

View File

@ -13,98 +13,23 @@
*****************************************************************************/
package org.compiere.grid;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.List;
import org.adempiere.base.Service;
import org.compiere.model.GridTab;
import org.compiere.model.I_C_BankStatement;
import org.compiere.model.I_C_Invoice;
import org.compiere.model.I_M_InOut;
import org.compiere.model.I_M_PackageMPS;
import org.compiere.model.I_M_RMA;
import org.compiere.util.CLogger;
import org.compiere.util.Env;
public class VCreateFromFactory
{
/** Static Logger */
private static CLogger s_log = CLogger.getCLogger (VCreateFromFactory.class);
/** Registered classes map (AD_Table_ID -> Class) */
private static HashMap<Integer, Class<? extends ICreateFrom>> s_registeredClasses = null;
/**
* Register custom VCreateFrom* class
* @param ad_table_id
* @param cl custom class
*/
public static final void registerClass(int ad_table_id, Class<? extends ICreateFrom> cl)
{
s_registeredClasses.put(ad_table_id, cl);
s_log.info("Registered AD_Table_ID="+ad_table_id+", Class="+cl);
}
static
{
// Register defaults:
s_registeredClasses = new HashMap<Integer, Class<? extends ICreateFrom>>();
s_registeredClasses.put(I_C_Invoice.Table_ID, VCreateFromInvoiceUI.class);
s_registeredClasses.put(I_C_BankStatement.Table_ID, VCreateFromStatementUI.class);
s_registeredClasses.put(I_M_InOut.Table_ID, VCreateFromShipmentUI.class);
s_registeredClasses.put(I_M_RMA.Table_ID, VCreateFromRMAUI.class);
s_registeredClasses.put(I_M_PackageMPS.Table_ID, VCreateFromPackageShipmentUI.class);
}
/**
* Factory - called from APanel
* @param mTab Model Tab for the trx
* @return JDialog
*/
public static ICreateFrom create (GridTab mTab)
{
// dynamic init preparation
int AD_Table_ID = Env.getContextAsInt(Env.getCtx(), mTab.getWindowNo(), mTab.getTabNo(), "_TabInfo_AD_Table_ID");
ICreateFrom retValue = null;
Class<? extends ICreateFrom> cl = s_registeredClasses.get(AD_Table_ID);
if (cl != null)
ICreateFrom createFrom = null;
List<ICreateFromFactory> factories = Service.locator().list(ICreateFromFactory.class).getServices();
for (ICreateFromFactory factory : factories)
{
try
{
java.lang.reflect.Constructor<? extends ICreateFrom> ctor = cl.getConstructor(GridTab.class);
retValue = ctor.newInstance(mTab);
}
catch (Throwable e)
{
s_log.log(Level.SEVERE, e.getLocalizedMessage(), e);
return null;
}
createFrom = factory.create(mTab);
if (createFrom != null)
break;
}
if (retValue == null)
{
AD_Table_ID = Env.getContextAsInt(Env.getCtx(), mTab.getWindowNo(), "BaseTable_ID");
retValue = null;
cl = s_registeredClasses.get(AD_Table_ID);
if (cl != null)
{
try
{
java.lang.reflect.Constructor<? extends ICreateFrom> ctor = cl.getConstructor(GridTab.class);
retValue = ctor.newInstance(mTab);
}
catch (Throwable e)
{
s_log.log(Level.SEVERE, e.getLocalizedMessage(), e);
return null;
}
}
s_log.info("Unsupported AD_Table_ID=" + AD_Table_ID);
return null;
}
return retValue;
} // create
return createFrom;
}
}

View File

@ -58,4 +58,4 @@ Bundle-Activator: org.adempiere.webui.WebUIActivator
Eclipse-ExtensibleAPI: true
Eclipse-RegisterBuddy: org.zkoss.zk.library
Web-ContextPath: webui
Service-Component: OSGI-INF/reportviewerprovider.xml, OSGI-INF/defaultinfofactory.xml, OSGI-INF/defaulteditorfactory.xml, OSGI-INF/jrviewerprovider.xml, OSGI-INF/resourcefinder.xml, OSGI-INF/defaultpaymentformfactory.xml, OSGI-INF/processfactory.xml, OSGI-INF/defaultprintshippinglabel.xml
Service-Component: OSGI-INF/reportviewerprovider.xml, OSGI-INF/defaultinfofactory.xml, OSGI-INF/defaulteditorfactory.xml, OSGI-INF/jrviewerprovider.xml, OSGI-INF/resourcefinder.xml, OSGI-INF/defaultpaymentformfactory.xml, OSGI-INF/processfactory.xml, OSGI-INF/defaultprintshippinglabel.xml, OSGI-INF/defaultcreatefromfactory.xml

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.adempiere.ui.zk.createfrom.factory">
<implementation class="org.adempiere.webui.apps.form.DefaultCreateFromFactory"/>
<service>
<provide interface="org.compiere.grid.ICreateFromFactory"/>
</service>
</scr:component>

View File

@ -0,0 +1,48 @@
/******************************************************************************
* Copyright (C) 2013 Elaine Tan *
* Copyright (C) 2013 Trek Global
* 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.webui.apps.form;
import org.compiere.grid.ICreateFrom;
import org.compiere.grid.ICreateFromFactory;
import org.compiere.model.GridTab;
import org.compiere.model.I_C_BankStatement;
import org.compiere.model.I_C_Invoice;
import org.compiere.model.I_M_InOut;
import org.compiere.model.I_M_PackageMPS;
import org.compiere.model.I_M_RMA;
/**
*
* @author Elaine
*
*/
public class DefaultCreateFromFactory implements ICreateFromFactory {
@Override
public ICreateFrom create(GridTab mTab) {
String tableName = mTab.getTableName();
if (tableName.equals(I_C_Invoice.Table_Name))
return new WCreateFromInvoiceUI(mTab);
else if (tableName.equals(I_C_BankStatement.Table_Name))
return new WCreateFromStatementUI(mTab);
else if (tableName.equals(I_M_InOut.Table_Name))
return new WCreateFromShipmentUI(mTab);
else if (tableName.equals(I_M_RMA.Table_Name))
return new WCreateFromRMAUI(mTab);
else if (tableName.equals(I_M_PackageMPS.Table_Name))
return new WCreateFromPackageShipmentUI(mTab);
return null;
}
}

View File

@ -13,99 +13,25 @@
*****************************************************************************/
package org.adempiere.webui.apps.form;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.List;
import org.adempiere.base.Service;
import org.compiere.grid.ICreateFrom;
import org.compiere.grid.ICreateFromFactory;
import org.compiere.model.GridTab;
import org.compiere.model.I_C_BankStatement;
import org.compiere.model.I_C_Invoice;
import org.compiere.model.I_M_InOut;
import org.compiere.model.I_M_PackageMPS;
import org.compiere.model.I_M_RMA;
import org.compiere.util.CLogger;
import org.compiere.util.Env;
public class WCreateFromFactory
{
/** Static Logger */
private static CLogger s_log = CLogger.getCLogger (WCreateFromFactory.class);
/** Registered classes map (AD_Table_ID -> Class) */
private static HashMap<Integer, Class<? extends ICreateFrom>> s_registeredClasses = null;
/**
* Register custom VCreateFrom* class
* @param ad_table_id
* @param cl custom class
*/
public static final void registerClass(int ad_table_id, Class<? extends ICreateFrom> cl)
{
s_registeredClasses.put(ad_table_id, cl);
s_log.info("Registered AD_Table_ID="+ad_table_id+", Class="+cl);
}
static
{
// Register defaults:
s_registeredClasses = new HashMap<Integer, Class<? extends ICreateFrom>>();
s_registeredClasses.put(I_C_Invoice.Table_ID, WCreateFromInvoiceUI.class);
s_registeredClasses.put(I_C_BankStatement.Table_ID, WCreateFromStatementUI.class);
s_registeredClasses.put(I_M_InOut.Table_ID, WCreateFromShipmentUI.class);
s_registeredClasses.put(I_M_RMA.Table_ID, WCreateFromRMAUI.class);
s_registeredClasses.put(I_M_PackageMPS.Table_ID, WCreateFromPackageShipmentUI.class);
}
/**
* Factory - called from APanel
* @param mTab Model Tab for the trx
* @return JDialog
*/
public static ICreateFrom create (GridTab mTab)
{
// dynamic init preparation
int AD_Table_ID = Env.getContextAsInt(Env.getCtx(), mTab.getWindowNo(), mTab.getTabNo(), "_TabInfo_AD_Table_ID");
ICreateFrom retValue = null;
Class<? extends ICreateFrom> cl = s_registeredClasses.get(AD_Table_ID);
if (cl != null)
ICreateFrom createFrom = null;
List<ICreateFromFactory> factories = Service.locator().list(ICreateFromFactory.class).getServices();
for (ICreateFromFactory factory : factories)
{
try
{
java.lang.reflect.Constructor<? extends ICreateFrom> ctor = cl.getConstructor(GridTab.class);
retValue = ctor.newInstance(mTab);
}
catch (Throwable e)
{
s_log.log(Level.SEVERE, e.getLocalizedMessage(), e);
return null;
}
createFrom = factory.create(mTab);
if (createFrom != null)
break;
}
if (retValue == null)
{
AD_Table_ID = Env.getContextAsInt(Env.getCtx(), mTab.getWindowNo(), "BaseTable_ID");
retValue = null;
cl = s_registeredClasses.get(AD_Table_ID);
if (cl != null)
{
try
{
java.lang.reflect.Constructor<? extends ICreateFrom> ctor = cl.getConstructor(GridTab.class);
retValue = ctor.newInstance(mTab);
}
catch (Throwable e)
{
s_log.log(Level.SEVERE, e.getLocalizedMessage(), e);
return null;
}
}
s_log.info("Unsupported AD_Table_ID=" + AD_Table_ID);
return null;
}
return retValue;
} // create
return createFrom;
}
}

View File

@ -1,51 +1,52 @@
output.. = WEB-INF/classes/
bin.includes = META-INF/,\
WEB-INF/,\
css/,\
images/,\
index.zul,\
js/,\
theme/,\
theme.zs,\
zul/,\
timeout.zul,\
plugin.xml,\
WEB-INF/classes/,\
calendar.css,\
calendar.zul,\
calendar_mini.zul,\
divarrow.zul,\
divtab.zul,\
OSGI-INF/,\
OSGI-INF/reportviewerprovider.xml,\
OSGI-INF/defaultinfofactory.xml,\
OSGI-INF/defaulteditorfactory.xml,\
OSGI-INF/jrviewerprovider.xml,\
OSGI-INF/resourcefinder.xml,\
OSGI-INF/defaultpaymentformfactory.xml,\
OSGI-INF/processfactory.xml,\
OSGI-INF/defaultprintshippinglabel.xml,\
WEB-INF/lib/atmosphere-compat-jbossweb-1.0.4.jar,\
WEB-INF/lib/atmosphere-compat-tomcat-1.0.4.jar,\
WEB-INF/lib/atmosphere-compat-tomcat7-1.0.4.jar,\
WEB-INF/lib/atmosphere-runtime-1.0.4.jar
src.includes = WEB-INF/classes/,\
WEB-INF/tld/,\
WEB-INF/web.xml,\
WEB-INF/xsd/,\
WEB-INF/zk.xml,\
css/,\
images/,\
index.zul,\
js/,\
theme/,\
theme.zs,\
zul/,\
calendar.css,\
calendar.zul,\
calendar_mini.zul,\
divarrow.zul,\
divtab.zul
source.. = WEB-INF/src/
bin.excludes = WEB-INF/src/,\
WEB-INF/web-2.5.xml
output.. = WEB-INF/classes/
bin.includes = META-INF/,\
WEB-INF/,\
css/,\
images/,\
index.zul,\
js/,\
theme/,\
theme.zs,\
zul/,\
timeout.zul,\
plugin.xml,\
WEB-INF/classes/,\
calendar.css,\
calendar.zul,\
calendar_mini.zul,\
divarrow.zul,\
divtab.zul,\
OSGI-INF/,\
OSGI-INF/reportviewerprovider.xml,\
OSGI-INF/defaultinfofactory.xml,\
OSGI-INF/defaulteditorfactory.xml,\
OSGI-INF/jrviewerprovider.xml,\
OSGI-INF/resourcefinder.xml,\
OSGI-INF/defaultpaymentformfactory.xml,\
OSGI-INF/processfactory.xml,\
OSGI-INF/defaultprintshippinglabel.xml,\
WEB-INF/lib/atmosphere-compat-jbossweb-1.0.4.jar,\
WEB-INF/lib/atmosphere-compat-tomcat-1.0.4.jar,\
WEB-INF/lib/atmosphere-compat-tomcat7-1.0.4.jar,\
WEB-INF/lib/atmosphere-runtime-1.0.4.jar,\
OSGI-INF/defaultcreatefromfactory.xml
src.includes = WEB-INF/classes/,\
WEB-INF/tld/,\
WEB-INF/web.xml,\
WEB-INF/xsd/,\
WEB-INF/zk.xml,\
css/,\
images/,\
index.zul,\
js/,\
theme/,\
theme.zs,\
zul/,\
calendar.css,\
calendar.zul,\
calendar_mini.zul,\
divarrow.zul,\
divtab.zul
source.. = WEB-INF/src/
bin.excludes = WEB-INF/src/,\
WEB-INF/web-2.5.xml

View File

@ -0,0 +1,27 @@
/******************************************************************************
* Copyright (C) 2013 Elaine Tan *
* Copyright (C) 2013 Trek Global
* 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.compiere.grid;
import org.compiere.model.GridTab;
/**
*
* @author Elaine
*
*/
public interface ICreateFromFactory {
public ICreateFrom create(GridTab mTab);
}