Package org.gwtoolbox.widget.client.form.renderer.simple

Source Code of org.gwtoolbox.widget.client.form.renderer.simple.FieldGroup

package org.gwtoolbox.widget.client.form.renderer.simple;

import org.gwtoolbox.widget.client.form.renderer.simple.hint.Hint;
import org.gwtoolbox.widget.client.form.renderer.simple.hint.Hints;

import java.util.HashMap;
import java.util.Map;

/**
* @author Uri Boness
*/
public class FieldGroup {

    private final String name;
    private final String[] fields;

    private Hints hints;

    private Map<String, Hints> hintsByFieldKey;


    public FieldGroup(String... fields) {
        this(null, fields);
    }

    public FieldGroup(String name, String[] fields) {
        this.name = name;
        this.fields = fields;
    }

    public void setHints(Hint... hints) {
        if (hints.length > 0 && this.hints == null) {
            this.hints = new Hints();
        }
        for (Hint hint : hints) {
            this.hints.set(hint);
        }
    }

    public void setHints(String fieldKey, Hint... hints) {
        if (hintsByFieldKey == null) {
            hintsByFieldKey = new HashMap<String, Hints>();
        }
        Hints fieldHints = hintsByFieldKey.get(fieldKey);
        if (hints.length > 0 && fieldHints == null) {
            fieldHints = new Hints();
            hintsByFieldKey.put(fieldKey, fieldHints);
        }
        for (Hint hint : hints) {
            fieldHints.set(hint);
        }
    }

    public String getName() {
        return name;
    }

    public String[] getFields() {
        return fields;
    }

    public Hints getHints(String fieldKey) {
        Hints hints = new Hints();
        if (this.hints != null) {
            hints.setAll(this.hints);
        }
        if (hintsByFieldKey != null) {
            Hints fieldHints = hintsByFieldKey.get(fieldKey);
            if (fieldHints != null) {
                hints.setAll(fieldHints);
            }
        }
        return hints;
    }

}
TOP

Related Classes of org.gwtoolbox.widget.client.form.renderer.simple.FieldGroup

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.