Package clips.userseach

Source Code of clips.userseach.TableModelUserSearch

/*
* TableModelFoundClients.java
*
* Created on 23 Декабрь 2007 г., 17:56
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package clips.userseach;

import clips.delegate.client.ClientLocal;
import cli_fmw.main.ClipsException;
import java.util.ArrayList;
import java.util.Date;
import javax.swing.table.AbstractTableModel;
import cli_fmw.utils.ErrorValue;
import clips.Main;

/**
* Модель таблицы, отображающая список найденных клиентов
* Необходимо передать clientList
* @author ViP
*/
public class TableModelUserSearch extends AbstractTableModel //Класс модели который запрещает редактирование всех ячеек
{

    private ArrayList<ClientLocal> clientList;
    public static final int COLCOUNT = 2;
    public static final int COL_FIO = 0;
    public static final int COL_DATE = 1;

    public TableModelUserSearch(ArrayList<ClientLocal> clientList) {
        this.clientList = clientList;
    }

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

    @Override
    public Class<?> getColumnClass(int columnIndex) {
        if (columnIndex == COL_DATE) return Date.class;
        if (columnIndex == COLCOUNT) return Integer.class;
        return super.getColumnClass(columnIndex);
    }


    @Override
    public Object getValueAt(int r, int c) {
        try {
            ClientLocal cl = clientList.get(r);
            switch (c) {
                case COL_FIO: {
                    return cl.getSurname() + " " + cl.getName() + " " +
                            cl.getPathron();
                }
                case COL_DATE: {
                    return cl.getBorn();
                }
                case COLCOUNT: {
                    return cl.getID();
                }
                default:
                    throw new IllegalArgumentException("Invalid column : " + c);
            }
        } catch (ClipsException ex) {
            return new ErrorValue(ex);
        }
    }

    @Override
    public int getColumnCount() {
        if (Main.DEVELOPED_ON) {
            return COLCOUNT + 1;
        } else {
            return COLCOUNT;
        }
    }

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

    @Override
    public String getColumnName(int c) {
        switch (c) {
            case COL_FIO:
                return "ФИО";
            case COL_DATE:
                return "Дата рождения";
            case COLCOUNT:
                return "ID";
            default:
                return null;

        }
    }
}
TOP

Related Classes of clips.userseach.TableModelUserSearch

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.