Package clips.userseach.clientExcemption

Source Code of clips.userseach.clientExcemption.TableModelClientDiscountCards

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

package clips.userseach.clientExcemption;

import cli_fmw.main.ClipsException;
import cli_fmw.utils.ErrorValue;
import clips.delegate.service.discount.DiscountCardLocal;
import framework.utils.Converter;
import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;

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

    public static final int COLCOUNT = 6;
    public static final int COL_TYPE = 0;
    public static final int COL_CREATE_DATE = 1;
    public static final int COL_COLLAB = 2;
    public static final int COL_MONEY = 3;
    public static final int COL_EXPIRE_DATE = 4;
    public static final int COL_BLOCKED = 5;


    private ArrayList<DiscountCardLocal> cards;

    public TableModelClientDiscountCards(ArrayList<DiscountCardLocal> cards) {
        this.cards = cards;
    }

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

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

    @Override
    public String getColumnName(int column) {
        switch (column) {
            case COL_TYPE: return "Тип";
            case COL_CREATE_DATE: return "Дата создания";
            case COL_COLLAB: return "Выдал";
            case COL_MONEY: return "Накопленная сумма";
            case COL_EXPIRE_DATE: return "Срок действия, до";
            case COL_BLOCKED: return "Заблокировано";
            default: return "error in switch-case";
        }
    }

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

    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return false;
    }

    @Override
    public Object getValueAt(int rowIndex, int col) {
        try {
            DiscountCardLocal card = cards.get(rowIndex);
            switch (col) {
                case COL_TYPE: return card.getCardType();
                case COL_CREATE_DATE: return Converter.dateToString(card.getCreatedDate());
                case COL_COLLAB: return card.getCollaborator();
                case COL_MONEY: return card.getMoney();
                case COL_EXPIRE_DATE: return Converter.dateToString(card.getExpiredDate());
                case COL_BLOCKED: return card.getBlocker() != null;
                default: return "error in switch-case";
            }
        } catch (ClipsException ex) {
            return new ErrorValue(ex);
        }
    }

}
TOP

Related Classes of clips.userseach.clientExcemption.TableModelClientDiscountCards

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.