[ 2165298 ] Calculator manage different decimal point than numeric field

This commit is contained in:
Heng Sin Low 2008-12-30 07:51:23 +00:00
parent 74e5ff4a59
commit 61a018f5f5
4 changed files with 34 additions and 9 deletions

View File

@ -23,6 +23,8 @@ import java.text.ParseException;
import org.adempiere.webui.LayoutUtils; import org.adempiere.webui.LayoutUtils;
import org.adempiere.webui.apps.AEnv; import org.adempiere.webui.apps.AEnv;
import org.compiere.util.DisplayType;
import org.compiere.util.Env;
import org.zkoss.zhtml.Table; import org.zkoss.zhtml.Table;
import org.zkoss.zhtml.Td; import org.zkoss.zhtml.Td;
import org.zkoss.zhtml.Tr; import org.zkoss.zhtml.Tr;
@ -191,10 +193,12 @@ public class NumberBox extends Div
Vbox vbox = new Vbox(); Vbox vbox = new Vbox();
char separatorChar = DisplayType.getNumberFormat(DisplayType.Number, Env.getLanguage(Env.getCtx())).getDecimalFormatSymbols().getDecimalSeparator();
txtCalc = new Textbox(); txtCalc = new Textbox();
txtCalc.setAction("onKeyPress : return calc.validate('" + txtCalc.setAction("onKeyPress : return calc.validate('" +
decimalBox.getId() + "','" + txtCalc.getId() decimalBox.getId() + "','" + txtCalc.getId()
+ "'," + integral + ", event);"); + "'," + integral + "," + (int)separatorChar + ", event);");
txtCalc.setMaxlength(250); txtCalc.setMaxlength(250);
txtCalc.setCols(30); txtCalc.setCols(30);
@ -312,17 +316,18 @@ public class NumberBox extends Div
btn0.setLabel("0"); btn0.setLabel("0");
btn0.setAction("onClick : calc.append('" + txtCalcId + "', '0')"); btn0.setAction("onClick : calc.append('" + txtCalcId + "', '0')");
String separator = Character.toString(separatorChar);
Button btnDot = new Button(); Button btnDot = new Button();
btnDot.setWidth("30px"); btnDot.setWidth("30px");
btnDot.setLabel("."); btnDot.setLabel(separator);
btnDot.setDisabled(integral); btnDot.setDisabled(integral);
btnDot.setAction("onClick : calc.append('" + txtCalcId + "', '.')"); btnDot.setAction("onClick : calc.append('" + txtCalcId + "', '" + separator + "')");
Button btnEqual = new Button(); Button btnEqual = new Button();
btnEqual.setWidth("30px"); btnEqual.setWidth("30px");
btnEqual.setLabel("="); btnEqual.setLabel("=");
btnEqual.setAction("onClick : calc.evaluate('" + decimalBox.getId() + "','" btnEqual.setAction("onClick : calc.evaluate('" + decimalBox.getId() + "','"
+ txtCalcId + "')"); + txtCalcId + "','" + separator + "')");
Button btnAdd = new Button(); Button btnAdd = new Button();
btnAdd.setWidth("30px"); btnAdd.setWidth("30px");

View File

@ -27,6 +27,7 @@ import org.adempiere.webui.event.ValueChangeEvent;
import org.compiere.model.GridField; import org.compiere.model.GridField;
import org.compiere.model.MRole; import org.compiere.model.MRole;
import org.compiere.util.DisplayType; import org.compiere.util.DisplayType;
import org.compiere.util.Env;
import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.Events; import org.zkoss.zk.ui.event.Events;
@ -106,7 +107,7 @@ public class WNumberEditor extends WEditor
if (!DisplayType.isNumeric(displayType)) if (!DisplayType.isNumeric(displayType))
displayType = DisplayType.Number; displayType = DisplayType.Number;
DecimalFormat format = DisplayType.getNumberFormat(displayType); DecimalFormat format = DisplayType.getNumberFormat(displayType, Env.getLanguage(Env.getCtx()));
getComponent().getDecimalbox().setFormat(format.toPattern()); getComponent().getDecimalbox().setFormat(format.toPattern());
} }

View File

@ -19,6 +19,8 @@ package org.adempiere.webui.session;
import java.util.List; import java.util.List;
import org.compiere.util.Env;
import org.zkoss.util.Locales;
import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Execution; import org.zkoss.zk.ui.Execution;
import org.zkoss.zk.ui.Executions; import org.zkoss.zk.ui.Executions;
@ -54,6 +56,9 @@ public class SessionContextListener implements ExecutionInit,
ServerContext.setCurrentInstance(ctx); ServerContext.setCurrentInstance(ctx);
} }
exec.setAttribute(SESSION_CTX, ctx); exec.setAttribute(SESSION_CTX, ctx);
//set locale
Locales.setThreadLocal(Env.getLanguage(ctx).getLocale());
} }
} }
@ -76,6 +81,9 @@ public class SessionContextListener implements ExecutionInit,
SESSION_CTX); SESSION_CTX);
ServerContext.setCurrentInstance(ctx); ServerContext.setCurrentInstance(ctx);
// set locale
Locales.setThreadLocal(Env.getLanguage(ctx).getLocale());
return true; return true;
} }

View File

@ -7,7 +7,7 @@ function Calc()
this.evaluate = evaluate; this.evaluate = evaluate;
this.append = append; this.append = append;
function validate(displayTextId, calcTextId, integral, e) function validate(displayTextId, calcTextId, integral, separatorKey, e)
{ {
var key; var key;
@ -45,7 +45,7 @@ function Calc()
{ {
return true; return true;
} }
else if ( key == 46 && !integral) else if ( key == separatorKey && !integral)
{ {
return true; return true;
} }
@ -85,12 +85,23 @@ function Calc()
} }
function evaluate(displayTextId, calcTextId) function evaluate(displayTextId, calcTextId, separator)
{ {
try try
{ {
var calcText = document.getElementById(calcTextId); var calcText = document.getElementById(calcTextId);
calcText.value = eval(calcText.value); var value = calcText.value;
if (separator != '.')
{
var re = new RegExp("[" + separator + "]");
value = value.replace(re,'.');
}
var result = "" + eval(value);
if (separator != '.')
{
result = result.replace(/\./, separator);
}
calcText.value = result;
var displayText = document.getElementById(displayTextId); var displayText = document.getElementById(displayTextId);