From 6003245f32812f275b582b49da83bc2ef4372da8 Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Wed, 24 Nov 2010 07:27:22 +0800 Subject: [PATCH] Implemented field editor factory extension for zk client --- .../webui/editor/WebEditorFactory.java | 141 ++------------ .../webui/factory/DefaultEditorFactory.java | 181 ++++++++++++++++++ .../webui/factory/IEditorFactory.java | 34 ++++ org.adempiere.ui.zk/plugin.xml | 10 + ...dempiere.webui.factory.IEditorFactory.exsd | 109 +++++++++++ 5 files changed, 347 insertions(+), 128 deletions(-) create mode 100644 org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/factory/DefaultEditorFactory.java create mode 100644 org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/factory/IEditorFactory.java create mode 100644 org.adempiere.ui.zk/schema/org.adempiere.webui.factory.IEditorFactory.exsd diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WebEditorFactory.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WebEditorFactory.java index cee0603dfd..4f450cfd9c 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WebEditorFactory.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WebEditorFactory.java @@ -17,17 +17,20 @@ package org.adempiere.webui.editor; +import java.util.List; + +import org.adempiere.base.Service; +import org.adempiere.webui.factory.IEditorFactory; import org.compiere.model.GridField; import org.compiere.model.GridTab; import org.compiere.util.CLogger; -import org.compiere.util.DisplayType; /** * * @author Ashley G Ramdass * @date Mar 12, 2007 * @version $Revision: 0.10 $ - * + * * @author Low Heng Sin * @date July 14 2008 */ @@ -36,145 +39,27 @@ public class WebEditorFactory @SuppressWarnings("unused") private final static CLogger logger; - + static { logger = CLogger.getCLogger(WebEditorFactory.class); } - + public static WEditor getEditor(GridField gridField, boolean tableEditor) { return getEditor(null, gridField, tableEditor); } - + public static WEditor getEditor(GridTab gridTab, GridField gridField, boolean tableEditor) { - if (gridField == null) - { - return null; - } - WEditor editor = null; - int displayType = gridField.getDisplayType(); - - /** Not a Field */ - if (gridField.isHeading()) + List factoryList = Service.list(IEditorFactory.class); + for(IEditorFactory factory : factoryList) { - return null; + editor = factory.getEditor(gridTab, gridField, tableEditor); + if (editor != null) + break; } - - /** String (clear/password) */ - if (displayType == DisplayType.String - || displayType == DisplayType.PrinterName - || (tableEditor && (displayType == DisplayType.Text || displayType == DisplayType.TextLong))) - { - if (gridField.isEncryptedField()) - { - editor = new WPasswordEditor(gridField); - } - else - { - editor = new WStringEditor(gridField, tableEditor); - } - } - /** File */ - else if (displayType == DisplayType.FileName) - { - editor = new WFilenameEditor(gridField); - } - /** File Path */ - else if (displayType == DisplayType.FilePath) - { - editor = new WFileDirectoryEditor(gridField); - } - /** Number */ - else if (DisplayType.isNumeric(displayType)) - { - editor = new WNumberEditor(gridField); - } - - /** YesNo */ - else if (displayType == DisplayType.YesNo) - { - editor = new WYesNoEditor(gridField); - if (tableEditor) - ((WYesNoEditor)editor).getComponent().setLabel(""); - } - - /** Text */ - else if (displayType == DisplayType.Text || displayType == DisplayType.Memo || displayType == DisplayType.TextLong) - { - editor = new WStringEditor(gridField); - } - - /** Date */ - else if (DisplayType.isDate(displayType)) - { - if (displayType == DisplayType.Time) - editor = new WTimeEditor(gridField); - else if (displayType == DisplayType.DateTime) - editor = new WDatetimeEditor(gridField); - else - editor = new WDateEditor(gridField); - } - - /** Button */ - else if (displayType == DisplayType.Button) - { - editor = new WButtonEditor(gridField); - } - - /** Table Direct */ - else if (displayType == DisplayType.TableDir || - displayType == DisplayType.Table || displayType == DisplayType.List - || displayType == DisplayType.ID ) - { - editor = new WTableDirEditor(gridField); - } - - else if (displayType == DisplayType.URL) - { - editor = new WUrlEditor(gridField); - } - - else if (displayType == DisplayType.Search) - { - editor = new WSearchEditor(gridField); - } - - else if (displayType == DisplayType.Location) - { - editor = new WLocationEditor(gridField); - } - else if (displayType == DisplayType.Locator) - { - editor = new WLocatorEditor(gridField); - } - else if (displayType == DisplayType.Account) - { - editor = new WAccountEditor(gridField); - } - else if (displayType == DisplayType.Image) - { - editor = new WImageEditor(gridField); - } - else if (displayType == DisplayType.Binary) - { - editor = new WBinaryEditor(gridField); - } - else if (displayType == DisplayType.PAttribute) - { - editor = new WPAttributeEditor(gridTab, gridField); - } - else if (displayType == DisplayType.Assignment) - { - editor = new WAssignmentEditor(gridField); - } - else - { - editor = new WUnknownEditor(gridField); - } - return editor; } } diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/factory/DefaultEditorFactory.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/factory/DefaultEditorFactory.java new file mode 100644 index 0000000000..2d1d8629f0 --- /dev/null +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/factory/DefaultEditorFactory.java @@ -0,0 +1,181 @@ +/****************************************************************************** + * 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.webui.factory; + +import org.adempiere.webui.editor.WAccountEditor; +import org.adempiere.webui.editor.WAssignmentEditor; +import org.adempiere.webui.editor.WBinaryEditor; +import org.adempiere.webui.editor.WButtonEditor; +import org.adempiere.webui.editor.WDateEditor; +import org.adempiere.webui.editor.WDatetimeEditor; +import org.adempiere.webui.editor.WEditor; +import org.adempiere.webui.editor.WFileDirectoryEditor; +import org.adempiere.webui.editor.WFilenameEditor; +import org.adempiere.webui.editor.WImageEditor; +import org.adempiere.webui.editor.WLocationEditor; +import org.adempiere.webui.editor.WLocatorEditor; +import org.adempiere.webui.editor.WNumberEditor; +import org.adempiere.webui.editor.WPAttributeEditor; +import org.adempiere.webui.editor.WPasswordEditor; +import org.adempiere.webui.editor.WSearchEditor; +import org.adempiere.webui.editor.WStringEditor; +import org.adempiere.webui.editor.WTableDirEditor; +import org.adempiere.webui.editor.WTimeEditor; +import org.adempiere.webui.editor.WUnknownEditor; +import org.adempiere.webui.editor.WUrlEditor; +import org.adempiere.webui.editor.WYesNoEditor; +import org.compiere.model.GridField; +import org.compiere.model.GridTab; +import org.compiere.util.DisplayType; + +/** + * + * @author hengsin + * + */ +public class DefaultEditorFactory implements IEditorFactory { + + @Override + public WEditor getEditor(GridTab gridTab, GridField gridField, + boolean tableEditor) { + if (gridField == null) + { + return null; + } + + WEditor editor = null; + int displayType = gridField.getDisplayType(); + + /** Not a Field */ + if (gridField.isHeading()) + { + return null; + } + + /** String (clear/password) */ + if (displayType == DisplayType.String + || displayType == DisplayType.PrinterName + || (tableEditor && (displayType == DisplayType.Text || displayType == DisplayType.TextLong))) + { + if (gridField.isEncryptedField()) + { + editor = new WPasswordEditor(gridField); + } + else + { + editor = new WStringEditor(gridField, tableEditor); + } + } + /** File */ + else if (displayType == DisplayType.FileName) + { + editor = new WFilenameEditor(gridField); + } + /** File Path */ + else if (displayType == DisplayType.FilePath) + { + editor = new WFileDirectoryEditor(gridField); + } + /** Number */ + else if (DisplayType.isNumeric(displayType)) + { + editor = new WNumberEditor(gridField); + } + + /** YesNo */ + else if (displayType == DisplayType.YesNo) + { + editor = new WYesNoEditor(gridField); + if (tableEditor) + ((WYesNoEditor)editor).getComponent().setLabel(""); + } + + /** Text */ + else if (displayType == DisplayType.Text || displayType == DisplayType.Memo || displayType == DisplayType.TextLong) + { + editor = new WStringEditor(gridField); + } + + /** Date */ + else if (DisplayType.isDate(displayType)) + { + if (displayType == DisplayType.Time) + editor = new WTimeEditor(gridField); + else if (displayType == DisplayType.DateTime) + editor = new WDatetimeEditor(gridField); + else + editor = new WDateEditor(gridField); + } + + /** Button */ + else if (displayType == DisplayType.Button) + { + editor = new WButtonEditor(gridField); + } + + /** Table Direct */ + else if (displayType == DisplayType.TableDir || + displayType == DisplayType.Table || displayType == DisplayType.List + || displayType == DisplayType.ID ) + { + editor = new WTableDirEditor(gridField); + } + + else if (displayType == DisplayType.URL) + { + editor = new WUrlEditor(gridField); + } + + else if (displayType == DisplayType.Search) + { + editor = new WSearchEditor(gridField); + } + + else if (displayType == DisplayType.Location) + { + editor = new WLocationEditor(gridField); + } + else if (displayType == DisplayType.Locator) + { + editor = new WLocatorEditor(gridField); + } + else if (displayType == DisplayType.Account) + { + editor = new WAccountEditor(gridField); + } + else if (displayType == DisplayType.Image) + { + editor = new WImageEditor(gridField); + } + else if (displayType == DisplayType.Binary) + { + editor = new WBinaryEditor(gridField); + } + else if (displayType == DisplayType.PAttribute) + { + editor = new WPAttributeEditor(gridTab, gridField); + } + else if (displayType == DisplayType.Assignment) + { + editor = new WAssignmentEditor(gridField); + } + else + { + editor = new WUnknownEditor(gridField); + } + + return editor; + } + +} diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/factory/IEditorFactory.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/factory/IEditorFactory.java new file mode 100644 index 0000000000..098fdd29b4 --- /dev/null +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/factory/IEditorFactory.java @@ -0,0 +1,34 @@ +/****************************************************************************** + * 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.webui.factory; + +import org.adempiere.webui.editor.WEditor; +import org.compiere.model.GridField; +import org.compiere.model.GridTab; + +/** + * + * @author hengsin + * + */ +public interface IEditorFactory { + + /** + * @param gridTab + * @param gridField + * @param tableEditor + * @return WEditor + */ + public WEditor getEditor(GridTab gridTab, GridField gridField, boolean tableEditor); +} diff --git a/org.adempiere.ui.zk/plugin.xml b/org.adempiere.ui.zk/plugin.xml index b8799b7136..cf173cc19d 100644 --- a/org.adempiere.ui.zk/plugin.xml +++ b/org.adempiere.ui.zk/plugin.xml @@ -3,6 +3,7 @@ + + + + + diff --git a/org.adempiere.ui.zk/schema/org.adempiere.webui.factory.IEditorFactory.exsd b/org.adempiere.ui.zk/schema/org.adempiere.webui.factory.IEditorFactory.exsd new file mode 100644 index 0000000000..929e25d6ee --- /dev/null +++ b/org.adempiere.ui.zk/schema/org.adempiere.webui.factory.IEditorFactory.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.] + + + + +