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

net.sf.sfac.editor.ValidationReportImpl Maven / Gradle / Ivy

Go to download

This project is the model side of the Swing Framework and Components (SFaC). If your doing a clean separation between model (or business) and view (or GUI or rendering) parts of your application, (like in the MVC pattern), then the only classes of SFaC your model can access are in this project. On the other hand, the classes in sfac-core project are GUI-specific and should not be known by your model.

The newest version!
/*-------------------------------------------------------------------------
 Copyright 2009 Olivier Berlanger

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 -------------------------------------------------------------------------*/
package net.sf.sfac.editor;


import java.util.ArrayList;
import java.util.List;

import net.sf.sfac.editor.ValidationMessage.Level;
import net.sf.sfac.lang.MultiLingualTextImpl;


public class ValidationReportImpl implements ValidationReport {

    // public static String buildPath(String basePath, String addedPath) {
    // if (Comparison.isEmpty(basePath)) return addedPath;
    // if (Comparison.isEmpty(addedPath)) return basePath;
    // return basePath + "." + addedPath;
    // }

    private List messages;


    public Level getGlobalValidationLevel() {
        Level lev = Level.OK;
        if (messages != null) {
            for (ValidationMessage msg : messages) {
                if (msg.getLevel().greaterThan(lev)) lev = msg.getLevel();
            }
        }
        return lev;
    }


    public void addValidationMessage(ValidationMessage validationMsg) {
        if (messages == null) messages = new ArrayList();
        messages.add(validationMsg);
    }


    public void removeValidationMessage(ValidationMessage validationMsg) {
        if (messages != null) {
            messages.remove(validationMsg);
        }
    }


    public void removeAllValidationMessages() {
        if (messages != null) {
            messages.clear();
        }
    }


    public void addMandatoryError(String fieldPath, String fieldName) {
        MultiLingualTextImpl translatedName = new MultiLingualTextImpl(fieldName);
        addError(fieldPath, "MANDATORY_FIELD", translatedName);
    }


    public void addError(String fieldPath, String key, Object... params) {
        String path = fieldPath;
        addValidationMessage(new ValidationMessageImpl(Level.ERROR, path, key, params));
    }


    public void addWarning(String fieldPath, String key, Object... params) {
        String path = fieldPath;
        addValidationMessage(new ValidationMessageImpl(Level.WARNING, path, key, params));
    }


    public void addInfo(String fieldPath, String key, Object... params) {
        String path = fieldPath;
        addValidationMessage(new ValidationMessageImpl(Level.INFO, path, key, params));
    }


    public List getValidationMessages() {
        return messages;
    }


    public ValidationReport getContextReport(String fieldPath) {
        return this;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy