package com.vci.client.workflow.task; import java.awt.BorderLayout; 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.JComboBox; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.JTextField; import javax.swing.ListSelectionModel; import javax.swing.SwingUtilities; import javax.swing.table.TableColumnModel; import com.vci.client.LogonApplication; import com.vci.client.common.objects.UserObject; import com.vci.client.framework.rightConfig.object.FunctionObject; import com.vci.client.ui.date.PopupCalendarMethod; import com.vci.client.ui.exception.VCIException; import com.vci.client.ui.image.BundleImage; import com.vci.client.ui.locale.LocaleDisplay; import com.vci.client.ui.swing.VCIOptionPane; import com.vci.client.ui.swing.VCISwingUtil; import com.vci.client.ui.swing.components.VCIJButton; import com.vci.client.ui.swing.components.VCIJCalendarPanel; import com.vci.client.ui.swing.components.VCIJComboBox; import com.vci.client.workflow.commom.ClientHelper; import com.vci.client.workflow.delegate.FlowInstanceClientDelegate; import com.vci.client.workflow.delegate.ProcessCustomClientDelegate; import com.vci.client.workflow.editor.TaskRevokeCObject; import com.vci.corba.common.VCIError; import com.vci.corba.workflow.data.FlowApproveHistoryInfo; import com.vci.corba.workflow.data.FlowTaskInfo; import com.vci.corba.workflow.data.ProcessTaskInfo; public class TrackTaskPanel extends JPanel { /** * 跟踪任务 */ private static final long serialVersionUID = 844086978269740691L; //查询日期:由 private String DATE_START = LocaleDisplay.getI18nString("rmip.framework.log.startDate", "RMIPFramework", getLocale()); //到 private String TO = LocaleDisplay.getI18nString("rmip.framework.log.to", "RMIPFramework", getLocale()); //查询 private String QUERY = LocaleDisplay.getI18nString("rmip.framework.log.query", "RMIPFramework", getLocale()); private JLabel dateLabelStart = new JLabel(DATE_START); private JLabel dateLabelTo = new JLabel(TO); private VCIJComboBox startDateBox = new VCIJComboBox(); private VCIJComboBox endDateBox = new VCIJComboBox(); private JButton startDateButton = new PopupCalendarMethod().createDateDialogButton("date.gif",startDateBox); private JButton endDateButton = new PopupCalendarMethod().createDateDialogButton("date.gif",endDateBox); private JButton queryBtn = new JButton("查询"); private JButton clearBtn = new JButton("清空"); private JLabel missionJLabel = new JLabel("任务名称:"); private JTextField missionField = new JTextField(); private JLabel applicaJLabel = new JLabel("创建人:"); private JTextField applicaField = new JTextField(); private JLabel applicaDepartJLabel = new JLabel("创建部门:"); private JTextField applicaDeparField = new JTextField(); private VCIJButton btnRefresh = VCISwingUtil.createVCIJButton("", "刷新", "刷新", "arrow_refresh.png"); private JButton btnStop;//终止流程 private JButton viewButton; private JPanel taskPanel; private JTable taskTable; private JButton btnRevoke; private JButton btnAppoint; private JButton btnAggsin; private TodoTaskTableModel taskTableModel; private VCIJCalendarPanel txtStartTime = new VCIJCalendarPanel(); private VCIJCalendarPanel txtEndTime = new VCIJCalendarPanel(); //added by ligang 分页功能的实现 private JButton firstPageButton = null; private JButton prePageButton = null; private JButton nextPageButton = null; private JButton lastPageButton = null; private JTextField textField = null; private JButton zhidingPageButton = 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 TrackTaskPanel trackTaskPanel; static String querySQL = ""; /** * 任务箱参数 */ static String taskType =""; FunctionObject funcObj = new FunctionObject(); public static TrackTaskPanel getInstance(FunctionObject funcObj,String taskType) { if (trackTaskPanel == null) { trackTaskPanel = new TrackTaskPanel(taskType); } return trackTaskPanel; } private TrackTaskPanel(String taskType) { this.taskType = taskType; 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()); JPanel topPanel = new JPanel(new BorderLayout()); JPanel palNorthBtn = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 5)); btnStop = new JButton(getI18nString("btnView")); btnStop.setIcon(VCISwingUtil.createImageIcon("cancel.png")); viewButton = new JButton("查看"); btnRevoke = new JButton("收回"); btnAppoint = new JButton("任务指派"); btnAggsin = new JButton("任务转发"); viewButton.setIcon(VCISwingUtil.createImageIcon("search.png")); btnRevoke.setIcon(VCISwingUtil.createImageIcon("arrow_undo.png")); palNorthBtn.add(btnStop); palNorthBtn.add(btnRevoke); palNorthBtn.add(viewButton); palNorthBtn.add(btnRefresh); palNorthBtn.add(btnAggsin); // palNorthBtn.add(btnAppoint); btnRefresh.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { SwingUtilities.invokeLater(new Runnable() { public void run() { initializeData(); } }); } }); //收回事件 btnRevoke.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { int selectedRow = taskTable.getSelectedRow(); if (selectedRow == -1) { JOptionPane.showMessageDialog(TrackTaskPanel.this, "请选择需要收回的任务!", "提示信息", JOptionPane.INFORMATION_MESSAGE); return; } FlowTaskInfo flowHistoryTaskInfo = taskTableModel.getValue(selectedRow); ProcessCustomClientDelegate processCustomClientDelegate = new ProcessCustomClientDelegate(LogonApplication.getUserEntityObject()); String jbpmDeploymentId; try { jbpmDeploymentId = processCustomClientDelegate.getDeploymentIdByExecutionId(flowHistoryTaskInfo.executionId); /** * 检查下一个任务是否已经完成:通过审核过程获得该任务的下一个任务是否被处理。如果被处理则不能进行撤销,如果没有被处理,则可以进行撤销。 * 此处的检查方式是根据在审核过程中,最后一个任务是未被处理的任务,此时判断倒数第二个任务是否与当前用户的已办任务的任务名称一致. * 如果一致则说明当前已办任务的下一个任务还没有被处理可以撤销,如果不一致,则不能撤销. */ boolean revokeFlag = false; String assignName = ""; FlowApproveHistoryInfo[] doneTaskByUserId = new ProcessCustomClientDelegate(LogonApplication.getUserEntityObject()).getHistoryActivityByProInsId(flowHistoryTaskInfo.executionId); String taskName = ""; int count =0; for(int i=doneTaskByUserId.length-1;i>=0;i--){ if(count==2){ break; } FlowApproveHistoryInfo flowApproveHistory = doneTaskByUserId[i]; taskName = flowApproveHistory.taskName; assignName = flowApproveHistory.assignee; if(count==0&&assignName.equals(LogonApplication.getUserEntityObject().getUserName())){ JOptionPane.showMessageDialog(TrackTaskPanel.this, "当前用户不是任务的处理者!", "提示信息", JOptionPane.INFORMATION_MESSAGE); return; } count ++; } TaskRevokeCObject[] taskRevokeCObject = new ProcessCustomClientDelegate(LogonApplication.getUserEntityObject()).getTaskRevokeList(jbpmDeploymentId, taskName); if(taskRevokeCObject!=null){ if(taskRevokeCObject.length!=0){ String plrevoke = taskRevokeCObject[0].getPlrevoke().toLowerCase(); if("off".equals(plrevoke)){ JOptionPane.showMessageDialog(TrackTaskPanel.this, "该任务不能收回!", "提示信息", JOptionPane.INFORMATION_MESSAGE); return; } }else{ JOptionPane.showMessageDialog(TrackTaskPanel.this, "该任务不能收回!", "提示信息", JOptionPane.INFORMATION_MESSAGE); return; } } boolean revokeTask = new ProcessCustomClientDelegate(LogonApplication.getUserEntityObject()).revokeTask(flowHistoryTaskInfo.name, taskName, flowHistoryTaskInfo.executionId); if(revokeTask){ JOptionPane.showMessageDialog(TrackTaskPanel.this, "收回成功!", "提示信息", JOptionPane.INFORMATION_MESSAGE); initializeData(); }else{ JOptionPane.showMessageDialog(TrackTaskPanel.this, "收回失败!", "提示信息", JOptionPane.INFORMATION_MESSAGE); return; } } catch (VCIError e) { e.printStackTrace(); } } }); JPanel searchPanel = new JPanel(new FlowLayout(FlowLayout.LEFT,5,5)); searchPanel.add(missionJLabel); missionField.setPreferredSize(new Dimension(100,25)); searchPanel.add(missionField); searchPanel.add(applicaJLabel); applicaField.setPreferredSize(new Dimension(100,25)); searchPanel.add(applicaField); searchPanel.add(applicaDepartJLabel); applicaDeparField.setPreferredSize(new Dimension(100,25)); searchPanel.add(applicaDeparField); JPanel dataPanel = new JPanel(new FlowLayout(FlowLayout.LEFT,5,5)); dataPanel.add(dateLabelStart); dataPanel.add(txtStartTime); dataPanel.add(dateLabelTo); dataPanel.add(txtEndTime); queryBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { SwingUtilities.invokeLater(new Runnable() { public void run() { queryBtn_ActionPerformed(); } }); } }); clearBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { SwingUtilities.invokeLater(new Runnable() { public void run() { clearBtn_ActionPerformed(); } }); } }); queryBtn.setIcon(VCISwingUtil.createImageIcon("search.png")); clearBtn.setIcon(VCISwingUtil.createImageIcon("clear.gif")); dataPanel.add(queryBtn); dataPanel.add(clearBtn); topPanel.add(searchPanel,BorderLayout.NORTH); topPanel.add(dataPanel,BorderLayout.CENTER); add(topPanel, BorderLayout.NORTH); taskTableModel = new TodoTaskTableModel(); taskTable = new JTable(); taskTable.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN); taskTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); taskTable.setModel(taskTableModel); taskTable.setRowHeight(25); taskTable.setShowGrid(true); taskTable.getTableHeader().setFont(VCISwingUtil.FONT_DEFAULT); //2012.03.06 ligang 双击事件的添加 taskTable.addMouseListener(new MouseAdapter(){ public void mouseClicked(MouseEvent e) { if(e.getClickCount()==2){ viewFlowInfo(); } } }); TableColumnModel todoModel = taskTable.getColumnModel(); todoModel.getColumn(0).setPreferredWidth(28); todoModel.getColumn(0).setMaxWidth(28); todoModel.getColumn(1).setPreferredWidth(150); todoModel.getColumn(2).setPreferredWidth(150); JScrollPane jspTable = new JScrollPane(); jspTable.getViewport().add(taskTable); add(jspTable, BorderLayout.CENTER); JPanel palPageBtns = new JPanel(); JPanel southPanel = new JPanel(new BorderLayout()); southPanel.add(palNorthBtn,BorderLayout.NORTH); southPanel.add(palPageBtns,BorderLayout.CENTER); add(southPanel, BorderLayout.SOUTH); initPageerButtons(palPageBtns); addListener(); } private void addListener() { btnAppoint.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { int selectedRow = taskTable.getSelectedRow(); if (selectedRow == -1) { JOptionPane.showMessageDialog(TrackTaskPanel.this, getI18nString("message"), getI18nString("title"), JOptionPane.INFORMATION_MESSAGE); return; } FlowTaskInfo flowTask = taskTableModel.getValue(selectedRow); if (flowTask == null) { JOptionPane.showMessageDialog(TrackTaskPanel.this, "请选择数据!", "", JOptionPane.INFORMATION_MESSAGE); return; } ProcessCustomClientDelegate processCustomClientDelegate = new ProcessCustomClientDelegate(LogonApplication.getUserEntityObject()); String jbpmDeploymentId; try { jbpmDeploymentId = processCustomClientDelegate.getDeploymentIdByExecutionId(flowTask.executionId); if ("".equals(jbpmDeploymentId)) { JOptionPane.showMessageDialog(trackTaskPanel, "该流程不存在或已经执行完成!", "", JOptionPane.INFORMATION_MESSAGE); initData(); return; } } catch (VCIError e) { e.printStackTrace(); } int showConfirmDialog = JOptionPane.showConfirmDialog(LogonApplication.frame, "确定要指派任务?", "提示对话框", JOptionPane.YES_NO_OPTION); if (showConfirmDialog == JOptionPane.YES_OPTION) { AppointTaskDialog atd = new AppointTaskDialog(flowTask.name,flowTask.executionId); initData(); } } }); btnAggsin.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { int selectedRow = taskTable.getSelectedRow(); if (selectedRow == -1) { JOptionPane.showMessageDialog(TrackTaskPanel.this, getI18nString("message"), getI18nString("title"), JOptionPane.INFORMATION_MESSAGE); return; } FlowTaskInfo flowTask = taskTableModel.getValue(selectedRow); if (flowTask == null) { JOptionPane.showMessageDialog(TrackTaskPanel.this, "请选择数据!", "", JOptionPane.INFORMATION_MESSAGE); return; } ProcessCustomClientDelegate processCustomClientDelegate = new ProcessCustomClientDelegate(LogonApplication.getUserEntityObject()); String jbpmDeploymentId; String executionId = flowTask.executionId; try { jbpmDeploymentId = processCustomClientDelegate.getDeploymentIdByExecutionId(executionId); if ("".equals(jbpmDeploymentId)) { JOptionPane.showMessageDialog(trackTaskPanel, "该流程不存在或已经执行完成!", "", JOptionPane.INFORMATION_MESSAGE); initData(); return; } } catch (VCIError e) { e.printStackTrace(); } int showConfirmDialog = JOptionPane.showConfirmDialog(LogonApplication.frame, "确定要转发任务?", "提示对话框", JOptionPane.YES_NO_OPTION); if (showConfirmDialog == JOptionPane.YES_OPTION) { TaskAssignedDialog dialog = new TaskAssignedDialog(LogonApplication.frame); UserObject[] userObjects = dialog.getProcessDefinitionObject(); String userName = getAssignName(userObjects); System.out.println(userName); try { String taskId = new ProcessCustomClientDelegate(LogonApplication.getUserEntityObject()).getTaskId(flowTask.name,flowTask.executionId); new ProcessCustomClientDelegate(LogonApplication.getUserEntityObject()).transmitTask(taskId, userName); } catch (VCIException e) { e.printStackTrace(); } initData(); } } }); btnStop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { int selectedRow = taskTable.getSelectedRow(); if (selectedRow == -1) { JOptionPane.showMessageDialog(taskPanel, getI18nString("message"), getI18nString("title"), JOptionPane.INFORMATION_MESSAGE); return; } FlowTaskInfo flowTask = taskTableModel.getValue(selectedRow); if (flowTask == null) { JOptionPane.showMessageDialog(taskPanel, "请选择数据!", getI18nString("title"), JOptionPane.INFORMATION_MESSAGE); return; } int showConfirmDialog = JOptionPane.showConfirmDialog(LogonApplication.frame, "是否要终止流程?", "提示对话框", JOptionPane.YES_NO_OPTION); if (showConfirmDialog == JOptionPane.YES_OPTION) { FlowInstanceClientDelegate flowInstanceClientDelegate = new FlowInstanceClientDelegate(LogonApplication.getUserEntityObject()); try { flowInstanceClientDelegate.endProcessInstance(flowTask.executionId); initData(); } catch (VCIException e) { e.printStackTrace(); VCIOptionPane.showError(TrackTaskPanel.this, "RMIPWorkflow", e); } } } }); viewButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { viewFlowInfo(); } }); } private String getAssignName(UserObject[] object){ String userName = ""; for(int i = 0 ;i 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(); } }); zhidingPageButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int i = getTextField(); if(i != 0 ){ curPage = i; initData(); updateBtnStatus(); } } }); pal.add(Box.createHorizontalStrut(30)); pal.add(laber_pageinfo); } private int getPageSize() { if(this.pagesize == 0){ String pageSize = "150"; // 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()).queryTraceTaskCount(LogonApplication.getUserObject().getUserName(),taskType); return new ProcessCustomClientDelegate(LogonApplication.getUserEntityObject()).queryTraceTaskCount(LogonApplication.getUserObject().getUserName(),querySQL); } 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 void queryBtn_ActionPerformed(){ getDateTimeFilterString(); initData(); updateBtnStatus(); } private void clearBtn_ActionPerformed(){ txtStartTime.setDateString(); txtEndTime.setDateString(); querySQL = ""; missionField.setText(""); applicaField.setText(""); applicaDeparField.setText(""); } public String getDateTimeFilterString(){ String filterString = ""; String startTime = txtStartTime.getDateString();//开始时间 String endTime = txtEndTime.getDateString();//结束时间 String mission = missionField.getText();//任务名称 String application = applicaField.getText();//创建人 String applicaDepar = applicaDeparField.getText();//创建人部门 if(startTime == null || "".equals(startTime.trim())){ startTime = "1900-01-01 00:00:00"; } else { startTime = startTime.substring(0, 10) + " 00:00:00"; } if(endTime == null || "".equals(endTime.trim())){ endTime = "9900-12-30 23:59:59"; } else { endTime = endTime.substring(0, 10) + " 23:59:59"; } filterString = " AND " + "(" + "createTime >= TO_DATE('" + startTime + "','yyyy-MM-dd HH24:mi:ss')" + " AND " + "createTime <= TO_DATE('" + endTime + "','yyyy-MM-dd HH24:mi:ss')"; filterString += ")" + ""; if(!"".equals(mission)){ filterString += " AND PLDESC = '" + mission +"'"; } if (!"".equals(application)){ filterString += " AND PLCREATOR like '%" + application +"%'"; } if (!"".equals(applicaDepar)){ filterString += "#"+applicaDepar; } querySQL = filterString; return querySQL; } private String getI18nString(String spCode) { return ClientHelper.getI18nStringForWorkflow(this.getClass().getName() + "." + spCode, this.getLocale()); } private int getTextField(){ int i = 0;//输入的页数 int count = getPageCount();//总页数 if(textField.getText() == ""){ VCIOptionPane.showMessage(this, "请输入要跳转的页数"); return i; }else { String field = textField.getText(); if(!field.matches("^[0-9_]+$")) { VCIOptionPane.showMessage(this, "请输入数字"); return i; }else if(Integer.parseInt(field)>count){ VCIOptionPane.showMessage(this, "输入的页数大于总页数"); return i; }else { i = Integer.parseInt(field); return i; } } } }