All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.ultreia.gc.lfn.ui.LogFieldNotesTableModel Maven / Gradle / Ivy

package io.ultreia.gc.lfn.ui;

/*-
 * #%L
 * GC toolkit :: LFN
 * %%
 * Copyright (C) 2017 Ultreia.io
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public
 * License along with this program.  If not, see
 * .
 * #L%
 */

import io.ultreia.gc.model.GcFieldNote;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import javax.swing.table.AbstractTableModel;

/**
 * Created by tchemit on 15/04/17.
 *
 * @author Tony Chemit - [email protected]
 */
public class LogFieldNotesTableModel extends AbstractTableModel implements Iterable {

    private static final String[] COLUMN_NAMES = {"F?", "Log type", "Date", "Name"};
    private static final Class[] COLUMN_TYPES = {boolean.class, String.class, String.class, String.class};

    private final LogFieldNotesUIModel model;

    LogFieldNotesTableModel(LogFieldNotesUIModel model) {
        this.model = model;
    }

    private Optional> getData() {
        return Optional.ofNullable(model.getFieldNotes());
    }

    public GcFieldNote getFieldNote(int row) {
        return getData().map(f -> f.get(row)).orElse(null);
    }

    @Override
    public int getRowCount() {
        return getData().map(List::size).orElse(0);
    }

    @Override
    public int getColumnCount() {
        return COLUMN_NAMES.length;
    }

    @Override
    public String getColumnName(int column) {
        return COLUMN_NAMES[column];
    }

    @Override
    public Class getColumnClass(int columnIndex) {
        return COLUMN_TYPES[columnIndex];
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        GcFieldNote fieldNote = getFieldNote(rowIndex);
        switch (columnIndex) {
            case 0:
                return fieldNote.isFavorite();
            case 1:
                return fieldNote.getLogType();
            case 2:
                return fieldNote.getDate();
            case 3:
                return fieldNote.getName();
        }
        return null;
    }

    @Override
    public Iterator iterator() {
        return getData().map(List::iterator).orElse(null);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy