package com.vci.client.framework.rightdistribution.roleRight;
|
|
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.event.ActionEvent;
|
import java.awt.event.ActionListener;
|
import java.awt.event.MouseAdapter;
|
import java.awt.event.MouseEvent;
|
import java.util.Date;
|
import java.util.HashMap;
|
import java.util.HashSet;
|
import java.util.Iterator;
|
import java.util.LinkedHashMap;
|
import java.util.LinkedList;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.Map.Entry;
|
import java.util.Set;
|
|
import javax.swing.JButton;
|
import javax.swing.JLabel;
|
import javax.swing.JList;
|
import javax.swing.JMenuItem;
|
import javax.swing.JPanel;
|
import javax.swing.JPopupMenu;
|
import javax.swing.JScrollPane;
|
import javax.swing.JSplitPane;
|
import javax.swing.JTextField;
|
import javax.swing.ListSelectionModel;
|
import javax.swing.tree.TreePath;
|
|
import com.vci.client.LogonApplication;
|
import com.vci.client.common.VCIBasePanel;
|
import com.vci.client.common.objects.RoleObject;
|
import com.vci.client.common.objects.UserObject;
|
import com.vci.client.framework.common.RightType;
|
import com.vci.client.framework.delegate.FuncOperationClientDelegate;
|
import com.vci.client.framework.delegate.FunctionClientDelegate;
|
import com.vci.client.framework.delegate.RightManagementClientDelegate;
|
import com.vci.client.framework.delegate.RoleRightClientDelegate;
|
import com.vci.client.framework.rightConfig.modelConfig.ModuleTreeCellRenderer;
|
import com.vci.client.framework.rightConfig.object.FuncOperationObject;
|
import com.vci.client.framework.rightConfig.object.FunctionObject;
|
import com.vci.client.framework.rightConfig.operate.ObjectListCellRenderer;
|
import com.vci.client.framework.rightdistribution.object.RoleRightObject;
|
import com.vci.client.framework.specialrole.ModuleInterface.IModuleShow;
|
import com.vci.client.framework.systemConfig.stafforgmanage.ListLabelCellRender;
|
import com.vci.client.framework.util.RightControlUtil;
|
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.KJButton;
|
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.VCIJLabel;
|
import com.vci.client.ui.swing.components.VCIJList;
|
import com.vci.client.ui.swing.components.VCIJOptionPane;
|
import com.vci.client.ui.swing.components.VCIJPanel;
|
import com.vci.client.ui.swing.components.VCIJScrollPane;
|
import com.vci.client.ui.tree.CheckBoxTreeManager;
|
import com.vci.client.ui.tree.VCIBaseTree;
|
import com.vci.client.ui.tree.VCIBaseTreeModel;
|
import com.vci.client.ui.tree.VCIBaseTreeNode;
|
|
/**
|
* 功能模块授权 升级版本,支持 角色权限复制、粘贴(将角色权限快速应用到其它角色)
|
*
|
* @author xchao
|
*
|
*/
|
public class CSRoleRightPanelV2 extends VCIBasePanel implements IModuleShow{
|
|
private static final long serialVersionUID = -2672216434571403222L;
|
private final JLabel roleListLab = new JLabel(LocaleDisplay.getI18nString("rmip.framework.rightdistribution.moduleRight.RoleList","RMIPFramework", getLocale()));// 角色列表Lab
|
JList roleList = new JList(); // 角色列表
|
|
private final JLabel titleLab = new JLabel(LocaleDisplay.getI18nString("rmip.framework.rightdistribution.moduleRight.name","RMIPFramework", getLocale()));// title
|
private final JButton addButton = new JButton();
|
private final JButton delButton = new JButton();
|
private final VCIJButton btnSaveToTemp = VCISwingUtil.createVCIJButton(
|
"saveToTemp", "复制", "复制", "copy.gif", new ActionListener() {
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
saveToTemp();
|
}
|
});
|
private final VCIJButton btnApplyFromTemp = VCISwingUtil.createVCIJButton(
|
"saveToTemp", "粘贴", "粘贴", "paste.gif", new ActionListener() {
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
applyFromTemp();
|
}
|
});
|
JScrollPane scrollTree = null;
|
JSplitPane jspConfigPanel; // 把Panel分成左右两部分
|
private final JScrollPane leftPanel = new JScrollPane();
|
VCIBaseTree tree;
|
VCIBaseTreeModel treeModel;
|
VCIBaseTreeNode rootNode;
|
|
private final JTextField top = new JTextField();// 上横线
|
private final JTextField bottom = new JTextField();// 下横线
|
RightManagementClientDelegate rightManagementClient = new RightManagementClientDelegate(LogonApplication.getUserEntityObject());
|
RoleRightClientDelegate moduleRightClientDelegate = new RoleRightClientDelegate(LogonApplication.getUserEntityObject());
|
CheckBoxTreeManager treeManager;
|
|
private final String currentUserName = LogonApplication.getUserEntityObject().getUserName();
|
/**
|
* 记录当前选中的角色
|
*/
|
private RoleObject curRole = null;
|
/**
|
* 存储需要保存的权限
|
*/
|
private Map<String,RoleRightObject> rightMap = new HashMap<String,RoleRightObject>();
|
|
/**
|
* 刷新按钮
|
*/
|
private JPopupMenu popupMenu;
|
private final JMenuItem refMenuItem = new JMenuItem("刷新", VCISwingUtil.createImageIcon("arrow_refresh.png"));//刷新
|
|
/**查询功能**/
|
private final JLabel searchLbl = new JLabel("查询:");
|
private final JTextField searchTxt = new JTextField(20);
|
private final KJButton searchBtn = new KJButton("", "search.gif");
|
|
private String logonUserId = "",logonRoleId;
|
private String moduleName = "";
|
private String iconName,moduleShowInfo ;
|
|
// private SpecialRoleObject specialRoleObject = new SpecialRoleObject();
|
// public SpecialRoleObject getSpecialRoleObject() {
|
// return specialRoleObject;
|
// }
|
//
|
// public void setSpecialRoleObject(SpecialRoleObject specialRoleObject) {
|
// this.specialRoleObject = specialRoleObject;
|
// }
|
public String getLogonUserId() {
|
return logonUserId;
|
}
|
public void setLogonUserId(String logonUserId) {
|
this.logonUserId = logonUserId;
|
}
|
public String getLogonRoleId() {
|
return logonRoleId;
|
}
|
public void setLogonRoleId(String logonRoleId) {
|
this.logonRoleId = logonRoleId;
|
}
|
public void setModuleName(String moduleName) {
|
this.moduleName = moduleName;
|
}
|
public void setIconName(String iconName) {
|
this.iconName = iconName;
|
}
|
public void setModuleShowInfo(String moduleShowInfo) {
|
this.moduleShowInfo = moduleShowInfo;
|
}
|
public CSRoleRightPanelV2(FunctionObject funcObj) {
|
super(funcObj);
|
rightRoleMap();
|
init();
|
LogonApplication.getUserEntityObject().setModules(this.getModuleName());
|
}
|
/**
|
* 初始化页面
|
*
|
*/
|
public void init() {
|
JPanel palMain = new JPanel();
|
JPanel contentPanel = new JPanel();
|
JPanel buttonPanel = new JPanel();
|
JPanel midPanel = new JPanel();
|
palMain.setLayout(new BorderLayout());
|
roleList("");
|
contentItem(contentPanel);
|
jButtonPanl(buttonPanel);
|
initTreeNode();
|
|
refMenuItem.addActionListener(new ActionListener() {
|
@Override
|
public void actionPerformed(ActionEvent arg0) {
|
refreshRole();
|
}
|
});
|
|
searchBtn.addActionListener(new ActionListener() {
|
@Override
|
public void actionPerformed(ActionEvent arg0) {
|
searchRoleList();
|
}
|
});
|
|
midPanel.setLayout(new BorderLayout());
|
midPanel.add(top, BorderLayout.NORTH);
|
midPanel.add(bottom, BorderLayout.SOUTH);
|
midPanel.add(contentPanel, BorderLayout.CENTER);
|
palMain.add(titleLab, BorderLayout.NORTH);
|
palMain.add(midPanel, BorderLayout.CENTER);
|
palMain.add(buttonPanel, BorderLayout.SOUTH);
|
|
JPanel leftMainPanel = new JPanel(new BorderLayout());
|
leftMainPanel.add(leftPanel,BorderLayout.CENTER);
|
leftMainPanel.add(getSearchPanel(),BorderLayout.NORTH);
|
|
jspConfigPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftMainPanel, palMain);
|
jspConfigPanel.setDividerSize(7);
|
jspConfigPanel.setContinuousLayout(true);
|
jspConfigPanel.setOneTouchExpandable(true);
|
jspConfigPanel.setDividerLocation(220);
|
this.setLayout(new BorderLayout());
|
this.add(jspConfigPanel, BorderLayout.CENTER);
|
}
|
|
private JPanel getSearchPanel() {
|
//JPanel searchPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
JPanel searchPanel = new JPanel();
|
searchPanel.add(searchLbl);
|
searchPanel.add(searchTxt);
|
searchPanel.add(searchBtn);
|
|
GridBagLayout layout = new GridBagLayout();
|
searchPanel.setLayout(layout);
|
|
GridBagConstraints s = new GridBagConstraints();
|
s.fill = GridBagConstraints.HORIZONTAL;
|
s.gridwidth = 1;
|
s.weightx = 0;
|
s.weighty = 0;
|
layout.setConstraints(searchLbl, s);
|
s.gridwidth = 1;
|
s.weightx = 1;
|
s.weighty = 0;
|
layout.setConstraints(searchTxt, s);
|
s.gridwidth = 0;
|
s.weightx = 0;
|
s.weighty = 0;
|
layout.setConstraints(searchBtn, s);
|
//GridLayout layout = new GridLayout(1, 3);
|
//searchPanel.add(searchLbl);
|
//searchPanel.add(searchTxt);
|
//searchPanel.add(searchBtn);
|
|
return searchPanel;
|
|
}
|
|
|
/**
|
* 根据父模块ID,过滤出CS的功能模块
|
* @param parentId 父模块oid
|
* @return
|
* @throws VCIException
|
*/
|
private FunctionObject[] getModuleListByParentIdForCS(String parentId) throws VCIException{
|
FunctionClientDelegate funcDel = new FunctionClientDelegate();
|
// 不分CS、B/S、.NET、Mobile,加载出全部的子功能模块
|
FunctionObject[] funcObjs = funcDel.getModuleListByParentId(parentId, false);
|
|
return funcObjs;
|
// 在客户端本地过滤
|
//return getFinalCSModules(funcObjs);
|
}
|
/**
|
* 过滤出CS功能模块
|
* @param funcs
|
* @return
|
*/
|
private FunctionObject[] getFinalCSModules(FunctionObject[] funcs){
|
List<FunctionObject> list = new LinkedList<FunctionObject>();
|
for(FunctionObject func : funcs){
|
// String cs = func.getResourceC();
|
//
|
// if(cs != null && !"".equals(cs)){
|
// }
|
list.add(func);
|
}
|
return list.toArray(new FunctionObject[0]);
|
}
|
|
public void initTreeNode(){
|
rootNode = new VCIBaseTreeNode(LocaleDisplay.getI18nString("rmip.framework.rightdistribution.moduleRight.moduleTree","RMIPFramework", getLocale()), "root");
|
treeModel = new VCIBaseTreeModel(rootNode);
|
tree = new VCIBaseTree(treeModel, new ModuleTreeCellRenderer());
|
FunctionObject[] funcObjs = null;
|
|
try {
|
String rootModel = "business";
|
|
UserObject curUser = LogonApplication.getUserObject();
|
|
// 超级管理员给三员账号授权
|
if (RightControlUtil.isAdminOrDeveloperOrRoot(curUser.getUserName())) {
|
rootModel = "system";
|
}
|
// 三员可以给普通用户授权业务功能
|
else if (RightControlUtil.isThreeAdminCurUser()) {
|
rootModel = "business";
|
}
|
// 其他用户不能授权
|
else {
|
return;
|
}
|
|
// 在客户端过滤出CS功能模块
|
funcObjs = getModuleListByParentIdForCS(rootModel);
|
funMap.clear();
|
for(int k = 0;k < funcObjs.length;k++) {
|
funMap.put(funcObjs[k].getName(), funcObjs[k].getId());
|
}
|
|
for (int i = 0; i < funcObjs.length; i++) {
|
VCIBaseTreeNode node = new VCIBaseTreeNode(funcObjs[i].getName(), funcObjs[i]);
|
if (rootModel.equals(funcObjs[i].getParentId())) {
|
treeModel.insertNodeInto(node, rootNode,rootNode.getChildCount());
|
}
|
setChildNode(node,funcObjs[i]);
|
}
|
} catch (VCIException e) {
|
e.printStackTrace();
|
VCIOptionPane.showError(LogonApplication.frame,LocaleDisplay.getI18nString(e, "RMIPFramework", getLocale()));
|
return;
|
}
|
treeManager = new CheckBoxTreeManager(tree);
|
scrollTree.getViewport().removeAll();
|
scrollTree.getViewport().add(tree);
|
scrollTree.repaint();
|
}
|
private void setChildNode(VCIBaseTreeNode node ,FunctionObject funcObj) {
|
/**0表示该模块下什么都没有,1表示有模块,2表示有操作**/
|
FunctionClientDelegate funcDel = new FunctionClientDelegate();
|
|
try{
|
int childType = funcDel.checkChildObject(funcObj.getId());
|
if(childType == 1){
|
// FunctionObject[] funcObjs = new FunctionClientDelegate().getModuleListByParentIdForCS(funcObj.getId(),false);
|
// 在CS客户端本地,过滤出CS功能模块
|
FunctionObject[] funcObjs = getModuleListByParentIdForCS(funcObj.getId());
|
|
for(int i=0;i<funcObjs.length;i++){
|
VCIBaseTreeNode curNode = new VCIBaseTreeNode(funcObjs[i].getName(), funcObjs[i]);
|
treeModel.insertNodeInto(curNode, node,node.getChildCount());
|
funMap.put(funcObjs[i].getName(), funcObjs[i].getId());
|
setChildNode(curNode,funcObjs[i]);
|
}
|
} else if(childType == 2) {
|
FuncOperationObject[] funcOperateObjs = new FuncOperationClientDelegate().getFuncOperationByModuleId(funcObj.getId(), "", true);
|
for (int j = 0; j < funcOperateObjs.length; j++) {
|
VCIBaseTreeNode childNode = new VCIBaseTreeNode(funcOperateObjs[j].getOperAlias(),funcOperateObjs[j]);
|
UserObject user = rightManagementClient.fetchUserInfoByName(LogonApplication.getUserEntityObject().getUserName());
|
// if(user.getUserType() == 0 || childNode.toString().equals("查看")){
|
// treeModel.insertNodeInto(childNode, node,node.getChildCount());
|
// childNode.setLeaf(true);
|
// }else{
|
// boolean res = initRoleRightByType(childNode);
|
// if(res){
|
treeModel.insertNodeInto(childNode, node,node.getChildCount());
|
childNode.setLeaf(true);
|
// }
|
// }
|
}
|
}else{
|
node.setLeaf(true);
|
}
|
}catch (VCIException e) {
|
e.printStackTrace();
|
VCIOptionPane.showError(LogonApplication.frame,LocaleDisplay.getI18nString(e, "RMIPFramework", getLocale()));
|
}
|
}
|
|
|
/**
|
*
|
* <p>Description:获取角色是0和1的授权(系统管理员,审计管理员,安全管理员所具有的权限) </p>
|
*
|
* @author sunbo
|
* @time 2013-2-21
|
*/
|
Map<String,Long> rightRoleMap = new HashMap<String,Long>();
|
public void rightRoleMap(){
|
RoleRightObject[] roleRightObjs;
|
try {
|
roleRightObjs = new RoleRightClientDelegate().getRoleRightListByType(new String[]{"0", "1"});
|
for(RoleRightObject obj : roleRightObjs){
|
String key = obj.getFuncId();
|
rightRoleMap.put(key, obj.getRightValue());
|
}
|
} catch (VCIException e) {
|
e.printStackTrace();
|
VCIOptionPane.showError(LogonApplication.frame, LocaleDisplay.getI18nString(e,"RMIPFramework", getLocale()));
|
}
|
|
}
|
|
public boolean initRoleRightByType(VCIBaseTreeNode childNode){
|
boolean res = true;
|
|
res = isShowChildNode(childNode,rightRoleMap);
|
return res;
|
}
|
private boolean isShowChildNode(VCIBaseTreeNode node, Map<String,Long> rightMap){
|
boolean res = true;
|
Object obj = node.getObj();
|
String id = ((FuncOperationObject) obj).getFuncId();
|
if(rightMap.containsKey(id)){
|
Object a = rightMap.get(id);
|
if(a instanceof HashSet){
|
HashSet set = (HashSet) a;
|
Iterator it = set.iterator();
|
while(it.hasNext()){
|
long rightValue = (Integer) it.next();
|
long nodeValue = ((FuncOperationObject) obj).getNumber();
|
//long preValue = (long)Math.pow(2, nodeValue);
|
//进行位与操作,如果相等则表示具有当前操作的权限
|
//if(preValue == (preValue & rightValue)){
|
long preValue = (rightValue >> nodeValue) & 1;
|
if (preValue == 1) {
|
res = false ;
|
}
|
}
|
}else{
|
long rightValue = (Integer) a;
|
long nodeValue = ((FuncOperationObject) obj).getNumber();
|
//long preValue = (long)Math.pow(2, nodeValue);
|
//进行位与操作,如果相等则表示具有当前操作的权限
|
//if(preValue == (preValue & rightValue)){
|
long preValue = (rightValue >> nodeValue) & 1;
|
if (preValue == 1) {
|
res = false ;
|
}
|
}
|
}
|
return res;
|
}
|
/**
|
* 按钮
|
*
|
* @return
|
*/
|
public void jButtonPanl(JPanel p) {
|
|
addButton.setText(LocaleDisplay.getI18nString("rmip.framework.rightdistribution.moduleRight.addButton.file","RMIPFramework", getLocale()));
|
addButton.setIcon(new BundleImage().createImageIcon("create.gif"));
|
addButton.addActionListener(new ActionListener() {
|
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
add_actionPerform();
|
}
|
});
|
|
|
delButton.setText(LocaleDisplay.getI18nString("rmip.framework.rightdistribution.moduleRight.delButton.file","RMIPFramework", getLocale()));
|
delButton.setIcon(new BundleImage().createImageIcon("delete.gif"));
|
delButton.addActionListener(new ActionListener() {
|
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
rightMap.clear();
|
treeManager.getSelectionModel().clearSelection();
|
}
|
});
|
p.add(addButton);
|
p.add(delButton);
|
p.add(btnSaveToTemp);
|
p.add(btnApplyFromTemp);
|
}
|
|
private void add_actionPerform(){
|
if (!checkItem()) {
|
return;
|
}
|
try {
|
rightMap.clear();
|
TreePath[] treePath = treeManager.getSelectionModel().getSelectionPaths();
|
//当没有选中模块的时候
|
if (treePath == null) {
|
new RoleRightClientDelegate(LogonApplication.getUserEntityObject()).saveRoleRight(new RoleRightObject[0],curRole.getId(),LogonApplication.getUserEntityObject().getUserName());
|
} else {
|
for(int i = 0;i < treePath.length;i++){
|
VCIBaseTreeNode node = (VCIBaseTreeNode)treePath[i].getLastPathComponent();
|
Object obj = node.getObj();
|
if(obj instanceof String){//如果是root节点,则保存所有模块的权限
|
getRightValue(node,false);//向下获取所有模块的权限值
|
}else if(obj instanceof FunctionObject){
|
getRightValue(node,true);//向上处理
|
getRightValue(node,false);//向下处理(包含当前节点)
|
}else if(obj instanceof FuncOperationObject){
|
VCIBaseTreeNode parentNode = (VCIBaseTreeNode)node.getParent();
|
String funcId = ((FunctionObject)parentNode.getObj()).getId();
|
getRightValue(parentNode,true);//向上处理该操作父级的上级模块权限(不包含父节点)
|
if(!rightMap.containsKey(funcId)){
|
RoleRightObject roleRightObj = new RoleRightObject();
|
roleRightObj.setFuncId(funcId);
|
roleRightObj.setRightType(RightType.Function);
|
roleRightObj.setRightValue(countRightValue(parentNode,false));//没有操作的模块权限值存储为0
|
roleRightObj.setRoleId(curRole.getId());
|
roleRightObj.setCreateUser(currentUserName);
|
roleRightObj.setCreateTime(new Date());
|
roleRightObj.setModifyUser(currentUserName);
|
roleRightObj.setModifyTime(new Date());
|
roleRightObj.setLicensor("");
|
rightMap.put(funcId, roleRightObj);
|
}
|
}
|
}
|
//1。先从所有权限对象中删除模块权限对象
|
Set<Entry<String, String>> funSet = funMap.entrySet();
|
Iterator<Entry<String, String>> funIt = funSet.iterator();
|
while(funIt.hasNext()){
|
Entry<String, String> next = funIt.next();
|
String key = next.getKey();
|
String value = next.getValue();
|
allRightRoleMap.remove(value);
|
}
|
//2。再保存选中的模块对象到所有权限中
|
Set<Entry<String, RoleRightObject>> entrySet = rightMap.entrySet();
|
Iterator<Entry<String, RoleRightObject>> iterator = entrySet.iterator();
|
while(iterator.hasNext()){
|
Entry<String, RoleRightObject> next = iterator.next();
|
String key = next.getKey();
|
RoleRightObject value = next.getValue();
|
if(!allRightRoleMap.containsKey(value.getFuncId())){
|
allRightRoleMap.put(value.getFuncId(), value);
|
}
|
}
|
rightMap = allRightRoleMap;
|
/**上面处理完成后,循环遍历取出MAP里的对象进行保存**/
|
RoleRightObject[] roleRightObjs = new RoleRightObject[rightMap.size()];
|
Set<String> objSet = rightMap.keySet();
|
Iterator<String> it = objSet.iterator();
|
int i = 0;
|
while(it.hasNext()){
|
roleRightObjs[i++] = rightMap.get(it.next());
|
}
|
boolean res = new RoleRightClientDelegate(LogonApplication.getUserEntityObject()).saveRoleRight(roleRightObjs,curRole.getId(),currentUserName);
|
if(res){
|
VCIOptionPane.showMessage(LogonApplication.frame, "功能模块授权成功!");
|
treeManager.getSelectionModel().clearSelection();
|
initRoleRight(curRole.getId());
|
}
|
// /**上面处理完成后,循环遍历取出MAP里的对象进行保存**/
|
// RoleRightObject[] roleRightObjs = new RoleRightObject[rightMap.size()];
|
// Set<String> objSet = rightMap.keySet();
|
// Iterator<String> it = objSet.iterator();
|
// int i = 0;
|
// while(it.hasNext()){
|
// roleRightObjs[i++] = rightMap.get(it.next());
|
// }
|
// boolean res = new RoleRightClientDelegate(LogonApplication.getUserEntityObject()).saveRoleRight(roleRightObjs,curRole.getId(),currentUserName);
|
// if(res){
|
// VCIOptionPane.showMessage(LogonApplication.frame, "功能模块授权成功!");
|
// }
|
}
|
}catch (VCIException e1) {
|
e1.printStackTrace();
|
VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework", e1);
|
}
|
}
|
/**
|
* 获取权限
|
* @param isUp 是否是向上获取,如果是向上获取,传进来的必然是模块节点,且上级模块必然是没有选中
|
*/
|
private void getRightValue(VCIBaseTreeNode node,boolean isUp){
|
if(isUp){//向上获取,存储每个上级模块的权限值
|
VCIBaseTreeNode parentNode = (VCIBaseTreeNode)node.getParent();
|
while(!"root".equals(parentNode.getObj())){
|
String funcId = ((FunctionObject)parentNode.getObj()).getId();
|
RoleRightObject obj = null;
|
if(!rightMap.containsKey(funcId)){
|
obj = new RoleRightObject();
|
obj.setFuncId(funcId);
|
obj.setRightType(RightType.Function);
|
obj.setRightValue(1);//没有操作的模块权限值存储为0
|
obj.setRoleId(curRole.getId());
|
|
obj.setCreateUser(currentUserName);
|
obj.setCreateTime(new Date());
|
obj.setModifyUser(currentUserName);
|
obj.setModifyTime(new Date());
|
obj.setLicensor("");
|
rightMap.put(funcId, obj);
|
} else{
|
obj = rightMap.get(funcId);
|
if (obj == null) {
|
obj = new RoleRightObject();
|
obj.setFuncId(funcId);
|
obj.setRightType(RightType.Function);
|
obj.setRightValue(1);//没有操作的模块权限值存储为0
|
obj.setRoleId(curRole.getId());
|
|
obj.setCreateUser(currentUserName);
|
obj.setCreateTime(new Date());
|
obj.setModifyUser(currentUserName);
|
obj.setModifyTime(new Date());
|
obj.setLicensor("");
|
}else {
|
obj.setRightValue(1);
|
}
|
}
|
parentNode = (VCIBaseTreeNode)parentNode.getParent();
|
}
|
}else{//向下获取,无需判断是否选中,但需要判断其子级是否是操作
|
//先存储当前节点
|
String funcId = "";
|
if(node.getObj() instanceof String){
|
funcId = (String)node.getObj();
|
}else if(node.getObj() instanceof FunctionObject){
|
funcId = ((FunctionObject)node.getObj()).getId();
|
}
|
if(!isChildOperate(node)){//子节点不是操作
|
if(!rightMap.containsKey(funcId)&&!funcId.equals("root")){
|
RoleRightObject roleRightObj = new RoleRightObject();
|
roleRightObj.setFuncId(funcId);
|
roleRightObj.setRightType(RightType.Function);
|
roleRightObj.setRightValue(0);//没有操作的模块权限值存储为0
|
roleRightObj.setRoleId(curRole.getId());
|
|
roleRightObj.setCreateUser(currentUserName);
|
roleRightObj.setCreateTime(new Date());
|
roleRightObj.setModifyUser(currentUserName);
|
roleRightObj.setModifyTime(new Date());
|
roleRightObj.setLicensor("");
|
rightMap.put(funcId, roleRightObj);
|
}
|
for(int i = 0;i < node.getChildCount();i++){
|
//对每个子向下递归遍历
|
getRightValue((VCIBaseTreeNode)node.getChildAt(i),false);
|
}
|
}else{//子节点是操作
|
if(!rightMap.containsKey(funcId)){
|
RoleRightObject roleRightObj = new RoleRightObject();
|
roleRightObj.setFuncId(funcId);
|
roleRightObj.setRightType(RightType.Function);
|
roleRightObj.setRightValue(countRightValue(node,true));//没有操作的模块权限值存储为0
|
roleRightObj.setRoleId(curRole.getId());
|
|
roleRightObj.setCreateUser(currentUserName);
|
roleRightObj.setCreateTime(new Date());
|
roleRightObj.setModifyUser(currentUserName);
|
roleRightObj.setModifyTime(new Date());
|
roleRightObj.setLicensor("");
|
rightMap.put(funcId, roleRightObj);
|
}
|
}
|
}
|
}
|
/**
|
* 传入直接挂接操作的模块的节点,计算该节点的权限值
|
* @param node 模块节点
|
* @param isAll 是否子级全部选中
|
* @return
|
*/
|
private long countRightValue(VCIBaseTreeNode node,boolean isAll){
|
long value = 0;
|
for(int i = 0;i < node.getChildCount();i++){
|
VCIBaseTreeNode childNode = (VCIBaseTreeNode)node.getChildAt(i);
|
if(isAll || treeManager.getSelectionModel().isPathSelected(new TreePath(childNode.getPath()))){
|
FuncOperationObject obj = (FuncOperationObject)childNode.getObj();
|
value += (long)Math.pow(2, obj.getNumber());//累计加上各个操作的权限值
|
}
|
}
|
return value;
|
}
|
|
/**
|
* 判断子级是否是操作
|
* @param node
|
* @return
|
*/
|
private boolean isChildOperate(VCIBaseTreeNode node){
|
if(node.getChildCount() > 0){
|
VCIBaseTreeNode childNode = (VCIBaseTreeNode)node.getChildAt(0);
|
if(childNode.getObj() instanceof FuncOperationObject){
|
return true;
|
}
|
}
|
return false;
|
}
|
|
/**
|
* 内容项
|
*
|
* @return
|
*/
|
public void contentItem(JPanel contentPanel) {
|
top.setPreferredSize(new Dimension(60,2));
|
scrollTree = new JScrollPane();
|
bottom.setPreferredSize(new Dimension(60,2));
|
contentPanel.setLayout(new BorderLayout());
|
contentPanel.add(roleListLab);
|
contentPanel.add(scrollTree);
|
}
|
|
public void roleList(String searchText) {
|
setRoleList(searchText);
|
roleList.setCellRenderer(new ListLabelCellRender());
|
roleList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
roleList.getSelectedValue();
|
roleList.addMouseListener(new MouseAdapter() {
|
@Override
|
public void mouseClicked(MouseEvent e) {
|
RoleObject roleObj = (RoleObject)roleList.getSelectedValue();
|
curRole = roleObj;
|
tree.clearSelection();
|
treeManager.getSelectionModel().clearSelection();
|
initRoleRight(roleObj.getId());
|
}
|
});
|
setComponentPopupMenu(roleList,getPopupMenu());
|
leftPanel.getViewport().add(roleList);
|
}
|
|
/**
|
* 角色刷新功能的添加
|
* <p>Description: </p>
|
*
|
* @author 李刚
|
* @time 2012-7-20
|
*/
|
private void refreshRole() {
|
roleList("");
|
treeManager.getSelectionModel().clearSelection();
|
}
|
|
/**查询满足条件的角色信息**/
|
private void searchRoleList() {
|
String search = this.searchTxt.getText().trim();
|
roleList(search);
|
treeManager.getSelectionModel().clearSelection();
|
}
|
|
/**
|
* 右键菜单
|
* @param parent
|
* @param menu
|
*/
|
private void setComponentPopupMenu(final java.awt.Component parent,
|
final javax.swing.JPopupMenu menu) {
|
parent.addMouseListener(new java.awt.event.MouseAdapter() {
|
@Override
|
public void mouseReleased(java.awt.event.MouseEvent e) {
|
int i = e.getButton();
|
if(i == 3) {//鼠标右键
|
popupMenu.removeAll();
|
popupMenu.add(refMenuItem);
|
menu.show(parent, e.getX(), e.getY());
|
}
|
}
|
|
});
|
}
|
Map<String,RoleRightObject> allRightRoleMap = new HashMap<String,RoleRightObject>();
|
Map<String, Map<String,Long> > roleRightMap = new HashMap<String, Map<String,Long>>();
|
/**
|
* 初始化角色权限
|
* @param roleId
|
*/
|
public void initRoleRight(String roleId){
|
try {
|
allRightRoleMap = new HashMap<String,RoleRightObject>();
|
RoleRightObject[] roleRightObjs = new RoleRightClientDelegate().getRoleRightList(roleId, LogonApplication.getUserEntityObject().getUserName());
|
Map<String,Long> rightMap = new HashMap<String,Long>();
|
for(RoleRightObject obj:roleRightObjs){
|
allRightRoleMap.put(obj.getFuncId(), obj);
|
rightMap.put(obj.getFuncId(), obj.getRightValue());
|
}
|
if(roleRightMap.containsKey(roleId)){
|
roleRightMap.remove(roleId);
|
}
|
roleRightMap.put(roleId, rightMap);
|
visitAllTreeNode(rootNode,rightMap);
|
} catch (VCIException e) {
|
e.printStackTrace();
|
VCIOptionPane.showError(LogonApplication.frame, LocaleDisplay.getI18nString(e,"RMIPFramework", getLocale()));
|
}
|
}
|
|
|
|
/**
|
* 遍历整棵树进行权限选中
|
* @param node
|
* @param rightMap
|
*/
|
private void visitAllTreeNode(VCIBaseTreeNode node,Map<String,Long> rightMap){
|
for(int i = 0;i < node.getChildCount();i++){
|
VCIBaseTreeNode childNode = (VCIBaseTreeNode)node.getChildAt(i);
|
Object obj = childNode.getObj();
|
//如果是模块,则先判断是否有此模块权限,如果有,则判断下级模块及操作
|
if(obj instanceof FunctionObject){
|
String id = ((FunctionObject) obj).getId();
|
if(rightMap.containsKey(id)){
|
visitAllTreeNode(childNode,rightMap);
|
}
|
}else if(obj instanceof FuncOperationObject){
|
String id = ((FuncOperationObject) obj).getFuncId();
|
if(rightMap.containsKey(id)){
|
long rightValue = rightMap.get(id);
|
long nodeValue = ((FuncOperationObject) obj).getNumber();
|
//long preValue = (long)Math.pow(2, nodeValue);
|
//进行位与操作,如果相等则表示具有当前操作的权限
|
//if(preValue == (preValue & rightValue)){
|
long preValue = (rightValue >> nodeValue) & 1;
|
if (preValue == 1) {
|
treeManager.getSelectionModel().addSelectionPath(new TreePath(childNode.getPath()));
|
}
|
}
|
}
|
}
|
}
|
|
|
//右键菜单
|
public JPopupMenu getPopupMenu() {
|
if (popupMenu == null) {
|
popupMenu = new JPopupMenu();
|
}
|
return popupMenu;
|
}
|
|
/**
|
* 给角色列表赋值
|
*/
|
private void setRoleList(String searchText) {
|
try {
|
RoleObject[] roleObjs = rightManagementClient.fetchRoleInfoByUserType(LogonApplication.getUserEntityObject().getUserName());// 取得角色信息
|
if(!"".equals(searchText)) {
|
List<RoleObject> list = new LinkedList<RoleObject>();
|
for(RoleObject roleObj : roleObjs) {
|
if(roleObj.getName().indexOf(searchText) != -1) {
|
list.add(roleObj);
|
}
|
}
|
roleList = new JList(list.toArray(new RoleObject[0]));
|
return ;
|
}
|
roleList = new JList(roleObjs);
|
roleList.setCellRenderer(new ObjectListCellRenderer());
|
} catch (VCIException e) {
|
e.printStackTrace();
|
VCIOptionPane.showError(LogonApplication.frame, LocaleDisplay.getI18nString(e,"RMIPFramework", getLocale()));
|
}
|
}
|
|
|
/**
|
* 提示信息框
|
*
|
* @param proValue
|
* 资源文件的值
|
* @param fileName
|
* 资源文件的名
|
* @param title
|
* 标题
|
*/
|
private void message(String proValue, String fileName) {
|
VCIOptionPane.showMessage(LogonApplication.frame,LocaleDisplay.getI18nString(proValue, fileName, getLocale()));
|
}
|
|
/**
|
* 校验
|
*
|
* @return
|
*/
|
public boolean checkItem() {
|
if (roleList.getSelectedValue() == null|| "null".equals(roleList.getSelectedValue())) {
|
message("rmip.framework.rightdistribution.moduleRight.roleListNotNull.message","RMIPFramework");
|
return false;
|
}
|
return true;
|
}
|
|
private static Map<String, String> funMap = new LinkedHashMap<String, String>();
|
// private ArrayList<String> getModelIds() {
|
// ArrayList<String> list = new ArrayList<String>();
|
// for(String name : funMap.keySet()) {
|
// if("日志管理".equals(name) || "权限管理".equals(name) || "人员组织管理".equals(name)) {
|
// list.add(funMap.get(name));
|
// }
|
// }
|
//
|
// return list;
|
// }
|
|
@Override
|
public String getUserID() {
|
return logonUserId;
|
}
|
@Override
|
public String getRoleID() {
|
return logonRoleId;
|
}
|
@Override
|
public JPanel getModuleComponent() {
|
return this;
|
}
|
@Override
|
public String getModuleName() {
|
if (this.getFuncObj() != null && this.getFuncObj().getName() != null)
|
return this.getFuncObj().getName();
|
else if (moduleName != null && !moduleName.isEmpty())
|
return moduleName;
|
else
|
return this.getClass().getName();
|
//return moduleName;
|
}
|
@Override
|
public String getIconName() {
|
return iconName;
|
}
|
@Override
|
public String getModuleShowInfo() {
|
return moduleShowInfo;
|
}
|
|
// private boolean isSecurtyAdmin() {
|
// String roleName = getRoleByConf();
|
// String userName = LogonApplication.frame.getUserEntityObject().getUserName();
|
// try {
|
// UserObject userObj = new RightManagementClientDelegate().fetchUserInfoByName(userName);
|
// RoleObject[] roleObjs = new RightManagementClientDelegate().fetchRoleInfoByUserId(userObj.getId());
|
// for(RoleObject obj : roleObjs) {
|
// if(roleName.equals(obj.getName())) {
|
// return true;
|
// }
|
// }
|
// } catch (VCIError e) {
|
// e.printStackTrace();
|
// }
|
//
|
//
|
// return false;
|
// }
|
|
// private String getRoleByConf() {
|
// try {
|
// String result = new SystemCfgClientDelegate().getConfigValue("user.Sysadmin");
|
// return result;
|
// } catch (VCIException e) {
|
// e.printStackTrace();
|
// }
|
// return "";
|
// }
|
|
private final LinkedHashMap<RoleObject, Map<String, Long>> roleRightObjsMap = new LinkedHashMap<RoleObject, Map<String, Long>>();
|
private void saveToTemp(){
|
if(!isSelectedRole()) return;
|
String ruleId = curRole.getId();
|
Map<String, Long> rightMap = roleRightMap.get(ruleId);
|
roleRightObjsMap.put(curRole, rightMap);
|
VCIJOptionPane.showMessage(this, "复制 成功!");
|
}
|
private void applyFromTemp(){
|
if(!isSelectedRole()) return;
|
if(roleRightObjsMap.size() == 0){
|
VCIJOptionPane.showMessage(this, "请先复制权限!");
|
return;
|
}
|
int index = 0;
|
int size = roleRightObjsMap.size();
|
Map<String, Long> rightMap = new HashMap<String, Long>();
|
Object[] roles = new Object[size];
|
Iterator<RoleObject> its = roleRightObjsMap.keySet().iterator();
|
while(its.hasNext()){
|
RoleObject roleObj = its.next();
|
roles[index++] = roleObj;
|
rightMap = roleRightObjsMap.get(roleObj);
|
}
|
|
if(size == 1){
|
tree.clearSelection();
|
treeManager.getSelectionModel().clearSelection();
|
visitAllTreeNode(rootNode, rightMap);
|
VCIJOptionPane.showMessage(this, "粘贴 成功!\n(点击‘授权’后才生效)");
|
} else {
|
Object[] messages = new Object[2];
|
messages[0] = new VCIJLabel("" +
|
"<html>" +
|
"<p>请选择角色:</p>" +
|
"<p>(将该角色权限应用到当前选择的角色)</p>" +
|
"<p> </p>" +
|
"</html>"
|
);
|
VCIJPanel pal = new VCIJPanel(new BorderLayout());
|
VCIJList list = new VCIJList(roles);
|
list.setSelectedIndex(0);
|
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
pal.add(new VCIJScrollPane(list), BorderLayout.CENTER);
|
pal.setPreferredSize(new Dimension(200, 100));
|
messages[1] = pal;
|
Object[] options = {"确定","取消"};
|
int res = VCIJOptionPane.showOptionDialog(
|
LogonApplication.frame,
|
messages,
|
"粘贴权限",
|
VCIJOptionPane.DEFAULT_OPTION,
|
VCIJOptionPane.INFORMATION_MESSAGE,
|
null,
|
options,
|
options[0]);
|
if(res == 0){
|
RoleObject roleObj = (RoleObject)list.getSelectedValue();
|
rightMap = roleRightObjsMap.get(roleObj);
|
tree.clearSelection();
|
treeManager.getSelectionModel().clearSelection();
|
visitAllTreeNode(rootNode, rightMap);
|
VCIJOptionPane.showMessage(this, "粘贴 成功!\n(点击‘授权’后才生效)");
|
}
|
}
|
}
|
private boolean isSelectedRole(){
|
if(curRole == null) {
|
VCIJOptionPane.showMessage(this, "请先选择角色!");
|
return false;
|
}
|
return true;
|
}
|
}
|