IDEMPIERE-694 ILookupFactory and DefaultLookupFactory to load subclasses of Lookup dynamically via OSGI components. Contributed by Jan Thielemann.

This commit is contained in:
Heng Sin Low 2013-03-11 17:32:48 +08:00
parent 824200314a
commit 7a5fd10add
4 changed files with 166 additions and 45 deletions

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.base.lookup.factory.default">
<implementation class="org.adempiere.base.DefaultLookupFactory"/>
<service>
<provide interface="org.adempiere.base.ILookupFactory"/>
</service>
</scr:component>

View File

@ -0,0 +1,77 @@
/******************************************************************************
* Product: iDempiere ERP & CRM Smart Business Solution *
* 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 org.compiere.model.GridFieldVO;
import org.compiere.model.Lookup;
import org.compiere.model.MAccountLookup;
import org.compiere.model.MLocationLookup;
import org.compiere.model.MLocatorLookup;
import org.compiere.model.MLookup;
import org.compiere.model.MPAttributeLookup;
import org.compiere.model.MPaymentLookup;
import org.compiere.util.DisplayType;
import static org.compiere.util.DisplayType.*;
/**
* @author Jan Thielemann - jan.thielemann@evenos.de
* @author hengsin
*
*/
public class DefaultLookupFactory implements ILookupFactory{
@Override
public Lookup getLookup(GridFieldVO gridFieldVO) {
Lookup lookup = null;
if (gridFieldVO.displayType == Location) // not cached
{
lookup = new MLocationLookup (gridFieldVO.ctx, gridFieldVO.WindowNo);
}
else if (gridFieldVO.displayType == DisplayType.Locator)
{
lookup = new MLocatorLookup (gridFieldVO.ctx, gridFieldVO.WindowNo);
}
else if (gridFieldVO.displayType == Account) // not cached
{
lookup = new MAccountLookup (gridFieldVO.ctx, gridFieldVO.WindowNo);
}
else if (gridFieldVO.displayType == PAttribute) // not cached
{
lookup = new MPAttributeLookup (gridFieldVO.ctx, gridFieldVO.WindowNo);
}
else if (gridFieldVO.displayType == Payment)
{
lookup = new MPaymentLookup (gridFieldVO.ctx, gridFieldVO.WindowNo, gridFieldVO.AD_Column_ID);
}
else if (DisplayType.isLookup(gridFieldVO.displayType) && gridFieldVO.lookupInfo != null)
{
lookup = new MLookup (gridFieldVO.lookupInfo, gridFieldVO.TabNo);
}
return lookup;
}
@Override
public boolean isLookup(GridFieldVO gridFieldVO) {
if (gridFieldVO.displayType == Location
|| gridFieldVO.displayType == Locator
|| gridFieldVO.displayType == Account
|| gridFieldVO.displayType == PAttribute
|| gridFieldVO.displayType == Payment
|| DisplayType.isLookup(gridFieldVO.displayType))
return true;
return false;
}
}

View File

@ -0,0 +1,37 @@
/******************************************************************************
* Product: iDempiere ERP & CRM Smart Business Solution *
* 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 org.compiere.model.GridFieldVO;
import org.compiere.model.Lookup;
/**
* @author Jan Thielemann - jan.thielemann@evenos.de
* @author evenos Consulting GmbH - www.evenos.org
*/
public interface ILookupFactory {
/**
*
* @param gridFieldVO
* @return lookup instance
*/
public Lookup getLookup (GridFieldVO gridFieldVO);
/**
*
* @param gridFieldVO
* @return true if the field's displaytype uses lookup
*/
public boolean isLookup(GridFieldVO gridFieldVO);
}

View File

@ -34,6 +34,8 @@ import java.util.Properties;
import java.util.StringTokenizer;
import java.util.logging.Level;
import org.adempiere.base.ILookupFactory;
import org.adempiere.base.Service;
import org.compiere.util.CLogMgt;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
@ -163,50 +165,45 @@ public class GridField
return;
if (log.isLoggable(Level.CONFIG)) log.config("(" + m_vo.ColumnName + ")");
if (DisplayType.isLookup(m_vo.displayType) && m_vo.IsDisplayed)
if (DisplayType.isLookup(m_vo.displayType))
{
if (m_vo.lookupInfo == null)
if (m_vo.IsDisplayed)
{
log.log(Level.SEVERE, "(" + m_vo.ColumnName + ") - No LookupInfo");
return;
if (m_vo.lookupInfo == null)
{
log.log(Level.SEVERE, "(" + m_vo.ColumnName + ") - No LookupInfo");
return;
}
// Prevent loading of CreatedBy/UpdatedBy
if (m_vo.displayType == DisplayType.Table
&& (m_vo.ColumnName.equals("CreatedBy") || m_vo.ColumnName.equals("UpdatedBy")) )
{
m_vo.lookupInfo.IsCreadedUpdatedBy = true;
m_vo.lookupInfo.DisplayType = DisplayType.Search;
}
//
loadLookupNoValidate();
}
// Prevent loading of CreatedBy/UpdatedBy
if (m_vo.displayType == DisplayType.Table
&& (m_vo.ColumnName.equals("CreatedBy") || m_vo.ColumnName.equals("UpdatedBy")) )
{
m_vo.lookupInfo.IsCreadedUpdatedBy = true;
m_vo.lookupInfo.DisplayType = DisplayType.Search;
}
//
loadLookupNoValidate();
}
else if (m_vo.displayType == DisplayType.Location) // not cached
else
{
MLocationLookup ml = new MLocationLookup (m_vo.ctx, m_vo.WindowNo);
m_lookup = ml;
}
else if (m_vo.displayType == DisplayType.Locator)
{
MLocatorLookup ml = new MLocatorLookup (m_vo.ctx, m_vo.WindowNo);
m_lookup = ml;
}
else if (m_vo.displayType == DisplayType.Account) // not cached
{
MAccountLookup ma = new MAccountLookup (m_vo.ctx, m_vo.WindowNo);
m_lookup = ma;
}
else if (m_vo.displayType == DisplayType.PAttribute) // not cached
{
MPAttributeLookup pa = new MPAttributeLookup (m_vo.ctx, m_vo.WindowNo);
m_lookup = pa;
}
else if (m_vo.displayType == DisplayType.Payment)
{
MPaymentLookup pl = new MPaymentLookup (m_vo.ctx, m_vo.WindowNo, m_vo.AD_Column_ID);
m_lookup = pl;
loadLookupFromFactory();
}
} // m_lookup
private void loadLookupFromFactory() {
//http://jira.idempiere.com/browse/IDEMPIERE-694
//see DefaultLookupFactory.java for the other default Lookups
List<ILookupFactory> factoryList = Service.locator().list(ILookupFactory.class).getServices();
for(ILookupFactory factory : factoryList)
{
m_lookup = factory.getLookup(m_vo);
if (m_lookup != null)
break;
}
}
/***
* bypass isdisplay validation, used by findwindow
*/
@ -218,8 +215,7 @@ public class GridField
return;
}
m_vo.lookupInfo.IsKey = isKey();
MLookup ml = new MLookup (m_vo.lookupInfo, m_vo.TabNo);
m_lookup = ml;
loadLookupFromFactory();
}
/**
@ -254,13 +250,17 @@ public class GridField
retValue = false;
// else if (m_vo.ColumnName.equals("CreatedBy") || m_vo.ColumnName.equals("UpdatedBy"))
// retValue = false;
else if (m_vo.displayType == DisplayType.Location
|| m_vo.displayType == DisplayType.Locator
|| m_vo.displayType == DisplayType.Account
|| m_vo.displayType == DisplayType.PAttribute
|| m_vo.displayType == DisplayType.Payment)
retValue = true;
else {
//http://jira.idempiere.com/browse/IDEMPIERE-694
//see DefaultLookupFactory.java for the other default Lookups
List<ILookupFactory> factoryList = Service.locator().list(ILookupFactory.class).getServices();
for(ILookupFactory factory : factoryList)
{
retValue = factory.isLookup(m_vo);
if (retValue == true)
break;
}
}
return retValue;
} // isLookup