Implemented field editor factory extension for swing client.

This commit is contained in:
Heng Sin Low 2010-11-24 07:38:02 +08:00
parent 6003245f32
commit 993c687788
5 changed files with 458 additions and 241 deletions

View File

@ -4,6 +4,7 @@
<extension-point id="org.adempiere.osgi.IMenuAction" name="MenuAction" schema="schema/org.adempiere.osgi.IMenuAction.exsd"/>
<extension-point id="org.adempiere.apps.Form" name="Form" schema="schema/org.adempiere.apps.Form.exsd"/>
<extension-point id="org.adempiere.osgi.IInfoFactory" name="Info Factory extension" schema="schema/org.adempiere.osgi.IInfoFactory.exsd"/>
<extension-point id="org.adempiere.osgi.IEditorFactory" name="Field editor factory" schema="schema/org.adempiere.osgi.IEditorFactory.exsd"/>
<extension
id="RF"
name="RF"
@ -59,5 +60,14 @@
priority="0">
</factory>
</extension>
<extension
id="org.adempiere.osgi.DefaultEditorFactory"
name="Default field editor factory"
point="org.adempiere.osgi.IEditorFactory">
<factory
class="org.adempiere.osgi.DefaultEditorFactory"
priority="0">
</factory>
</extension>
</plugin>

View File

@ -0,0 +1,109 @@
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
<schema targetNamespace="org.adempiere.ui.swing" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appinfo>
<meta.schema plugin="org.adempiere.ui.swing" id="org.adempiere.osgi.IEditorFactory" name="Field editor factory"/>
</appinfo>
<documentation>
[Enter description of this extension point.]
</documentation>
</annotation>
<element name="extension">
<annotation>
<appinfo>
<meta.element />
</appinfo>
</annotation>
<complexType>
<choice>
<element ref="factory"/>
</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="factory">
<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.osgi.IEditorFactory"/>
</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,292 @@
/******************************************************************************
* 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.osgi;
import org.compiere.grid.ed.ADempiereAutoCompleteDecorator;
import org.compiere.grid.ed.VAccount;
import org.compiere.grid.ed.VAssignment;
import org.compiere.grid.ed.VBinary;
import org.compiere.grid.ed.VButton;
import org.compiere.grid.ed.VCheckBox;
import org.compiere.grid.ed.VColor;
import org.compiere.grid.ed.VDate;
import org.compiere.grid.ed.VEditor;
import org.compiere.grid.ed.VFile;
import org.compiere.grid.ed.VImage;
import org.compiere.grid.ed.VLocation;
import org.compiere.grid.ed.VLocator;
import org.compiere.grid.ed.VLookup;
import org.compiere.grid.ed.VMemo;
import org.compiere.grid.ed.VNumber;
import org.compiere.grid.ed.VPAttribute;
import org.compiere.grid.ed.VPassword;
import org.compiere.grid.ed.VString;
import org.compiere.grid.ed.VText;
import org.compiere.grid.ed.VTextLong;
import org.compiere.grid.ed.VURL;
import org.compiere.model.GridField;
import org.compiere.model.GridTab;
import org.compiere.model.MAccountLookup;
import org.compiere.model.MLocationLookup;
import org.compiere.model.MLocatorLookup;
import org.compiere.model.MPAttributeLookup;
import org.compiere.util.DisplayType;
/**
*
* @author hengsin
*
*/
public class DefaultEditorFactory implements IEditorFactory {
@Override
public VEditor getEditor(GridTab mTab, GridField mField, boolean tableEditor) {
if (mField == null)
return null;
VEditor editor = null;
int displayType = mField.getDisplayType();
String columnName = mField.getColumnName();
boolean mandatory = mField.isMandatory(false); // no context check
boolean readOnly = mField.isReadOnly();
boolean updateable = mField.isUpdateable();
int WindowNo = mField.getWindowNo();
// Not a Field
if (mField.isHeading())
return null;
// String (clear/password)
if (displayType == DisplayType.String
|| displayType == DisplayType.PrinterName
|| (tableEditor && (displayType == DisplayType.Text || displayType == DisplayType.TextLong)) )
{
if (mField.isEncryptedField())
{
VPassword vs = new VPassword (columnName, mandatory, readOnly, updateable,
mField.getDisplayLength(), mField.getFieldLength(), mField.getVFormat());
vs.setName (columnName);
vs.setField (mField);
editor = vs;
}
else
{
VString vs = new VString (columnName, mandatory, readOnly, updateable,
mField.getDisplayLength(), mField.getFieldLength(),
mField.getVFormat(), mField.getObscureType());
vs.setName (columnName);
vs.setField (mField);
if (mField.isAutocomplete()) {
ADempiereAutoCompleteDecorator.decorate(vs, mField.getEntries(), false);
}
editor = vs;
}
}
// URL
else if (displayType == DisplayType.URL)
{
VURL vs = new VURL (columnName, mandatory, readOnly, updateable,
mField.getDisplayLength(), mField.getFieldLength());
vs.setName (columnName);
vs.setField (mField);
editor = vs;
}
/** Printer Name
else if (displayType == DisplayType.PrinterName)
{
VPrinterName vs = new VPrinterName (columnName, mandatory, readOnly, updateable,
mField.getDisplayLength(), mField.getFieldLength(), mField.getVFormat());
vs.setName (columnName);
vs.setField (mField);
editor = vs;
} **/
// File Path / Name
else if (displayType == DisplayType.FilePath || displayType == DisplayType.FileName)
{
VFile file = new VFile (columnName, mandatory, readOnly, updateable,
mField.getFieldLength(), displayType == DisplayType.FileName);
file.setName(columnName);
file.setField(mField);
editor = file;
}
// Lookup
else if (DisplayType.isLookup(displayType) || displayType == DisplayType.ID)
{
VLookup vl = new VLookup(columnName, mandatory, readOnly, updateable,
mField.getLookup());
vl.setName(columnName);
vl.setField (mField);
editor = vl;
}
// Number
else if (DisplayType.isNumeric(displayType))
{
VNumber vn = new VNumber(columnName, mandatory, readOnly, updateable,
displayType, mField.getHeader());
vn.setRange(mField.getValueMin(), mField.getValueMax());
vn.setName(columnName);
vn.setField (mField);
editor = vn;
}
// YesNo
else if (displayType == DisplayType.YesNo)
{
VCheckBox vc = new VCheckBox(columnName, mandatory, readOnly, updateable,
mField.getHeader(), mField.getDescription(), tableEditor);
vc.setName(columnName);
vc.setField (mField);
editor = vc;
}
// Text (single row)
else if (displayType == DisplayType.Text)
{
VText vt = new VText(columnName, mandatory, readOnly, updateable,
mField.getDisplayLength(), mField.getFieldLength());
vt.setName(columnName);
vt.setField (mField);
editor = vt;
}
// Memo (single row)
else if (displayType == DisplayType.Memo)
{
VMemo vt = new VMemo(columnName, mandatory, readOnly, updateable,
mField.getDisplayLength(), mField.getFieldLength());
vt.setName(columnName);
vt.setField (mField);
editor = vt;
}
// Date
else if (DisplayType.isDate(displayType))
{
if (displayType == DisplayType.DateTime)
readOnly = true;
VDate vd = new VDate(columnName, mandatory, readOnly, updateable,
displayType, mField.getHeader());
vd.setName(columnName);
vd.setField (mField);
editor = vd;
}
// Location
else if (displayType == DisplayType.Location)
{
VLocation loc = new VLocation (mTab, columnName, mandatory, readOnly, updateable,
(MLocationLookup)mField.getLookup());
loc.setName(columnName);
loc.setField (mField);
editor = loc;
}
// Locator
else if (displayType == DisplayType.Locator)
{
VLocator loc = new VLocator (columnName, mandatory, readOnly, updateable,
(MLocatorLookup)mField.getLookup(), WindowNo);
loc.setName(columnName);
loc.setField (mField);
editor = loc;
}
// Account
else if (displayType == DisplayType.Account)
{
//hengsin: bug [ 1711795 ] Combination copied itself in Grid mode
/*
VAccount acct = new VAccount (columnName, mandatory, readOnly, updateable,
(MAccountLookup)mField.getLookup(), mField.getHeader());*/
VAccount acct = new VAccount (columnName, mandatory, readOnly, updateable,
new MAccountLookup (mField.getVO().ctx, mField.getWindowNo()), mField.getHeader());
acct.setName(columnName);
acct.setField (mField);
editor = acct;
}
// Button
else if (displayType == DisplayType.Button)
{
VButton button = new VButton(columnName, mandatory, readOnly, updateable,
mField.getHeader(), mField.getDescription(), mField.getHelp(), mField.getAD_Process_ID());
button.setName(columnName);
button.setField (mField);
editor = button;
}
// Assignment
else if (displayType == DisplayType.Assignment)
{
VAssignment assign = new VAssignment (mandatory, readOnly, updateable);
assign.setName(columnName);
assign.setField (mField);
editor = assign;
}
// Color
else if (displayType == DisplayType.Color)
{
VColor color = new VColor (mTab, mandatory, readOnly);
color.setName(columnName);
color.setField (mField);
editor = color;
}
// Image
else if (displayType == DisplayType.Image)
{
VImage image = new VImage (columnName, WindowNo);
image.setName(columnName);
image.setField (mField);
editor = image;
}
// PAttribute
else if (displayType == DisplayType.PAttribute)
{
VPAttribute attrib = new VPAttribute (mTab, mandatory, readOnly, updateable, WindowNo,
(MPAttributeLookup)mField.getLookup());
attrib.setName(columnName);
attrib.setField (mField);
editor = attrib;
}
// Long Text (CLob)
else if (displayType == DisplayType.TextLong)
{
VTextLong vt = new VTextLong (columnName, mandatory, readOnly, updateable,
mField.getDisplayLength(), mField.getFieldLength());
vt.setName(columnName);
vt.setField (mField);
editor = vt;
}
// Binary (BLob)
else if (displayType == DisplayType.Binary)
{
VBinary bin = new VBinary (columnName, WindowNo);
bin.setName(columnName);
bin.setField (mField);
editor = bin;
}
return editor;
}
}

View File

@ -0,0 +1,36 @@
/******************************************************************************
* 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.osgi;
import org.compiere.grid.ed.VEditor;
import org.compiere.model.GridField;
import org.compiere.model.GridTab;
/**
*
* @author hengsin
*
*/
public interface IEditorFactory {
/**
* Create Editor for MField.
* The Name is set to the column name for dynamic display management
* @param mTab MTab
* @param mField MField
* @param tableEditor true if table editor
* @return grid editor
*/
public VEditor getEditor (GridTab mTab, GridField mField, boolean tableEditor);
}

View File

@ -16,14 +16,12 @@
*****************************************************************************/
package org.compiere.grid.ed;
import java.util.logging.Level;
import java.util.List;
import org.adempiere.base.Service;
import org.adempiere.osgi.IEditorFactory;
import org.compiere.model.GridField;
import org.compiere.model.GridTab;
import org.compiere.model.MAccountLookup;
import org.compiere.model.MLocationLookup;
import org.compiere.model.MLocatorLookup;
import org.compiere.model.MPAttributeLookup;
import org.compiere.swing.CLabel;
import org.compiere.util.CLogger;
import org.compiere.util.DisplayType;
@ -59,243 +57,14 @@ public class VEditorFactory
*/
public static VEditor getEditor (GridTab mTab, GridField mField, boolean tableEditor)
{
if (mField == null)
return null;
VEditor editor = null;
int displayType = mField.getDisplayType();
String columnName = mField.getColumnName();
boolean mandatory = mField.isMandatory(false); // no context check
boolean readOnly = mField.isReadOnly();
boolean updateable = mField.isUpdateable();
int WindowNo = mField.getWindowNo();
// Not a Field
if (mField.isHeading())
return null;
// String (clear/password)
if (displayType == DisplayType.String
|| displayType == DisplayType.PrinterName
|| (tableEditor && (displayType == DisplayType.Text || displayType == DisplayType.TextLong)) )
List<IEditorFactory> factoryList = Service.list(IEditorFactory.class);
for(IEditorFactory factory : factoryList)
{
if (mField.isEncryptedField())
{
VPassword vs = new VPassword (columnName, mandatory, readOnly, updateable,
mField.getDisplayLength(), mField.getFieldLength(), mField.getVFormat());
vs.setName (columnName);
vs.setField (mField);
editor = vs;
editor = factory.getEditor(mTab, mField, tableEditor);
if (editor != null)
break;
}
else
{
VString vs = new VString (columnName, mandatory, readOnly, updateable,
mField.getDisplayLength(), mField.getFieldLength(),
mField.getVFormat(), mField.getObscureType());
vs.setName (columnName);
vs.setField (mField);
if (mField.isAutocomplete()) {
ADempiereAutoCompleteDecorator.decorate(vs, mField.getEntries(), false);
}
editor = vs;
}
}
// URL
else if (displayType == DisplayType.URL)
{
VURL vs = new VURL (columnName, mandatory, readOnly, updateable,
mField.getDisplayLength(), mField.getFieldLength());
vs.setName (columnName);
vs.setField (mField);
editor = vs;
}
/** Printer Name
else if (displayType == DisplayType.PrinterName)
{
VPrinterName vs = new VPrinterName (columnName, mandatory, readOnly, updateable,
mField.getDisplayLength(), mField.getFieldLength(), mField.getVFormat());
vs.setName (columnName);
vs.setField (mField);
editor = vs;
} **/
// File Path / Name
else if (displayType == DisplayType.FilePath || displayType == DisplayType.FileName)
{
VFile file = new VFile (columnName, mandatory, readOnly, updateable,
mField.getFieldLength(), displayType == DisplayType.FileName);
file.setName(columnName);
file.setField(mField);
editor = file;
}
// Lookup
else if (DisplayType.isLookup(displayType) || displayType == DisplayType.ID)
{
VLookup vl = new VLookup(columnName, mandatory, readOnly, updateable,
mField.getLookup());
vl.setName(columnName);
vl.setField (mField);
editor = vl;
}
// Number
else if (DisplayType.isNumeric(displayType))
{
VNumber vn = new VNumber(columnName, mandatory, readOnly, updateable,
displayType, mField.getHeader());
vn.setRange(mField.getValueMin(), mField.getValueMax());
vn.setName(columnName);
vn.setField (mField);
editor = vn;
}
// YesNo
else if (displayType == DisplayType.YesNo)
{
VCheckBox vc = new VCheckBox(columnName, mandatory, readOnly, updateable,
mField.getHeader(), mField.getDescription(), tableEditor);
vc.setName(columnName);
vc.setField (mField);
editor = vc;
}
// Text (single row)
else if (displayType == DisplayType.Text)
{
VText vt = new VText(columnName, mandatory, readOnly, updateable,
mField.getDisplayLength(), mField.getFieldLength());
vt.setName(columnName);
vt.setField (mField);
editor = vt;
}
// Memo (single row)
else if (displayType == DisplayType.Memo)
{
VMemo vt = new VMemo(columnName, mandatory, readOnly, updateable,
mField.getDisplayLength(), mField.getFieldLength());
vt.setName(columnName);
vt.setField (mField);
editor = vt;
}
// Date
else if (DisplayType.isDate(displayType))
{
if (displayType == DisplayType.DateTime)
readOnly = true;
VDate vd = new VDate(columnName, mandatory, readOnly, updateable,
displayType, mField.getHeader());
vd.setName(columnName);
vd.setField (mField);
editor = vd;
}
// Location
else if (displayType == DisplayType.Location)
{
VLocation loc = new VLocation (mTab, columnName, mandatory, readOnly, updateable,
(MLocationLookup)mField.getLookup());
loc.setName(columnName);
loc.setField (mField);
editor = loc;
}
// Locator
else if (displayType == DisplayType.Locator)
{
VLocator loc = new VLocator (columnName, mandatory, readOnly, updateable,
(MLocatorLookup)mField.getLookup(), WindowNo);
loc.setName(columnName);
loc.setField (mField);
editor = loc;
}
// Account
else if (displayType == DisplayType.Account)
{
//hengsin: bug [ 1711795 ] Combination copied itself in Grid mode
/*
VAccount acct = new VAccount (columnName, mandatory, readOnly, updateable,
(MAccountLookup)mField.getLookup(), mField.getHeader());*/
VAccount acct = new VAccount (columnName, mandatory, readOnly, updateable,
new MAccountLookup (mField.getVO().ctx, mField.getWindowNo()), mField.getHeader());
acct.setName(columnName);
acct.setField (mField);
editor = acct;
}
// Button
else if (displayType == DisplayType.Button)
{
VButton button = new VButton(columnName, mandatory, readOnly, updateable,
mField.getHeader(), mField.getDescription(), mField.getHelp(), mField.getAD_Process_ID());
button.setName(columnName);
button.setField (mField);
editor = button;
}
// Assignment
else if (displayType == DisplayType.Assignment)
{
VAssignment assign = new VAssignment (mandatory, readOnly, updateable);
assign.setName(columnName);
assign.setField (mField);
editor = assign;
}
// Color
else if (displayType == DisplayType.Color)
{
VColor color = new VColor (mTab, mandatory, readOnly);
color.setName(columnName);
color.setField (mField);
editor = color;
}
// Image
else if (displayType == DisplayType.Image)
{
VImage image = new VImage (columnName, WindowNo);
image.setName(columnName);
image.setField (mField);
editor = image;
}
// PAttribute
else if (displayType == DisplayType.PAttribute)
{
VPAttribute attrib = new VPAttribute (mTab, mandatory, readOnly, updateable, WindowNo,
(MPAttributeLookup)mField.getLookup());
attrib.setName(columnName);
attrib.setField (mField);
editor = attrib;
}
// Long Text (CLob)
else if (displayType == DisplayType.TextLong)
{
VTextLong vt = new VTextLong (columnName, mandatory, readOnly, updateable,
mField.getDisplayLength(), mField.getFieldLength());
vt.setName(columnName);
vt.setField (mField);
editor = vt;
}
// Binary (BLob)
else if (displayType == DisplayType.Binary)
{
VBinary bin = new VBinary (columnName, WindowNo);
bin.setName(columnName);
bin.setField (mField);
editor = bin;
}
else
log.log(Level.WARNING, columnName + " - Unknown Type: " + displayType);
return editor;
} // getEditor
@ -327,6 +96,7 @@ public class VEditorFactory
} // getLabel
/** Logger */
@SuppressWarnings("unused")
private static CLogger log = CLogger.getCLogger(VEditorFactory.class);