From 23f02e6b45dd7cf0ab2e7827144913ca59575ea4 Mon Sep 17 00:00:00 2001
From: jinlin <jinlin>
Date: 星期二, 04 三月 2025 18:59:23 +0800
Subject: [PATCH] jar
---
src/main/java/com/example/client/utils/CommonTable.java | 38 ++++++++------------------------------
1 files changed, 8 insertions(+), 30 deletions(-)
diff --git a/src/main/java/com/example/client/utils/CommonTable.java b/src/main/java/com/example/client/utils/CommonTable.java
index f9e4232..6321b72 100644
--- a/src/main/java/com/example/client/utils/CommonTable.java
+++ b/src/main/java/com/example/client/utils/CommonTable.java
@@ -37,7 +37,7 @@
}
};
table.setModel(dataModel);
- setColumnType(dtoList,table);
+ setColumnType(dtoList, table);
return table;
}
@@ -87,41 +87,16 @@
table.getColumnModel().getColumn(j).setCellRenderer(new CellComboBoxRenderer(itemMap));
table.getColumnModel().getColumn(j).setCellEditor(new CellComboBoxEditor(comboBox, itemMap));
}
- if ("dicts".equals(dtoList.get(j).getColumnType())) {
- Map<Long, JComboBoxItem> itemMap = new HashMap<>();
- JComboBoxItem[] dictList = dtoList.get(j).getDictList();
- for (JComboBoxItem item : dictList) {
- itemMap.put(item.getId(), item);
- }
-
- // 鍒涘缓 JComboBox 骞舵坊鍔� Item 瀵硅薄
- JComboBox<JComboBoxItem> comboBox = new JComboBox<>(dictList);
-
- // 璁剧疆鑷畾涔夋覆鏌撳櫒
- comboBox.setRenderer(new BasicComboBoxRenderer() {
- @Override
- public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
- super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
- if (value instanceof JComboBoxItem) {
- JComboBoxItem item = (JComboBoxItem) value;
- setText(item.getName()); // 鏄剧ず name
- }
- return this;
- }
- });
- table.getColumnModel().getColumn(j).setCellRenderer(new CellComboBoxRenderer(itemMap));
- table.getColumnModel().getColumn(j).setCellEditor(new CellComboBoxEditor(comboBox, itemMap));
- }
}
}
public static void refreshTable(List<?> list, List<ColumnDto> dtoList, JTable table) {
TableModel dataModel = createCommonTableModel(list, dtoList);
table.setModel(dataModel);
- setColumnType(dtoList,table);
+ setColumnType(dtoList, table);
}
- public static TableModel createCommonTableModel(List<?> list, List<ColumnDto> dtoList) {
+ public static String[][] getRowData(List<?> list, List<ColumnDto> dtoList) {
String[][] rowData = new String[list.size()][dtoList.size()];
for (int i = 0; i < list.size(); i++) {
@@ -143,8 +118,6 @@
rowData[i][j] = valueStr;
} else if (dtoList.get(j).getColumnType().equals("dict")) {
rowData[i][j] = valueStr;
- } else if (dtoList.get(j).getColumnType().equals("dicts")) {
- rowData[i][j] = valueStr;
} else if (dtoList.get(j).getColumnType().equals("autoCreate")) {
rowData[i][j] = "" + (i + 1);
}
@@ -153,6 +126,11 @@
}
}
}
+ return rowData;
+ }
+
+ public static TableModel createCommonTableModel(List<?> list, List<ColumnDto> dtoList) {
+ String[][] rowData = getRowData(list, dtoList);
String[] columnNames = new String[dtoList.size()];
for (int j = 0; j < dtoList.size(); j++) {
columnNames[j] = dtoList.get(j).getColumnDesc();
--
Gitblit v1.9.1