[Bug #648] Add new more lenient decimal box
It always supports dot and comma as decimal separator. FEA: ItEr74S04BugFixing
This commit is contained in:
parent
1ddeb946fa
commit
f4d4bddff6
3 changed files with 68 additions and 2 deletions
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* This file is part of NavalPlan
|
||||
*
|
||||
* Copyright (C) 2011 Igalia, S.L.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.navalplanner.web.common;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
|
||||
import org.zkoss.util.Locales;
|
||||
import org.zkoss.zk.ui.WrongValueException;
|
||||
import org.zkoss.zul.Decimalbox;
|
||||
|
||||
/**
|
||||
* Same behavior as a {@link Decimalbox}, but it always interprets <b>,</b> and
|
||||
* <b>.</b> as decimals separators. So you can use both freely as decimal
|
||||
* separators.
|
||||
*
|
||||
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
||||
*
|
||||
*/
|
||||
public class LenientDecimalBox extends Decimalbox {
|
||||
|
||||
public LenientDecimalBox() {
|
||||
super();
|
||||
}
|
||||
|
||||
public LenientDecimalBox(BigDecimal value) throws WrongValueException {
|
||||
super(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object coerceFromString(String value) throws WrongValueException {
|
||||
return super
|
||||
.coerceFromString(interpretCommasAndPointsAsDecimalSeparator(value));
|
||||
}
|
||||
|
||||
private String interpretCommasAndPointsAsDecimalSeparator(String value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
final DecimalFormatSymbols symbols = new DecimalFormatSymbols(
|
||||
Locales.getCurrent());
|
||||
|
||||
char decimalSeparator = symbols.getDecimalSeparator();
|
||||
return value.replace('.', decimalSeparator).replace(',',
|
||||
decimalSeparator);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -58,6 +58,7 @@ import org.navalplanner.business.workingday.EffortDuration;
|
|||
import org.navalplanner.business.workingday.EffortDuration.IEffortFrom;
|
||||
import org.navalplanner.business.workingday.ResourcesPerDay;
|
||||
import org.navalplanner.web.common.EffortDurationBox;
|
||||
import org.navalplanner.web.common.LenientDecimalBox;
|
||||
import org.navalplanner.web.common.Util;
|
||||
import org.navalplanner.web.planner.allocation.ResourceAllocationController.DerivedAllocationColumn;
|
||||
import org.zkoss.zk.au.out.AuWrongValue;
|
||||
|
|
@ -272,7 +273,7 @@ public abstract class AllocationRow {
|
|||
|
||||
private EffortDurationBox effortInput = new EffortDurationBox();
|
||||
|
||||
private final Decimalbox intendedResourcesPerDayInput = new Decimalbox();
|
||||
private final Decimalbox intendedResourcesPerDayInput = new LenientDecimalBox();
|
||||
|
||||
private ResourcesPerDay editedValue;
|
||||
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ import org.navalplanner.business.resources.entities.ResourceEnum;
|
|||
import org.navalplanner.web.I18nHelper;
|
||||
import org.navalplanner.web.common.EffortDurationBox;
|
||||
import org.navalplanner.web.common.IMessagesForUser;
|
||||
import org.navalplanner.web.common.LenientDecimalBox;
|
||||
import org.navalplanner.web.common.Util;
|
||||
import org.navalplanner.web.common.components.AllocationSelector;
|
||||
import org.navalplanner.web.common.components.NewAllocationSelector;
|
||||
|
|
@ -154,7 +155,7 @@ public class ResourceAllocationController extends GenericForwardComposer {
|
|||
@Override
|
||||
public void doAfterCompose(Component comp) throws Exception {
|
||||
super.doAfterCompose(comp);
|
||||
allResourcesPerDay = new Decimalbox();
|
||||
allResourcesPerDay = new LenientDecimalBox();
|
||||
allResourcesPerDay.setWidth("80px");
|
||||
initAllocationLabels();
|
||||
makeReadyInputsForCalculationTypes();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue