package com.vci.client.workflow.editor.user; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.GridLayout; import java.awt.Insets; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import javax.swing.ButtonGroup; import javax.swing.DefaultListModel; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.JScrollPane; import javax.swing.JTabbedPane; import javax.swing.JTextField; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.event.TreeExpansionEvent; import javax.swing.event.TreeExpansionListener; import javax.swing.event.TreeSelectionEvent; import javax.swing.event.TreeSelectionListener; import javax.swing.tree.TreePath; import org.dom4j.DocumentException; import com.vci.client.LogonApplication; import com.vci.client.bof.ClientBusinessObject; import com.vci.client.bof.ClientBusinessObjectOperation; import com.vci.client.bof.ClientLinkObjectOperation; import com.vci.client.common.TransmitTreeObject; import com.vci.client.common.oq.OQTool; import com.vci.client.framework.systemConfig.stafforgmanage.RightManagementTreeCellRenderer; import com.vci.client.oq.QTClient; import com.vci.client.portal.utility.TableDataUtil; import com.vci.client.ui.locale.LocaleDisplay; import com.vci.client.ui.swing.KJButton; import com.vci.client.ui.swing.components.VCIJDialog; import com.vci.client.ui.tree.VCIBaseTree; import com.vci.client.ui.tree.VCIBaseTreeModel; import com.vci.client.ui.tree.VCIBaseTreeNode; import com.vci.common.qt.object.Condition; import com.vci.common.qt.object.QueryTemplate; import com.vci.corba.common.VCIError; import com.vci.corba.omd.data.BusinessObject; public class TaskUserDialog extends VCIJDialog { private ButtonGroup bgroup = new ButtonGroup(); private JRadioButton allUserBtn = new JRadioButton("所有人"); private JRadioButton creatorBtn = new JRadioButton("拟稿人"); private JRadioButton creator_departmentBtn = new JRadioButton("拟稿人所在部门"); private JRadioButton owner_departmentBtn = new JRadioButton("当前处理人所在部门"); private JRadioButton allLeadersBtn = new JRadioButton("所有领导"); private JRadioButton allSecretsBtn = new JRadioButton("所有秘书"); private JRadioButton creator_department_leaderBtn = new JRadioButton("拟稿人所在部门领导"); private JRadioButton owner_department_leaderBtn = new JRadioButton("当前处理人所在部门领导"); private JRadioButton curNodeUserBtn = new JRadioButton("当前节点处理人"); private JRadioButton postAllUsersBtn = new JRadioButton("某一级别的所有人"); private JRadioButton nodeUserBtn = new JRadioButton("某一节点处理人"); private JRadioButton selectByFormBtn = new JRadioButton("从业务表单中选择"); private JRadioButton owner_deptBtn = new JRadioButton("当前人的自定义组"); private JRadioButton owner_organizationBtn = new JRadioButton("当前处理人的一级部门"); private JRadioButton reflectClassBtn = new JRadioButton("反射类名"); RadioButtonListener radioBtnListener = new RadioButtonListener(); private String selectJBtnText = "所有人"; private String selectJBtnClass = "all"; private JList list; private DefaultListModel listModel; private DefaultListModel departmentlistModel = new DefaultListModel(); private JList departmentlist = new JList(departmentlistModel); private DefaultListModel rolelistModel = new DefaultListModel(); private JList rolelist = new JList(rolelistModel); private DefaultListModel deptlistModel = new DefaultListModel(); private JList deptlist = new JList(deptlistModel); private DefaultListModel linelistModel = new DefaultListModel(); private JList linelist = new JList(linelistModel); private DefaultListModel deptUserlistModel = new DefaultListModel(); private JList deptUserlist = new JList(deptUserlistModel); private String userName = LogonApplication.getUserEntityObject().getUserName(); private List resultList = new ArrayList(); private List departresultList = new ArrayList(); private List roleresultList = new ArrayList(); private List deptresultList = new ArrayList(); private List lineresultList = new ArrayList(); private List lineShowList = new ArrayList(); private List deptUserresultList = new ArrayList(); private VCIBaseTree rightManagementTree; private VCIBaseTreeModel treeModel; private VCIBaseTreeNode rootNode = new VCIBaseTreeNode("人员组织", "root"); private TransmitTreeObject transmitTreeObject = new TransmitTreeObject(); private ClientLinkObjectOperation cloo = new ClientLinkObjectOperation(); private ClientBusinessObjectOperation cboo = new ClientBusinessObjectOperation(); //初始化tab页面 private JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP); //当前选中的页签 private String selectedPanelFlag = "用户部门"; // 用户部门 private JPanel deptPanel = new JPanel(); // 用户角色 private JPanel rolePanel = new JPanel(); // 用户群组 private JPanel orgPanel = new JPanel(); // 用户关系 private JPanel relationPanel = new JPanel(); // 部门用户关系 JPanel deptAndUserPanel = new JPanel(); private KJButton okBtn = new KJButton("确定", "ok.gif"); private KJButton cancelBtn = new KJButton("取消", "cancel.gif"); private boolean initTruth = true; //左侧的JScrollPane JScrollPane scrollPane = new JScrollPane(); //右侧的JScrollPane JScrollPane scrollPane_1 = new JScrollPane(); JButton rightChose = new JButton(">>"); JButton liftRight = new JButton("<<"); List deptAndUserList = new ArrayList(); public List getLineShowList() { return lineShowList; } public void setLineShowList(List lineShowList) { this.lineShowList = lineShowList; } public List getDepartresultList() { return departresultList; } public void setDepartresultList(List departresultList) { this.departresultList = departresultList; } public List getRoleresultList() { return roleresultList; } public void setRoleresultList(List roleresultList) { this.roleresultList = roleresultList; } public List getDeptresultList() { return deptresultList; } public void setDeptresultList(List deptresultList) { this.deptresultList = deptresultList; } public List getLineresultList() { return lineresultList; } public void setLineresultList(List lineresultList) { this.lineresultList = lineresultList; } public List getDeptUserresultList() { return deptUserresultList; } public void setDeptUserresultList(List deptUserresultList) { this.deptUserresultList = deptUserresultList; } public List getDeptAndUserList() { return deptAndUserList; } public void setDeptAndUserList(List deptAndUserList) { this.deptAndUserList = deptAndUserList; } public DefaultListModel getListModel() { return listModel; } public void setListModel(DefaultListModel listModel) { this.listModel = listModel; } public List getResultList() { return resultList; } public void setResultList(List resultList) { this.resultList = resultList; } public String getSelectedPanelFlag() { return selectedPanelFlag; } public void setSelectedPanelFlag(String selectedPanelFlag) { this.selectedPanelFlag = selectedPanelFlag; } public TaskUserDialog() { super(LogonApplication.frame, true); initData(); initUI(); addListener(); this.setLocationRelativeTo(null); } private void initUI() { setSize(680, 500); setTitle("处理人设置"); centerToScreen(); JPanel panel = new JPanel(); getContentPane().add(panel, BorderLayout.CENTER); panel.setLayout(new BorderLayout(0, 0)); panel.add(tabbedPane, BorderLayout.CENTER); tabbedPane.addTab("用户部门", null, deptPanel, null); tabbedPane.addTab("用户角色", null, rolePanel, null); tabbedPane.addTab("用户群组", null, orgPanel, null); tabbedPane.addTab("用户关系", null, relationPanel, null); tabbedPane.addTab("部门用户关系", null, deptAndUserPanel, null); //初始化tab页数据 initTabPanel(selectedPanelFlag); } protected void initTabPanel(String selectedPanelFlag) { JPanel totalPanel = new JPanel(); totalPanel.setLayout(new BorderLayout(0, 0)); if ("用户部门".equals(selectedPanelFlag)) { if (deptPanel.getComponents().length == 0) { deptPanel.add(totalPanel); } else { deptPanel.removeAll(); deptPanel.add(totalPanel); } } else if ("用户角色".equals(selectedPanelFlag)) { if (rolePanel.getComponents().length == 0) { rolePanel.add(totalPanel); } else { rolePanel.removeAll(); rolePanel.add(totalPanel); } } else if ("用户群组".equals(selectedPanelFlag)) { if (orgPanel.getComponents().length == 0) { orgPanel.add(totalPanel); } else { orgPanel.removeAll(); orgPanel.add(totalPanel); } } else if ("用户关系".equals(selectedPanelFlag)) { if (relationPanel.getComponents().length == 0) { relationPanel.add(totalPanel); } else { relationPanel.removeAll(); relationPanel.add(totalPanel); } } else if ("部门用户关系".equals(selectedPanelFlag)) { if (deptAndUserPanel.getComponents().length == 0) { deptAndUserPanel.add(totalPanel); } else { deptAndUserPanel.removeAll(); deptAndUserPanel.add(totalPanel); } } JPanel panel_3 = new JPanel(); totalPanel.add(panel_3, BorderLayout.SOUTH); okBtn = new KJButton("确定", "ok.gif"); cancelBtn = new KJButton("取消", "ok.gif"); panel_3.add(okBtn); panel_3.add(cancelBtn); JPanel panel_1 = new JPanel(); totalPanel.add(panel_1, BorderLayout.CENTER); GridBagLayout gbl_panel_1 = new GridBagLayout(); panel_1.setLayout(gbl_panel_1); JPanel panel_2 = new JPanel(); GridBagConstraints gbc_panel_2 = new GridBagConstraints(); gbc_panel_2.weighty = 1.0; gbc_panel_2.weightx = 1.0; gbc_panel_2.insets = new Insets(0, 0, 0, 5); gbc_panel_2.fill = GridBagConstraints.BOTH; gbc_panel_2.gridx = 0; gbc_panel_2.gridy = 0; panel_1.add(panel_2, gbc_panel_2); panel_2.setLayout(new BorderLayout(0, 0)); Dimension listDim = new Dimension(250, 350); if ("用户关系".equals(selectedPanelFlag)) { GridLayout layout = new GridLayout(15, 1); panel_2.setLayout(layout); panel_2.add(allUserBtn); panel_2.add(creatorBtn); panel_2.add(creator_departmentBtn); panel_2.add(owner_departmentBtn); panel_2.add(allLeadersBtn); panel_2.add(allSecretsBtn); panel_2.add(creator_department_leaderBtn); panel_2.add(owner_department_leaderBtn); panel_2.add(curNodeUserBtn); panel_2.add(postAllUsersBtn); panel_2.add(nodeUserBtn); panel_2.add(selectByFormBtn); panel_2.add(owner_deptBtn); panel_2.add(owner_organizationBtn); panel_2.add(reflectClassBtn); } else { //初始化设置用户部门树 scrollPane = new JScrollPane(); panel_2.add(scrollPane); scrollPane.setPreferredSize(listDim); VCIBaseTreeNode rootNode = new VCIBaseTreeNode(selectedPanelFlag, "root"); treeModel = new VCIBaseTreeModel(rootNode); initUserTree(rootNode, "root"); rightManagementTree = new VCIBaseTree(treeModel, new RightManagementTreeCellRenderer()); scrollPane.setViewportView(rightManagementTree); } JPanel panel_5 = new JPanel(); GridBagConstraints gbc_panel_5 = new GridBagConstraints(); gbc_panel_5.weightx = 1.0; gbc_panel_5.weighty = 1.0; gbc_panel_5.insets = new Insets(0, 0, 0, 5); gbc_panel_5.fill = GridBagConstraints.NONE; gbc_panel_5.gridx = 1; gbc_panel_5.gridy = 0; panel_1.add(panel_5, gbc_panel_5); panel_5.setLayout(new BorderLayout(0, 0)); rightChose = new JButton(">>"); liftRight = new JButton("<<"); panel_5.add(rightChose,BorderLayout.NORTH); panel_5.add(liftRight); JPanel panel_4 = new JPanel(); GridBagConstraints gbc_panel_4 = new GridBagConstraints(); gbc_panel_4.weightx = 1.0; gbc_panel_4.weighty = 1.0; gbc_panel_4.insets = new Insets(0, 0, 0, 5); gbc_panel_4.fill = GridBagConstraints.BOTH; gbc_panel_4.gridx = 2; gbc_panel_4.gridy = 0; panel_1.add(panel_4, gbc_panel_4); panel_4.setLayout(new BorderLayout(0, 0)); scrollPane_1 = new JScrollPane(); panel_4.add(scrollPane_1); if ("用户部门".equals(selectedPanelFlag)) { scrollPane_1.setViewportView(departmentlist); } else if ("用户角色".equals(selectedPanelFlag)) { scrollPane_1.setViewportView(rolelist); } else if ("用户群组".equals(selectedPanelFlag)) { scrollPane_1.setViewportView(deptlist); } else if ("用户关系".equals(selectedPanelFlag)) { scrollPane_1.setViewportView(linelist); } else if ("部门用户关系".equals(selectedPanelFlag)) { scrollPane_1.setViewportView(deptUserlist); } // listModel = new DefaultListModel(); // list = new JList(listModel); // list.setBackground(Color.WHITE); // scrollPane_1.setViewportView(list); scrollPane_1.setPreferredSize(listDim); //重新给控件添加方法 addListener(); this.initTruth = false; } private void initData() { bgroup.add(allUserBtn); bgroup.add(creatorBtn); bgroup.add(creator_departmentBtn); bgroup.add(owner_departmentBtn); bgroup.add(allLeadersBtn); bgroup.add(allSecretsBtn); bgroup.add(creator_department_leaderBtn); bgroup.add(owner_department_leaderBtn); bgroup.add(curNodeUserBtn); bgroup.add(postAllUsersBtn); bgroup.add(nodeUserBtn); bgroup.add(selectByFormBtn); bgroup.add(owner_deptBtn); bgroup.add(owner_organizationBtn); bgroup.add(reflectClassBtn); allUserBtn.setSelected(true); } private void addListener() { allUserBtn.addActionListener(radioBtnListener); creatorBtn.addActionListener(radioBtnListener); creator_departmentBtn.addActionListener(radioBtnListener); owner_departmentBtn.addActionListener(radioBtnListener); allLeadersBtn.addActionListener(radioBtnListener); allSecretsBtn.addActionListener(radioBtnListener); creator_department_leaderBtn.addActionListener(radioBtnListener); owner_department_leaderBtn.addActionListener(radioBtnListener); curNodeUserBtn.addActionListener(radioBtnListener); postAllUsersBtn.addActionListener(radioBtnListener); nodeUserBtn.addActionListener(radioBtnListener); selectByFormBtn.addActionListener(radioBtnListener); owner_deptBtn.addActionListener(radioBtnListener); owner_organizationBtn.addActionListener(radioBtnListener); reflectClassBtn.addActionListener(radioBtnListener); //tab页面变化的方法 if(this.initTruth) { tabbedPane.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { int num = tabbedPane.getSelectedIndex(); String title = tabbedPane.getTitleAt(num); selectedPanelFlag = title; initTabPanel(selectedPanelFlag); } }); } rightChose.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if ("用户关系".equals(selectedPanelFlag)) { boolean res = true; int size = linelistModel.getSize(); for(int i = 0; i < size; i++){ if(linelistModel.get(i).equals(selectJBtnText)){ res = false; break; } } if (res) { linelistModel.addElement(selectJBtnText); lineShowList.add(selectJBtnText); lineresultList.add(selectJBtnClass); } } else { addToUserListFromTreeNode(false); } } }); liftRight.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { removeUserFromUserList(false); } }); okBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { dispose(); } }); cancelBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { departmentlistModel = new DefaultListModel(); departresultList = new ArrayList(); rolelistModel = new DefaultListModel(); roleresultList = new ArrayList(); deptlistModel = new DefaultListModel(); deptresultList = new ArrayList(); linelistModel = new DefaultListModel(); lineresultList = new ArrayList(); deptUserlistModel = new DefaultListModel(); deptUserresultList = new ArrayList(); deptAndUserList = new ArrayList(); dispose(); } }); rightManagementTree.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { if(e.getClickCount() != 2) return; TreePath path = rightManagementTree.getPathForLocation(e.getX(), e.getY()); if(path == null) return; if(path != null && !(path.getLastPathComponent() instanceof VCIBaseTreeNode)) return; VCIBaseTreeNode clickedNode = (VCIBaseTreeNode)path.getLastPathComponent(); if(clickedNode.getLevel()<2) return; transmitTreeObject.setCurrentTreeNode(clickedNode); addToUserListFromTreeNode(true); } }); rightManagementTree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { TreePath treePath = e.getPath(); VCIBaseTreeNode selectNode = (VCIBaseTreeNode) treePath.getLastPathComponent(); transmitTreeObject.setCurrentTreeNode(selectNode); } }); /** * 树的展开事件 */ rightManagementTree.addTreeExpansionListener(new TreeExpansionListener() { public void treeExpanded(TreeExpansionEvent event) { TreePath treePath = event.getPath(); VCIBaseTreeNode selectNode = (VCIBaseTreeNode) treePath.getLastPathComponent(); transmitTreeObject.setCurrentTreeNode(selectNode); Object object = selectNode.getObj(); String objClsName = object.getClass().getName(); if (!selectNode.isExpand() && "plm.bs.bom.clientobject.ClientBusinessObject".equals(objClsName)) { selectNode.setExpand(true); transmitTreeObject.getCurrentTreeNode().removeAllChildren(); if ("用户部门".equals(selectedPanelFlag)) { ClientBusinessObject cboObject = (ClientBusinessObject) object; Map map = new HashMap(); try { if ("root".equals(cboObject.getId())) { List list = searchBo("department", map); for (int i = 0; i < list.size(); i++) { ClientBusinessObject cbo = list.get(i); treeModel.insertNodeInto(new VCIBaseTreeNode(cbo.getName(), cbo), selectNode, selectNode.getChildCount()); } } else { Map conditionMap = new HashMap(); conditionMap.put("isparttime", "0"); conditionMap.put("f_oid", cboObject.getOid()); // List> dataModel = searchLo("deptPersonTemplate", "deptperson", conditionMap); List> dataModel = searchLo("deptUserTemplate", "deptuser", conditionMap); if (dataModel != null && dataModel.size() > 0) { for (int i = 0 ; i < dataModel.size(); i++) { Map personMap = dataModel.get(i); String userId = (String) personMap.get("oid"); // ClientBusinessObject cbo = cboo.readBusinessObjectById(userId, "person"); ClientBusinessObject cbo = cboo.readBusinessObjectById(userId, "user"); treeModel.insertNodeInto(new VCIBaseTreeNode(cbo.getName(), cbo), selectNode, selectNode.getChildCount()); } } } } catch (VCIError e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else if ("用户角色".equals(selectedPanelFlag)) { ClientBusinessObject cboObject = (ClientBusinessObject) object; Map map = new HashMap(); try { if ("root".equals(cboObject.getId())) { List list = searchBo("role", map); for (int i = 0; i < list.size(); i++) { ClientBusinessObject cbo = list.get(i); treeModel.insertNodeInto(new VCIBaseTreeNode(cbo.getName(), cbo), selectNode, selectNode.getChildCount()); } } else { Map conditionMap = new HashMap(); conditionMap.put("f_oid", cboObject.getOid()); // List> dataModel = searchLo("rolePersonTemplate", "roleperson", conditionMap); List> dataModel = searchLo("roleUserTemplate", "roleuser", conditionMap); if (dataModel != null && dataModel.size() > 0) { for (int i = 0 ; i < dataModel.size(); i++) { Map personMap = dataModel.get(i); String userId = (String) personMap.get("oid"); // ClientBusinessObject cbo = cboo.readBusinessObjectById(userId, "person"); ClientBusinessObject cbo = cboo.readBusinessObjectById(userId, "user"); treeModel.insertNodeInto(new VCIBaseTreeNode(cbo.getName(), cbo), selectNode, selectNode.getChildCount()); } } } } catch (VCIError e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else if ("用户群组".equals(selectedPanelFlag)) { ClientBusinessObject cboObject = (ClientBusinessObject) object; Map map = new HashMap(); try { if ("root".equals(cboObject.getId())) { List list = searchBo("organization", map); for (int i = 0; i < list.size(); i++) { ClientBusinessObject cbo = list.get(i); treeModel.insertNodeInto(new VCIBaseTreeNode(cbo.getName(), cbo), selectNode, selectNode.getChildCount()); } } else { Map conditionMap = new HashMap(); conditionMap.put("f_oid", cboObject.getOid()); // List> dataModel = searchLo("orgpersonTemplate", "orgperson", conditionMap); List> dataModel = searchLo("orgUserTemplate", "orguser", conditionMap); if (dataModel != null && dataModel.size() > 0) { for (int i = 0 ; i < dataModel.size(); i++) { Map personMap = dataModel.get(i); String userId = (String) personMap.get("oid"); // ClientBusinessObject cbo = cboo.readBusinessObjectById(userId, "person"); ClientBusinessObject cbo = cboo.readBusinessObjectById(userId, "user"); treeModel.insertNodeInto(new VCIBaseTreeNode(cbo.getName(), cbo), selectNode, selectNode.getChildCount()); } } } } catch (VCIError e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else if ("部门用户关系".equals(selectedPanelFlag)) { ClientBusinessObject cboObject = (ClientBusinessObject) object; Map map = new HashMap(); try { if ("root".equals(cboObject.getId())) { map.put("PARENTDEPT", "NULL"); List list = searchBo("department", map); for (int i = 0; i < list.size(); i++) { ClientBusinessObject cbo = list.get(i); treeModel.insertNodeInto(new VCIBaseTreeNode(cbo.getName(), cbo), selectNode, selectNode.getChildCount()); } } else { map.put("PARENTDEPT", cboObject.getOid()); List list = searchBo("department", map); for (int i = 0; i < list.size(); i++) { ClientBusinessObject cbo = list.get(i); treeModel.insertNodeInto(new VCIBaseTreeNode(cbo.getName(), cbo), selectNode, selectNode.getChildCount()); } } } catch (VCIError e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } public void treeCollapsed(TreeExpansionEvent arg0) { } }); } private static List searchBo(String btmName, Map queryCondition) throws VCIError{ QueryTemplate qt = new QueryTemplate(); qt.setId("queryBusinessQT"); qt.setType("btm"); qt.setBtmType(btmName); List clauseList = new ArrayList(); clauseList.add("*"); qt.setClauseList(clauseList); Condition condition = OQTool.getCondition(queryCondition); qt.setCondition(condition); BusinessObject[] bos = QTClient.getService().findBTMObjects(qt.getId(), OQTool.getQTTextByQT(qt)); List clos = new ArrayList(); if(bos != null && bos.length > 0){ for(BusinessObject bo: bos){ ClientBusinessObject cbo = new ClientBusinessObject(); cbo.setBusinessObject(bo); clos.add(cbo); } } return clos; } private static List> searchLo(String qtName, String showType, Map queryCondition) throws VCIError, DocumentException{ Map queryColumnsMap = new HashMap(); queryColumnsMap.put("*", "标题"); TableDataUtil util = new TableDataUtil(); List> dataModel = util.getObjectDataList(qtName, null, queryCondition , null, null, showType, queryColumnsMap, null, null); return dataModel; } /** * Description: 初始化人员组织结构树 * @author cmk * @param rootNode * @param puid */ private void initUserTree(VCIBaseTreeNode rootNode, String puid) { // try { // userInfo = new RightManagementClientDelegate(LogonApplication.getUserEntityObject()).fetchUserInfoByName(userName); // } catch (VCIException e) { // e.printStackTrace(); // return; // } ClientBusinessObject cboObject = new ClientBusinessObject(); cboObject.setId("root"); VCIBaseTreeNode userNode = new VCIBaseTreeNode(LocaleDisplay.getI18nString("rmip.stafforg.menu.staff", "RMIPFramework", getLocale()), cboObject); rootNode.add(userNode); } private void removeUserFromUserList(boolean batch){ if ("部门用户关系".equals(selectedPanelFlag)) { int[] selectedNum = deptUserlist.getSelectedIndices(); for (int i = 0;i < selectedNum.length;i++) { deptUserlistModel.removeElementAt(selectedNum[i] - i); deptUserresultList.remove(selectedNum[i] - i); deptAndUserList.remove(selectedNum[i] - i); } } else if ("用户关系".equals(selectedPanelFlag)){ int[] selectedNum = linelist.getSelectedIndices(); for (int i = 0;i < selectedNum.length;i++) { linelistModel.removeElementAt(selectedNum[i] - i); lineresultList.remove(selectedNum[i] - i); lineShowList.remove(selectedNum[i] - i); } } else if ("用户部门".equals(selectedPanelFlag)){ int[] selectedNum = departmentlist.getSelectedIndices(); for (int i = 0;i < selectedNum.length;i++) { departmentlistModel.removeElementAt(selectedNum[i] - i); departresultList.remove(selectedNum[i] - i); } } else if ("用户角色".equals(selectedPanelFlag)){ int[] selectedNum = rolelist.getSelectedIndices(); for (int i = 0;i < selectedNum.length;i++) { rolelistModel.removeElementAt(selectedNum[i] - i); roleresultList.remove(selectedNum[i] - i); } } else if ("用户群组".equals(selectedPanelFlag)){ int[] selectedNum = deptlist.getSelectedIndices(); for (int i = 0;i < selectedNum.length;i++) { deptlistModel.removeElementAt(selectedNum[i] - i); deptresultList.remove(selectedNum[i] - i); } } } /** * 添加左侧节点数据 * @param batch */ private void addToUserListFromTreeNode(boolean batch){ LinkedList nodeList = new LinkedList(); TreePath[] paths = rightManagementTree.getSelectionPaths(); if(batch && paths != null){ if ("部门用户关系".equals(selectedPanelFlag)) { if(paths.length > 1){ JOptionPane.showMessageDialog(LogonApplication.frame, "请选择一个节点"); return; } } for(TreePath path : paths){ nodeList.add((VCIBaseTreeNode)path.getLastPathComponent()); } } else{ nodeList.add(transmitTreeObject.getCurrentTreeNode()); } for(VCIBaseTreeNode selectNode : nodeList){ if(selectNode == null) { continue; } else { Object object = selectNode.getObj(); if ("部门用户关系".equals(selectedPanelFlag)) { DepartmentChooseDialog dialog = new DepartmentChooseDialog(((ClientBusinessObject) object).getOid()); dialog.setLocationRelativeTo(null); dialog.setVisible(true); String isShowSubDept = dialog.getSelectDepartmentText().equals("显示子部门")?"Y":"N"; String isShowDeptPerson = dialog.getSelectDepartmentPersonText().equals("显示部门员工")?"Y":"N"; String selectedPost = dialog.getPostText(); String postId = dialog.getPostId(); if (postId != null && !"".equals(postId)) { ClientBusinessObject cbo = (ClientBusinessObject) object; if(checkUserIdAdded(cbo, deptUserresultList)) return; String ele = ((ClientBusinessObject) object).getName() + ":" + selectedPost + ":" + isShowSubDept + ":" + isShowDeptPerson; deptUserlistModel.addElement(ele); String [] str = new String[2]; str[1] = ele; str[0] = postId; deptAndUserList.add(str); deptUserresultList.add(object); } } else { if (object instanceof ClientBusinessObject) { ClientBusinessObject cbo = (ClientBusinessObject) object; if("root".equals(cbo.getId())){ continue; } if ("用户部门".equals(selectedPanelFlag)) { if(checkUserIdAdded(cbo, departresultList)) return; departmentlistModel.addElement(((ClientBusinessObject) object).getName()); departresultList.add(object); } else if ("用户角色".equals(selectedPanelFlag)) { if(checkUserIdAdded(cbo, roleresultList)) return; rolelistModel.addElement(((ClientBusinessObject) object).getName()); roleresultList.add(object); } else if ("用户群组".equals(selectedPanelFlag)) { if(checkUserIdAdded(cbo, deptresultList)) return; deptlistModel.addElement(((ClientBusinessObject) object).getName()); deptresultList.add(object); } } } } } } //判断用户是否已经被选中 private boolean checkUserIdAdded(Object obj, List curlist){ boolean res = false; int size = curlist.size(); for(int i = 0; i < size; i++){ if(curlist.get(i) instanceof ClientBusinessObject && obj instanceof ClientBusinessObject){ obj = (ClientBusinessObject)obj; res = ((ClientBusinessObject) obj).getOid().equals(((ClientBusinessObject)curlist.get(i)).getOid()); if(res) break; } } return res; } /** * 居中屏幕 */ private void centerToScreen() { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension componentSize = getSize(); if (componentSize.height > screenSize.height) { componentSize.height = screenSize.height; } if (componentSize.width > screenSize.width) { componentSize.width = screenSize.width; } setLocation((screenSize.width - componentSize.width) / 2, (screenSize.height - componentSize.height) / 2); } /** * 内部类--单选框点击事件 * @author cmk * */ class RadioButtonListener implements ActionListener { public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub JRadioButton btn = (JRadioButton) e.getSource(); if (btn.isSelected()) { if ("反射类名".equals(btn.getText())) { ReflectClassDialog dialog = new ReflectClassDialog(); dialog.setLocationRelativeTo(null); dialog.setVisible(true); String reflectClass = dialog.getReflectClass(); if (reflectClass != null && !"".equals(reflectClass)) { selectJBtnClass = reflectClass; linelistModel.addElement(btn.getText()); lineShowList.add(btn.getText()); lineresultList.add(selectJBtnClass); } else { // return; } allUserBtn.setSelected(true); } else if ("所有人".equals(btn.getText())) { selectJBtnClass = "expression:all"; } else if ("拟稿人".equals(btn.getText())) { selectJBtnClass = "expression:creator"; } else if ("拟稿人所在部门".equals(btn.getText())) { selectJBtnClass = "expression:creator.dept"; } else if ("当前处理人所在部门".equals(btn.getText())) { selectJBtnClass = "expression:owner.dept"; } else if ("所有领导".equals(btn.getText())) { selectJBtnClass = "expression:allleader"; } else if ("所有秘书".equals(btn.getText())) { selectJBtnClass = "expression:allsecretary"; } else if ("拟稿人所在部门领导".equals(btn.getText())) { selectJBtnClass = "expression:creator.dept.leader"; } else if ("当前处理人所在部门领导".equals(btn.getText())) { selectJBtnClass = "expression:owner.dept.leader"; } else if ("当前节点处理人".equals(btn.getText())) { selectJBtnClass = "expression:owner"; } else if ("某一级别的所有人".equals(btn.getText())) { selectJBtnClass = "expression:onenode.alluser"; } else if ("某一节点处理人".equals(btn.getText())) { selectJBtnClass = "expression:onenode.manager"; } else if ("从业务表单中选择".equals(btn.getText())) { selectJBtnClass = "expression:chooseByForm"; } else if ("当前人的自定义组".equals(btn.getText())) {//暂不处理 selectJBtnClass = "expression:owner.customorg"; } else if ("当前处理人的一级部门".equals(btn.getText())) { selectJBtnClass = "expression:owner.childdept"; } selectJBtnText = btn.getText(); // btn.setSelected(false); } } } } //反射类名弹出框 class ReflectClassDialog extends VCIJDialog { private JButton okReflectClassBtn = new JButton("确定"); private JButton cancelReflectClassBtn = new JButton("取消"); private JLabel label = new JLabel("反射类名:"); private JTextField textField = new JTextField(); private String reflectClass = ""; private boolean flag = false; public ReflectClassDialog() { this.setModal(true); initUI(); addLisner(); } private void initUI() { setSize(300, 110); setTitle("自定义反射类"); JPanel panel = new JPanel(); getContentPane().add(panel, BorderLayout.CENTER); panel.setLayout(new BorderLayout(0, 2)); JPanel centerPanel = new JPanel(new FlowLayout()); // centerPanel.add(label); // textField.setSize(120, 20); // centerPanel.add(textField); centerPanel.setLayout(new GridLayout(1, 2)); centerPanel.add(label); centerPanel.add(textField); panel.add(centerPanel, BorderLayout.CENTER); JPanel bottomPanel = new JPanel(new FlowLayout()); bottomPanel.add(okReflectClassBtn); bottomPanel.add(cancelReflectClassBtn); panel.add(bottomPanel, BorderLayout.SOUTH); } private void addLisner() { okReflectClassBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String text = textField.getText(); if (text != null && !"".equals(text)) { setReflectClass("custom:" + text); } else { setReflectClass(""); } dispose(); } }); cancelReflectClassBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setReflectClass(""); dispose(); } }); } public String getReflectClass() { return reflectClass; } public void setReflectClass(String reflectClass) { this.reflectClass = reflectClass; } } //弹出框展示用户部门关系 class DepartmentChooseDialog extends VCIJDialog { private JComboBox positionCom = new JComboBox(); private JRadioButton showDepartmentBtn = new JRadioButton("显示子部门", true); private JRadioButton hideDepartmentBtn = new JRadioButton("不显示子部门"); private JRadioButton showDepartmentPersonBtn = new JRadioButton("显示部门员工", true); private JRadioButton hideDepartmentPersonBtn = new JRadioButton("不显示部门员工"); private ButtonGroup departmentBG = new ButtonGroup(); private ButtonGroup departmentPersonBG = new ButtonGroup(); private JButton okBtn = new JButton("确定"); private JButton cancelBtn = new JButton("取消"); private String selectDepartmentText = "显示子部门"; private String selectDepartmentPersonText = "显示部门员工"; private String postText = ""; private String deptId; private String postId = ""; public DepartmentChooseDialog(String deptId) { this.deptId = deptId; this.setModal(true); initUI(); try { initData(); } catch (Exception e) { e.printStackTrace(); } addLisner(); } public String getSelectDepartmentText() { return selectDepartmentText; } public void setSelectDepartmentText(String selectDepartmentText) { this.selectDepartmentText = selectDepartmentText; } public String getSelectDepartmentPersonText() { return selectDepartmentPersonText; } public void setSelectDepartmentPersonText(String selectDepartmentPersonText) { this.selectDepartmentPersonText = selectDepartmentPersonText; } public String getPostText() { return postText; } public void setPostText(String postText) { this.postText = postText; } public String getPostId() { return postId; } public void setPostId(String postId) { this.postId = postId; } public DepartmentChooseDialog () { } private void initUI() { setSize(400, 300); setTitle("设置部门用户关系"); departmentBG.add(showDepartmentBtn); departmentBG.add(hideDepartmentBtn); departmentPersonBG.add(showDepartmentPersonBtn); departmentPersonBG.add(hideDepartmentPersonBtn); JPanel panel = new JPanel(); getContentPane().add(panel, BorderLayout.CENTER); panel.setLayout(new BorderLayout(0, 2)); JPanel topPanel = new JPanel(); topPanel.add(positionCom); panel.add(topPanel, BorderLayout.NORTH); JPanel bgPanel = new JPanel(); panel.add(bgPanel, BorderLayout.CENTER); bgPanel.setLayout(new GridLayout(2, 2)); bgPanel.add(showDepartmentBtn); bgPanel.add(hideDepartmentBtn); bgPanel.add(showDepartmentPersonBtn); bgPanel.add(hideDepartmentPersonBtn); JPanel bottomPanel = new JPanel(new FlowLayout()); bottomPanel.add(okBtn); bottomPanel.add(cancelBtn); panel.add(bottomPanel, BorderLayout.SOUTH); } private static List> searchLo(String qtName, String showType, Map queryCondition) throws VCIError, DocumentException{ Map queryColumnsMap = new HashMap(); queryColumnsMap.put("*", "标题"); TableDataUtil util = new TableDataUtil(); List> dataModel = util.getObjectDataList(qtName, null, queryCondition , null, null, showType, queryColumnsMap, null, null); return dataModel; } private ClientBusinessObjectOperation cboo = new ClientBusinessObjectOperation(); private void initData() throws VCIError, DocumentException { Map conditionMap = new HashMap(); //conditionMap.put("isparttime", "0"); conditionMap.put("f_oid", deptId); List> dataModel = searchLo("deptpostTemplate", "deptpost", conditionMap); if (dataModel != null && dataModel.size() > 0) { for (int i = 0 ; i < dataModel.size(); i++) { Map personMap = dataModel.get(i); String postId = (String) personMap.get("oid"); this.postId = postId; ClientBusinessObject cbo = cboo.readBusinessObjectById(postId, "post"); positionCom.addItem(personMap.get("name")); //positionCom.setSelectedItem(anObject) } } } private void addLisner() { okBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Object item = positionCom.getSelectedItem(); if (item != null) { postText = item.toString(); } dispose(); } }); cancelBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setPostId(""); dispose(); } }); showDepartmentBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JRadioButton btn = (JRadioButton) e.getSource(); if (btn.isSelected()) { selectDepartmentText = btn.getText(); } } }); hideDepartmentBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JRadioButton btn = (JRadioButton) e.getSource(); if (btn.isSelected()) { selectDepartmentText = btn.getText(); } } }); showDepartmentPersonBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JRadioButton btn = (JRadioButton) e.getSource(); if (btn.isSelected()) { selectDepartmentPersonText = btn.getText(); } } }); hideDepartmentPersonBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JRadioButton btn = (JRadioButton) e.getSource(); if (btn.isSelected()) { selectDepartmentPersonText = btn.getText(); } } }); } }