org.bidib.wizard.localhost.client.view.SubscribedClientTableTableModel Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bidibwizard-localhost-client Show documentation
Show all versions of bidibwizard-localhost-client Show documentation
jBiDiB BiDiB Wizard localhost client POM
package org.bidib.wizard.localhost.client.view;
import org.apache.commons.lang3.StringUtils;
import org.bidib.jbidibc.messages.utils.ByteUtils;
import org.bidib.jbidibc.messages.utils.NodeUtils;
import org.bidib.wizard.api.locale.Resources;
import org.bidib.wizard.localhost.client.model.SubscribedClientModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.jgoodies.binding.adapter.AbstractTableAdapter;
import com.jgoodies.binding.list.SelectionInList;
public class SubscribedClientTableTableModel extends AbstractTableAdapter {
private static final long serialVersionUID = 1L;
private static final Logger LOGGER = LoggerFactory.getLogger(SubscribedClientTableTableModel.class);
public static final int COLUMN_ADDRESS = 0;
public static final int COLUMN_UNIQUE_ID = 1;
public static final int COLUMN_SUBSCRIPTIONS = 2;
private static final String[] COLUMNNAMES =
new String[] { Resources.getString(SubscribedClientTableTableModel.class, "address"),
Resources.getString(SubscribedClientTableTableModel.class, "uniqueId"),
Resources.getString(SubscribedClientTableTableModel.class, "subscriptions") };
public SubscribedClientTableTableModel(SelectionInList subscribedClientList) {
super(subscribedClientList, COLUMNNAMES);
LOGGER.info("Current listModel: {}", getListModel());
}
@Override
public Class> getColumnClass(int column) {
switch (column) {
case COLUMN_ADDRESS:
return String.class;
case COLUMN_UNIQUE_ID:
return String.class;
case COLUMN_SUBSCRIPTIONS:
return String.class;
default:
return Object.class;
}
}
@Override
public boolean isCellEditable(int row, int column) {
return false;
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
SubscribedClientModel subscribedClient = getRow(rowIndex);
switch (columnIndex) {
case COLUMN_ADDRESS:
return NodeUtils.formatAddressLong(subscribedClient.getNodeAddress());
case COLUMN_UNIQUE_ID:
return ByteUtils.getUniqueIdAsString(subscribedClient.getUniqueId());
case COLUMN_SUBSCRIPTIONS:
return subscribedClient.getMessageClasses() != null
? StringUtils.leftPad(Integer.toString(subscribedClient.getMessageClasses(), 2), 16, "0") : null;
default:
return null;
}
}
}