Package ch.pterrettaz.jmess.gui

Source Code of ch.pterrettaz.jmess.gui.ResultTableModel

package ch.pterrettaz.jmess.gui;

import java.util.Collection;
import java.util.List;

import javax.swing.table.AbstractTableModel;

import ch.pterrettaz.jmess.core.ClassData;
import ch.pterrettaz.jmess.core.Data;

import com.google.common.collect.Lists;

public class ResultTableModel extends AbstractTableModel {

    private static final long serialVersionUID = -9064277097019459570L;

    private enum Column {
        Package(0), //
        Class(1), //
        Location(2);
        private final int index;

        private Column(int index) {
            this.index = index;
        }

        static Column forIndex(int index) {
            for (Column c : values()) {
                if (c.index == index)
                    return c;
            }
            return null;
        }

    }

    private final List<Data> results;

    public ResultTableModel() {
        results = Lists.newArrayList();
    }

    @Override
    public String getColumnName(int column) {
        return Column.forIndex(column).name();
    }

    public int getColumnCount() {
        return Column.values().length;
    }

    public int getRowCount() {
        return results.size();
    }

    public Object getValueAt(int row, int column) {
        Data data = results.get(row);
        switch (Column.forIndex(column)) {
        case Package:
            return data instanceof ClassData ? ((ClassData) data).getPackageName() : "";
        case Class:
            return data.getName();
        case Location:
            return data.getLocation();
        }
        return "";
    }

    @Override
    public Class<?> getColumnClass(int columnIndex) {
        return super.getColumnClass(columnIndex);
    }

    public void setResults(Collection<Data> results) {
        this.results.clear();
        this.results.addAll(results);
        fireTableDataChanged();
    }

    public void clear() {
        this.results.clear();
        fireTableDataChanged();
    }
}
TOP

Related Classes of ch.pterrettaz.jmess.gui.ResultTableModel

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.