package com.example.client.service;
|
|
import com.example.client.dto.ColumnDto;
|
import com.example.client.dto.JComboBoxItem;
|
import com.example.client.model.TableButton;
|
import com.example.client.utils.CommonTable;
|
import com.example.server.boatFleet.service.BoatFleetService;
|
import com.example.server.teamGroup.model.SysTeamGroupClass;
|
import com.example.server.teamGroup.service.SysTeamGroupClassService;
|
import com.example.server.user.model.SysUser;
|
import com.example.server.user.service.UserService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import javax.swing.*;
|
import javax.swing.event.TableModelEvent;
|
import javax.swing.table.DefaultTableModel;
|
import java.awt.*;
|
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionListener;
|
import java.util.ArrayList;
|
import java.util.List;
|
|
|
@Service
|
public class TeamGroupManageService {
|
@Autowired
|
private SysTeamGroupClassService sysTeamGroupClassService;
|
|
private JTable table;
|
private List<ColumnDto> columnDto;
|
|
public JPanel createTable(Integer width, Integer height, JFrame jFrame) {
|
JPanel panel = new JPanel();
|
List<SysTeamGroupClass> list;
|
JPanel topJpanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
topJpanel.setPreferredSize(new Dimension(width, 37));
|
topJpanel.setBackground(Color.WHITE);
|
JPanel centerJpanel = new JPanel();
|
centerJpanel.setPreferredSize(new Dimension(width - 20, height - 100));
|
centerJpanel.setBackground(Color.WHITE);
|
panel.add(topJpanel, BorderLayout.NORTH);
|
panel.add(centerJpanel, BorderLayout.CENTER);
|
|
JButton btnInsert = new JButton("新增");
|
|
topJpanel.add(btnInsert);
|
|
|
List<TableButton> buttonList = new ArrayList<>();
|
buttonList.add(new TableButton("edit", "编辑"));
|
buttonList.add(new TableButton("del", "删除"));
|
list = sysTeamGroupClassService.getListByTree();
|
|
columnDto = new ArrayList<>();
|
//columnDto.add(new ColumnDto("ID", "id", -1, null,false));
|
columnDto.add(new ColumnDto("序号", "", (width - 10) / 3, "autoCreate", false, null,null));
|
columnDto.add(new ColumnDto("部门/专业", "name", (width - 3) / 3, null, false, null,null));
|
columnDto.add(new ColumnDto("操作", "", (width - 10) / 3, "", true, buttonList,null));
|
|
table = CommonTable.createCommonTable(list, columnDto);
|
table.setRowHeight(25);
|
table.setAutoCreateRowSorter(true);
|
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
|
|
//tableModelListener(table,jFrame,list);
|
|
/* btnInsert.addActionListener(new ActionListener() {
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
SysUser data = new SysUser();
|
addOrUpdate.openDialog(data,jFrame, columnDto,table);
|
jFrame.setEnabled(false);
|
}
|
});*/
|
|
JScrollPane scrollPane = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
|
scrollPane.setViewportView(table);
|
scrollPane.getViewport().setBackground(Color.WHITE);
|
scrollPane.setPreferredSize(new Dimension(width - 20, height - 100));
|
centerJpanel.add(scrollPane);
|
|
return panel;
|
}
|
|
/* public void tableModelListener(JTable table,JFrame jFrame,List<SysUser> list){
|
table.getModel().addTableModelListener(e -> {
|
// 检查事件类型
|
if (e.getType() == TableModelEvent.UPDATE) {
|
// 获取变化的行和列
|
int row = e.getFirstRow();
|
int column = e.getColumn();
|
|
// 获取新的值
|
Object newValue = table.getModel().getValueAt(row, column);
|
// 输出变化信息
|
if (newValue.equals("edit")){
|
SysUser data = list.get(row);
|
addOrUpdate.openDialog(data,jFrame, columnDto,table);
|
jFrame.setEnabled(false);
|
}else if(newValue.equals("del")) {
|
int n = JOptionPane.showConfirmDialog(null, "是否删除?", "提示", JOptionPane.YES_NO_OPTION);
|
if (n == 0) {
|
DefaultTableModel model = (DefaultTableModel) table.getModel();
|
SysUser data = list.get(row);
|
userService.deleteLogic(data.getId());
|
list.remove(row);
|
model.removeRow(row);
|
}
|
}
|
System.out.println("单元格变化: 行=" + row + ", 列=" + column + ", 新值=" + newValue);
|
}
|
});
|
}
|
*/
|
|
}
|