package com.vci.client.workflow.task; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.text.MessageFormat; import javax.swing.Box; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.ListSelectionModel; import javax.swing.UIManager; import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.TableColumnModel; import com.vci.client.LogonApplication; import com.vci.client.ui.exception.VCIException; import com.vci.client.ui.image.BundleImage; import com.vci.client.workflow.commom.ClientHelper; import com.vci.client.workflow.delegate.ProcessCustomClientDelegate; import com.vci.client.workflow.editor.user.FowardUserDialog; import com.vci.corba.common.VCIError; import com.vci.corba.workflow.data.FlowTaskInfo; import com.vci.corba.workflow.data.ProcessTaskInfo; public class CCTaskPanel extends JPanel { /** * */ private static final long serialVersionUID = 1L; private JButton btnNewButton; private JPanel todoTasksPanel; private JTable toDoTasksTable; private TodoTaskTableModel todoTaskTableModel; //added by ligang 分页功能的实现 private JButton firstPageButton = null; private JButton prePageButton = null; private JButton nextPageButton = null; private JButton lastPageButton = null; int pagesize = getPageSize();//每页记录数 int pageCount = 0;//总页数 int rowCount = 0;//总记录数 int curPage = 1; int TABLE_PAGE = 1;//当前页数 private JLabel laber_pageinfo = new JLabel(getI18nString("pageInfo"));//当前页/总页数 private static CCTaskPanel ccTaskPanel; public static CCTaskPanel getInstance() { if (ccTaskPanel == null) { ccTaskPanel = new CCTaskPanel(); } return ccTaskPanel; } private CCTaskPanel() { initUI(); initializeData(); //2012.04.26 ligang 去除任务箱权限校验,所有人都有操作权限 // checkPermission() ; } /** 权限检查的模块标识 **/ private String checkPermissionModuleId = "com.vci.rmip.workflow.client.task.ProcessTaskPanel"; @SuppressWarnings("unchecked") private void checkPermission() { } private void initUI() { setLayout(new BorderLayout(0, 0)); todoTaskTableModel = new TodoTaskTableModel(); todoTasksPanel = new JPanel(); add(todoTasksPanel, BorderLayout.CENTER); todoTasksPanel.setLayout(new BorderLayout(0, 0)); JPanel panel_2 = new JPanel(); todoTasksPanel.add(panel_2, BorderLayout.NORTH); panel_2.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5)); btnNewButton = new JButton(getI18nString("btnView")); btnNewButton.setBorder(UIManager.getBorder("Button.border")); panel_2.add(btnNewButton); JPanel pane3 = new JPanel(); todoTasksPanel.add(pane3,BorderLayout.SOUTH); initPageerButtons(pane3); JPanel panel_3 = new JPanel(); panel_3.setBackground(Color.WHITE); todoTasksPanel.add(panel_3, BorderLayout.CENTER); panel_3.setLayout(new BorderLayout(0, 0)); toDoTasksTable = new JTable(); toDoTasksTable.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN); toDoTasksTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); toDoTasksTable.setModel(todoTaskTableModel); toDoTasksTable.setRowHeight(25); //2012.03.06 ligang 双击事件的添加 toDoTasksTable.addMouseListener(new MouseAdapter(){ public void mouseClicked(MouseEvent e) { if(e.getClickCount()==2){ viewFlowInfo(); } } }); JScrollPane scrollPane = new JScrollPane(toDoTasksTable); scrollPane.setAutoscrolls(true); panel_3.add(scrollPane); TableColumnModel todoModel = toDoTasksTable.getColumnModel(); todoModel.getColumn(0).setPreferredWidth(28); todoModel.getColumn(0).setMaxWidth(28); todoModel.getColumn(2).setPreferredWidth(150); // todoModel.getColumn(2).setMaxWidth(200); DefaultTableCellRenderer r = new DefaultTableCellRenderer(); r.setHorizontalAlignment(JLabel.CENTER); todoModel.getColumn(0).setCellRenderer(r); Dimension size = toDoTasksTable.getTableHeader().getPreferredSize(); size.height = 22; toDoTasksTable.getTableHeader().setPreferredSize(size); addListener(); } private void addListener() { btnNewButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { viewFlowInfo(); } }); } public void initData() { FlowTaskInfo[] dataObjs; try { dataObjs = new ProcessCustomClientDelegate(LogonApplication.getUserEntityObject()).getCCTaskByUserId(LogonApplication.getUserObject().getUserName(),curPage,pagesize); todoTaskTableModel.setData(dataObjs); } catch (VCIError e) { e.printStackTrace(); } updateUI(); } private void viewFlowInfo() { int selectedRow = toDoTasksTable.getSelectedRow(); if (selectedRow == -1) { JOptionPane.showMessageDialog(todoTasksPanel, getI18nString("message"), getI18nString("title"), JOptionPane.INFORMATION_MESSAGE); return; } FlowTaskInfo flowTask = todoTaskTableModel.getValue(selectedRow); if (flowTask == null) { return; } // 查出阶段名称 ProcessCustomClientDelegate processCustomClientDelegate = new ProcessCustomClientDelegate(); String jbpmDeploymentId; try { jbpmDeploymentId = processCustomClientDelegate.getDeploymentIdByExecutionId(flowTask.executionId); if ("".equals(jbpmDeploymentId)) { JOptionPane.showMessageDialog(todoTasksPanel, "该流程不存在或已经执行完成!", getI18nString("title"), JOptionPane.INFORMATION_MESSAGE); initData(); return; } ProcessTaskInfo frocessTaskInfo = processCustomClientDelegate.findById(jbpmDeploymentId, flowTask.name); CCTaskDialog todoTaskDialog = new CCTaskDialog(flowTask, frocessTaskInfo); todoTaskDialog.setVisible(true); // //处理代办任务之后,显示剩余任务数量。 // String currentUser = LocaleDisplay.getI18nString("rmip.framework.current.user", "RMIPFramework",this.getLocale()); // new VciFrameTimerTask(currentUser).displayTaskCount(); initializeData(); } catch (VCIError e) { e.printStackTrace(); } } /** * 任务转发 */ private void foward(){ int selectedRow = toDoTasksTable.getSelectedRow(); if (selectedRow == -1) { JOptionPane.showMessageDialog(todoTasksPanel, "请选择要转发的任务!", getI18nString("title"), JOptionPane.INFORMATION_MESSAGE); return; } FlowTaskInfo flowTask = todoTaskTableModel.getValue(selectedRow); if (flowTask == null) { return; } ProcessCustomClientDelegate processCustomClientDelegate = new ProcessCustomClientDelegate(); String jbpmDeploymentId; try { jbpmDeploymentId = processCustomClientDelegate.getDeploymentIdByExecutionId(flowTask.executionId); if ("".equals(jbpmDeploymentId)) { JOptionPane.showMessageDialog(todoTasksPanel, "该流程不存在或已经执行完成!", getI18nString("title"), JOptionPane.INFORMATION_MESSAGE); initData(); return; } // ProcessTaskInfo frocessTaskInfo = processCustomClientDelegate.findById(jbpmDeploymentId, flowTask.name); FowardUserDialog dialog = new FowardUserDialog(flowTask.executionId); // TodoTaskDialog todoTaskDialog = new TodoTaskDialog(flowTask, frocessTaskInfo); // todoTaskDialog.setVisible(true); // //处理代办任务之后,显示剩余任务数量。 // String currentUser = LocaleDisplay.getI18nString("rmip.framework.current.user", "RMIPFramework",this.getLocale()); // new VciFrameTimerTask(currentUser).displayTaskCount(); initializeData(); } catch (VCIError e) { e.printStackTrace(); } } public void initializeData() { curPage = 1; rowCount = getRowCount(); pageCount = getPageCount(); initData(); updateBtnStatus(); laber_pageinfo.setText(MessageFormat.format(getI18nString("pageInfo"), rowCount, pageCount, curPage)); } private void initPageerButtons(JPanel pal){ firstPageButton = new JButton(""); pal.add(firstPageButton); firstPageButton.setIcon(new BundleImage().createImageIcon("resultset_first.png")); prePageButton = new JButton(""); pal.add(prePageButton); prePageButton.setIcon(new BundleImage().createImageIcon("resultset_previous.png")); nextPageButton = new JButton(""); pal.add(nextPageButton); nextPageButton.setIcon(new BundleImage().createImageIcon("resultset_next.png")); lastPageButton = new JButton(""); pal.add(lastPageButton); lastPageButton.setIcon(new BundleImage().createImageIcon("resultset_last.png")); firstPageButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { curPage = 1; initData(); updateBtnStatus(); } }); prePageButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if(curPage > 1){ curPage--; } initData(); updateBtnStatus(); } }); nextPageButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if(curPage < getPageCount()){ curPage++; } initData(); updateBtnStatus(); } }); lastPageButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { curPage = getPageCount(); initData(); updateBtnStatus(); } }); pal.add(Box.createHorizontalStrut(30)); pal.add(laber_pageinfo); } private int getPageSize() { if(this.pagesize == 0){ String pageSize = "15"; // try { // pageSize = new UserRightClientDelegate().getConfigValue("log.query.pagesize"); // } catch (VCIError e) { // e.printStackTrace(); // } int pageSizeGet = Integer.parseInt(pageSize); this.pagesize = pageSizeGet; } return pagesize; } private int getRowCount(){ try { return new ProcessCustomClientDelegate(LogonApplication.getUserEntityObject()).queryCCTaskCount(LogonApplication.getUserObject().getUserName()); } catch (VCIException e) { e.printStackTrace(); return 1; } } private int getPageCount(){ int dataRowCount = getRowCount(); int pageSize = getPageSize(); int pageCount = dataRowCount / pageSize; if (dataRowCount % pageSize > 0) { pageCount++; } return pageCount; } private void updateBtnStatus() { int rowCount = this.getRowCount(); int pageSize = getPageSize(); int pageCount = rowCount / pageSize; if (rowCount % pageSize > 0) { pageCount++; } if (pageCount <= 1) { firstPageButton.setEnabled(false); prePageButton.setEnabled(false); lastPageButton.setEnabled(false); nextPageButton.setEnabled(false); } else { if (curPage == 1) { firstPageButton.setEnabled(false); prePageButton.setEnabled(false); lastPageButton.setEnabled(true); nextPageButton.setEnabled(true); } else if (curPage >= pageCount) { firstPageButton.setEnabled(true); prePageButton.setEnabled(true); lastPageButton.setEnabled(false); nextPageButton.setEnabled(false); } else { firstPageButton.setEnabled(true); prePageButton.setEnabled(true); lastPageButton.setEnabled(true); nextPageButton.setEnabled(true); } } laber_pageinfo.setText(MessageFormat.format(getI18nString("pageInfo"), rowCount, pageCount, curPage)); } private String getI18nString(String spCode) { return ClientHelper.getI18nStringForWorkflow(this.getClass().getName() + "." + spCode, this.getLocale()); } }