All Downloads are FREE. Search and download functionalities are using the official Maven repository.

fr.ird.observe.client.form.spi.FormUIValidationMessageManager Maven / Gradle / Ivy

package fr.ird.observe.client.form.spi;

/*-
 * #%L
 * ObServe Toolkit :: Common Client
 * %%
 * Copyright (C) 2008 - 2017 IRD, Ultreia.io
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU 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 General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public
 * License along with this program.  If not, see
 * .
 * #L%
 */

import fr.ird.observe.client.form.FormUI;
import fr.ird.observe.dto.decoration.ObserveI18nDecoratorHelper;
import org.nuiton.jaxx.validator.swing.SwingValidatorMessageTableModel;
import org.nuiton.validator.NuitonValidatorScope;


import static fr.ird.observe.dto.decoration.ObserveI18nDecoratorHelper.getTypeI18nKey;
import static org.nuiton.i18n.I18n.t;

/**
 * Created by tchemit on 01/10/17.
 *
 * @author Tony Chemit - [email protected]
 */
public class FormUIValidationMessageManager {

    private final Class type;

    private final FormUI ui;

    public FormUIValidationMessageManager(Class type, FormUI ui) {
        this.type = type;
        this.ui = ui;
    }

    public void addInfoMessage(String message) {
        addInfoMessage(type, t(message));
    }

    public void addInfoMessage(Class fieldName, String message) {
        SwingValidatorMessageTableModel model = this.ui.getErrorTableModel();
        model.addMessages(this.ui, getTypeI18nKey(fieldName), NuitonValidatorScope.INFO, message);
    }

    public void addTitleInfoMessage(String message) {
        addTitleMessage(NuitonValidatorScope.INFO, type, t(message));
    }

    private void addTitleMessage(NuitonValidatorScope scope, Class fieldName, String message) {
        SwingValidatorMessageTableModel model = ui.getErrorTableModel();
        model.addMessages(ui, ObserveI18nDecoratorHelper.getTitle(fieldName), scope, message);
    }


    public void clear() {
        ui.getErrorTableModel().clear();
    }

    public void removeAllMessages() {
        SwingValidatorMessageTableModel model = ui.getErrorTableModel();
        model.clear();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy