123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- package com.its.pis.ui;
- import com.its.pis.entity.TbPisInfr;
- import lombok.extern.slf4j.Slf4j;
- import javax.swing.table.AbstractTableModel;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.List;
- @Slf4j
- public class CtlrSttsTableModel extends AbstractTableModel {
- private static final long serialVersionUID = 1331132425472559704L;
- private List<TbPisInfr> ctlrList = Collections.synchronizedList(new ArrayList<TbPisInfr>());
- private final String[] columnNames = {
- "#",
- "번호",
- "주차장 ID",
- "명칭",
- "IP",
- "PORT",
- "연결상태",
- "유형",
- "주기",
- "END-POINT",
- "TOKEN",
- "연결 시각",
- "연결종료 시각",
- "정보수신 시각"
- };
- public static final String[] netStateStr = {
- "Close", "Login", "Connect",
- };
- public CtlrSttsTableModel(List<TbPisInfr> ctlrList) {
- this.ctlrList = ctlrList;
- int indexCount = 1;
- for (TbPisInfr obj : ctlrList) {
- obj.setIndex(indexCount++);
- }
- if (ctlrList.size() == 0) {
- log.error("CtrlSttsTableModel Data zero: {}", 0);
- }
- }
- @Override
- public int getColumnCount() {
- return columnNames.length;
- }
- @Override
- public int getRowCount() {
- int size = 0;
- synchronized (this.ctlrList) {
- size = this.ctlrList.size();
- }
- return size;
- }
- @Override
- public String getColumnName(int columnIndex) {
- if (columnIndex < columnNames.length) {
- return columnNames[columnIndex];
- }
- return super.getColumnName(columnIndex);
- }
- @Override
- public Class<?> getColumnClass(int columnIndex) {
- if (ctlrList.isEmpty()) {
- return Object.class;
- }
- return getValueAt(0, columnIndex).getClass();
- }
- public TbPisInfr getControllerInfo(int row) {
- TbPisInfr info = this.ctlrList.get(row);
- return info;
- }
- @Override
- public Object getValueAt(int rowIndex, int columnIndex) {
- Object returnValue = null;
- synchronized (this.ctlrList) {
- TbPisInfr info = this.ctlrList.get(rowIndex);
- if (info == null) {
- return "";
- }
- int netState = info.getNetState();
- switch (columnIndex) {
- case 0:
- returnValue = info.getIndex();
- break;
- case 1:
- returnValue = info.getPIS_NMBR();
- break;
- case 2:
- returnValue = info.getPIS_ID();
- break;
- case 3:
- returnValue = info.getPIS_NM();
- break;
- case 4:
- returnValue = info.getPIS_IP();
- break;
- case 5:
- returnValue = String.valueOf(info.getPIS_PORT());
- break;
- case 6:
- returnValue = netStateStr[netState];
- break;
- case 7: returnValue = info.getPIS_TP(); break;
- case 8: returnValue = String.valueOf(info.getPIS_CYCLE()); break;
- case 9: returnValue = info.getPIS_END_POINT(); break;
- case 10: returnValue = info.getPIS_TOKEN(); break;
- case 11:
- returnValue = info.getConnectTm();
- break;
- case 12:
- returnValue = info.getDisConnectTm();
- break;
- case 13:
- returnValue = info.getLastRecvTimeFmt();
- break;
- }
- }
- return returnValue;
- }
- @Override
- public void setValueAt(Object value, int rowIndex, int columnIndex) {
- synchronized (this.ctlrList) {
- TbPisInfr obj = ctlrList.get(rowIndex);
- if (columnIndex == 0) {
- obj.setIndex((int) value);
- }
- }
- }
- public void setValueAt(TbPisInfr obj, int rowIdx, int colIdx) {
- synchronized (this.ctlrList) {
- }
- fireTableCellUpdated(rowIdx, colIdx);
- fireTableDataChanged();
- }
- public void Add(TbPisInfr info) {
- int index = 0;
- synchronized (this.ctlrList) {
- index = this.ctlrList.size();
- this.ctlrList.add(info);
- }
- fireTableRowsInserted(index, index);
- }
- public void setValue(TbPisInfr obj, int viewRow, int modelRow) {
- fireTableDataChanged();
- }
- }
|