Package clips.service

Source Code of clips.service.TableModelTransactionList

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

package clips.service;

import cli_fmw.main.ClipsException;
import clips.delegate.service.MoneyTransactionLocal;
import cli_fmw.utils.ErrorValue;
import clips.delegate.directory.ro.DirectoryCollaboratorItem;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import javax.swing.table.AbstractTableModel;

/**
*
* @author lacoste
*/
public class TableModelTransactionList extends AbstractTableModel {
    private List<MoneyTransactionLocal> transactionList;
    public static final int COLCOUNT = 5;
    public static final int COL_DATE = 0;
    public static final int COL_CASHIER = 1;
    public static final int COL_MONEY = 2;
    public static final int COL_DESC = 3;
    public static final int COL_ORDERED = 4;
   
    public TableModelTransactionList(List<MoneyTransactionLocal> transactions) {
        this.transactionList = transactions;
    }

    @Override
    public boolean isCellEditable(int r, int c) {
        return false;
    }

    @Override
    public String getColumnName(int c) {
        String s = null;
        switch (c) {
            case COL_DATE: s = "Дата"; break;
            case COL_CASHIER: s = "Кассир"; break;
            case COL_MONEY: s = "Сумма"; break;
            case COL_DESC: s = "Описание"; break;
            case COL_ORDERED: s = "Выполнена"; break;
            default: assert false;
        }
        return s;
    }
      
   
    @Override
    public int getRowCount() {
        if (transactionList != null) {
           return transactionList.size();
        }       
        return 0;
    }

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

    @Override
    public Object getValueAt(int r, int c) {
        try {
            MoneyTransactionLocal transaction = transactionList.get(r);
            Object s = "";           
            switch(c) {               
                case COL_DATE: {
                    //дата 
                    Date date = transaction.getDate();
                    SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy");
                    s = formatter.format(date);
                    break;                   
                }               
                case COL_CASHIER: {
                    //кассир
                    DirectoryCollaboratorItem coll = transaction.getCollaborator();
                    if(coll != null) {
                        s = coll.toString();
                    } else {
                        s = "-----";
                    }
                    break;                   
                }
                case COL_MONEY: {
                    //сумма
                    s = String.format("%.2f", ((float) transaction.getMoney()) / 100);
                    break;
                }
                case COL_DESC: {
                    //Описание
                    s = transaction.getDescription();
                    break;
                }
                case COL_ORDERED: {
                    if(transaction.getPermitted()) {
                        s = "Да";
                    } else {
                        s = "Нет";
                    }
                    break;
                }
                default:
                    s = "Не сработал swith-case";
            }
            return s;
        } catch(ClipsException ex) {
            return new ErrorValue(ex);
        }
   
    }
   
   
}
TOP

Related Classes of clips.service.TableModelTransactionList

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.