/*******************************************************************************
* Copyright (c) 2016 Weasis Team and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Nicolas Roduit - initial API and implementation
*******************************************************************************/
package org.weasis.core.ui.util;
import javax.swing.table.AbstractTableModel;
import org.weasis.core.ui.Messages;
public class SimpleTableModel extends AbstractTableModel {
private String[] columnNames =
{ Messages.getString("SimpleTableModel.param"), Messages.getString("SimpleTableModel.val") }; //$NON-NLS-1$ //$NON-NLS-2$
private Object[][] data = {};
private final boolean editable;
public SimpleTableModel(String[] columnNames, Object[][] data) {
this(columnNames, data, false);
}
public SimpleTableModel(String[] columnNames, Object[][] data, boolean editable) {
if (columnNames != null) {
this.columnNames = columnNames;
}
if (data != null) {
this.data = data;
}
this.editable = editable;
}
@Override
public int getColumnCount() {
return columnNames.length;
}
@Override
public int getRowCount() {
return data.length;
}
@Override
public String getColumnName(int col) {
return columnNames[col];
}
@Override
public boolean isCellEditable(int row, int col) {
return editable;
}
@Override
public Object getValueAt(int row, int col) {
return data[row][col];
}
@Override
public void setValueAt(Object value, int row, int col) {
data[row][col] = value;
fireTableCellUpdated(row, col);
}
@Override
public Class<?> getColumnClass(int c) {
return getValueAt(0, c).getClass();
}
}