OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Blame | Last modification | View Log | RSS feed

/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 * 
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
 * 
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
 * language governing permissions and limitations under the License.
 * 
 * When distributing the software, include this License Header Notice in each file.
 */
 
 package org.openconcerto.erp.core.finance.accounting.ui;

import org.openconcerto.sql.element.SQLElement;
import org.openconcerto.sql.model.SQLRowValues;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

import javax.swing.table.AbstractTableModel;

public class PropoLettrageTableModel extends AbstractTableModel {

    List<SQLRowValues> datas;

    List<String> colName = Arrays.asList("Libellé", "N° Mouvement", "Pièce", "Pièce commerciale", "Date", "Débit", "Crédit");
    List<String> fieldName = Arrays.asList("NOM", "ID_MOUVEMENT", "ID_PIECE", "PIECE_COMMERCIALE", "DATE", "DEBIT", "CREDIT");
    List<Class<?>> colClass = Arrays.asList(String.class, Integer.class, String.class, String.class, Date.class, Long.class, Long.class);
    SQLElement eltEcr;

    public PropoLettrageTableModel(SQLElement eltEcr, List<SQLRowValues> datas) {
        this.datas = datas;
        this.eltEcr = eltEcr;
    }

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

    @Override
    public Class<?> getColumnClass(int columnIndex) {

        
        return this.colClass.get(columnIndex);
    }

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

    @Override
    public int getColumnCount() {
        return this.fieldName.size();
    }

    @Override
    public String getColumnName(int column) {
        String field = this.colName.get(column);
        return field;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        final SQLRowValues sqlRowValues = this.datas.get(rowIndex);

        final String fieldName2 = this.fieldName.get(columnIndex);
        if (fieldName2.startsWith("ID_")) {
            if (fieldName2.equals("ID_MOUVEMENT")) {
                return sqlRowValues.getForeign("ID_MOUVEMENT").getInt("NUMERO");
            } else {
                return sqlRowValues.getForeign("ID_MOUVEMENT").getForeign("ID_PIECE").getString("NOM");
            }
        } else {
            return sqlRowValues.getObject(fieldName2);
        }
    }

    public boolean isSelectionEqual(int[] selectionIndex) {
        if (selectionIndex == null || selectionIndex.length == 0) {
            return false;
        } else {
            long l = 0;
            for (int i : selectionIndex) {
                l += this.datas.get(i).getLong("DEBIT");
                l -= this.datas.get(i).getLong("CREDIT");
            }
            return l == 0;
        }
    }

    @Override
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {

        // this.datas.get(rowIndex).put(columnIndex, aValue);
    }

    public SQLRowValues getRowValuesAt(int index) {
        return this.datas.get(index);
    }

}