Package clips.directory.editors.servicePacketTemplate

Source Code of clips.directory.editors.servicePacketTemplate.TableModelEditPacketItems

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

package clips.directory.editors.servicePacketTemplate;

import clips.delegate.directory.complex.DirectoryPacketTemplateItem;
import clips.delegate.directory.complex.DirectoryPacketTemplateListItem;
import cli_fmw.main.ClipsException;
import cli_fmw.utils.ErrorValue;
import cli_fmw.utils.MessageBox;
import java.util.ArrayList;
import java.util.Collections;
import javax.swing.table.AbstractTableModel;

/**
*
* @author lacoste
*/
public class TableModelEditPacketItems extends AbstractTableModel {
    public static final int COLCOUNT = 5;
    public static final int COL_ID = 0;   
    public static final int COL_SERVICE = 1;
    public static final int COL_WEIGHT = 2;
    public static final int COL_DURATION = 3;
    public static final int COL_DISCOUNT = 4;
   
    private DirectoryPacketTemplateItem packet;
    private ArrayList<DirectoryPacketTemplateListItem> list = new ArrayList<DirectoryPacketTemplateListItem>();

    public TableModelEditPacketItems(DirectoryPacketTemplateItem packet) throws ClipsException {
        this.packet = packet;
       
        list.clear();
        if (packet != null) {           
            for (int i = 0; i < packet.getPacketItemCount(); i++) {
                list.add(packet.getPacketItem(i));
            }
        }
        Collections.sort(list);
    }

    @Override
    public Class<?> getColumnClass(int col) {
        if (col == COL_DISCOUNT || col == COL_DURATION || col == COL_WEIGHT) {
            return Integer.class;
        }
        return super.getColumnClass(col);
    }

    @Override
    public String getColumnName(int column) {
        switch (column) {
            case COL_ID: return "ID";           
            case COL_SERVICE: return "Услуга";
            case COL_WEIGHT: return "Порядок";
            case COL_DURATION: return "Продолжительность";
            case COL_DISCOUNT: return "Скидка";
            default: return "";
        }
    }

    @Override
    public boolean isCellEditable(int rowIndex, int col) {
        if (col == COL_ID || col == COL_SERVICE) {
            return false;
        }
        return true;
    }

    @Override
    public void setValueAt(Object aValue, int rowIndex, int col) {
        try {
            DirectoryPacketTemplateListItem item = list.get(rowIndex);           
            if (col == COL_DISCOUNT) {
                item.setDiscount(Integer.parseInt(aValue.toString()));
            }
            if (col == COL_DURATION) {
                item.setDefaultDuration(Integer.parseInt(aValue.toString()));
            }
            if (col == COL_WEIGHT) {
                item.setWeight(Integer.parseInt(aValue.toString()));
            }           
        } catch (ClipsException ex) {
            MessageBox.showException(ex);
        }
    }

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

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

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        DirectoryPacketTemplateListItem item = list.get(rowIndex);
        switch (columnIndex) {
            case COL_ID : return item.getID();            
            case COL_SERVICE: {
                try {
                    return item.getService();
                } catch (ClipsException e) {
                    MessageBox.showException(e);
                    return new ErrorValue(e);
                }
            }              
            case COL_WEIGHT: return item.getWeight();
            case COL_DURATION: return item.getDefaultDuration();
            case COL_DISCOUNT: return item.getDiscount();
            default: return null;
        }
    }
}
TOP

Related Classes of clips.directory.editors.servicePacketTemplate.TableModelEditPacketItems

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.