From 7a5fd10add2409985222f4610a75ed2510ef3bad Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Mon, 11 Mar 2013 17:32:48 +0800 Subject: [PATCH] IDEMPIERE-694 ILookupFactory and DefaultLookupFactory to load subclasses of Lookup dynamically via OSGI components. Contributed by Jan Thielemann. --- .../OSGI-INF/defaultlookupfactory.xml | 7 ++ .../adempiere/base/DefaultLookupFactory.java | 77 ++++++++++++++++ .../org/adempiere/base/ILookupFactory.java | 37 ++++++++ .../src/org/compiere/model/GridField.java | 90 +++++++++---------- 4 files changed, 166 insertions(+), 45 deletions(-) create mode 100644 org.adempiere.base/OSGI-INF/defaultlookupfactory.xml create mode 100644 org.adempiere.base/src/org/adempiere/base/DefaultLookupFactory.java create mode 100644 org.adempiere.base/src/org/adempiere/base/ILookupFactory.java diff --git a/org.adempiere.base/OSGI-INF/defaultlookupfactory.xml b/org.adempiere.base/OSGI-INF/defaultlookupfactory.xml new file mode 100644 index 0000000000..08c074aa56 --- /dev/null +++ b/org.adempiere.base/OSGI-INF/defaultlookupfactory.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/org.adempiere.base/src/org/adempiere/base/DefaultLookupFactory.java b/org.adempiere.base/src/org/adempiere/base/DefaultLookupFactory.java new file mode 100644 index 0000000000..d1fd5f9f64 --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/DefaultLookupFactory.java @@ -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; + } + +} diff --git a/org.adempiere.base/src/org/adempiere/base/ILookupFactory.java b/org.adempiere.base/src/org/adempiere/base/ILookupFactory.java new file mode 100644 index 0000000000..2775e06c93 --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/ILookupFactory.java @@ -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); +} diff --git a/org.adempiere.base/src/org/compiere/model/GridField.java b/org.adempiere.base/src/org/compiere/model/GridField.java index e94706c157..e8326d7a18 100644 --- a/org.adempiere.base/src/org/compiere/model/GridField.java +++ b/org.adempiere.base/src/org/compiere/model/GridField.java @@ -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 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 factoryList = Service.locator().list(ILookupFactory.class).getServices(); + for(ILookupFactory factory : factoryList) + { + retValue = factory.isLookup(m_vo); + if (retValue == true) + break; + } + } return retValue; } // isLookup