Package clips.doctor.sicklist.clientSicklist

Source Code of clips.doctor.sicklist.clientSicklist.TableModelSicklist

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

import clips.delegate.doctor.sicklist.SicklistLocal;
import cli_fmw.main.ClipsException;
import cli_fmw.utils.ErrorValue;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.swing.table.AbstractTableModel;

/**
*
* @author axe
*/
public class TableModelSicklist extends AbstractTableModel {
  private static final long serialVersionUID = 1;

    public static final int COL_COLLABORATOR = 0;
    public static final int COL_CLIENT = 1;
    public static final int COL_SERIAL = 2;
    public static final int COL_DATEOPEN = 3;
    public static final int COL_DIAGNOSIS = 4;
    public static final int COL_CLOSED = 5;
    public static final int COLUMN_COUNT = 6;
    private List<SicklistLocal> sicklistList;


    public TableModelSicklist(List<SicklistLocal> sicklistList) {
        this.sicklistList = sicklistList;
    }

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

    @Override
    public String getColumnName(int col) {
        switch (col) {
            case COL_CLIENT:
                return "Пациент";
            case COL_SERIAL:
                return "Серийный номер";
            case COL_COLLABORATOR:
                return "Врач";
            case COL_CLOSED:
                return "Закрыт";
            case COL_DATEOPEN:
                return "Открыт";
            case COL_DIAGNOSIS:
                return "Диагноз";
            default: throw new IllegalArgumentException("Некорректный номер столбца");
        }
    }

    @Override
    public int getRowCount() {
        return sicklistList == null? 0 : sicklistList.size();
    }


    @Override
    public Object getValueAt(int row, int col) {
        try {
            SicklistLocal dl = sicklistList.get(row);
            switch (col) {
                case COL_CLIENT: {
                    return dl.getClient().getFIO();
                }
                case COL_SERIAL: {
                    return dl.getSerial();
                }
                case COL_COLLABORATOR: {
                    if (dl.getOpener() == null) {
                        return dl.getAltOpener();
                    } else {
                        return  dl.getOpener().toString();
                    }
                }
                case COL_CLOSED: {
                    return dl.isClosed();
                }
                case COL_DATEOPEN: {
                    return dl.getDateOpen().getTime();
                }
                case COL_DIAGNOSIS: {
          if (dl.isClosed()){
            return dl.getDiagnosisClose().getMkb().toString();
          }
          else{
            return dl.getDiagnosisOpen().getMkb().toString();
          }
                }
                default: throw new IllegalArgumentException("Некорректный номер столбца");
            }
        } catch (ClipsException ex) {
            return new ErrorValue(ex);
        }
    }

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

    /**
     * Определяет, должен ли рендер подсветить ячейку
     * @param row строка
     * @param col столбец
     * @return истина если нет номера
     */
    public boolean isCellColored(int row, int col){
        if (col == COL_SERIAL) {
            try {
                SicklistLocal dl = sicklistList.get(row);
                if (!dl.isClosed()) {
                    if (dl.isSerialNotSavedYet()) {
                        return true;
                    }
                }
            } catch (ClipsException ex) {
                ex.printStackTrace();
            }
        }
        return false;
    }


    @Override
    public Class<?> getColumnClass(int col) {
        if (col == COL_CLOSED) {
            return Boolean.class;
        }
        if (col == COL_DATEOPEN) {
            return Date.class;
        }
        return super.getColumnClass(col);
    }
}
TOP

Related Classes of clips.doctor.sicklist.clientSicklist.TableModelSicklist

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.