[Bug #931] Added helper class for printing a ValidatonExcepton as a WrongValidationException, showing up next to a widget
FEA: ItEr74S04BugFixing
This commit is contained in:
parent
ecece6fd03
commit
892bbc629c
3 changed files with 65 additions and 22 deletions
|
|
@ -31,7 +31,6 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.hibernate.validator.InvalidValue;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.common.exceptions.ValidationException;
|
||||
|
|
@ -45,10 +44,9 @@ import org.navalplanner.web.common.MessagesForUser;
|
|||
import org.navalplanner.web.common.OnlyOneVisible;
|
||||
import org.navalplanner.web.common.Util;
|
||||
import org.navalplanner.web.common.components.Autocomplete;
|
||||
import org.navalplanner.web.util.ValidationExceptionPrinter;
|
||||
import org.navalplanner.web.workreports.WorkReportCRUDController;
|
||||
import org.zkoss.ganttz.util.ComponentsFinder;
|
||||
import org.zkoss.zk.ui.Component;
|
||||
import org.zkoss.zk.ui.WrongValueException;
|
||||
import org.zkoss.zk.ui.event.CheckEvent;
|
||||
import org.zkoss.zk.ui.event.Event;
|
||||
import org.zkoss.zk.ui.event.EventListener;
|
||||
|
|
@ -175,7 +173,7 @@ public class CostCategoryCRUDController extends GenericForwardComposer
|
|||
try {
|
||||
costCategoryModel.validateHourCostsOverlap();
|
||||
} catch (ValidationException e) {
|
||||
showHoursCostsOverlapValidationException(e);
|
||||
ValidationExceptionPrinter.showAt(listHourCosts, e);
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
@ -189,15 +187,6 @@ public class CostCategoryCRUDController extends GenericForwardComposer
|
|||
return false;
|
||||
}
|
||||
|
||||
private void showHoursCostsOverlapValidationException(ValidationException e) {
|
||||
InvalidValue invalid = e.getInvalidValue();
|
||||
Row comp = ComponentsFinder.findRowByValue(listHourCosts,
|
||||
invalid.getValue());
|
||||
if (comp != null) {
|
||||
throw new WrongValueException(comp, invalid.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public CostCategory getCostCategory() {
|
||||
return costCategoryModel.getCostCategory();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@ import java.util.Date;
|
|||
import java.util.List;
|
||||
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.hibernate.validator.InvalidValue;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.navalplanner.business.common.exceptions.ValidationException;
|
||||
import org.navalplanner.business.costcategories.entities.CostCategory;
|
||||
|
|
@ -39,10 +38,9 @@ import org.navalplanner.web.common.Level;
|
|||
import org.navalplanner.web.common.MessagesForUser;
|
||||
import org.navalplanner.web.common.Util;
|
||||
import org.navalplanner.web.common.components.Autocomplete;
|
||||
import org.navalplanner.web.util.ValidationExceptionPrinter;
|
||||
import org.navalplanner.web.workreports.WorkReportCRUDController;
|
||||
import org.zkoss.ganttz.util.ComponentsFinder;
|
||||
import org.zkoss.zk.ui.Component;
|
||||
import org.zkoss.zk.ui.WrongValueException;
|
||||
import org.zkoss.zk.ui.event.Event;
|
||||
import org.zkoss.zk.ui.event.EventListener;
|
||||
import org.zkoss.zk.ui.event.Events;
|
||||
|
|
@ -334,13 +332,9 @@ public class ResourcesCostCategoryAssignmentController extends GenericForwardCom
|
|||
try {
|
||||
CostCategory.validateCostCategoryOverlapping(costCategoryAssignments);
|
||||
} catch (ValidationException e) {
|
||||
InvalidValue invalidValue = e.getInvalidValue();
|
||||
Component comp = ComponentsFinder.findRowByValue(
|
||||
listResourcesCostCategoryAssignments,
|
||||
invalidValue.getValue());
|
||||
throw new WrongValueException(comp, invalidValue.getMessage());
|
||||
ValidationExceptionPrinter.showAt(listResourcesCostCategoryAssignments, e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* 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.util;
|
||||
|
||||
import org.hibernate.validator.InvalidValue;
|
||||
import org.navalplanner.business.common.exceptions.ValidationException;
|
||||
import org.zkoss.ganttz.util.ComponentsFinder;
|
||||
import org.zkoss.zk.ui.Component;
|
||||
import org.zkoss.zk.ui.WrongValueException;
|
||||
import org.zkoss.zul.Grid;
|
||||
import org.zkoss.zul.Row;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Diego Pino García <dpino@igalia.com>
|
||||
*
|
||||
* Helper class for printing a {@link ValidationException} at a
|
||||
* component.
|
||||
*
|
||||
*/
|
||||
public class ValidationExceptionPrinter {
|
||||
|
||||
public static void showAt(Component comp, ValidationException e) {
|
||||
InvalidValue invalidValue = e.getInvalidValue();
|
||||
if (comp instanceof Grid) {
|
||||
showAt((Grid) comp, invalidValue);
|
||||
} else {
|
||||
showAt(comp, invalidValue);
|
||||
}
|
||||
}
|
||||
|
||||
private static void showAt(Component comp, InvalidValue invalidValue) {
|
||||
throw new WrongValueException(comp, invalidValue.getMessage());
|
||||
}
|
||||
|
||||
private static void showAt(Grid comp, InvalidValue invalidValue) {
|
||||
Row row = ComponentsFinder.findRowByValue(comp, invalidValue.getValue());
|
||||
if (row != null) {
|
||||
throw new WrongValueException(row, invalidValue.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue