package com.vci.client.auth2.view; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.List; import javax.swing.JButton; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.event.TreeExpansionEvent; import javax.swing.event.TreeExpansionListener; import javax.swing.table.DefaultTableModel; import javax.swing.tree.TreePath; import com.vci.client.LogonApplication; import com.vci.client.common.objects.DeptObject; import com.vci.client.common.objects.UserObject; import com.vci.client.framework.delegate.RightManagementClientDelegate; import com.vci.client.framework.systemConfig.stafforgmanage.DeptInfoTreeTableCellRender; import com.vci.client.framework.systemConfig.stafforgmanage.PLDeptInfoDataTreeModel; import com.vci.client.framework.systemConfig.stafforgmanage.UserTablePanel; import com.vci.client.logon.base.BaseJDialog; 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.treeTable.InterfaceTreeTableModel; import com.vci.client.ui.treeTable.JTreeTable; import com.vci.client.ui.treeTable.TreeTableModel; public class DeptingTreeDialog extends BaseJDialog { private static final long serialVersionUID = 1L; private JButton conformBut = new JButton(LocaleDisplay.getI18nString( "rmip.stafforg.operate.conform", "RMIPFramework", getLocale())); private JButton cancelBut = new JButton(LocaleDisplay.getI18nString( "rmip.stafforg.operate.cancel", "RMIPFramework", getLocale())); private boolean fromManualExpand = false; private static DeptingTreeDialog instance; private String[] columns = { "名称", "编号", "描述" }; DeptObject rootObj; private Class[] classes = { InterfaceTreeTableModel.class, String.class, String.class }; private PLDeptInfoDataTreeModel treeTableModel = null; private Object transObject = ""; private JTreeTable treeTable = null; private TreeTableModel.TreeTableNode rootNode = null; public static DeptingTreeDialog getInstance() { if (instance == null) { instance = new DeptingTreeDialog(); } return instance; } private DeptObject deptObj = null; private String type = "2"; public boolean isgetDatas = false; public List deptList = new ArrayList(); public boolean isIsgetDatas() { return this.isgetDatas; } public void setIsgetDatas(boolean isgetDatas) { this.isgetDatas = isgetDatas; } public List getDeptList() { return this.deptList; } public void setDeptList(List deptList) { this.deptList = deptList; } public DeptingTreeDialog(UserTablePanel userPanel, List userList) { super(LogonApplication.frame); setModal(true); init(); } public DeptingTreeDialog() { super(LogonApplication.frame); setModal(true); init(); } public DeptingTreeDialog(String type) { super(LogonApplication.frame); this.type = type; setModal(true); init(); } private void init() { initControl(); } private void initControl() { setLayout(new BorderLayout()); setTitle("选择部门"); try { JScrollPane jspTable = reloadTree(); add(jspTable, "Center"); } catch (VCIException e) { VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework", e); return; } JPanel palSubmit = new JPanel(); palSubmit.setLayout(new FlowLayout()); palSubmit.add(this.conformBut); palSubmit.add(this.cancelBut); this.conformBut.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { DeptingTreeDialog.this.addButton_actionPerformed(); } }); this.cancelBut.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { DeptingTreeDialog.this.cancelCreate(); } }); add(palSubmit, "South"); Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); int x = dim.width / 2 - 200; int y = dim.height / 2 - 200; setLocation(x, y); setSize(550, 450); } public JScrollPane reloadTree() throws VCIException { DeptObject rootDeptObj = new DeptObject(); this.treeTableModel = new PLDeptInfoDataTreeModel(this.transObject, this.columns, this.classes); this.rootNode = this.treeTableModel.getRootNode(); this.rootObj = new DeptObject(); this.rootObj.setName("部门"); this.rootNode.setObj(this.rootObj); loadTreeTableData(this.rootNode, rootDeptObj); this.treeTable = new JTreeTable(this.treeTableModel); this.treeTable.setRowHeight(25); this.treeTable.setSelectionMode(1); this.treeTable.getTableHeader().setReorderingAllowed(false); this.treeTable.getTableHeader().setResizingAllowed(true); this.treeTable.setColumnSelectionAllowed(false); this.treeTable.setShowGrid(true); this.treeTable.getColumnModel().getColumn(0).setMinWidth(200); this.treeTable.getTree().setCellRenderer( new DeptInfoTreeTableCellRender()); this.treeTable.setAutoResizeMode(0); this.treeTable.getColumnModel().getColumn(1).setMinWidth(100); this.treeTable.getColumnModel().getColumn(2).setMinWidth(250); this.treeTable.getTree().addTreeExpansionListener( new TreeExpansionListener() { public void treeExpanded(TreeExpansionEvent e) { if (DeptingTreeDialog.this.fromManualExpand) return; TreePath path = e.getPath(); TreeTableModel.TreeTableNode tableNode = (TreeTableModel.TreeTableNode) path .getLastPathComponent(); if (!(tableNode.isExpand())) { DeptingTreeDialog.this .loadSelectedTreeNodeChild(tableNode); tableNode.setExpand(true); } } public void treeCollapsed(TreeExpansionEvent e) { } }); JScrollPane jspTable = new JScrollPane(); jspTable.getViewport().add(this.treeTable); return jspTable; } private void loadSelectedTreeNodeChild( TreeTableModel.TreeTableNode parentTableNode) { try { if (parentTableNode.getObj() instanceof DeptObject) { DeptObject parentObj = (DeptObject) parentTableNode.getObj(); DeptObject[] childStructDatas = null; if (parentObj.getId() == null) { parentTableNode.removeAll(); childStructDatas = new RightManagementClientDelegate( LogonApplication.getUserEntityObject()) .fetchDepartmentInfoRoot(); } else { childStructDatas = new RightManagementClientDelegate( LogonApplication.getUserEntityObject()) .fetchDepartmentInfoByParentId(parentObj.getId()); } parentTableNode.setExpand(true); if (childStructDatas != null) { for (int i = 0; i < childStructDatas.length; ++i) { PLDeptInfoDataTreeModel tmp89_86 = this.treeTableModel; tmp89_86.getClass(); TreeTableModel.TreeTableNode tableNode = tmp89_86.new TreeTableNode( parentTableNode, childStructDatas[i]); parentTableNode.addChild(tableNode); setPropertyValue(tableNode); } } this.treeTable.getTree().setSelectionPath( new TreePath(parentTableNode)); } } catch (VCIException e) { VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework", e); return; } } private void setPropertyValue(TreeTableModel.TreeTableNode tableNode) { DeptObject deptObj = (DeptObject) tableNode.getObj(); tableNode.setPropertyValueByName(this.columns[1], (deptObj.getNum() == null) ? "" : deptObj.getNum()); tableNode.setPropertyValueByName(this.columns[2], (deptObj .getDescription() == null) ? "" : deptObj.getDescription()); } private void loadTreeTableData(TreeTableModel.TreeTableNode rootNode, DeptObject rootDeptObj) { DeptObject[] deptObjs = null; try { deptObjs = new RightManagementClientDelegate( LogonApplication.getUserEntityObject()) .fetchDepartmentInfoRoot(); if (deptObjs.length > 0) for (int i = 0; i < deptObjs.length; ++i) { PLDeptInfoDataTreeModel tmp35_32 = this.treeTableModel; tmp35_32.getClass(); TreeTableModel.TreeTableNode tableNode = tmp35_32.new TreeTableNode( rootNode, deptObjs[i]); rootNode.addChild(tableNode); setPropertyValue(tableNode); } } catch (VCIException e) { VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework", e); return; } } private void addButton_actionPerformed() { if ("1".equals(this.type)) { if (this.treeTable.getTree().getSelectionPaths() == null) { this.deptObj = new DeptObject(); return; } if (this.treeTable.getTree().getSelectionPaths().length > 1) { this.deptObj = new DeptObject(); VCIOptionPane.showMessage(this, "系统当前只支持单个部门的查询,请重新选择!"); return; } TreePath path = this.treeTable.getTree().getSelectionPaths()[0]; TreeTableModel.TreeTableNode treeNode = (TreeTableModel.TreeTableNode) path .getLastPathComponent(); this.deptObj = ((DeptObject) treeNode.getObj()); } else if ("2".equals(this.type)) { if (this.treeTable.getTree().getSelectionPaths() == null) { this.deptObj = new DeptObject(); return; } int len = this.treeTable.getTree().getSelectionPaths().length; for (int i = 0; i < len; ++i) { TreePath path = this.treeTable.getTree().getSelectionPaths()[i]; TreeTableModel.TreeTableNode treeNode = (TreeTableModel.TreeTableNode) path .getLastPathComponent(); this.deptObj = ((DeptObject) treeNode.getObj()); this.deptList.add(this.deptObj); setIsgetDatas(true); } getParentModel().setRowCount(deptList.size()); for (int i = 0; i < deptList.size(); i++) { getParentModel().setValueAt((Object) deptList.get(i).getNum(), i, 0); getParentModel().setValueAt((Object) deptList.get(i).getName(), i, 1); } } else { if (this.treeTable.getTree().getSelectionPaths() == null) { VCIOptionPane.showMessage(this, "请选择部门节点!"); return; } if (this.treeTable.getTree().getSelectionPaths().length > 1) { VCIOptionPane.showMessage(this, "每次只能选择一个部门节点!"); return; } TreePath path = this.treeTable.getTree().getSelectionPaths()[0]; TreeTableModel.TreeTableNode treeNode = (TreeTableModel.TreeTableNode) path .getLastPathComponent(); DeptObject parentObj = (DeptObject) treeNode.getObj(); String detpId = parentObj.getId(); if (("".equals(detpId)) || (detpId == null) || ("null".equals(detpId))) { VCIOptionPane.showMessage(this, "选择的是部门根节点,请重新选择!!"); return; } // String[] userIds = new String[this.userList.size()]; // for (int i = 0; i < this.userList.size(); ++i) { // userIds[i] = ((UserObject) this.userList.get(i)).getId(); // } // try { // new RightManagementClientDelegate( // LogonApplication.getUserEntityObject()).saveUserDept( // userIds, parentObj.getId()); // } catch (VCIException e) { // VCIOptionPane.showError(LogonApplication.frame, // "RMIPFramework", e); // return; // } // this.userPanel.tablePanel.refreshTableData(); } dispose(); } public void cancelCreate() { dispose(); } public DeptObject getDeptObj() { return this.deptObj; } public DefaultTableModel getParentModel() { return parentModel; } public void setParentModel(DefaultTableModel parentModel) { this.parentModel = parentModel; } private DefaultTableModel parentModel = new DefaultTableModel(); }