package com.vci.client.framework.rightdistribution.roleRight;
|
|
import java.awt.BorderLayout;
|
import java.awt.Dimension;
|
import java.awt.FlowLayout;
|
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.Iterator;
|
import java.util.LinkedHashMap;
|
import java.util.LinkedList;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.Set;
|
import java.util.Map.Entry;
|
|
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.corba.omd.btm.BtmItem;
|
import com.vci.corba.portal.data.PLCommandParameter;
|
import com.vci.corba.portal.data.PLPageDefination;
|
import com.vci.corba.portal.data.PLUILayout;
|
import com.vci.corba.portal.data.PLTabButton;
|
import com.vci.corba.portal.data.PLTabPage;
|
import com.vci.client.LogonApplication;
|
import com.vci.client.common.VCIBasePanel;
|
import com.vci.client.common.objects.RoleObject;
|
import com.vci.client.framework.common.RightType;
|
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.FunctionObject;
|
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.omd.provider.BtmProvider;
|
import com.vci.client.portal.utility.UITools;
|
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;
|
import com.vci.corba.common.VCIError;
|
|
/**
|
* <p>UI 模块授权 升级版</p>
|
* <p>与BSTypeRoleRightPanel的区别是:</p>
|
* <p>点击角色时:只列出这个角色在功能模块授权下拥有的模块对应的上下文、业务类型关联出的UI定义中及按钮</p>
|
* @author xchao
|
*
|
*/
|
public class BSTypeRoleRightPanelV2 extends VCIBasePanel implements IModuleShow{
|
|
private JLabel roleListLab = new JLabel(LocaleDisplay.getI18nString("rmip.framework.rightdistribution.moduleRight.RoleList","RMIPFramework", getLocale()));// 角色列表Lab
|
private JLabel titleLab = new JLabel(LocaleDisplay.getI18nString("rmip.framework.rightdistribution.moduleRight.name","RMIPFramework", getLocale()));// title
|
JList roleList = new JList(); // 角色列表
|
private String moduleName = "";
|
|
private JButton addButton = new JButton();
|
private JButton delButton = new JButton();
|
|
private VCIJButton btnSaveToTemp = VCISwingUtil.createVCIJButton(
|
"saveToTemp", "保存权限模板", "保存权限模板", "wand.png", new ActionListener() {
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
saveToTemp();
|
}
|
});
|
private VCIJButton btnApplyFromTemp = VCISwingUtil.createVCIJButton(
|
"saveToTemp", "应用权限模板", "应用权限模板", "tick.png", new ActionListener() {
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
applyFromTemp();
|
}
|
});
|
JScrollPane scrollTree = null;
|
JSplitPane jspConfigPanel; // 把Panel分成左右两部分
|
private JScrollPane leftPanel = new JScrollPane();
|
VCIBaseTree tree;
|
VCIBaseTreeModel treeModel;
|
VCIBaseTreeNode rootNode;
|
CheckBoxTreeManager treeManager;
|
private RoleObject curRole = null;
|
|
private JTextField top = new JTextField();// 上横线
|
private JTextField bottom = new JTextField();// 下横线
|
private static Map<String, String> funMap = new LinkedHashMap<String, String>();
|
private Map<String,RoleRightObject> rightMap = new HashMap<String,RoleRightObject>();
|
|
/**
|
* 刷新按钮
|
*/
|
private JPopupMenu popupMenu;
|
private JMenuItem refMenuItem = new JMenuItem("刷新", VCISwingUtil.createImageIcon("arrow_refresh.png"));//刷新
|
|
/**查询功能**/
|
private JLabel searchLbl = new JLabel("查询:");
|
private JTextField searchTxt = new JTextField(20);
|
private KJButton searchBtn = new KJButton("", "search.gif");
|
private String currentUserName = LogonApplication.getUserEntityObject().getUserName();
|
|
public BSTypeRoleRightPanelV2(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);
|
}
|
|
public void roleList(String searchText) {
|
setRoleList(searchText);
|
roleList.setCellRenderer(new ListLabelCellRender());
|
roleList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
roleList.getSelectedValue();
|
roleList.addMouseListener(new MouseAdapter() {
|
public void mouseClicked(MouseEvent e) {
|
RoleObject roleObj = (RoleObject)roleList.getSelectedValue();
|
curRole = roleObj;
|
tree.clearSelection();
|
treeManager.getSelectionModel().clearSelection();
|
initRoleRight(roleObj.getId());
|
}
|
});
|
leftPanel.getViewport().add(roleList);
|
}
|
|
Map<String,RoleRightObject> allRightRoleMap = new HashMap<String,RoleRightObject>();
|
public void initRoleRight(String roleId){
|
try {
|
loadModuleRight();
|
|
allRightRoleMap = new HashMap<String,RoleRightObject>();
|
RoleRightObject[] roleRightObjs = new RoleRightClientDelegate().getRoleRightList(roleId, LogonApplication.getUserEntityObject().getUserName());
|
visitAllTreeNode(rootNode, roleRightObjs);
|
} catch (VCIException e) {
|
e.printStackTrace();
|
VCIOptionPane.showError(LogonApplication.frame, LocaleDisplay.getI18nString(e,"RMIPFramework", getLocale()));
|
}
|
}
|
private void visitAllTreeNode(VCIBaseTreeNode node, RoleRightObject[] roleRightObjs){
|
Map<String,Long> rightMap = new HashMap<String,Long>();
|
for(RoleRightObject obj:roleRightObjs){
|
allRightRoleMap.put(obj.getFuncId(), obj);
|
rightMap.put(obj.getFuncId(), obj.getRightValue());
|
}
|
visitAllTreeNode(node,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 BtmItem){
|
String id = ((BtmItem) obj).name;
|
if(rightMap.containsKey(id)){
|
visitAllTreeNode(childNode,rightMap);
|
}
|
} else if(obj instanceof PLUILayout){
|
visitAllTreeNode(childNode,rightMap);
|
} else if (obj instanceof PLTabPage) {
|
visitAllTreeNode(childNode,rightMap);
|
} else if (obj instanceof PLPageDefination) {
|
visitAllTreeNode(childNode,rightMap);
|
} else if (obj instanceof PLTabButton) {
|
visitAllTreeNode(childNode,rightMap);
|
String id = ((PLTabButton) obj).plTableOId;
|
//if(rightMap.containsKey(id))
|
{
|
long rightValue = 0;
|
if (rightMap.containsKey(id))
|
rightValue = rightMap.get(id);
|
|
int nodeValue = ((PLTabButton) obj).plSeq;
|
if (nodeValue >= 0 && nodeValue <= 63) {
|
//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()));
|
}
|
}
|
}
|
}
|
}
|
}
|
|
/**
|
* 给角色列表赋值
|
*/
|
private void setRoleList(String searchText) {
|
try {
|
RightManagementClientDelegate rightManagementClient = new RightManagementClientDelegate(LogonApplication.getUserEntityObject());
|
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);
|
} catch (VCIException e) {
|
e.printStackTrace();
|
VCIOptionPane.showError(LogonApplication.frame, LocaleDisplay.getI18nString(e,"RMIPFramework", getLocale()));
|
}
|
}
|
|
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 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() {
|
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() {
|
public void actionPerformed(ActionEvent e) {
|
rightMap.clear();
|
treeManager.getSelectionModel().clearSelection();
|
}
|
});
|
p.add(addButton);
|
p.add(delButton);
|
// p.add(btnSaveToTemp);
|
// p.add(btnApplyFromTemp);
|
}
|
|
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());
|
// BtmItem[] btmItems = BtmProvider.getInstance().getAllBtmItems();
|
funMap.clear();
|
for(int k = 0;k < btmItems.length;k++) {
|
funMap.put(btmItems[k].name, btmItems[k].name);
|
}
|
|
for (int i = 0; i < btmItems.length; i++) {
|
VCIBaseTreeNode node = new VCIBaseTreeNode(btmItems[i].label+"("+ btmItems[i].name+")", btmItems[i]);
|
treeModel.insertNodeInto(node, rootNode,rootNode.getChildCount());
|
setChildNode(node, btmItems[i]);
|
}
|
treeManager = new CheckBoxTreeManager(tree);
|
scrollTree.getViewport().removeAll();
|
scrollTree.getViewport().add(tree);
|
scrollTree.repaint();
|
}
|
|
private void refreshRole() {
|
roleList("");
|
treeManager.getSelectionModel().clearSelection();
|
}
|
|
/**查询满足条件的角色信息**/
|
private void searchRoleList() {
|
String search = this.searchTxt.getText().trim();
|
roleList(search);
|
treeManager.getSelectionModel().clearSelection();
|
}
|
|
private JPanel getSearchPanel() {
|
JPanel searchPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
searchPanel.add(searchLbl);
|
searchPanel.add(searchTxt);
|
searchPanel.add(searchBtn);
|
|
return searchPanel;
|
|
}
|
|
private void add_actionPerform(){
|
if (!checkItem()) {
|
return;
|
}
|
try {
|
rightMap.clear();
|
boolean refresh = true;
|
TreePath[] treePath = treeManager.getSelectionModel().getSelectionPaths();
|
//当没有选中模块的时候
|
if (treePath == null) {
|
refresh = false;
|
}
|
RoleRightObject[] roleRightObjs = getSelectedRoleRightObjs(treePath);
|
boolean res = new RoleRightClientDelegate(LogonApplication.getUserEntityObject()).saveRoleRight(roleRightObjs,curRole.getId(),currentUserName);
|
if(res){
|
VCIOptionPane.showMessage(LogonApplication.frame, "功能模块授权成功!");
|
}
|
// if(refresh){
|
// treeManager.getSelectionModel().clearSelection();
|
// initRoleRight(curRole.getId());
|
// }
|
}catch (VCIException e1) {
|
e1.printStackTrace();
|
VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework", e1);
|
}
|
}
|
private RoleRightObject[] getSelectedRoleRightObjs(TreePath[] treePath){
|
boolean isNew = false;
|
if(isNew){
|
return getSelectedRoleRightObjsV2(treePath);
|
}
|
rightMap.clear();
|
RoleRightObject[] roleRightObjs = new RoleRightObject[0];
|
if(treePath == null){
|
//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(key);
|
}
|
//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();
|
allRightRoleMap.put(value.getFuncId(), value);
|
}
|
rightMap = allRightRoleMap;
|
/**上面处理完成后,循环遍历取出MAP里的对象进行保存**/
|
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());
|
}
|
} 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(!(node.getObj() instanceof PLTabButton)){
|
getRightValue(node,true);//向上处理
|
getRightValue(node,false);//向下处理(包含当前节点)
|
}else if(node.getObj() instanceof PLTabButton){
|
VCIBaseTreeNode parentNode = (VCIBaseTreeNode)node.getParent();
|
String funcId = ((PLPageDefination)parentNode.getObj()).plOId;
|
getRightValue(parentNode,true);//向上处理该操作父级的上级模块权限(不包含父节点)
|
if(!rightMap.containsKey(funcId)){
|
RoleRightObject roleRightObj = new RoleRightObject();
|
roleRightObj.setFuncId(funcId);
|
roleRightObj.setRightType(RightType.UI);
|
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(key);
|
}
|
//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();
|
allRightRoleMap.put(value.getFuncId(), value);
|
}
|
rightMap = allRightRoleMap;
|
/**上面处理完成后,循环遍历取出MAP里的对象进行保存**/
|
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());
|
}
|
}
|
return roleRightObjs;
|
}
|
private RoleRightObject[] getSelectedRoleRightObjsV2(TreePath[] treePath){
|
if(treeManager.getSelectionModel().isPathSelected(new TreePath(rootNode.getPath()), true)){
|
System.out.println("1");
|
}else {
|
System.out.println("2");
|
}
|
rightMap.clear();
|
RoleRightObject[] roleRightObjs = new RoleRightObject[0];
|
return roleRightObjs;
|
}
|
|
/**
|
* 获取权限
|
* @param isUp 是否是向上获取,如果是向上获取,传进来的必然是模块节点,且上级模块必然是没有选中
|
*/
|
private void getRightValue(VCIBaseTreeNode node,boolean isUp){
|
if(isUp){//向上获取,存储每个上级模块的权限值
|
VCIBaseTreeNode parentNode = (VCIBaseTreeNode)node.getParent();
|
while(!"root".equals(parentNode.getObj())){
|
String funcId = "";
|
if (parentNode.getObj() instanceof BtmItem) {
|
BtmItem btmItem = (BtmItem) parentNode.getObj();
|
funcId = btmItem.name;
|
} else if (parentNode.getObj() instanceof PLUILayout) {
|
PLUILayout context = (PLUILayout) parentNode.getObj();
|
funcId = context.plOId;
|
} else if (parentNode.getObj() instanceof PLTabPage) {
|
PLTabPage tab = (PLTabPage) parentNode.getObj();
|
funcId = tab.plOId;
|
} else if (parentNode.getObj() instanceof PLPageDefination){
|
PLPageDefination pageDef = (PLPageDefination) parentNode.getObj();
|
funcId = pageDef.plOId;
|
} else if (parentNode.getObj() instanceof PLTabButton) {
|
PLTabButton but = (PLTabButton)parentNode.getObj();
|
funcId = but.plOId;
|
}
|
RoleRightObject obj = new RoleRightObject();
|
obj.setFuncId(funcId);
|
obj.setRightType(RightType.UI);
|
obj.setRightValue(1);//没有操作的模块权限值存储为0
|
obj.setRoleId(curRole.getId());
|
|
obj.setCreateUser(currentUserName);
|
obj.setCreateTime(new Date());
|
obj.setModifyUser(currentUserName);
|
obj.setModifyTime(new Date());
|
obj.setLicensor("");
|
if(!rightMap.containsKey(funcId)){
|
rightMap.put(funcId, obj);
|
}
|
parentNode = (VCIBaseTreeNode)parentNode.getParent();
|
}
|
}else{//向下获取,无需判断是否选中,但需要判断其子级是否是操作
|
//先存储当前节点
|
String funcId = "";
|
if(node.getObj() instanceof String){
|
funcId = (String)node.getObj();
|
} else if (node.getObj() instanceof BtmItem) {
|
BtmItem btmItem = (BtmItem) node.getObj();
|
funcId = btmItem.name;
|
} else if (node.getObj() instanceof PLUILayout) {
|
PLUILayout context = (PLUILayout) node.getObj();
|
funcId = context.plOId;
|
} else if (node.getObj() instanceof PLTabPage) {
|
PLTabPage tab = (PLTabPage) node.getObj();
|
funcId = tab.plOId;
|
} else if (node.getObj() instanceof PLPageDefination){
|
PLPageDefination pageDef = (PLPageDefination) node.getObj();
|
funcId = pageDef.plOId;
|
} else if (node.getObj() instanceof PLTabButton) {
|
PLTabButton but = (PLTabButton)node.getObj();
|
funcId = but.plOId;
|
}
|
if(!(node.getObj() instanceof PLPageDefination)){//子节点不是操作
|
if(!rightMap.containsKey(funcId)&&!funcId.equals("root")){
|
RoleRightObject roleRightObj = new RoleRightObject();
|
roleRightObj.setFuncId(funcId);
|
roleRightObj.setRightType(RightType.UI);
|
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.UI);
|
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()))){
|
PLTabButton obj = (PLTabButton)childNode.getObj();
|
value += (long)Math.pow(2, obj.plSeq);//累计加上各个操作的权限值
|
}
|
}
|
return value;
|
}
|
|
private void setChildNode(VCIBaseTreeNode node ,Object funcObj) {
|
try{
|
if (funcObj instanceof BtmItem) {
|
BtmItem btmItem = (BtmItem) funcObj;
|
PLUILayout[] contexts = UITools.getService().getPLUILayoutsByRelatedType(btmItem.name);
|
for(int i = 0; i < contexts.length; i++){
|
VCIBaseTreeNode curNode = new VCIBaseTreeNode(contexts[i].plName+"("+contexts[i].plCode+")", contexts[i]);
|
treeModel.insertNodeInto(curNode, node,node.getChildCount());
|
funMap.put(contexts[i].plOId, contexts[i].plCode);
|
setChildNode(curNode, contexts[i]);
|
}
|
} else if (funcObj instanceof PLUILayout) {
|
PLUILayout context = (PLUILayout) funcObj;
|
PLTabPage[] tabs = UITools.getService().getPLTabPagesByPageDefinationOId(context.plOId);
|
for(int i = 0; i < tabs.length; i++){
|
VCIBaseTreeNode curNode = new VCIBaseTreeNode(tabs[i].plName, tabs[i]);
|
treeModel.insertNodeInto(curNode, node,node.getChildCount());
|
funMap.put(tabs[i].plOId, tabs[i].plName);
|
setChildNode(curNode, tabs[i]);
|
}
|
} else if (funcObj instanceof PLTabPage) {
|
PLTabPage tab = (PLTabPage) funcObj;
|
PLPageDefination[] pageDefinations = UITools.getService().getPLPageDefinationsByPageContextOId(tab.plOId);
|
for (int i = 0; i < pageDefinations.length; i++) {
|
VCIBaseTreeNode curNode = new VCIBaseTreeNode(pageDefinations[i].name, pageDefinations[i]);
|
treeModel.insertNodeInto(curNode, node,node.getChildCount());
|
funMap.put(pageDefinations[i].plOId, pageDefinations[i].name);
|
setChildNode(curNode, pageDefinations[i]);
|
}
|
} else if (funcObj instanceof PLPageDefination) {
|
PLPageDefination pageDef = (PLPageDefination) funcObj;
|
PLTabButton[] buttons = UITools.getService().getPLTabButtonsByTableOId(pageDef.plOId);
|
for(int i = 0; i < buttons.length; i++){
|
VCIBaseTreeNode curNode = new VCIBaseTreeNode(buttons[i].plLabel, buttons[i]);
|
treeModel.insertNodeInto(curNode, node,node.getChildCount());
|
funMap.put(buttons[i].plTableOId, buttons[i].plLabel);
|
setChildNode(curNode, buttons[i]);
|
curNode.setLeaf(true);
|
}
|
}
|
else if (funcObj instanceof PLTabButton) {
|
node.setLeaf(true);
|
}
|
} catch (VCIError e) {
|
//TODO 抛出异常
|
e.printStackTrace();
|
}
|
}
|
|
/**
|
* 校验
|
*
|
* @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 void message(String proValue, String fileName) {
|
VCIOptionPane.showMessage(LogonApplication.frame,LocaleDisplay.getI18nString(proValue, fileName, getLocale()));
|
}
|
|
/**
|
*
|
*/
|
private static final long serialVersionUID = 120493240584388454L;
|
|
@Override
|
public String getUserID() {
|
// TODO Auto-generated method stub
|
return null;
|
}
|
|
@Override
|
public String getRoleID() {
|
// TODO Auto-generated method stub
|
return null;
|
}
|
|
@Override
|
public JPanel getModuleComponent() {
|
// TODO Auto-generated method stub
|
return null;
|
}
|
|
@Override
|
public String getModuleName() {
|
// TODO Auto-generated method stub
|
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();
|
}
|
|
@Override
|
public String getIconName() {
|
// TODO Auto-generated method stub
|
return null;
|
}
|
|
@Override
|
public String getModuleShowInfo() {
|
// TODO Auto-generated method stub
|
return null;
|
}
|
|
|
private LinkedHashMap<RoleObject, RoleRightObject[]> roleRightObjsMap = new LinkedHashMap<RoleObject, RoleRightObject[]>();
|
private void saveToTemp(){
|
if(!isSelectedRole()) return;
|
TreePath[] treePath = treeManager.getSelectionModel().getSelectionPaths();
|
RoleRightObject[] lastRoleRightObjs = getSelectedRoleRightObjs(treePath);
|
if(roleRightObjsMap.containsKey(curRole)){
|
roleRightObjsMap.remove(curRole);
|
}
|
roleRightObjsMap.put(curRole, lastRoleRightObjs);
|
VCIJOptionPane.showMessage(this, "存储成功!");
|
}
|
private void applyFromTemp(){
|
if(!isSelectedRole()) return;
|
if(roleRightObjsMap.size() == 0){
|
VCIJOptionPane.showMessage(this, "请先存储模板!");
|
return;
|
}
|
int index = 0;
|
int size = roleRightObjsMap.size();
|
RoleObject[] roles = new RoleObject[size];
|
RoleRightObject[] lastRoleRightObjs = new RoleRightObject[0];
|
Iterator<RoleObject> it = roleRightObjsMap.keySet().iterator();
|
while(it.hasNext()){
|
RoleObject roleObj = it.next();
|
roles[index] = roleObj;
|
lastRoleRightObjs = roleRightObjsMap.get(roleObj);
|
index += 1;
|
}
|
|
if(size == 1){
|
tree.clearSelection();
|
treeManager.getSelectionModel().clearSelection();
|
visitAllTreeNode(rootNode, lastRoleRightObjs);
|
} else {
|
Object[] messages = new Object[2];
|
messages[0] = new VCIJLabel("请选择:");
|
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();
|
lastRoleRightObjs = roleRightObjsMap.get(roleObj);
|
tree.clearSelection();
|
treeManager.getSelectionModel().clearSelection();
|
visitAllTreeNode(rootNode, lastRoleRightObjs);
|
VCIJOptionPane.showMessage(this, "应用成功!");
|
}
|
}
|
}
|
private boolean isSelectedRole(){
|
if(curRole == null) {
|
VCIJOptionPane.showMessage(this, "请先选择角色!");
|
return false;
|
}
|
return true;
|
}
|
|
|
private Map<String, BtmItem> btmItemsMap = new LinkedHashMap<String, BtmItem>();
|
private BtmItem[] btmItems = BtmProvider.getInstance().getAllBtmItems();
|
private Map<String, BtmItem> getBtmItemsMap(){
|
if(btmItemsMap.size() == 0){
|
synchronized (BSTypeRoleRightPanelV2.class) {
|
if(btmItemsMap.size() == 0){
|
for(BtmItem btmItem : btmItems){
|
btmItemsMap.put(btmItem.name, btmItem);
|
}
|
}
|
}
|
}
|
return btmItemsMap;
|
}
|
private void loadModuleRight(){
|
String roleId = curRole.getId();
|
try {
|
// 查询出有权限的功能模块权限
|
RoleRightObject[] roleRightObjs = new RoleRightClientDelegate().getRoleRightList(roleId, currentUserName);
|
FunctionClientDelegate funcDel = new FunctionClientDelegate();
|
|
btmItemsMap = this.getBtmItemsMap();
|
rootNode.removeAllChildren();
|
btnNameToTreeNodeMap.clear();
|
btmContextToMap.clear();
|
|
for(RoleRightObject rightObj : roleRightObjs){
|
FunctionObject funcObj = funcDel.getFunctionObjectById(rightObj.getFuncId());
|
if("".equals(funcObj.getId())) continue;
|
|
getParamMap(funcObj.getResourceC(), btmItemsMap);
|
}
|
tree.updateUI();
|
scrollTree.repaint();
|
} catch (VCIException e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
} catch (VCIError e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
}
|
}
|
|
private void getParamMap(String resourceCS, Map<String, BtmItem> btmItemsMap) throws VCIError{
|
//plm.uif.engine.client.UILayoutPanel?type=product&context=productManagement
|
String compareString = ",type,context,";
|
String paramSplitChar = "?";
|
if(!resourceCS.contains(paramSplitChar)) return ;
|
int indexSplit = resourceCS.indexOf(paramSplitChar);
|
String paramStrings = resourceCS.substring(indexSplit + 1);
|
if("".equals(paramStrings)) return ;
|
|
String btmName = "";
|
String contextValue = "";
|
String[] paramGroups = paramStrings.split("&");
|
for(String paramGroup : paramGroups){
|
String[] keyVals = paramGroup.split("=");
|
if(keyVals.length != 2) continue;
|
String key = keyVals[0];
|
String value = keyVals[1];
|
if(!compareString.contains("," + key + ",")) continue;
|
if(key.equals("type")){
|
btmName = value;
|
} else if(key.equals("context")){
|
contextValue = value;
|
}
|
}
|
if(!btmItemsMap.containsKey(btmName)) return;
|
if("".equals(btmName) || "".equals(contextValue)) return;
|
|
setChildNodeV2(rootNode, btmName, contextValue);
|
}
|
|
|
private LinkedHashMap<String, VCIBaseTreeNode> btnNameToTreeNodeMap = new LinkedHashMap<String, VCIBaseTreeNode>();
|
private LinkedHashMap<String, VCIBaseTreeNode> btmContextToMap = new LinkedHashMap<String, VCIBaseTreeNode>();
|
private void setChildNodeV2(VCIBaseTreeNode parentNode, String btmName, String contextValue) throws VCIError{
|
String btmNameContext = btmName + "." + contextValue;
|
if(btmContextToMap.containsKey(btmNameContext)) return;
|
|
BtmItem btmItem = btmItemsMap.get(btmName);
|
VCIBaseTreeNode node = new VCIBaseTreeNode(btmItem.label+"("+ btmItem.name+")", btmItem);
|
|
// if(btnNameToTreeNodeMap.containsKey(btmName)){
|
// node = btnNameToTreeNodeMap.get(btmName);
|
// } else {
|
// treeModel.insertNodeInto(node, rootNode, rootNode.getChildCount());
|
// }
|
|
treeModel.insertNodeInto(node, parentNode, parentNode.getChildCount());
|
|
// if(btnNameToTreeNodeMap.containsKey(btmName)){
|
//// treeModel.insertNodeInto(node, parentNode, parentNode.getChildCount());
|
// node = parentNode;
|
// } else {
|
//// treeModel.insertNodeInto(node, parentNode, parentNode.getChildCount());
|
// treeModel.insertNodeInto(node, rootNode, rootNode.getChildCount());
|
// }
|
|
btnNameToTreeNodeMap.put(btmName, node);
|
btmContextToMap.put(btmNameContext, node);
|
|
PLUILayout[] contexts = UITools.getService().getPLUILayoutsByRelatedType(btmName);
|
for(int i = 0; i < contexts.length; i++){
|
if(!contextValue.equals(contexts[i].plCode)) continue;
|
|
VCIBaseTreeNode curNode = new VCIBaseTreeNode(contexts[i].plName+"("+contexts[i].plCode+")", contexts[i]);
|
treeModel.insertNodeInto(curNode, node, node.getChildCount());
|
funMap.put(contexts[i].plOId, contexts[i].plCode);
|
|
setChildNodeV2(curNode, contexts[i]);
|
}
|
}
|
|
private void setChildNodeV2(VCIBaseTreeNode node ,Object funcObj) {
|
try{
|
if (funcObj instanceof BtmItem) {
|
BtmItem btmItem = (BtmItem) funcObj;
|
PLUILayout[] contexts = UITools.getService().getPLUILayoutsByRelatedType(btmItem.name);
|
for(int i = 0; i < contexts.length; i++){
|
VCIBaseTreeNode curNode = new VCIBaseTreeNode(contexts[i].plName+"("+contexts[i].plCode+")", contexts[i]);
|
treeModel.insertNodeInto(curNode, node,node.getChildCount());
|
funMap.put(contexts[i].plOId, contexts[i].plCode);
|
setChildNodeV2(curNode, contexts[i]);
|
}
|
} else if (funcObj instanceof PLUILayout) {
|
PLUILayout context = (PLUILayout) funcObj;
|
PLTabPage[] tabs = UITools.getService().getPLTabPagesByPageDefinationOId(context.plOId);
|
for(int i = 0; i < tabs.length; i++){
|
VCIBaseTreeNode curNode = new VCIBaseTreeNode(tabs[i].plName, tabs[i]);
|
treeModel.insertNodeInto(curNode, node,node.getChildCount());
|
funMap.put(tabs[i].plOId, tabs[i].plName);
|
setChildNodeV2(curNode, tabs[i]);
|
}
|
} else if (funcObj instanceof PLTabPage) {
|
PLTabPage tab = (PLTabPage) funcObj;
|
PLPageDefination[] pageDefinations = UITools.getService().getPLPageDefinationsByPageContextOId(tab.plOId);
|
for (int i = 0; i < pageDefinations.length; i++) {
|
VCIBaseTreeNode curNode = new VCIBaseTreeNode(pageDefinations[i].name, pageDefinations[i]);
|
treeModel.insertNodeInto(curNode, node,node.getChildCount());
|
funMap.put(pageDefinations[i].plOId, pageDefinations[i].name);
|
setChildNodeV2(curNode, pageDefinations[i]);
|
}
|
} else if (funcObj instanceof PLPageDefination) {
|
PLPageDefination pageDef = (PLPageDefination) funcObj;
|
PLTabButton[] buttons = UITools.getService().getPLTabButtonsByTableOId(pageDef.plOId);
|
for(int i = 0; i < buttons.length; i++){
|
VCIBaseTreeNode curNode = new VCIBaseTreeNode(buttons[i].plLabel, buttons[i]);
|
treeModel.insertNodeInto(curNode, node,node.getChildCount());
|
funMap.put(buttons[i].plTableOId, buttons[i].plLabel);
|
setChildNode(curNode, buttons[i]);
|
curNode.setLeaf(true);
|
|
String btnParamBtmType = "";
|
String btnParamContextValue = "";
|
PLCommandParameter[] btnParams = UITools.getService().getPLCommandParametersByCommandOId(buttons[i].plOId);
|
for(PLCommandParameter cp : btnParams){
|
String key = cp.plKey;
|
String value = cp.plValue;
|
|
if(key.equals("type")){
|
btnParamBtmType = value;
|
} else if(key.equals("context")){
|
btnParamContextValue = value;
|
}
|
}
|
|
if(!"".equals(btnParamBtmType) && !"".equals(btnParamContextValue)) {
|
curNode.setLeaf(false);
|
setChildNodeV2(curNode, btnParamBtmType, btnParamContextValue);
|
}
|
}
|
}
|
else if (funcObj instanceof PLTabButton) {
|
node.setLeaf(true);
|
}
|
} catch (VCIError e) {
|
//TODO 抛出异常
|
e.printStackTrace();
|
}
|
}
|
}
|