Implementováno filtrování datového typu BigDecimal do gridů požadavků.
closes #272
This commit is contained in:
@@ -4,6 +4,7 @@ import java.math.BigDecimal;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import static org.apache.commons.lang.StringUtils.strip;
|
||||
|
||||
public class BigDecimalUtils
|
||||
{
|
||||
@@ -23,6 +24,17 @@ public class BigDecimalUtils
|
||||
|
||||
String valueS = value.toPlainString();
|
||||
String searchS = search.toPlainString();
|
||||
|
||||
if (valueS.contains(".") || valueS.contains(",")) {
|
||||
valueS = strip(valueS, "0");
|
||||
valueS = strip(valueS, ".,");
|
||||
}
|
||||
|
||||
if (searchS.contains(".") || searchS.contains(",")) {
|
||||
searchS = strip(searchS, "0");
|
||||
searchS = strip(searchS, ".,");
|
||||
}
|
||||
|
||||
boolean result = (valueS.compareTo(searchS) == 0);
|
||||
|
||||
String s = "search='" + searchS + "', value='" + valueS + "', equal=" + (result ? "true" : "false");
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package info.bukova.isspst.filters;
|
||||
|
||||
import info.bukova.isspst.BigDecimalUtils;
|
||||
import info.bukova.isspst.BooleanUtils;
|
||||
import info.bukova.isspst.DateTimeUtils;
|
||||
import info.bukova.isspst.StringUtils;
|
||||
@@ -48,7 +49,8 @@ public class RequirementFilter implements Filter<Requirement>
|
||||
boolean foundDeliveryDate = DateTimeUtils.isEqualByDateForFilter(item.getDeliveryDate(), condition.getDeliveryDate());
|
||||
boolean foundUser = User.isEqualByUserForFilter(item.getOwnedBy(), condition.getOwnedBy());
|
||||
boolean foundProject = BooleanUtils.isEqualByBooleanValue(item.getProject(), condition.getProject());
|
||||
return (foundNumser && foundReqDate && foundCenter && foundDescription && foundDeliveryDate && foundUser && foundProject);
|
||||
boolean foundSumTotal = BigDecimalUtils.isEqualByDecimalForFilter(item.getSumTotal(), condition.getSumTotal());
|
||||
return (foundNumser && foundReqDate && foundCenter && foundDescription && foundDeliveryDate && foundUser && foundProject && foundSumTotal);
|
||||
}
|
||||
|
||||
@Factory
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
package info.bukova.isspst.ui;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.zkoss.bind.BindContext;
|
||||
import org.zkoss.bind.Converter;
|
||||
import org.zkoss.util.Locales;
|
||||
import org.zkoss.zk.ui.Component;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.ParseException;
|
||||
import java.util.Locale;
|
||||
|
||||
public class BigDecimalFilterConverter implements Converter<String, BigDecimal, Component>
|
||||
{
|
||||
private final static Logger log = LoggerFactory.getLogger(BigDecimalFilterConverter.class.getName());
|
||||
|
||||
@Override
|
||||
public BigDecimal coerceToBean(String str, Component component, BindContext cx)
|
||||
{
|
||||
// BigDecimal val = BigDecimal.ZERO;
|
||||
BigDecimal val = null;
|
||||
|
||||
if (str != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
Locale loc = Locales.getCurrent();
|
||||
DecimalFormat format = (DecimalFormat) DecimalFormat.getInstance(loc);
|
||||
format.setParseBigDecimal(true);
|
||||
val = (BigDecimal) format.parse(str);
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
log.warn(str, e);
|
||||
}
|
||||
catch (ParseException e)
|
||||
{
|
||||
log.warn(str, e);
|
||||
}
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String coerceToUi(BigDecimal val, Component component, BindContext cx)
|
||||
{
|
||||
Locale loc = Locales.getCurrent();
|
||||
|
||||
if (val == null)
|
||||
{
|
||||
return "";
|
||||
//val = BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
val = val.setScale(2, BigDecimal.ROUND_DOWN);
|
||||
|
||||
DecimalFormat format = (DecimalFormat) DecimalFormat.getInstance(loc);
|
||||
format.setMaximumFractionDigits(2);
|
||||
format.setMinimumFractionDigits(0);
|
||||
format.setGroupingUsed(true);
|
||||
format.setGroupingSize(3);
|
||||
String formatted = format.format(val);
|
||||
return formatted;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,6 +16,18 @@ import org.zkoss.zul.Messagebox;
|
||||
|
||||
public class DocumentViewModel
|
||||
{
|
||||
protected BigDecimalFilterConverter standardBigDecimalFilterConverter;
|
||||
|
||||
public BigDecimalFilterConverter getStandardBigDecimalFilterConverter()
|
||||
{
|
||||
return standardBigDecimalFilterConverter;
|
||||
}
|
||||
|
||||
public void setStandardBigDecimalFilterConverter(BigDecimalFilterConverter standardBigDecimalFilterConverter)
|
||||
{
|
||||
this.standardBigDecimalFilterConverter = standardBigDecimalFilterConverter;
|
||||
}
|
||||
|
||||
protected BigDecimalConverter standardBigDecimalConverter;
|
||||
|
||||
protected BoolConverter standardBoolConverter;
|
||||
@@ -53,6 +65,7 @@ public class DocumentViewModel
|
||||
@Init
|
||||
public void initDocumentViewModel()
|
||||
{
|
||||
this.standardBigDecimalFilterConverter = new BigDecimalFilterConverter();
|
||||
this.standardBigDecimalConverter = new BigDecimalConverter();
|
||||
this.standardBoolConverter = new BoolConverter();
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@
|
||||
<div sclass="find-grid-cell">
|
||||
<div sclass="find-grid-divtextbox">
|
||||
<textbox
|
||||
value="@bind(vm.filterTemplate.sumTotal) @converter(vm.bigDecimalConverter)"
|
||||
value="@bind(vm.filterTemplate.sumTotal) @converter(vm.standardBigDecimalFilterConverter)"
|
||||
instant="true"
|
||||
onChange="@command('doFilter')"
|
||||
maxlength="@load(vm.lengthText)"
|
||||
|
||||
@@ -136,7 +136,7 @@
|
||||
<div sclass="find-grid-cell">
|
||||
<div sclass="find-grid-divtextbox">
|
||||
<textbox
|
||||
value="@bind(vm.filterTemplate.sumTotal) @converter(vm.bigDecimalConverter)"
|
||||
value="@bind(vm.filterTemplate.sumTotal) @converter(vm.standardBigDecimalFilterConverter)"
|
||||
instant="true"
|
||||
onChange="@command('doFilter')"
|
||||
maxlength="@load(vm.lengthText)"
|
||||
|
||||
@@ -136,7 +136,7 @@
|
||||
<div sclass="find-grid-cell">
|
||||
<div sclass="find-grid-divtextbox">
|
||||
<textbox
|
||||
value="@bind(vm.filterTemplate.sumTotal) @converter(vm.bigDecimalConverter)"
|
||||
value="@bind(vm.filterTemplate.sumTotal) @converter(vm.standardBigDecimalFilterConverter)"
|
||||
instant="true"
|
||||
onChange="@command('doFilter')"
|
||||
maxlength="@load(vm.lengthText)"
|
||||
|
||||
@@ -136,7 +136,7 @@
|
||||
<div sclass="find-grid-cell">
|
||||
<div sclass="find-grid-divtextbox">
|
||||
<textbox
|
||||
value="@bind(vm.filterTemplate.sumTotal) @converter(vm.bigDecimalConverter)"
|
||||
value="@bind(vm.filterTemplate.sumTotal) @converter(vm.standardBigDecimalFilterConverter)"
|
||||
instant="true"
|
||||
onChange="@command('doFilter')"
|
||||
maxlength="@load(vm.lengthText)"
|
||||
|
||||
Reference in New Issue
Block a user