package com.vci.client.framework.specialrole;
|
|
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.JTable;
|
import javax.swing.ListSelectionModel;
|
import javax.swing.border.EmptyBorder;
|
import javax.swing.event.TreeExpansionEvent;
|
import javax.swing.event.TreeExpansionListener;
|
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.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;
|
|
/**
|
* <p>Title: DeptingDialog</p>
|
* <p>Description:为人员分配部门 </p>
|
* <p>Copyright: Copyright (c) 2012</p>
|
* <p>Company: VCI</p>
|
* @author wangxl
|
* @time 2012-5-13
|
* @version 1.0
|
*/
|
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 UserTablePanel userPanel;
|
private List<UserObject> userList;
|
|
private boolean fromManualExpand = false;
|
// private boolean fromManualSelectedTreeNode = false;
|
private String[] columns = {"名称","编号","代号","描述"};
|
DeptObject rootObj;
|
private Class[] classes = {InterfaceTreeTableModel.class,String.class,String.class,String.class} ;
|
private PLDeptInfoDataTreeModel treeTableModel = null;
|
private Object transObject = "";
|
private JTreeTable treeTable = null;
|
private TreeTableModel.TreeTableNode rootNode = null;
|
|
private DeptObject deptObj = null;
|
|
private String type = "0";
|
public boolean isgetDatas = false;
|
public boolean isIsgetDatas() {
|
return isgetDatas;
|
}
|
public void setIsgetDatas(boolean isgetDatas) {
|
this.isgetDatas = isgetDatas;
|
}
|
|
public List<DeptObject> deptList = new ArrayList<DeptObject>();
|
public List<DeptObject> getDeptList() {
|
return deptList;
|
}
|
public void setDeptList(List<DeptObject> deptList) {
|
this.deptList = deptList;
|
}
|
|
public DeptingTreeDialog(UserTablePanel userPanel ,List<UserObject> userList){
|
super(LogonApplication.frame);
|
this.userList = userList;
|
this.userPanel = userPanel;
|
this.setModal(true);
|
init();
|
}
|
|
public DeptingTreeDialog(String type) {
|
super(LogonApplication.frame);
|
this.type = type;
|
this.setModal(true);
|
init();
|
}
|
|
|
/**
|
* 初始化界面
|
*/
|
private void init() {
|
initControl();
|
}
|
|
private void initControl() {
|
this.setLayout(new BorderLayout());
|
this.setTitle("选择部门");
|
try{
|
JScrollPane jspTable = reloadTree();
|
this.add(jspTable, BorderLayout.CENTER);
|
}catch (VCIException e) {
|
VCIOptionPane.showError(LogonApplication.frame,"RMIPFramework",e);
|
return ;
|
}
|
|
JPanel palSubmit = new JPanel();
|
palSubmit.setLayout(new FlowLayout());
|
palSubmit.setBorder(new EmptyBorder(7, 7, 7, 7));
|
|
palSubmit.add(conformBut);
|
palSubmit.add(cancelBut);
|
conformBut.addActionListener(new ActionListener() {
|
@Override
|
public void actionPerformed(ActionEvent arg0) {
|
addButton_actionPerformed();
|
}
|
});
|
cancelBut.addActionListener(new ActionListener() {
|
@Override
|
public void actionPerformed(ActionEvent arg0) {
|
cancelCreate();
|
}
|
});
|
|
this.add(palSubmit, BorderLayout.SOUTH);
|
|
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
|
int x = dim.width/2 - 200;
|
int y = dim.height/2 - 200;
|
|
// int x = (int)(this.getParent().getLocationOnScreen().getX()) + 200;
|
// int y = (int)(this.getParent().getLocationOnScreen().getY()) + 80;
|
this.setLocation(x , y);
|
this.setSize(550, 450);
|
this.setVisible(true);
|
|
}
|
|
public JScrollPane reloadTree() throws VCIException{
|
DeptObject rootDeptObj = new DeptObject();
|
treeTableModel = new PLDeptInfoDataTreeModel(transObject, columns, classes);
|
rootNode = treeTableModel.getRootNode();
|
rootObj = new DeptObject(); rootObj.setName("部门");
|
rootNode.setObj(rootObj);
|
this.loadTreeTableData(rootNode, rootDeptObj);
|
treeTable = new JTreeTable(treeTableModel);
|
treeTable.setRowHeight(25);
|
treeTable.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
|
treeTable.getTableHeader().setReorderingAllowed(false);
|
treeTable.getTableHeader().setResizingAllowed(true);
|
treeTable.setColumnSelectionAllowed(false);
|
treeTable.setShowGrid(true);
|
treeTable.getColumnModel().getColumn(0).setMinWidth(200);
|
treeTable.getTree().setCellRenderer(new DeptInfoTreeTableCellRender());
|
treeTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
|
|
|
treeTable.getColumnModel().getColumn(1).setMinWidth(100);
|
treeTable.getColumnModel().getColumn(2).setMinWidth(250);
|
|
treeTable.getTree().addTreeExpansionListener(new TreeExpansionListener(){
|
public void treeExpanded(TreeExpansionEvent e) {
|
if(fromManualExpand) return;
|
TreePath path = e.getPath();
|
TreeTableModel.TreeTableNode tableNode = (TreeTableModel.TreeTableNode)path.getLastPathComponent();
|
if(!tableNode.isExpand()){
|
loadSelectedTreeNodeChild(tableNode);
|
// 展开过就不再加载数据
|
tableNode.setExpand(true);
|
}
|
}
|
public void treeCollapsed(TreeExpansionEvent e) {}
|
});
|
JScrollPane jspTable = new JScrollPane();
|
jspTable.getViewport().add(treeTable);
|
return jspTable;
|
}
|
|
/**
|
* <p>Description:获取子部门 </p>
|
*
|
* @author wangxl
|
* @time 2012-5-14
|
* @param parentTableNode
|
*/
|
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 ++){
|
TreeTableModel.TreeTableNode tableNode = treeTableModel.new TreeTableNode(parentTableNode, childStructDatas[i]);
|
parentTableNode.addChild(tableNode);
|
setPropertyValue(tableNode);
|
}
|
}
|
|
// 设置选择节点
|
// this.treeTable.repaint();
|
this.treeTable.getTree().setSelectionPath(new TreePath(parentTableNode));
|
}
|
} catch (VCIException e) {
|
VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework", e);
|
return;
|
}
|
}
|
|
/**
|
* <p>Description:单元格属性填充 </p>
|
*
|
* @author wangxl
|
* @time 2012-5-14
|
* @param tableNode
|
*/
|
private void setPropertyValue(TreeTableModel.TreeTableNode tableNode){
|
DeptObject deptObj = (DeptObject)tableNode.getObj();
|
tableNode.setPropertyValueByName(columns[1], deptObj.getNum() == null ? "" : deptObj.getNum());
|
tableNode.setPropertyValueByName(columns[2], deptObj.getCode() == null ? "" : deptObj.getCode());
|
tableNode.setPropertyValueByName(columns[3], deptObj.getDescription() == null ? "" : deptObj.getDescription());
|
|
}
|
|
/**
|
* <p>Description: 获取顶级部门</p>
|
*
|
* @author wangxl
|
* @time 2012-5-14
|
* @param rootNode
|
* @param rootDeptObj
|
*/
|
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 ++){
|
TreeTableModel.TreeTableNode tableNode = treeTableModel.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(type)) {
|
if (null == this.treeTable.getTree().getSelectionPaths()){
|
deptObj = new DeptObject();
|
return;
|
}
|
|
if( this.treeTable.getTree().getSelectionPaths().length > 1) {
|
deptObj = new DeptObject();
|
VCIOptionPane.showMessage(this, "系统当前只支持单个部门的查询,请重新选择!");
|
return;
|
}
|
TreePath path = this.treeTable.getTree().getSelectionPaths()[0];
|
TreeTableModel.TreeTableNode treeNode = (TreeTableModel.TreeTableNode)path.getLastPathComponent();
|
deptObj =(DeptObject)treeNode.getObj();
|
}else if("2".equals(type)){//业务系统调用此dialog
|
if (null == this.treeTable.getTree().getSelectionPaths()){
|
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();
|
deptObj =(DeptObject)treeNode.getObj();
|
deptList.add(deptObj);
|
setIsgetDatas(true);
|
}
|
}else {
|
if (null == this.treeTable.getTree().getSelectionPaths()){
|
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) || null == detpId || "null".equals(detpId)) {
|
VCIOptionPane.showMessage(this, "选择的是部门根节点,请重新选择!!");
|
return;
|
}
|
String[] userIds = new String[userList.size()];
|
for (int i = 0 ; i < userList.size() ; i ++){
|
userIds[i] = userList.get(i).getId();
|
}
|
try{
|
|
new RightManagementClientDelegate(LogonApplication.getUserEntityObject())
|
.saveUserDept(userIds,parentObj.getId());
|
|
}catch(VCIException e) {
|
VCIOptionPane.showError(LogonApplication.frame,"RMIPFramework", e);
|
return ;
|
}
|
userPanel.tablePanel.refreshTableData();
|
}
|
this.dispose();
|
}
|
|
public void cancelCreate(){
|
this.dispose();
|
}
|
|
public DeptObject getDeptObj() {
|
return deptObj;
|
}
|
|
}
|