IDEMPIERE-878 WebServices casts wrong / Custom DisplayType / Load DisplayTypes via OSGI. Merge custom display type patch from Jan Thielemann.
This commit is contained in:
parent
ff9ced3152
commit
870bf1e773
|
@ -0,0 +1,51 @@
|
||||||
|
/******************************************************************************
|
||||||
|
* Copyright (C) 2013 Jan Thielemann - jan.thielemann@evenos-consulting.de *
|
||||||
|
* 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 java.text.DecimalFormat;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
|
||||||
|
import org.compiere.util.Language;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Jan Thielemann - jan.thielemann@evenos-consulting.de
|
||||||
|
* @author evenos Consulting GmbH - www.evenos.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
public interface IDisplayTypeFactory {
|
||||||
|
|
||||||
|
public boolean isID(int displayType);
|
||||||
|
public boolean isNumeric(int displayType);
|
||||||
|
public Integer getDefaultPrecision(int displayType);
|
||||||
|
public boolean isText(int displayType);
|
||||||
|
public boolean isDate (int displayType);
|
||||||
|
public boolean isLookup(int displayType);
|
||||||
|
public boolean isLOB (int displayType);
|
||||||
|
public DecimalFormat getNumberFormat(int displayType, Language language, String pattern);
|
||||||
|
public SimpleDateFormat getDateFormat (int displayType, Language language, String pattern);
|
||||||
|
public Class<?> getClass (int displayType, boolean yesNoAsBoolean);
|
||||||
|
public String getSQLDataType (int displayType, String columnName, int fieldLength);
|
||||||
|
public String getDescription (int displayType);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -50,12 +50,16 @@ import static org.compiere.model.SystemIDs.REFERENCE_DATATYPE_TIME;
|
||||||
import static org.compiere.model.SystemIDs.REFERENCE_DATATYPE_URL;
|
import static org.compiere.model.SystemIDs.REFERENCE_DATATYPE_URL;
|
||||||
import static org.compiere.model.SystemIDs.REFERENCE_DATATYPE_YES_NO;
|
import static org.compiere.model.SystemIDs.REFERENCE_DATATYPE_YES_NO;
|
||||||
|
|
||||||
|
import org.adempiere.base.IDisplayTypeFactory;
|
||||||
|
import org.adempiere.base.Service;
|
||||||
|
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import java.text.NumberFormat;
|
import java.text.NumberFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* System Display Types.
|
* System Display Types.
|
||||||
|
@ -184,6 +188,13 @@ public final class DisplayType
|
||||||
|| displayType == Account || displayType == Assignment || displayType == PAttribute
|
|| displayType == Account || displayType == Assignment || displayType == PAttribute
|
||||||
|| displayType == Image || displayType == Color)
|
|| displayType == Image || displayType == Color)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
List<IDisplayTypeFactory> factoryList = Service.locator().list(IDisplayTypeFactory.class).getServices();
|
||||||
|
for(IDisplayTypeFactory factory : factoryList){
|
||||||
|
if(factory.isID(displayType))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
} // isID
|
} // isID
|
||||||
|
|
||||||
|
@ -198,6 +209,13 @@ public final class DisplayType
|
||||||
if (displayType == Amount || displayType == Number || displayType == CostPrice
|
if (displayType == Amount || displayType == Number || displayType == CostPrice
|
||||||
|| displayType == Integer || displayType == Quantity)
|
|| displayType == Integer || displayType == Quantity)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
List<IDisplayTypeFactory> factoryList = Service.locator().list(IDisplayTypeFactory.class).getServices();
|
||||||
|
for(IDisplayTypeFactory factory : factoryList){
|
||||||
|
if(factory.isNumeric(displayType))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
} // isNumeric
|
} // isNumeric
|
||||||
|
|
||||||
|
@ -216,6 +234,14 @@ public final class DisplayType
|
||||||
if (displayType == CostPrice
|
if (displayType == CostPrice
|
||||||
|| displayType == Quantity)
|
|| displayType == Quantity)
|
||||||
return 4;
|
return 4;
|
||||||
|
|
||||||
|
List<IDisplayTypeFactory> factoryList = Service.locator().list(IDisplayTypeFactory.class).getServices();
|
||||||
|
for(IDisplayTypeFactory factory : factoryList){
|
||||||
|
if(factory.getDefaultPrecision(displayType) != null)
|
||||||
|
return factory.getDefaultPrecision(displayType).intValue();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
} // getDefaultPrecision
|
} // getDefaultPrecision
|
||||||
|
|
||||||
|
@ -232,6 +258,12 @@ public final class DisplayType
|
||||||
|| displayType == FilePath || displayType == FileName
|
|| displayType == FilePath || displayType == FileName
|
||||||
|| displayType == URL || displayType == PrinterName)
|
|| displayType == URL || displayType == PrinterName)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
List<IDisplayTypeFactory> factoryList = Service.locator().list(IDisplayTypeFactory.class).getServices();
|
||||||
|
for(IDisplayTypeFactory factory : factoryList){
|
||||||
|
if(factory.isText(displayType))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
} // isText
|
} // isText
|
||||||
|
|
||||||
|
@ -245,6 +277,13 @@ public final class DisplayType
|
||||||
{
|
{
|
||||||
if (displayType == Date || displayType == DateTime || displayType == Time)
|
if (displayType == Date || displayType == DateTime || displayType == Time)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
List<IDisplayTypeFactory> factoryList = Service.locator().list(IDisplayTypeFactory.class).getServices();
|
||||||
|
for(IDisplayTypeFactory factory : factoryList){
|
||||||
|
if(factory.isDate(displayType))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
} // isDate
|
} // isDate
|
||||||
|
|
||||||
|
@ -259,6 +298,13 @@ public final class DisplayType
|
||||||
if (displayType == List || displayType == Table
|
if (displayType == List || displayType == Table
|
||||||
|| displayType == TableDir || displayType == Search)
|
|| displayType == TableDir || displayType == Search)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
List<IDisplayTypeFactory> factoryList = Service.locator().list(IDisplayTypeFactory.class).getServices();
|
||||||
|
for(IDisplayTypeFactory factory : factoryList){
|
||||||
|
if(factory.isLookup(displayType))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
} // isLookup
|
} // isLookup
|
||||||
|
|
||||||
|
@ -272,6 +318,13 @@ public final class DisplayType
|
||||||
if (displayType == Binary
|
if (displayType == Binary
|
||||||
|| displayType == TextLong)
|
|| displayType == TextLong)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
List<IDisplayTypeFactory> factoryList = Service.locator().list(IDisplayTypeFactory.class).getServices();
|
||||||
|
for(IDisplayTypeFactory factory : factoryList){
|
||||||
|
if(factory.isLOB(displayType))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
} // isLOB
|
} // isLOB
|
||||||
|
|
||||||
|
@ -327,8 +380,16 @@ public final class DisplayType
|
||||||
format.setMaximumFractionDigits(MAX_FRACTION);
|
format.setMaximumFractionDigits(MAX_FRACTION);
|
||||||
format.setMinimumFractionDigits(AMOUNT_FRACTION);
|
format.setMinimumFractionDigits(AMOUNT_FRACTION);
|
||||||
}
|
}
|
||||||
else // if (displayType == Number)
|
else
|
||||||
{
|
{
|
||||||
|
List<IDisplayTypeFactory> factoryList = Service.locator().list(IDisplayTypeFactory.class).getServices();
|
||||||
|
for(IDisplayTypeFactory factory : factoryList){
|
||||||
|
DecimalFormat osgiFormat = factory.getNumberFormat(displayType, myLanguage, pattern);
|
||||||
|
if(osgiFormat!=null){
|
||||||
|
return osgiFormat;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
format.setMaximumIntegerDigits(MAX_DIGITS);
|
format.setMaximumIntegerDigits(MAX_DIGITS);
|
||||||
format.setMaximumFractionDigits(MAX_FRACTION);
|
format.setMaximumFractionDigits(MAX_FRACTION);
|
||||||
format.setMinimumFractionDigits(1);
|
format.setMinimumFractionDigits(1);
|
||||||
|
@ -426,6 +487,15 @@ public final class DisplayType
|
||||||
return myLanguage.getDateTimeFormat();
|
return myLanguage.getDateTimeFormat();
|
||||||
else if (displayType == Time)
|
else if (displayType == Time)
|
||||||
return myLanguage.getTimeFormat();
|
return myLanguage.getTimeFormat();
|
||||||
|
else{
|
||||||
|
List<IDisplayTypeFactory> factoryList = Service.locator().list(IDisplayTypeFactory.class).getServices();
|
||||||
|
for(IDisplayTypeFactory factory : factoryList){
|
||||||
|
SimpleDateFormat osgiFormat = factory.getDateFormat(displayType, myLanguage, pattern);
|
||||||
|
if(osgiFormat!=null)
|
||||||
|
return osgiFormat;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// else if (displayType == Date)
|
// else if (displayType == Date)
|
||||||
return myLanguage.getDateFormat(); // default
|
return myLanguage.getDateFormat(); // default
|
||||||
} // getDateFormat
|
} // getDateFormat
|
||||||
|
@ -476,6 +546,15 @@ public final class DisplayType
|
||||||
return String.class;
|
return String.class;
|
||||||
else if (isLOB(displayType)) // CLOB is String
|
else if (isLOB(displayType)) // CLOB is String
|
||||||
return byte[].class;
|
return byte[].class;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
List<IDisplayTypeFactory> factoryList = Service.locator().list(IDisplayTypeFactory.class).getServices();
|
||||||
|
for(IDisplayTypeFactory factory : factoryList){
|
||||||
|
Class<?> osgiClass = factory.getClass(displayType, yesNoAsBoolean);
|
||||||
|
if(osgiClass!=null)
|
||||||
|
return osgiClass;
|
||||||
|
}
|
||||||
|
}
|
||||||
//
|
//
|
||||||
return Object.class;
|
return Object.class;
|
||||||
} // getClass
|
} // getClass
|
||||||
|
@ -542,6 +621,14 @@ public final class DisplayType
|
||||||
else
|
else
|
||||||
return "CHAR(" + fieldLength + ")";
|
return "CHAR(" + fieldLength + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<IDisplayTypeFactory> factoryList = Service.locator().list(IDisplayTypeFactory.class).getServices();
|
||||||
|
for(IDisplayTypeFactory factory : factoryList){
|
||||||
|
String osgiSQLDataType = factory.getSQLDataType(displayType, columnName, fieldLength);
|
||||||
|
if(osgiSQLDataType!=null)
|
||||||
|
return osgiSQLDataType;
|
||||||
|
}
|
||||||
|
|
||||||
if (!DisplayType.isText(displayType))
|
if (!DisplayType.isText(displayType))
|
||||||
s_log.severe("Unhandled Data Type = " + displayType);
|
s_log.severe("Unhandled Data Type = " + displayType);
|
||||||
|
|
||||||
|
@ -621,6 +708,14 @@ public final class DisplayType
|
||||||
return "PrinterName";
|
return "PrinterName";
|
||||||
if (displayType == Payment)
|
if (displayType == Payment)
|
||||||
return "Payment";
|
return "Payment";
|
||||||
|
|
||||||
|
List<IDisplayTypeFactory> factoryList = Service.locator().list(IDisplayTypeFactory.class).getServices();
|
||||||
|
for(IDisplayTypeFactory factory : factoryList){
|
||||||
|
String osgiDescription = factory.getDescription(displayType);
|
||||||
|
if(osgiDescription!=null)
|
||||||
|
return osgiDescription;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
return "UNKNOWN DisplayType=" + displayType;
|
return "UNKNOWN DisplayType=" + displayType;
|
||||||
} // getDescription
|
} // getDescription
|
||||||
|
|
Loading…
Reference in New Issue