001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.gui.dialogs.changeset;
003
004import java.util.ArrayList;
005import java.util.List;
006
007import javax.swing.table.AbstractTableModel;
008
009import org.openstreetmap.josm.data.osm.ChangesetDiscussionComment;
010
011/**
012 * Model of changeset discussion table.
013 * @since 7715
014 */
015public class ChangesetDiscussionTableModel extends AbstractTableModel {
016
017    private final transient List<ChangesetDiscussionComment> data = new ArrayList<>();
018
019    @Override
020    public int getRowCount() {
021        return data.size();
022    }
023
024    @Override
025    public int getColumnCount() {
026        return 3;
027    }
028
029    @Override
030    public Object getValueAt(int rowIndex, int columnIndex) {
031        if (rowIndex < 0 || rowIndex >= data.size())
032            return null;
033        switch (columnIndex) {
034        case 0:
035            return data.get(rowIndex).getDate();
036        case 1:
037            return data.get(rowIndex).getUser();
038        default:
039            return data.get(rowIndex).getText();
040        }
041    }
042
043    /**
044     * Populates the model with the discussion of a changeset. If ds is null, the table is cleared.
045     *
046     * @param list the changeset discussion.
047     */
048    public void populate(List<ChangesetDiscussionComment> list) {
049        data.clear();
050        if (list != null) {
051            data.addAll(list);
052        }
053        fireTableDataChanged();
054    }
055}