Package clips.doctor.followup

Source Code of clips.doctor.followup.TableModelFollowupList

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package clips.doctor.followup;

import clips.delegate.doctor.followup.FollowupEventData;
import clips.delegate.doctor.followup.FollowupLocal;
import cli_fmw.main.ClipsException;
import cli_fmw.utils.ErrorValue;
import cli_fmw.utils.SelectorEditable;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.table.DefaultTableModel;

/**
* Модель таблицы списка диагнозов
* @author vip
*/
public class TableModelFollowupList extends DefaultTableModel {

    public static final int COL_DATEUP = 0;
    public static final int COL_MKB = 1;
    public static final int COL_REASON = 2;
    public static final int COL_DAY = 3;
    public static final int COL_DATEDOWN = 4;
    public static final int COLUMN_COUNT = 5;
    private SelectorEditable<FollowupLocal> ii;

    /**
     *
     * @param ii selector, can be null
     */
    public TableModelFollowupList(SelectorEditable<FollowupLocal> ii) {
        this.ii = ii;
    }

    @Override
    public int getColumnCount() {
        return COLUMN_COUNT;
    }

    @Override
    public String getColumnName(int col) {
        switch (col) {
            case COL_DATEUP:
                return "Дата постановки";
            case COL_MKB:
                return "Диагноз";
            case COL_REASON:
                return "Причина";
            case COL_DAY:
                return "День приема";
            case COL_DATEDOWN:
                return "Дата снятия";
        }
        return "";
    }

    @Override
    public int getRowCount() {
        if (ii == null) {
            return 0;
        }
        return ii.size();
    }

    @Override
    public Object getValueAt(int row, int col) {
        try {
            FollowupLocal followUp = ii.get(row);
            switch (col) {
                case COL_DATEUP: {
                    return followUp.getDateUp();
                }
                case COL_MKB: {
                    return followUp.getDiagnosis().getMkb();
                }
                case COL_REASON: {
                    return followUp.getReasonUp();
                }
                case COL_DAY: {
                    if (!followUp.isDown()) {
                        SelectorEditable<FollowupEventData> list = followUp.getFollowupEventList();
                        if (list != null && list.size() != 0) {
                            //Берем дату из последнего назначения
                            FollowupEventData event = list.get(list.size() - 1);
                            return (new SimpleDateFormat("dd.MM.yyyy")).format(event.getDate());
                        } else {
                            return "";
                        }
                    } else {
                        return "";
                    }
                }
                case COL_DATEDOWN: {
                    if (followUp.isDown()) {
                        return followUp.getDateDown();
                    }
                }
            }
        } catch (ClipsException ex) {
            return new ErrorValue(ex);
        }
        return null;
    }

    @Override
    public boolean isCellEditable(int row, int col) {
        return false;
    }

    @Override
    public Class<?> getColumnClass(int columnIndex) {
        if (columnIndex == COL_DATEUP || columnIndex == COL_DATEDOWN){
            return Date.class;
        }else{
            return super.getColumnClass(columnIndex);
        }
    }
}
TOP

Related Classes of clips.doctor.followup.TableModelFollowupList

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.