CtlrSttsTableModel.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. package com.its.pis.ui;
  2. import com.its.pis.entity.TbPisInfr;
  3. import lombok.extern.slf4j.Slf4j;
  4. import javax.swing.table.AbstractTableModel;
  5. import java.util.ArrayList;
  6. import java.util.Collections;
  7. import java.util.List;
  8. @Slf4j
  9. public class CtlrSttsTableModel extends AbstractTableModel {
  10. private static final long serialVersionUID = 1331132425472559704L;
  11. private List<TbPisInfr> ctlrList = Collections.synchronizedList(new ArrayList<TbPisInfr>());
  12. private final String[] columnNames = {
  13. "#",
  14. "번호",
  15. "주차장 ID",
  16. "명칭",
  17. "IP",
  18. "PORT",
  19. "연결상태",
  20. "유형",
  21. "주기",
  22. "END-POINT",
  23. "TOKEN",
  24. "연결 시각",
  25. "연결종료 시각",
  26. "정보수신 시각"
  27. };
  28. public static final String[] netStateStr = {
  29. "Close", "Login", "Connect",
  30. };
  31. public CtlrSttsTableModel(List<TbPisInfr> ctlrList) {
  32. this.ctlrList = ctlrList;
  33. int indexCount = 1;
  34. for (TbPisInfr obj : ctlrList) {
  35. obj.setIndex(indexCount++);
  36. }
  37. if (ctlrList.size() == 0) {
  38. log.error("CtrlSttsTableModel Data zero: {}", 0);
  39. }
  40. }
  41. @Override
  42. public int getColumnCount() {
  43. return columnNames.length;
  44. }
  45. @Override
  46. public int getRowCount() {
  47. int size = 0;
  48. synchronized (this.ctlrList) {
  49. size = this.ctlrList.size();
  50. }
  51. return size;
  52. }
  53. @Override
  54. public String getColumnName(int columnIndex) {
  55. if (columnIndex < columnNames.length) {
  56. return columnNames[columnIndex];
  57. }
  58. return super.getColumnName(columnIndex);
  59. }
  60. @Override
  61. public Class<?> getColumnClass(int columnIndex) {
  62. if (ctlrList.isEmpty()) {
  63. return Object.class;
  64. }
  65. return getValueAt(0, columnIndex).getClass();
  66. }
  67. public TbPisInfr getControllerInfo(int row) {
  68. TbPisInfr info = this.ctlrList.get(row);
  69. return info;
  70. }
  71. @Override
  72. public Object getValueAt(int rowIndex, int columnIndex) {
  73. Object returnValue = null;
  74. synchronized (this.ctlrList) {
  75. TbPisInfr info = this.ctlrList.get(rowIndex);
  76. if (info == null) {
  77. return "";
  78. }
  79. int netState = info.getNetState();
  80. switch (columnIndex) {
  81. case 0:
  82. returnValue = info.getIndex();
  83. break;
  84. case 1:
  85. returnValue = info.getPIS_NMBR();
  86. break;
  87. case 2:
  88. returnValue = info.getPIS_ID();
  89. break;
  90. case 3:
  91. returnValue = info.getPIS_NM();
  92. break;
  93. case 4:
  94. returnValue = info.getPIS_IP();
  95. break;
  96. case 5:
  97. returnValue = String.valueOf(info.getPIS_PORT());
  98. break;
  99. case 6:
  100. returnValue = netStateStr[netState];
  101. break;
  102. case 7: returnValue = info.getPIS_TP(); break;
  103. case 8: returnValue = String.valueOf(info.getPIS_CYCLE()); break;
  104. case 9: returnValue = info.getPIS_END_POINT(); break;
  105. case 10: returnValue = info.getPIS_TOKEN(); break;
  106. case 11:
  107. returnValue = info.getConnectTm();
  108. break;
  109. case 12:
  110. returnValue = info.getDisConnectTm();
  111. break;
  112. case 13:
  113. returnValue = info.getLastRecvTimeFmt();
  114. break;
  115. }
  116. }
  117. return returnValue;
  118. }
  119. @Override
  120. public void setValueAt(Object value, int rowIndex, int columnIndex) {
  121. synchronized (this.ctlrList) {
  122. TbPisInfr obj = ctlrList.get(rowIndex);
  123. if (columnIndex == 0) {
  124. obj.setIndex((int) value);
  125. }
  126. }
  127. }
  128. public void setValueAt(TbPisInfr obj, int rowIdx, int colIdx) {
  129. synchronized (this.ctlrList) {
  130. }
  131. fireTableCellUpdated(rowIdx, colIdx);
  132. fireTableDataChanged();
  133. }
  134. public void Add(TbPisInfr info) {
  135. int index = 0;
  136. synchronized (this.ctlrList) {
  137. index = this.ctlrList.size();
  138. this.ctlrList.add(info);
  139. }
  140. fireTableRowsInserted(index, index);
  141. }
  142. public void setValue(TbPisInfr obj, int viewRow, int modelRow) {
  143. fireTableDataChanged();
  144. }
  145. }