package com.vci.client.workflow.template; import java.awt.BorderLayout; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.Locale; import java.util.Map; import javax.swing.JPanel; import javax.swing.border.TitledBorder; import com.vci.client.LogonApplication; import com.vci.client.common.VCIBasePanel; import com.vci.client.framework.rightConfig.object.FunctionObject; import com.vci.client.framework.util.RightControlUtil; import com.vci.client.ui.exception.VCIException; 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.VCIJPanel; import com.vci.client.ui.swing.components.table.AbstractVCIJTableDataProvider; import com.vci.client.ui.swing.components.table.VCIJTableNode; import com.vci.client.ui.swing.components.table.VCIJTablePanel; import com.vci.client.workflow.commom.ClientHelper; import com.vci.client.workflow.delegate.ProcessCustomClientDelegate; import com.vci.client.workflow.template.object.ProcessCategoryObject; import com.vci.client.workflow.template.object.ProcessDefinitionObject; public class ProcessCustomTypePanel extends VCIBasePanel{ private static final long serialVersionUID = 1L; private VCIJButton addButton = VCISwingUtil.createVCIJButton("","增加" ,"增加" , "create.gif",null); private VCIJButton editButton = VCISwingUtil.createVCIJButton("","修改" ,"修改" , "modify.gif",null); private VCIJButton deleteButton = VCISwingUtil.createVCIJButton("","删除" ,"删除", "delete.gif" ,null); private String userName = LogonApplication.getUserEntityObject().getUserName(); private LinkedList selfCustomButtons = new LinkedList(); { selfCustomButtons.add(addButton); selfCustomButtons.add(editButton); selfCustomButtons.add(deleteButton); } public ProcessCustomTypePanel(FunctionObject funcObj){ super(funcObj); init(); checkPermission(); } private void init() { LogonApplication.getUserEntityObject().setModules(this.getClass().getName()); initComponents(); initAction();//初始化按钮点击事件 } private void initComponents() { setLayout(new BorderLayout()); add(initTablePanel(), BorderLayout.CENTER); } private void checkPermission(){ checkRight(RightControlUtil.CREATE, addButton); checkRight(RightControlUtil.UPDATE, editButton); checkRight(RightControlUtil.DELETE, deleteButton); } class MyDataProvider extends AbstractVCIJTableDataProvider{ public ProcessCategoryObject[] getDatas(int arg0, int arg1) { ProcessCategoryObject[] processCategories = null; ProcessCategoryObject[] processCategoriesCount = null; try { ProcessCustomClientDelegate delSrv = new ProcessCustomClientDelegate(LogonApplication.getUserEntityObject()); processCategoriesCount = delSrv.getProcessCategories("root"); processCategories = delSrv.getProcessCategoriesByPage("root",arg1,arg0); this.total = processCategoriesCount.length; } catch (VCIException e) { e.printStackTrace(); } return processCategories; } public VCIJTableNode getNewRowNode(ProcessCategoryObject dataObj) { VCIJTableNode node = new VCIJTableNode(dataObj); node.setPropertyValue(getSpecialColumns()[0], dataObj.getName()); node.setPropertyValue(getSpecialColumns()[1], dataObj.getDesc()); return node; } public String[] getSpecialColumns() { return "分类名称, 描述".split(","); } public int getTotal() { return this.total; } } MyDataProvider dataProvider = new MyDataProvider(); VCIJTablePanel tablePanel = new VCIJTablePanel(dataProvider); private VCIJPanel tablePanel(){ int startIndex = dataProvider.getDataColumnStartIndex(); LinkedHashMap widthMaps = new LinkedHashMap(); widthMaps.put(startIndex++, 250);widthMaps.put(startIndex++, 250);widthMaps.put(startIndex++, 250); tablePanel.setColumnWidthMaps(widthMaps); tablePanel.setCustomButtonFlowAlign(FlowLayout.CENTER); tablePanel.setPageButtonFlowAlign(FlowLayout.CENTER); tablePanel.setCustomButtons(selfCustomButtons); tablePanel.setShowPaging(false); tablePanel.setShowExport(false); tablePanel.buildTablePanel(); tablePanel.refreshTableData(); return tablePanel; } public JPanel initTablePanel(){ JPanel pal = new JPanel(); pal.setLayout(new BorderLayout()); pal.setBorder(new TitledBorder("流程分类定义")); pal.add(tablePanel(), BorderLayout.CENTER); pal.setVisible(true); return pal; } /** * 事件 */ private void initAction(){ addButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { addButton_conform(); } }); editButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { editButton_conform(); } }); deleteButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { deleteButton_conform(); } }); } /** * 添加事件 */ private void addButton_conform(){ showCreateDialog(); tablePanel.refreshTableData(); } private void showCreateDialog() { showProcessCategoryDialog("create",null); } private void showProcessCategoryDialog(String optType,ProcessCategoryObject obj) { try { ProcessCategoryTypeDialog dialog = new ProcessCategoryTypeDialog("",optType,obj,funcObj); dialog.setVisible(true); } catch (VCIException exp) { VCIOptionPane.showError(LogonApplication.frame, "RMIPWorkflow", exp); } } /** * 修改事件 */ private void editButton_conform(){ int len = tablePanel.getSelectedRowIndexs().length; if(len == 0){ VCIOptionPane.showMessage(this, "请选择数据再进行修改操作!"); return; } if (len > 1){ VCIOptionPane.showMessage(this, LocaleDisplay.getI18nString("rmip.stafforg.operate.deptedit2", "RMIPFramework", getLocale())); return; } ProcessCategoryObject obj = tablePanel.getSelectedRowObjects().get(0); showProcessCategoryDialog("modify", (ProcessCategoryObject) obj); tablePanel.refreshTableData(); } /** * 删除事件 */ private void deleteButton_conform(){ int len = tablePanel.getSelectedRowIndexs().length; if(len == 0){ VCIOptionPane.showMessage(this, "请选择要删除的对象!"); return; } String[] puids = new String[len]; Map map = new HashMap(); for (int i = 0; i < len; i++) { ProcessCategoryObject roleInfo = tablePanel.getSelectedRowObjects().get(i); puids[i] = roleInfo.getId(); map.put(roleInfo.getId(), roleInfo.getName()); } int ok=VCIOptionPane.showQuestion(LogonApplication.frame, ClientHelper .getI18nStringForWorkflow(this.getClass().getName() + "." + "deleteProcessCategoryConfirmMessage", getLocale())); if (ok == 0) { boolean rs=true; try { // ProcessCustomClientDelegate delegate = new ProcessCustomClientDelegate(LogonApplication.frame.getUserEntityObject()); // rs = delegate.deleteProcessCategory(puids[0]); for(String id : puids){ ProcessCustomClientDelegate delegate = new ProcessCustomClientDelegate(LogonApplication.getUserEntityObject()); ProcessDefinitionObject[] processDefinitions = new ProcessCustomClientDelegate(LogonApplication.getUserEntityObject()).getProcessDefinitions(id); if(processDefinitions.length>0){ VCIOptionPane.showMessage(LogonApplication.frame, "分类下有模板,请先删除模版!"); return; }else{ rs = delegate.deleteProcessCategory(id); } } } catch (VCIException e) { VCIOptionPane.showError(LogonApplication.frame, "RMIPWorkflow", e); e.printStackTrace(); } if (!rs) { return; } }else{ return; } tablePanel.refreshTableData(); } private String getI18nString(String spCode){ return ClientHelper.getI18nStringForWorkflow(this.getClass().getName() + "." + spCode, Locale.getDefault()); } }