Package clips.delegate.doctor.certificate.tag.interfaces

Source Code of clips.delegate.doctor.certificate.tag.interfaces.TypeSelectable

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package clips.delegate.doctor.certificate.tag.interfaces;

import clips.delegate.doctor.DiseaseLocal;
import clips.delegate.doctor.certificate.CertificateLocal;
import cli_fmw.delegate.report.ReportParam;
import cli_fmw.main.ClipsException;
import java.util.ArrayList;
import framework.utils.PairIntStr;

/**
* Интерфейс, позволяющий выставлять одно значение из выбора
* @author vip
*/
abstract public class TypeSelectable extends CertTag implements AbstrMultiTag, AbstrHasParam, AbstrHasText {
    /**
     * Массив, содержащий все итемы, которые можно выбрать.
     * Заполняется в потомке методом fillItems()
     */
    protected ArrayList<PairIntStr> allItems = new ArrayList<PairIntStr>();

    public TypeSelectable() throws ClipsException {
        fillItems();
    }

    public TypeSelectable(CertificateLocal certificateLocal, ReportParam reportParam, DiseaseLocal diseaseLocal) throws ClipsException {
        super(certificateLocal, reportParam, diseaseLocal);
        fillItems();
    }

    abstract public void fillItems() throws ClipsException;
    /**
     * Данная функция должна изменить текст тега
     * @param id
     */
    public void setItem(int id) throws ClipsException {
        certTagResult.items = new ArrayList<Integer>();
        certTagResult.items.add(id);
        int founded = -1;
        for (int i = 0; i < allItems.size(); i++) {
            PairIntStr pairIntStr = allItems.get(i);
            if (pairIntStr.num == id) {
                founded = i;
            }
        }
        if (founded != -1) {
            certTagResult.text = allItems.get(founded).str;
        } else {
            certTagResult.text = "";
        }
        setTagResult(certTagResult);
    }

   
    public void setText(String text, boolean forced) throws ClipsException {
        if (certTagResult.text.equals(text)) {
            return;
        }
        if (isEditable() || forced) {
            certTagResult.text = text;
            setTagResult(certTagResult);
        } else {
            throw new ClipsException("Запрещено изменять " + this.getTitle());
        }
    }

    @Override
    final public String getText() {
        return certTagResult.text;
    }

    @Override
    final public PairIntStr[] getAllItems() {
        return allItems.toArray(new PairIntStr[allItems.size()]);
    }

    final public Integer getItem() {
        return certTagResult.items.size() == 0? null: certTagResult.items.get(0);
    }
}
TOP

Related Classes of clips.delegate.doctor.certificate.tag.interfaces.TypeSelectable

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.