Package clips.service.search

Source Code of clips.service.search.TableModelSerRenFactory$SerRenByDateComparator

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

package clips.service.search;

import cli_fmw.main.ClipsException;
import cli_fmw.utils.ErrorValue;
import cli_fmw.utils.MessageBox;
import clips.delegate.contract.PolisData;
import clips.delegate.directory.ro.DirectoryCollaboratorItem;
import clips.delegate.service.SerRenLocal;
import framework.utils.Converter;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import javax.swing.table.AbstractTableModel;

/**
*
* @author lacoste
*/
public class TableModelSerRenFactory extends AbstractTableModel {

    private List<SerRenLocal> serRenIterator;
    public static final int COLCOUNT     = 5;
    public static final int COL_SERVICE  = 0;
    public static final int COL_CONTRACT = 1;
    public static final int COL_CLIENT   = 2;
    public static final int COL_DIRECTED = 3;
    public static final int COL_RENDERED = 4;

    public TableModelSerRenFactory(List<SerRenLocal> serRens) {
        this.serRenIterator = serRens;
        if (serRens != null) {
            java.util.Collections.sort(serRenIterator, new SerRenByDateComparator());
        }
    }

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

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

    @Override
    public String getColumnName(int c) {
        String s;
        switch (c) {
            case COL_SERVICE:
                s = "Услуга";
                break;
            case COL_CONTRACT:
                s = "Договор";
                break;
            case COL_CLIENT:
                s = "Пациент";
                break;
            case COL_DIRECTED:
                s = "Назначена";
                break;
            case COL_RENDERED:
                s = "Оказана";
                break;
            default:
                throw new IllegalArgumentException("Некорректный номер столбца");
        }
        return s;
    }

    @Override
    public boolean isCellEditable(int r, int c) {
        return false;
    }

    @Override
    public Object getValueAt(int r, int c) {
        try {
            SerRenLocal serRenLocal = serRenIterator.get(r);
            PolisData polisData = serRenLocal.getPolisData();
            switch (c) {
                case COL_SERVICE: {
                    //наименование услуги
                    return serRenLocal.getService();
                }
                case COL_CONTRACT: {
                    return polisData.getContract().getInfo();
                }
                case COL_CLIENT: {
                    return polisData.getClient().getFIO();
                }
                case COL_DIRECTED: {
                    DirectoryCollaboratorItem serRenDirector = serRenLocal.getSerRenDirector();
                    Date date = serRenLocal.getSerDate();
                    return Converter.dateToString(date) + " " + serRenDirector.toString();
                }
                case COL_RENDERED: {
                    if (serRenLocal.isRendered()) {
                        DirectoryCollaboratorItem cl = serRenLocal.getCollaboratorFunctions().getCollaborator();
                        Date dateOrder = serRenLocal.getSerRenderDate();
                        return Converter.dateToString(dateOrder) + " " + cl.toString();
                    } else {
                        return "Не оказана";
                    }
                }
                default:
                    return null;
            }
        } catch (ClipsException ex) {
            return new ErrorValue(ex);
        }
    }

    class SerRenByDateComparator implements Comparator<SerRenLocal> {

        @Override
        public int compare(SerRenLocal o1, SerRenLocal o2) {
            try {
                if (o1.getSerDate().after(o2.getSerDate())) {
                    return 1;
                } else {
                    return -1;
                }
            } catch (ClipsException ex) {
                MessageBox.showException(ex);
                return 0;
            }
        }

    }

}
TOP

Related Classes of clips.service.search.TableModelSerRenFactory$SerRenByDateComparator

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.