package com.vci.client.auth2.view;
|
|
import java.awt.BorderLayout;
|
import java.awt.Component;
|
import java.awt.Dimension;
|
import java.awt.FlowLayout;
|
import java.awt.GridBagConstraints;
|
import java.awt.GridBagLayout;
|
import java.awt.Insets;
|
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionListener;
|
import java.util.ArrayList;
|
import java.util.List;
|
|
import javax.swing.BorderFactory;
|
import javax.swing.DefaultComboBoxModel;
|
import javax.swing.JButton;
|
import javax.swing.JComboBox;
|
import javax.swing.JLabel;
|
import javax.swing.JOptionPane;
|
import javax.swing.JPanel;
|
import javax.swing.JScrollPane;
|
import javax.swing.JTable;
|
import javax.swing.JTextField;
|
import javax.swing.event.DocumentEvent;
|
import javax.swing.event.DocumentListener;
|
import javax.swing.table.JTableHeader;
|
import javax.swing.table.TableCellRenderer;
|
import javax.swing.table.TableColumn;
|
import javax.swing.table.TableColumnModel;
|
|
import org.jdesktop.swingx.JXTable;
|
import org.jdesktop.swingx.decorator.HighlighterFactory;
|
|
import com.vci.client.LogonApplication;
|
import com.vci.client.auth2.action.QueryAction;
|
import com.vci.client.auth2.component.RefTextField;
|
import com.vci.client.auth2.model.BooleanTableModel;
|
import com.vci.client.auth2.utils.IRightConstant;
|
import com.vci.client.auth2.utils.RightManagerHelper;
|
import com.vci.client.auth2.vo.OpItem;
|
import com.vci.client.common.objects.DeptObject;
|
import com.vci.client.common.objects.RoleObject;
|
import com.vci.client.common.objects.UserObject;
|
import com.vci.client.framework.delegate.RightManagementClientDelegate;
|
import com.vci.client.logon.base.BaseJDialog;
|
import com.vci.client.ui.exception.VCIException;
|
import com.vci.corba.framework.data.CheckValue;
|
import com.vci.corba.omd.btm.BtmItem;
|
import com.vci.corba.omd.data.BusinessObject;
|
|
public class CheckRightResultView extends BaseJDialog {
|
/**
|
*
|
*/
|
private static final long serialVersionUID = 2310057621717549497L;
|
private static CheckRightResultView instance;
|
private final int TABLE_HEADER_HEIGHT = 25;
|
private final int ROW_HEIGHT = 30;
|
private JXTable OPTable = new JXTable();
|
private BusinessObject businessObject;
|
private int length = 0;;
|
// 主体
|
private JPanel userPanel = new JPanel();
|
|
private JPanel objectPanel = new JPanel();
|
// 用户
|
private JComboBox userCombbox = new JComboBox();
|
// 角色
|
private JComboBox roleCombbox = new JComboBox();
|
// 用户组
|
private JComboBox userGroupCombbox = new JComboBox();
|
|
private RefTextField objectTextField = new RefTextField(15);
|
|
private JScrollPane opPanel = new JScrollPane();
|
private QueryAction query = new QueryAction("查询业务对象");
|
@SuppressWarnings("unused")
|
private BtmItem resourceType;
|
private RightManagementClientDelegate dao = new RightManagementClientDelegate();
|
private AbstractUIFunclet funclet;
|
|
public static CheckRightResultView getInstance() {
|
if (instance == null) {
|
instance = new CheckRightResultView();
|
}
|
return instance;
|
}
|
|
private CheckRightResultView() {
|
super(LogonApplication.frame);
|
setTitle("查看授权结果");
|
setModal(true);
|
initUI();
|
}
|
|
public void refresh() {
|
initData();
|
}
|
|
public BusinessObject getBusinessObject() {
|
return businessObject;
|
}
|
|
public void setBusinessObject(BusinessObject businessObject) {
|
this.businessObject = businessObject;
|
}
|
|
private void initObjectListener() {
|
objectTextField.getText().getDocument().addDocumentListener(
|
new DocumentListener() {
|
@Override
|
public void removeUpdate(DocumentEvent e) {
|
// textValueChange();
|
}
|
|
@Override
|
public void insertUpdate(DocumentEvent e) {
|
textValueChange();
|
}
|
|
@Override
|
public void changedUpdate(DocumentEvent e) {
|
textValueChange();
|
}
|
});
|
objectTextField.getText().addActionListener(new ActionListener() {
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
textValueChange();
|
}
|
});
|
}
|
|
private void textValueChange() {
|
CheckValue params = new CheckValue();
|
params.users = getString(userCombbox);
|
params.roles = getString(roleCombbox);
|
params.userGroups = getString(userGroupCombbox);
|
params.businesstype = getResourceType(objectTextField.getText().getText().trim()
|
.equals("") ? "22385E82-485C-549D-E2F4-91278E9E0A76"
|
: objectTextField.getText().getText().trim());
|
params.opname = IRightConstant.OPS;
|
params.objectmoid = "";
|
params.objectroid = "";
|
params.objectoid = objectTextField.getText().getText().trim().equals("") ? "22385E82-485C-549D-E2F4-91278E9E0A76"
|
: objectTextField.getText().getText().trim();
|
initData(params);
|
}
|
|
private void initSubjectDatas() {
|
// 主体
|
UserObject uo = com.vci.client.LogonApplication.userObject;
|
switch (uo.getUserType()) {
|
case 0:
|
|
case 1:
|
// 管理员用户(系统)
|
// 查询所有的普通用户信息
|
UserObject[] userInfos = null;
|
try {
|
userInfos = new RightManagementClientDelegate(
|
LogonApplication.getUserEntityObject())
|
.fetchUserInfoByType(1);
|
} catch (Exception e) {
|
JOptionPane.showMessageDialog(
|
com.vci.client.LogonApplication.frame,
|
"查询用户信息出错\n" + e.getMessage(), "提示",
|
JOptionPane.ERROR_MESSAGE);
|
}
|
initCombobox(userCombbox, userInfos);
|
break;
|
case 2:
|
// 普通用户
|
addSubjectData(uo, dao);
|
break;
|
default:
|
// 普通用户
|
addSubjectData(uo, dao);
|
}
|
}
|
|
private void addUserComboboxListener() {
|
// 增加选择监听
|
userCombbox.addActionListener(new ActionListener() {
|
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
UserObject uo = (UserObject) userCombbox.getSelectedItem();
|
if (uo != null) {
|
// 查询角色
|
initRoleAndUserGroupCombobox(uo, dao);
|
}
|
|
}
|
});
|
}
|
|
private void initRoleAndUserGroupCombobox(UserObject uo,
|
RightManagementClientDelegate dao) {
|
if (uo == null)
|
return;
|
// 角色
|
RoleObject[] roleObjects = null;
|
DeptObject depObject = null;
|
try {
|
roleObjects = dao.fetchRoleInfoByUserId(uo.getId());
|
depObject = dao.fetchDeptByUserId(uo.getId());
|
} catch (VCIException e) {
|
JOptionPane.showMessageDialog(
|
com.vci.client.LogonApplication.frame,
|
"查询信息出错\n" + e.getMessage(), "提示",
|
JOptionPane.ERROR_MESSAGE);
|
}
|
initCombobox(roleCombbox, roleObjects);
|
initCombobox(userGroupCombbox, new Object[] { depObject });
|
}
|
|
private void initCombobox(JComboBox combobox, Object[] datas) {
|
DefaultComboBoxModel model = (DefaultComboBoxModel) combobox.getModel();
|
model.removeAllElements();
|
if (datas != null && datas.length != 0) {
|
for (Object o : datas) {
|
combobox.addItem(o);
|
}
|
}
|
}
|
|
private void addSubjectData(UserObject uo, RightManagementClientDelegate dao) {
|
initCombobox(userCombbox, new Object[] { uo });
|
initRoleAndUserGroupCombobox(uo, dao);
|
}
|
|
private String getString(JComboBox combobox) {
|
StringBuffer sb = new StringBuffer();
|
if (combobox.getItemCount() == 0) {
|
return "";
|
}
|
Object eachItem = combobox.getSelectedItem();
|
if (eachItem instanceof UserObject) {
|
sb.append(((UserObject) eachItem).getUserName());
|
return sb.toString();
|
}
|
|
for (int i = 0; i < combobox.getItemCount(); i++) {
|
Object item = combobox.getItemAt(i);
|
sb.append(item);
|
sb.append(",");
|
}
|
|
return sb.substring(0, sb.lastIndexOf(","));
|
|
}
|
|
private void initData(CheckValue params) {
|
// 操作
|
List<OpItem> opitems = new ArrayList<OpItem>();
|
try {
|
String where = RightManagerHelper.getFrameworkService().checkRight(params);
|
String[] ops = where.split(":");
|
|
for (String s : ops) {
|
if (s != null && !s.equals("")) {
|
OpItem item = new OpItem();
|
String[] op = s.split(",");
|
item.setName(op[0]);
|
item.setValue(op[1]);
|
opitems.add(item);
|
}
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
JOptionPane.showMessageDialog(
|
com.vci.client.LogonApplication.frame, "鉴权出错\n"
|
+ e.getLocalizedMessage(), "提示",
|
JOptionPane.ERROR_MESSAGE);
|
}
|
// 设置列头
|
// 操作信息
|
// 设置Table列头信息
|
List<String> tableHeader = new ArrayList<String>();
|
|
for (int m = 0; m < opitems.size(); m++) {
|
tableHeader.add(opitems.get(m).getName());
|
|
}
|
BooleanTableModel booleanModel = new BooleanTableModel();
|
booleanModel.setColumnCount(tableHeader.size());
|
booleanModel.setColumnIdentifiers(tableHeader.toArray(new String[tableHeader.size()]));
|
getOPTable().setModel(booleanModel);
|
booleanModel.setColumnCount(tableHeader.size());
|
booleanModel.setColumnIdentifiers(tableHeader.toArray(new String[tableHeader.size()]));
|
// 设置列宽
|
JTable table = getOPTable();
|
TableColumnModel columnModel = table.getColumnModel();
|
double maxWidth = 0;
|
for (int i = 0; i < columnModel.getColumnCount(); i++) {
|
TableColumn column = columnModel.getColumn(i);
|
TableCellRenderer cellRenderer = column.getHeaderRenderer();
|
if (cellRenderer == null)
|
cellRenderer = table.getDefaultRenderer(columnModel.getColumn(i).getClass());
|
Object headerValue = column.getHeaderValue();
|
Component columnComp = cellRenderer.getTableCellRendererComponent(
|
(JTable) table, headerValue, false, false, 0, i);
|
|
maxWidth = Math.max(maxWidth, columnComp.getPreferredSize().getWidth());
|
}
|
|
JTableHeader jtableHeader = table.getTableHeader();
|
Dimension size = jtableHeader.getPreferredSize();
|
size.width = (int) maxWidth;
|
jtableHeader.setPreferredSize(size);
|
// 设置数据
|
booleanModel.setRowCount(1);
|
for (int n = 0; n < opitems.size(); n++) {
|
booleanModel.setValueAt(
|
opitems.get(n).getValue().equals("1") ? true : false, 0, n);
|
|
}
|
// Action
|
query.setFunclet(getFunclet());
|
query.setUiContainer(this);
|
refreshUI();
|
}
|
|
private void initData() {
|
initSubjectDatas();
|
// 操作
|
CheckValue params = new CheckValue();
|
params.users = getString(userCombbox);
|
params.roles = getString(roleCombbox);
|
params.userGroups = getString(userGroupCombbox);
|
params.paramValues="";
|
params.businesstype = getResourceType(objectTextField.getText().getText().trim()
|
.equals("") ? "22385E82-485C-549D-E2F4-91278E9E0A76"
|
: objectTextField.getText().getText().trim());
|
params.opname = IRightConstant.OPS;
|
params.objectmoid = "";
|
params.objectroid = "";
|
params.objectoid = objectTextField.getText().getText().trim().equals("") ? "22385E82-485C-549D-E2F4-91278E9E0A76"
|
: objectTextField.getText().getText().trim();
|
initData(params);
|
}
|
|
private void refreshUI() {
|
//
|
initDialogSize(opPanel.getPreferredSize().width + 20, 450);
|
userPanel.setPreferredSize(new Dimension(
|
opPanel.getPreferredSize().width, 60));
|
opPanel.setPreferredSize(new Dimension(
|
opPanel.getPreferredSize().width, 120));
|
}
|
|
private void initUI() {
|
JPanel mainPanel = new JPanel();
|
// 主体信息
|
GridBagConstraints g_mpnl = new GridBagConstraints();
|
g_mpnl.insets = new Insets(5, 5, 5, 5);
|
g_mpnl.anchor = GridBagConstraints.EAST;
|
g_mpnl.gridx = 0;
|
g_mpnl.gridy = 0;
|
JLabel userLable = new JLabel(" 用户:");
|
userPanel.add(userLable, g_mpnl);
|
g_mpnl.gridx = 1;
|
userPanel.add(userCombbox, g_mpnl);
|
g_mpnl.anchor = GridBagConstraints.CENTER;
|
g_mpnl.gridx = 2;
|
JLabel roleLable = new JLabel(" 角色:");
|
userPanel.add(roleLable, g_mpnl);
|
g_mpnl.gridx = 3;
|
userPanel.add(roleCombbox, g_mpnl);
|
JLabel usergLable = new JLabel(" 用户组:");
|
g_mpnl.anchor = GridBagConstraints.WEST;
|
g_mpnl.gridx = 4;
|
userPanel.add(usergLable, g_mpnl);
|
g_mpnl.gridx = 5;
|
userPanel.add(userGroupCombbox, g_mpnl);
|
userPanel.setBorder(BorderFactory.createTitledBorder("用户信息"));
|
|
userPanel.setLayout(new GridBagLayout());
|
|
userPanel.setPreferredSize(new Dimension(this.length == 0 ? 450
|
: this.length, 300));
|
|
// 客体
|
|
objectTextField.setLable(" 业务对象:");
|
objectPanel.add(objectTextField);
|
((RefTextField) objectTextField).setParent(objectPanel);
|
((RefTextField) objectTextField).setRefButton((JButton) query);
|
((RefTextField) objectTextField).updateUI();
|
initObjectListener();
|
// 操作
|
JPanel OpMainPanel = new JPanel();
|
OpMainPanel.setLayout(new BorderLayout());
|
// UIAction ok = new UIAction("确定");
|
JPanel actionPanel = new JPanel();
|
actionPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 0, 0));
|
// actionPanel.add(ok);
|
// table
|
OpMainPanel.add(opPanel, BorderLayout.NORTH);
|
OpMainPanel.add(actionPanel, BorderLayout.CENTER);
|
opPanel.setBorder(BorderFactory.createTitledBorder(" 授权结果:"));
|
getOPTable().setRowHeight(ROW_HEIGHT);
|
getOPTable().setHorizontalScrollEnabled(true);
|
getOPTable().setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
|
getOPTable().setHighlighters(
|
HighlighterFactory.createAlternateStriping());
|
// ruleTable.setSortable(true);
|
getOPTable().setDragEnabled(false);
|
JTableHeader tableHeader = getOPTable().getTableHeader();
|
Dimension size = tableHeader.getPreferredSize();
|
size.height = TABLE_HEADER_HEIGHT;
|
size.width = TABLE_HEADER_HEIGHT;
|
tableHeader.setPreferredSize(size);
|
opPanel.setViewportView(getOPTable());
|
initDialogSize(600, 450);
|
mainPanel.add(objectPanel, BorderLayout.NORTH);
|
mainPanel.add(userPanel, BorderLayout.CENTER);
|
mainPanel.add(OpMainPanel, BorderLayout.SOUTH);
|
add(mainPanel);
|
addUserComboboxListener();
|
}
|
|
public JXTable getOPTable() {
|
return OPTable;
|
}
|
|
public void setOPTable(JXTable oPTable) {
|
OPTable = oPTable;
|
}
|
|
private String getResourceType(String objectId) {
|
if (getResourceType() == null) {
|
JOptionPane.showMessageDialog(
|
com.vci.client.LogonApplication.frame,
|
"请选择类型树信息", "提示", JOptionPane.INFORMATION_MESSAGE);
|
}
|
return getResourceType().name;
|
}
|
|
public BtmItem getResourceType() {
|
return RightManagerHelper.getResourceType(funclet);
|
}
|
|
public void setResourceType(BtmItem resourceType) {
|
this.resourceType = resourceType;
|
}
|
|
public JTextField getObjectTextField() {
|
return objectTextField.getText();
|
}
|
|
|
public AbstractUIFunclet getFunclet() {
|
return funclet;
|
}
|
|
public void setFunclet(AbstractUIFunclet funclet) {
|
this.funclet = funclet;
|
}
|
}
|