* revert revision 12190.

* improve the dynamic translation of swing form and process classname in db, removing the need of extension to use the ADClassNameMap class.
Link to SF Tracker: http://sourceforge.net/support/tracker.php?aid=2898490
This commit is contained in:
Heng Sin Low 2010-05-02 16:37:18 +00:00
parent f204c5662f
commit 85b684429b
6 changed files with 235 additions and 51 deletions

View File

@ -888,7 +888,7 @@ public class LayoutEngine implements Pageable, Printable, Doc
*/
public boolean isXspaceFor (float width)
{
return (getXspace()-width) > 0f;
return (getXspace()-width) >= 0f;
} // isXspaceFor
/**
@ -913,7 +913,7 @@ public class LayoutEngine implements Pageable, Printable, Doc
*/
public boolean isYspaceFor (float height)
{
return (getYspace()-height) > 0f;
return (getYspace()-height) >= 0f;
} // isYspaceFor
/**************************************************************************

View File

@ -551,6 +551,8 @@ public class TableElement extends PrintElement
m_headerHeight += (4*m_tFormat.getLineStroke().floatValue()) + (2*V_GAP); // Thick lines
p_height += m_headerHeight;
// Last row Lines
p_height += m_tFormat.getLineStroke().floatValue(); // last fat line
// Page Layout *******************************************************
@ -575,6 +577,13 @@ public class TableElement extends PrintElement
float rowHeight = ((Float)m_rowHeights.get(dataRow)).floatValue();
// Y page break before
boolean pageBreak = isPageBreak(dataRow);
//adjust for lastrow
if (dataRow + 1 == m_rowHeights.size())
{
availableHeight -= m_tFormat.getLineStroke().floatValue();
}
if (!pageBreak && availableHeight < rowHeight)
{
if (availableHeight > 40 && rowHeight > 40)
@ -663,9 +672,6 @@ public class TableElement extends PrintElement
} // for acc columns
} // multiple - X pages
// Last row Lines
p_height += m_tFormat.getLineStroke().floatValue(); // last fat line
log.fine("Pages=" + getPageCount()
+ " X=" + m_firstColumnOnPage.size() + "/Y=" + m_firstRowOnPage.size()
+ " - Width=" + p_width + ", Height=" + p_height);

View File

@ -460,7 +460,7 @@ public class TrialBalance extends SvrProcess
// Update AccountValue
String sql2 = "UPDATE T_TrialBalance tb SET AccountValue = "
+ "(SELECT Value FROM C_ElementValue ev WHERE ev.C_ElementValue_ID=tb.Account_ID) "
+ "WHERE tb.Account_ID IS NOT NULL";
+ "WHERE tb.Account_ID IS NOT NULL AND tb.AD_PInstance_ID = " + getAD_PInstance_ID();
no = DB.executeUpdate(sql2, get_TrxName());
if (no > 0)
log.fine("Set AccountValue #" + no);

View File

@ -18,17 +18,16 @@
package org.adempiere.webui.panel;
import java.util.logging.Level;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.adempiere.webui.component.Window;
import org.adempiere.webui.exception.ApplicationException;
import org.adempiere.webui.session.SessionManager;
import org.adempiere.common.ADClassNameMap;
import org.adempiere.webui.util.ADClassNameMap;
import org.compiere.model.MForm;
import org.compiere.process.ProcessInfo;
import org.compiere.util.CLogger;
import org.compiere.util.Env;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
@ -130,46 +129,153 @@ public abstract class ADForm extends Window implements EventListener
*/
private static String translateFormClassName(String originalName)
{
String modifiedName;
/* match any field containing the string ".compiere."
* Usually of the form "org.compiere.apps.form.<classname>".
* Although there are special cases which also need handling
*/
final String regex = "(.*)\\.compiere\\.(.*\\.)V(\\w*)$";
//final String regex = "(.*)\\.compiere\\.(.*\\.)V(\\w*)$";
String zkName = null;
/*
* replacement string to translate class paths to the form
* "org.adempiere.webui.apps.form.<classname>"
*/
final String replacementPackage = ".adempiere.webui.";
final String zkPackage = "org.adempiere.webui.";
/*
* replacement string to translate custom form class name from
* "V<name>" to "W<name>"
*/
final String replacementPrefix = "W";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(originalName);
int group = 1;
final String zkPrefix = "W";
final String swingPrefix = "V";
/*
* If no match is found throw an exception stating that the form
* has not been implemented in the webUI
*/
if (matcher.find()== false)
String tail = null;
//first, try replace package
if (originalName.startsWith("org.compiere."))
{
return originalName;
tail = originalName.substring("org.compiere.".length());
}
else if(originalName.startsWith("org.adempiere."))
{
tail = originalName.substring("org.adempiere.".length());
}
if (tail != null)
{
zkName = zkPackage + tail;
try {
Class<?> clazz = ADForm.class.getClassLoader().loadClass(zkName);
if (!isZkFormClass(clazz))
{
zkName = null;
}
} catch (ClassNotFoundException e) {
zkName = null;
}
//try replace package and add W prefix to class name
if (zkName == null)
{
String packageName = zkPackage;
int lastdot = tail.lastIndexOf(".");
String className = null;
if (lastdot >= 0)
{
if (lastdot > 0)
packageName = packageName + tail.substring(0, lastdot+1);
className = tail.substring(lastdot+1);
}
else
{
className = tail;
}
//try convert V* to W*
if (className.startsWith(swingPrefix))
{
zkName = packageName + zkPrefix + className.substring(1);
try {
Class<?> clazz = ADForm.class.getClassLoader().loadClass(zkName);
if (!isZkFormClass(clazz))
{
zkName = null;
}
} catch (ClassNotFoundException e) {
zkName = null;
}
}
//try append W prefix to original class name
if (zkName == null)
{
zkName = packageName + zkPrefix + className;
try {
Class<?> clazz = ADForm.class.getClassLoader().loadClass(zkName);
if (!isZkFormClass(clazz))
{
zkName = null;
}
} catch (ClassNotFoundException e) {
zkName = null;
}
}
}
}
/*
* reconstruct the name using the captured groups and the replacement strings
* not found, try changing only the class name
*/
modifiedName = matcher.group(group++)
+ replacementPackage
+ matcher.group(group++)
+ replacementPrefix
+ matcher.group(group++);
if (zkName == null)
{
int lastdot = originalName.lastIndexOf(".");
String packageName = originalName.substring(0, lastdot);
String className = originalName.substring(lastdot+1);
//try convert V* to W*
if (className.startsWith(swingPrefix))
{
String zkClassName = zkPrefix + className.substring(1);
zkName = packageName + "." + zkClassName;
try {
Class<?> clazz = ADForm.class.getClassLoader().loadClass(zkName);
if (!isZkFormClass(clazz))
{
zkName = null;
}
} catch (ClassNotFoundException e) {
zkName = null;
}
}
return modifiedName;
//try just append W to the original class name
if (zkName == null)
{
String zkClassName = zkPrefix + className;
zkName = packageName + "." + zkClassName;
try {
Class<?> clazz = ADForm.class.getClassLoader().loadClass(zkName);
if (!isZkFormClass(clazz))
{
zkName = null;
}
} catch (ClassNotFoundException e) {
zkName = null;
}
}
if (zkName == null)
{
//finally try whether same name is used for zk
zkName = originalName;
try {
Class<?> clazz = ADForm.class.getClassLoader().loadClass(zkName);
if (!isZkFormClass(clazz))
{
zkName = null;
}
} catch (ClassNotFoundException e) {
zkName = null;
}
}
}
return zkName;
}
private static boolean isZkFormClass(Class<?> clazz) {
return IFormController.class.isAssignableFrom(clazz) || Component.class.isAssignableFrom(clazz);
}
/**
@ -200,12 +306,20 @@ public abstract class ADForm extends Window implements EventListener
webClassName = ADClassNameMap.get(richClassName);
//fallback to dynamic translation
if (webClassName == null || webClassName.trim().length() == 0)
{
webClassName = translateFormClassName(richClassName);
}
if (webClassName == null)
{
throw new ApplicationException("Web UI form not implemented for the swing form " +
richClassName);
}
try
{
// Create instance w/o parameters
obj = Class.forName(webClassName).newInstance();
obj = ADForm.class.getClassLoader().loadClass(webClassName).newInstance();
}
catch (Exception e)
{

View File

@ -13,7 +13,7 @@
*****************************************************************************/
package org.adempiere.webui.process;
import org.adempiere.common.ADClassNameMap;
import org.adempiere.webui.util.ADClassNameMap;
import org.compiere.process.ProcessInfo;
/**
@ -47,14 +47,83 @@ public class WProcessInfo extends ProcessInfo {
}
@Override
public void setClassName(String ClassName) {
String name = ClassName;
if (name != null && name.trim().length() > 0) {
name = ADClassNameMap.get(ClassName);
if (name == null || name.trim().length() == 0) {
name = ClassName;
public void setClassName(String className) {
String zkName = null;
if (className != null && className.trim().length() > 0) {
zkName = ADClassNameMap.get(className);
if (zkName == null)
{
zkName = dynamicTranslate(className);
}
}
super.setClassName(name);
if (zkName == null)
zkName = className;
super.setClassName(zkName);
}
private String dynamicTranslate(String className) {
String zkName = null;
String tail = null;
//null check
if (className == null || className.trim().length() == 0)
return null;
String zkPackage = "org.adempiere.webui.";
String zkPrefix = "W";
//first, try replace package
if (className.startsWith("org.compiere."))
{
tail = className.substring("org.compiere.".length());
}
else if(className.startsWith("org.adempiere."))
{
tail = className.substring("org.adempiere.".length());
}
if (tail != null)
{
zkName = zkPackage + tail;
try {
this.getClass().getClassLoader().loadClass(zkName);
} catch (ClassNotFoundException e) {
zkName = null;
}
//try replace package and add W prefix to class name
if (zkName == null)
{
zkName = zkPackage;
int lastdot = tail.lastIndexOf(".");
if (lastdot >= 0)
{
if (lastdot > 0)
zkName = zkName + tail.substring(0, lastdot+1);
zkName = zkName + zkPrefix + tail.substring(lastdot+1);
}
else
{
zkName = zkName + zkPrefix + tail;
}
try {
this.getClass().getClassLoader().loadClass(zkName);
} catch (ClassNotFoundException e) {
zkName = null;
}
}
}
//try append W prefix to class name
if (zkName == null)
{
int lastdot = className.lastIndexOf(".");
zkName = className.substring(0, lastdot) + ".W" + className.substring(lastdot+1);
try {
this.getClass().getClassLoader().loadClass(zkName);
} catch (ClassNotFoundException e) {
zkName = null;
}
}
return zkName;
}
}

View File

@ -1,4 +1,4 @@
package org.adempiere.common;
package org.adempiere.webui.util;
import java.util.HashMap;
import java.util.Map;
@ -8,12 +8,7 @@ public class ADClassNameMap {
private static Map<String, String> map = new HashMap<String, String>();
static {
map.put("org.compiere.apps.form.ArchiveViewer", "org.adempiere.webui.apps.form.WArchiveViewer");
map.put("org.compiere.apps.wf.WFActivity", "org.adempiere.webui.apps.wf.WWFActivity");
map.put("org.compiere.apps.wf.WFPanel", "org.adempiere.webui.apps.wf.WFEditor");
map.put("org.compiere.process.InvoicePrint", "org.adempiere.webui.process.InvoicePrint");
map.put("org.compiere.process.CacheReset", "org.adempiere.webui.process.CacheReset");
map.put("org.adempiere.apps.graph.ViewPI", "org.adempiere.webui.apps.graph.WViewPI");
}
/**