| | |
| | | } |
| | | }; |
| | | table.setModel(dataModel); |
| | | setColumnType(dtoList,table); |
| | | setColumnType(dtoList, table); |
| | | |
| | | return table; |
| | | } |
| | |
| | | public static void setColumnType(List<ColumnDto> dtoList, JTable table) { |
| | | for (int j = 0; j < dtoList.size(); j++) { |
| | | table.getColumnModel().getColumn(j).setPreferredWidth(dtoList.get(j).getColumnWidth()); |
| | | table.getColumnModel().getColumn(j).setMinWidth(2); |
| | | if (dtoList.get(j).getButtonList() != null) { |
| | | CreateTableButton.AcceptRejectRenderer renderer = new CreateTableButton.AcceptRejectRenderer(dtoList.get(j).getButtonList()); |
| | | table.getColumnModel().getColumn(j).setCellRenderer(renderer); |
| | |
| | | }); |
| | | table.getColumnModel().getColumn(j).setCellEditor(new DatePickerEditor(datePicker)); |
| | | } |
| | | if ("dict".equals(dtoList.get(j).getColumnType())) { |
| | | if ("dict".equals(dtoList.get(j).getColumnType()) || "dicts".equals(dtoList.get(j).getColumnType())) { |
| | | Map<Long, JComboBoxItem> itemMap = new HashMap<>(); |
| | | JComboBoxItem[] dictList = dtoList.get(j).getDictList(); |
| | | for (JComboBoxItem item : dictList) { |
| | |
| | | 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)); |
| | | if ("Circle".equals(dtoList.get(j).getColumnType())) { |
| | | table.getColumnModel().getColumn(j).setCellRenderer(new CircleRenderer()); |
| | | } |
| | | } |
| | | } |
| | |
| | | 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++) { |
| | |
| | | rowData[i][j] = valueStr; |
| | | } else if (dtoList.get(j).getColumnType().equals("dicts")) { |
| | | rowData[i][j] = valueStr; |
| | | } else if (dtoList.get(j).getColumnType().equals("Circle")) { |
| | | rowData[i][j] = valueStr; |
| | | } else if (dtoList.get(j).getColumnType().equals("autoCreate")) { |
| | | rowData[i][j] = "" + (i + 1); |
| | | } |
| | |
| | | } |
| | | } |
| | | } |
| | | 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(); |
| | |
| | | if (StringUtils.isNotBlank(fieldName)) { |
| | | if ("dict".equals(dtoList.get(j).getColumnType())) { |
| | | method = c1azz.getMethod("set" + StringUtils.capitalize(fieldName), Long.class); |
| | | } else if ("dicts".equals(dtoList.get(j).getColumnType())) { |
| | | method = c1azz.getMethod("set" + StringUtils.capitalize(fieldName), Integer.class); |
| | | } else { |
| | | method = c1azz.getMethod("set" + StringUtils.capitalize(fieldName), String.class); |
| | | } |
| | | Object value = table.getModel().getValueAt(i, j); |
| | | if (value != null) { |
| | | if (value != null && !value.equals("") ) { |
| | | if ("selectDate".equals(dtoList.get(j).getColumnType())) { |
| | | method.invoke(object, value.toString()); |
| | | System.out.println(value.toString().length()); |
| | | String valueStr = value.toString(); |
| | | Method method2 = c1azz.getMethod("set" + StringUtils.capitalize(fieldName) + "Digit", Long.class); |
| | | //Method method2 = c1azz.getMethod("set" + StringUtils.capitalize(fieldName) + "Digit", Long.class); |
| | | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); |
| | | Date date = null; |
| | | try { |
| | |
| | | e.printStackTrace(); |
| | | } |
| | | Long timestamp = date.getTime(); |
| | | method2.invoke(object, timestamp); |
| | | // method2.invoke(object, timestamp); |
| | | } else if ("dict".equals(dtoList.get(j).getColumnType())) { |
| | | method.invoke(object, Long.parseLong(value.toString())); |
| | | } else if ("dicts".equals(dtoList.get(j).getColumnType())) { |
| | | method.invoke(object, Integer.valueOf(value.toString())); |
| | | } else { |
| | | method.invoke(object, value.toString()); |
| | | } |