Package clips.doctor.medexam

Source Code of clips.doctor.medexam.TableModelMedexamResult

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

package clips.doctor.medexam;

import cli_fmw.main.ClipsException;
import cli_fmw.main.ContentStateListener;
import cli_fmw.utils.ErrorValue;
import cli_fmw.utils.MessageBox;
import clips.delegate.directory.simple.profcheckupResult.DirectoryProfcheckupResultItem;
import clips.delegate.doctor.medexam.MedSerrenResultData;
import clips.delegate.doctor.medexam.MedexamLocal;
import clips.delegate.doctor.medexam.HasSerrenResult;
import clips.delegate.service.SerRenLocal;
import clips.login.UserInfo;
import java.util.Date;
import javax.swing.table.AbstractTableModel;

/**
*
* @author vip
*/
public class TableModelMedexamResult extends AbstractTableModel implements ContentStateListener {
    public static final int COL_COUNT = 4;
    public static final int COL_SERVICE = 0;
    public static final int COL_RENDER = 1;
    public static final int COL_DATE = 2;
    public static final int COL_RESULT = 3;
    private int rowCount;

    private HasSerrenResult medexam;

    public TableModelMedexamResult(HasSerrenResult medexam) throws ClipsException {
        this.medexam = medexam;
        rowCount = medexam.getSerrenCount();
    }



    @Override
    public int getRowCount() {
        return rowCount;
    }

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

    @Override
    public String getColumnName(int col) {
        switch (col) {
            case COL_SERVICE: return "Услуга";
            case COL_RENDER: return "Оказана";
            case COL_DATE: return "Дата";
            case COL_RESULT: return "Результат";
            default: throw new IllegalArgumentException("Некорректный номер столбца : " + col);
        }
    }

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

    @Override
    public Object getValueAt(int row, int col) {
        try {
            MedSerrenResultData res = medexam.getResultList().get(row);
            SerRenLocal serren = medexam.getSerRen(res);
            switch (col) {
                case COL_SERVICE:
                    return serren.getService().getTitle();
                case COL_RENDER:
                    return serren.getCollaboratorFunctions();
                case COL_DATE:
                    return serren.getSerRenderDate();
                case COL_RESULT:
                    return res.getResult();
                default:
                    throw new IllegalArgumentException("Некорректный номер столбца : " + col);
            }
        } catch (ClipsException ex) {
            return new ErrorValue(ex);
        }
    }

    @Override
    public boolean isCellEditable(int row, int col) {
        if (col == COL_RESULT) {
            return getValueAt(row, COL_RENDER) != null;
        }
        return false;
    }

    @Override
    public void setValueAt(Object aValue, int row, int col) {
        try {
            if (col == COL_RESULT) {
                if (medexam.getResultList().get(row).getResult().equals(aValue)) {
                    //Нет изменений
                    return;
                }
                MedSerrenResultData res = medexam.getResultList().get(row);
                SerRenLocal serren = medexam.getSerRen(res);
                if (UserInfo.get().isSuperUser() || serren.getCollaboratorFunctions() != null
                        && serren.getCollaboratorFunctions().getCollaborator().getID() == UserInfo.get().getCollaborator().getID() ) {
                    medexam.getResultList().get(row).setResult((DirectoryProfcheckupResultItem) aValue);
                    return;
                } else {
                    MessageBox.showWarning("Ставить результаты может только сотрудник, оказавший услугу");
                    return;
                }
            }
        } catch (ClipsException ex) {
            MessageBox.showException(ex);
        }
        throw new IllegalArgumentException("Некорректный номер столбца : " + col);
    }

    @Override
    public void contentStateChanged() {
        fireTableDataChanged();
    }



}
TOP

Related Classes of clips.doctor.medexam.TableModelMedexamResult

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.