Package clips.directory.editors.danger

Source Code of clips.directory.editors.danger.TableModelDangerService

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

package clips.directory.editors.danger;

import clips.delegate.directory.complex.DangerServiceData;
import cli_fmw.main.ClipsException;
import cli_fmw.utils.ErrorValue;
import cli_fmw.utils.MessageBox;
import cli_fmw.utils.SelectorEditableExceptional;
import clips.delegate.directory.simple.speciality.DirectorySpecialityItem;
import javax.swing.table.AbstractTableModel;

/**
*
* @author lacoste
*/
public class TableModelDangerService extends AbstractTableModel {
    public static final int COLCOUNT = 4;
    public static final int COL_DS_TITLE = 0;
    public static final int COL_DS_SPECIALITY = 1;
    public static final int COL_DS_DURATION = 2;
    public static final int COL_DS_DESCRIPTION = 3;
   
    private SelectorEditableExceptional<DangerServiceData> dangerServices;
   
    public TableModelDangerService(SelectorEditableExceptional<DangerServiceData> dangerServices) {
        this.dangerServices = dangerServices;
    }

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

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

    @Override
    public String getColumnName(int column) {
        switch (column) {
            case COL_DS_TITLE: return "Услуга";
            case COL_DS_SPECIALITY: return "Специальность";
            case COL_DS_DURATION: return "Продолжительность";
            case COL_DS_DESCRIPTION: return "Примечание";
            default: return "";
        }
    }

    @Override
    public boolean isCellEditable(int rowIndex, int col) {
        if (col == COL_DS_DESCRIPTION) {
            return true;
        }
        if (col == COL_DS_SPECIALITY) {
            return true;
        }
        else {
            return false;
        }
    }

    @Override
    public Object getValueAt(int row, int col) {
        try {
            DangerServiceData dangerService = dangerServices.get(row);
            if (col == COL_DS_TITLE) {
                return dangerService.getService();
            }
            if (col == COL_DS_SPECIALITY) {
                return dangerService.getSpeciality();
            }
            else if (col == COL_DS_DURATION) {
                return dangerService.getService().getDefaultDuration();
            }
            else if (col == COL_DS_DESCRIPTION) {
                return dangerService.getDescription();
            }
            else {
                return col + " из " + COLCOUNT;
            }
        } catch (ClipsException ex) {
            return new ErrorValue(ex);
        }
    }

    @Override
    public void setValueAt(Object aValue, int row, int col) {
        try {
            DangerServiceData data = dangerServices.get(row);
            if (col == COL_DS_DESCRIPTION) {
                String description = data.getDescription();
                try {
                    data.setDescription(aValue.toString());
                    dangerServices.append(data);
                } catch (ClipsException ex) {
                    data.setDescription(description);
                    MessageBox.showException(ex);
                }
            }
            if (col == COL_DS_SPECIALITY) {
                DirectorySpecialityItem speciality = data.getSpeciality();
                try {
                    data.setSpeciality((DirectorySpecialityItem) aValue);
                    dangerServices.append(data);
                } catch (ClipsException ex) {
                    data.setSpeciality(speciality);
                    MessageBox.showException(ex);
                }
            }
        } catch (ClipsException ex) {
            MessageBox.showException(ex);
        }
    }

}
TOP

Related Classes of clips.directory.editors.danger.TableModelDangerService

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.