Package org.libreplan.web.util

Source Code of org.libreplan.web.util.ValidationExceptionPrinter

/*
* This file is part of LibrePlan
*
* 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.libreplan.web.util;

import static org.libreplan.web.I18nHelper._;

import org.libreplan.business.common.exceptions.ValidationException;
import org.libreplan.business.common.exceptions.ValidationException.InvalidValue;
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.getInvalidValue());
        if (row != null) {
            throw new WrongValueException(row, _(invalidValue.getMessage()));
        }
    }

}
TOP

Related Classes of org.libreplan.web.util.ValidationExceptionPrinter

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.