| | |
| | | import com.example.client.dto.JComboBoxItem; |
| | | import com.example.client.model.TableButton; |
| | | import com.example.client.utils.CommonTable; |
| | | import com.example.client.utils.Compute; |
| | | import com.example.client.utils.GBC; |
| | | import com.example.server.progressTrack.model.DjJdgzNetworkLevel1; |
| | | import com.example.server.progressTrack.model.DjJdgzShip; |
| | |
| | | @Autowired |
| | | private DjJdgzShipService djJdgzShipService; |
| | | @Autowired |
| | | private ShipManageService shipManageService; |
| | | @Autowired |
| | | private Level1AddOrUpdate addOrUpdate; // 注入 AddOrupdate 实例 |
| | | |
| | | private JTable table; |
| | |
| | | private List<ColumnDto> columnDto; |
| | | |
| | | public JPanel createTable(Integer width, Integer height, JFrame jFrame) { |
| | | JPanel panel = new JPanel(); |
| | | JPanel panel = new JPanel(new BorderLayout()); |
| | | |
| | | JPanel topJpanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); |
| | | topJpanel.setPreferredSize(new Dimension(width, 37)); |
| | | topJpanel.setPreferredSize(new Dimension(width, 40)); |
| | | topJpanel.setBackground(Color.WHITE); |
| | | JPanel centerJpanel = new JPanel(); |
| | | centerJpanel.setPreferredSize(new Dimension(width - 20, height - 100)); |
| | | |
| | | centerJpanel.setPreferredSize(new Dimension(width - 20, Compute.ComputeHeight(40, jFrame))); |
| | | centerJpanel.setBackground(Color.WHITE); |
| | | panel.add(topJpanel, BorderLayout.NORTH); |
| | | panel.add(centerJpanel, BorderLayout.CENTER); |
| | |
| | | List<DjJdgzShip> shipList = djJdgzShipService.getList(); |
| | | JComboBox comboBox = new JComboBox(); |
| | | JButton btnInsert = new JButton("新增"); |
| | | JButton btnShip = new JButton("X号管理"); |
| | | |
| | | topJpanel.add(comboBox); |
| | | topJpanel.add(btnInsert); |
| | | topJpanel.add(btnShip); |
| | | |
| | | comboBox.setPreferredSize(new Dimension(300, 28)); |
| | | |
| | |
| | | |
| | | columnDto = new ArrayList<>(); |
| | | //columnDto.add(new ColumnDto("ID", "id", -1, null,false)); |
| | | columnDto.add(new ColumnDto("序号", "", (width - 10) / 4, "autoCreate", false, null,null)); |
| | | columnDto.add(new ColumnDto("工程", "ProjectName", (width - 10) / 4, null, false, null,null)); |
| | | columnDto.add(new ColumnDto("起始时间", "StartDate", (width - 10) / 4, "selectDate", false, null,null)); |
| | | columnDto.add(new ColumnDto("操作", "", (width - 10) / 4, "", true, buttonList,null)); |
| | | columnDto.add(new ColumnDto("序号", "", (width - 10) / 4, "autoCreate", false, null, null)); |
| | | columnDto.add(new ColumnDto("工程", "ProjectName", (width - 10) / 4, null, false, null, null)); |
| | | columnDto.add(new ColumnDto("起始时间", "StartDate", (width - 10) / 4, "selectDate", false, null, null)); |
| | | columnDto.add(new ColumnDto("操作", "", (width - 10) / 4, "", true, buttonList, null)); |
| | | |
| | | table = CommonTable.createCommonTable(list, columnDto); |
| | | table.setRowHeight(25); |
| | |
| | | Long shipId = shipMap.get(content); |
| | | list = level1Service.getList(shipId); |
| | | if (!isFirstLoadData[0]) { |
| | | CommonTable.refreshTable(list, columnDto,table); |
| | | CommonTable.refreshTable(list, columnDto, table); |
| | | table.setRowHeight(25); |
| | | |
| | | table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); |
| | | |
| | | tableModelListener(table,jFrame); |
| | | }else{ |
| | | tableModelListener(table, jFrame); |
| | | } else { |
| | | isFirstLoadData[0] = false; |
| | | } |
| | | } |
| | |
| | | for (int i = 0; i < shipList.size(); i++) { |
| | | shipMap.put(shipList.get(i).getShipNo(), shipList.get(i).getId()); |
| | | comboBox.addItem(shipList.get(i).getShipNo()); |
| | | } |
| | | } |
| | | comboBox.setSelectedItem(shipList.get(0).getShipNo()); |
| | | |
| | | tableModelListener(table,jFrame); |
| | | tableModelListener(table, jFrame); |
| | | |
| | | btnInsert.addActionListener(new ActionListener() { |
| | | @Override |
| | |
| | | insert(jFrame); |
| | | } |
| | | }); |
| | | btnShip.addActionListener(new ActionListener() { |
| | | @Override |
| | | public void actionPerformed(ActionEvent e) { |
| | | jFrame.setEnabled(false); |
| | | shipManageService.createTable(jFrame); |
| | | } |
| | | }); |
| | | |
| | | 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)); |
| | | scrollPane.setPreferredSize(new Dimension(width - 20, Compute.ComputeHeight(40, jFrame))); |
| | | centerJpanel.add(scrollPane); |
| | | jFrame.addComponentListener(new ComponentAdapter() { |
| | | @Override |
| | | public void componentResized(ComponentEvent e) { |
| | | centerJpanel.setPreferredSize(new Dimension(width - 20, Compute.ComputeHeight(40, jFrame))); |
| | | scrollPane.setPreferredSize(new Dimension(width - 20, Compute.ComputeHeightWithScroll(40, jFrame))); |
| | | centerJpanel.revalidate(); |
| | | centerJpanel.repaint(); |
| | | scrollPane.revalidate(); |
| | | scrollPane.repaint(); |
| | | } |
| | | }); |
| | | |
| | | return panel; |
| | | } |
| | |
| | | new JComboBoxItem(1L, "三级"), |
| | | }; |
| | | |
| | | JLabel JLabel1 = new JLabel("玄号"); |
| | | JLabel JLabel1 = new JLabel("X号"); |
| | | JComboBox<JComboBoxItem> comboBox0 = new JComboBox<>(shipList); |
| | | comboBox0.setPreferredSize(new Dimension(185, 28)); |
| | | |
| | |
| | | |
| | | JButton btnSave = new JButton("保存"); |
| | | |
| | | frame1.add(JLabel1, new GBC(0, 0,1,1).setAnchor(GBC.SOUTHEAST).setInsets(5)); |
| | | frame1.add(JLabel1, new GBC(0, 0, 1, 1).setAnchor(GBC.SOUTHEAST).setInsets(5)); |
| | | frame1.add(comboBox0, new GBC(1, 0, 1, 1).setAnchor(GBC.SOUTHWEST).setInsets(5)); |
| | | |
| | | frame1.add(JLabel2, new GBC(0, 1, 1, 1).setAnchor(GBC.SOUTHEAST).setInsets(5)); |
| | | frame1.add(comboBox1, new GBC(1, 1, 1, 1).setAnchor(GBC.SOUTHWEST).setInsets(5)); |
| | | |
| | | frame1.add(JLabel3, new GBC(0, 2,1,1).setAnchor(GBC.SOUTHEAST).setInsets(5)); |
| | | frame1.add(JLabel3, new GBC(0, 2, 1, 1).setAnchor(GBC.SOUTHEAST).setInsets(5)); |
| | | frame1.add(yearPicker, new GBC(1, 2, 1, 1).setAnchor(GBC.SOUTHWEST).setInsets(5)); |
| | | |
| | | frame1.add(JLabel4, new GBC(0, 3,1,1).setAnchor(GBC.SOUTHEAST).setInsets(5)); |
| | | frame1.add(JLabel4, new GBC(0, 3, 1, 1).setAnchor(GBC.SOUTHEAST).setInsets(5)); |
| | | frame1.add(beginDate, new GBC(1, 3, 1, 1).setAnchor(GBC.NORTHWEST).setInsets(5)); |
| | | |
| | | frame1.add(btnSave, new GBC(0, 4, 2, 1).setWeight(1, 0)); |
| | |
| | | data.setStartDate(sdFormat.format(beginDate.getDate())); |
| | | data.setYear((Integer) yearPicker.getValue()); |
| | | data.setAdventDay(7); |
| | | data.setProjectName(level.getName()+"修理"+ship.getName()+"项目"); |
| | | data.setProjectName(level.getName() + "修理" + ship.getName() + "项目"); |
| | | level1Service.insert(data); |
| | | list = level1Service.getList(ship.getId()); |
| | | CommonTable.refreshTable(list,columnDto,table); |
| | | CommonTable.refreshTable(list, columnDto, table); |
| | | table.setRowHeight(25); |
| | | |
| | | table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); |
| | | tableModelListener(table,jFrame); |
| | | tableModelListener(table, jFrame); |
| | | frame1.dispose(); |
| | | jFrame.setEnabled(true);//将主界面再设置为可操作的 |
| | | }); |
| | | } |
| | | |
| | | public void tableModelListener(JTable table,JFrame jFrame){ |
| | | public void tableModelListener(JTable table, JFrame jFrame) { |
| | | table.getModel().addTableModelListener(e -> { |
| | | // 检查事件类型 |
| | | if (e.getType() == TableModelEvent.UPDATE) { |
| | |
| | | // 获取新的值 |
| | | Object newValue = table.getModel().getValueAt(row, column); |
| | | // 输出变化信息 |
| | | if (newValue.equals("edit")){ |
| | | if (newValue.equals("edit")) { |
| | | DjJdgzNetworkLevel1 data = list.get(row); |
| | | addOrUpdate.openDialog(data,jFrame); |
| | | addOrUpdate.openDialog(data, jFrame); |
| | | jFrame.setEnabled(false); |
| | | }else if(newValue.equals("del")) { |
| | | } else if (newValue.equals("del")) { |
| | | int n = JOptionPane.showConfirmDialog(null, "是否删除?", "提示", JOptionPane.YES_NO_OPTION); |
| | | if (n == 0) { |
| | | DefaultTableModel model = (DefaultTableModel) table.getModel(); |