Package clips.directory.tempMapper

Source Code of clips.directory.tempMapper.TableModelTempMapper

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

package clips.directory.tempMapper;

import cli_fmw.delegate.directory.complex.DirectoryLocator;
import cli_fmw.main.ClipsException;
import cli_fmw.main.DirectoryItemNotFoundException;
import cli_fmw.utils.ErrorValue;
import clips.delegate.directory.filtered.DirectoryService;
import clips.delegate.directory.filtered.DirectoryServiceItem;
import beans.directory.danger.TempMapperChunk;
import clips.delegate.directory.simple.speciality.DirectorySpeciality;
import clips.delegate.directory.simple.speciality.DirectorySpecialityItem;
import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;

/**
*
* @author vip
*/
public class TableModelTempMapper extends AbstractTableModel{

    private ArrayList<TempMapperChunk> tempMapperList;
    private DirectoryService dirService;
    private DirectorySpeciality dirSpec;

    public static final int COL_SERVICE1 = 0;
    public static final int COL_SERVICE2 = 1;
    public static final int COL_SPEC = 2;
    public static final int COLCOUNT = 3;

    public TableModelTempMapper(ArrayList<TempMapperChunk> tempMapperList) throws ClipsException {
        this.tempMapperList = tempMapperList;
        dirService = DirectoryLocator.getDirectory(DirectoryService.class);
        dirSpec = DirectoryLocator.getDirectory(DirectorySpeciality.class);
    }

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

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

    @Override
    public String getColumnName(int col) {
        switch (col) {
            case (COL_SERVICE1) : return "Заменить";
            case (COL_SERVICE2) : return "На посещение";
            case (COL_SPEC) : return "Специальность";
            default: throw new IllegalArgumentException("Неверный номер столбца " + col);
        }
    }

    @Override
    public Object getValueAt(int row, int col) {
        try {
            TempMapperChunk d = tempMapperList.get(row);
            switch (col) {
                case COL_SERVICE1:
                    return dirService.getItemFromID(d.service1ID);
                case COL_SERVICE2:
                    return dirService.getItemFromID(d.service2ID);
                case COL_SPEC:
                    return dirSpec.getItemFromID(d.specialityID);
                default:
                    throw new IllegalArgumentException("Неверный номер столбца " + col);
            }
        } catch (DirectoryItemNotFoundException ex) {
            return new ErrorValue(ex);
        }
    }

    @Override
    public boolean isCellEditable(int row, int col) {
        if (col == COL_SERVICE2 || col == COL_SPEC) {
            return true;
        }
        return false;
    }

    @Override
    public void setValueAt(Object aValue, int row, int col) {
        TempMapperChunk d = tempMapperList.get(row);
        switch (col) {
            case COL_SERVICE2: {
                d.service2ID = ((DirectoryServiceItem) aValue).getID();
                break;
            }
            case COL_SPEC: {
                d.specialityID = ((DirectorySpecialityItem) aValue).getID();
                break;
            }
            default:
                throw new IllegalArgumentException("Неверный номер столбца " + col);
        }
    }


}
TOP

Related Classes of clips.directory.tempMapper.TableModelTempMapper

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.