// System.out.println("DeviceName = " + deviceList.get(table.getSelectedRow()).getName());
int row = table.getSelectedRow();
// System.out.println("mouseClicked col=" + col);
if ((row > -1) && (row < deviceList.size())) {
IDevice device = deviceList.get(row);
String completeAttributeName = device.getName();
bean.setCompleteAttributeName(completeAttributeName);
cardLayout.show(controlPanel, "DEVICE");
int col = table.getSelectedColumn();
if (col == 0) {
table.setValueAt(!device.isEnabled(), row, col);
}
} else {
bean.setModel(null);
cardLayout.show(controlPanel, "NONE");
}
addToAllButton.setEnabled(false);
removeFromAllButton.setEnabled(false);
int[] rows = table.getSelectedRows();
if ((rows != null) && (rows.length > 0)) {
removeFromAllButton.setEnabled(true);
for (int singleRow : rows) {
Object value = table.getValueAt(singleRow, 1);
if (value instanceof IDevice) {
if(!((IDevice)value).isCommon()) {
addToAllButton.setEnabled(true);
break;
}
}
}
}
}
});
tableModel = new AbstractTableModel() {
private static final long serialVersionUID = 4480875677500863631L;
@Override
public int getRowCount() {
if (deviceList != null) {
return deviceList.size();
}
return 0;
}
@Override
public int getColumnCount() {
return 2;
}
@Override
public String getColumnName(int column) {
if (column == 0) {
return "Enable";
}
return "Device";
}
@Override
public Class<?> getColumnClass(int columnIndex) {
if (columnIndex == 0) {
return Boolean.class;
}
return IDevice.class;
}
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
boolean isEditable = false;
if (columnIndex == 0) {
isEditable = editable;
} else {
isEditable = management;
}
// System.out.println("isCellEditable=" + isEditable);
return isEditable;
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
Object value = null;
if ((deviceList != null) && (deviceList.size() > rowIndex)) {
IDevice device = deviceList.get(rowIndex);
if (columnIndex == 0) {
value = device.isEnabled();
} else {
value = device;
}
}
return value;
}
@Override
public void setValueAt(Object value, int rowIndex, int columnIndex) {
// System.out.println("setValueAt=" + rowIndex + "," + columnIndex);
// System.out.println("deviceList=" + deviceList.size());
if ((value != null) && (deviceList != null) && (deviceList.size() > rowIndex)) {
IDevice device = deviceList.get(rowIndex);
if (columnIndex == 0) {
device.setEnabled((Boolean) value);
// System.out.println("setValueAt=" + value + "=> " + device);
if (listener != null) {
listener.deviceEnabled(device.getName(), (Boolean) value);
}
} else {
String oldName = device.getName();
String newName = value.toString().toLowerCase();
device.setName(newName);
// System.out.println("oldName=" + oldName);
// System.out.println("newName=" + newName);
if (listener != null) {
listener.deviceRenamed(oldName, newName);
}