Package clips.shedule.reception

Source Code of clips.shedule.reception.ServicesTableModel$SR

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

package clips.shedule.reception;

import clips.delegate.service.SerRenLocal;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.swing.table.AbstractTableModel;

/**
*
* @author axe
*/
public class ServicesTableModel extends AbstractTableModel {

    private final static int COL_CHECKBOX = 0;
    private final static int COL_SERVICENAME = 1;
    private final static int COL_DIRECTOR = 2;
    private final static int COL_INRECEPTION = 3;
    private final static int COL_FULLPAYED = 4;
    private final static int COL_COUNT = 5;

    private class SR {
        public SR(SerRenLocal sr) {
            this.sr = sr;
        }
        public SerRenLocal sr;
        public boolean checked;
    }
    private List<SR> services;
   
    public ServicesTableModel(Iterator<SerRenLocal> s) {
        services = new ArrayList<SR>();
        while(s.hasNext()) {
            services.add(new SR(s.next()));
        }
    }

    void setSelectedList(List<Integer> s) {
        Iterator<SR> i = services.iterator();
        while(i.hasNext()) {
            SR srl = i.next();
            if(s.contains(srl.sr.getID())) {
                srl.checked = true;
            }
        }
    }
            
    @Override
    public String getColumnName(int column) {
        switch (column) {
            case COL_SERVICENAME: {
                return "Услуга";
            }               
            case COL_DIRECTOR: {
                return "Сотрудник";
            }               
            case COL_INRECEPTION: {
                return "Записана на прием";
            }
            case COL_FULLPAYED: {
                return "Оплачена";
            }
            case COL_CHECKBOX: {
                return "Включить";
            }
        }
        return null;
    }
   
   

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

    @Override
    public int getRowCount() {
        return services.size();
    }

    @Override
    public Object getValueAt(int row, int column) {
        SerRenLocal sr = services.get(row).sr;
        try {
            switch (column) {
                case COL_SERVICENAME: {
                    return sr.getService().getTitle();
                }               
                case COL_DIRECTOR: {
                    return sr.getSerRenDirector().getTitle();
                }               
                case COL_INRECEPTION: {
                    return (sr.getReception() != null);
                }
                case COL_FULLPAYED: {
                    return sr.isSerPayed();
                }
                case COL_CHECKBOX: {
                    return services.get(row).checked;
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
       
        return null;
    }

    @Override
    public boolean isCellEditable(int row, int column) {
        return column == COL_CHECKBOX;
    }

    @Override
    public void setValueAt(Object aValue, int row, int column) {
        if(column == COL_CHECKBOX) {
            SR sr = services.get(row);
            sr.checked = (Boolean)aValue;
        }
    }

    @Override
    public Class<?> getColumnClass(int columnIndex) {
        if(columnIndex == COL_CHECKBOX
                ||columnIndex == COL_INRECEPTION
                || columnIndex == COL_FULLPAYED) {
            return Boolean.class;
        }
        return super.getColumnClass(columnIndex);
    }

    /**
     *
     * @return
     */
    public List<SerRenLocal> getSelectedList() {
        List<SerRenLocal> res = new ArrayList<SerRenLocal>();
        for(int i=0; i<services.size(); i++) {
            SR sr = services.get(i);
            if(sr.checked) {
                res.add(sr.sr);
            }
        }
        return res;
    }
   
}
TOP

Related Classes of clips.shedule.reception.ServicesTableModel$SR

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.