package com.vci.client.auth2.view;
|
|
import java.awt.BorderLayout;
|
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.Arrays;
|
import java.util.Comparator;
|
import java.util.List;
|
|
import javax.swing.JButton;
|
import javax.swing.JDialog;
|
import javax.swing.JOptionPane;
|
import javax.swing.JPanel;
|
import javax.swing.JScrollPane;
|
import javax.swing.JSplitPane;
|
import javax.swing.JTable;
|
import javax.swing.JTree;
|
import javax.swing.event.TreeSelectionEvent;
|
import javax.swing.event.TreeSelectionListener;
|
import javax.swing.table.AbstractTableModel;
|
import javax.swing.tree.DefaultMutableTreeNode;
|
import javax.swing.tree.DefaultTreeModel;
|
import javax.swing.tree.TreePath;
|
import javax.swing.tree.TreeSelectionModel;
|
|
import com.vci.client.common.PinyinCommon;
|
import com.vci.client.portal.NewNewUI.actionmng.ClientPLActionCls;
|
import com.vci.client.portal.utility.UITools;
|
import com.vci.corba.common.VCIError;
|
import com.vci.corba.portal.data.Constraint;
|
import com.vci.corba.portal.data.PLAction;
|
import com.vci.corba.portal.data.PLActionCls;
|
import com.vci.mw.ClientContextVariable;
|
|
public class PLActionSelectionDialog extends JDialog implements ActionListener{
|
|
private static final long serialVersionUID = 1L;
|
|
private static final String ADD_COMMAND = "add";
|
private static final String DEL_COMMAND = "del";
|
|
private MyTableModel tableModel;
|
private JTable table;
|
private JSplitPane contentPanel;
|
private boolean isOK = false;
|
|
private ArrayList<PLAction> selActions = null;
|
|
private JTree clsTree;
|
/**
|
* 当前选择的分类节点
|
* 当选择根节点时为null
|
*/
|
private PLActionCls currentCls = null;
|
|
public PLActionSelectionDialog(){
|
super(ClientContextVariable.getFrame(), "action选择", true);
|
this.initUI();
|
setSize(900, 600);
|
setLocationRelativeTo(null);
|
setVisible(true);
|
}
|
private void initUI(){
|
this.initContentPanel();
|
getContentPane().add(contentPanel, BorderLayout.CENTER);
|
this.refreshTableData();
|
}
|
/**
|
* 设置table查询条件
|
* @return
|
*/
|
private Constraint[] getFilterConstraints(){
|
Constraint[] consArray = new Constraint[1];
|
if(this.currentCls == null) {
|
consArray = new Constraint[0];
|
}
|
if(this.currentCls != null) {
|
if(this.currentCls.name.equals("未分类")) {
|
consArray[0] = new Constraint("plactioncls", "");
|
} else {
|
consArray[0] = new Constraint("plactioncls", this.currentCls.id);
|
}
|
}
|
return consArray;
|
}
|
private void refreshTableData() {
|
try {
|
PLAction[] allPLActions = UITools.getService().getPLActionsByConsArray(getFilterConstraints());
|
Arrays.sort(allPLActions, new Comparator<PLAction>(){
|
@Override
|
public int compare(PLAction o1, PLAction o2) {
|
String py1 = PinyinCommon.getPingYin(o1.plName);
|
String py2 = PinyinCommon.getPingYin(o2.plName);
|
return py1.compareTo(py2);
|
}});
|
List<PLAction> allActionList = Arrays.asList(allPLActions);
|
tableModel.setData(allActionList);
|
} catch (VCIError e) {
|
e.printStackTrace();
|
}
|
}
|
private void initContentPanel() {
|
JPanel treePanel = this.getTreePanel();
|
//刷新分类树
|
refreshClsTree(clsTree.getPathForRow(0));
|
JPanel rightPanel = this.getRigthPanel();
|
contentPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
|
contentPanel.setDividerSize(2);
|
//contentPanel.setDividerLocation(0.7);
|
contentPanel.add(treePanel, JSplitPane.LEFT);
|
contentPanel.add(rightPanel, JSplitPane.RIGHT);
|
}
|
private void refreshClsTree(TreePath tp) {
|
try {
|
//分类较少,直接查询所有分类
|
PLActionCls[] clses = UITools.getService().getPLActionClsArray();
|
|
DefaultTreeModel dtml = (DefaultTreeModel) clsTree.getModel();
|
DefaultMutableTreeNode node = (DefaultMutableTreeNode)
|
tp.getLastPathComponent();
|
addClsTreeNode(dtml, node, clses);
|
} catch (VCIError e1) {
|
e1.printStackTrace();
|
JOptionPane.showMessageDialog(ClientContextVariable.getFrame(),
|
"刷新分类树异常:" + e1.getMessage(), "系统异常", JOptionPane.ERROR_MESSAGE);
|
}
|
}
|
/**
|
* 添加分类树节点
|
* @param dtml 树模型
|
* @param node 节点
|
* @param clses 分类
|
*/
|
private void addClsTreeNode(DefaultTreeModel dtml,
|
DefaultMutableTreeNode node, PLActionCls[] clses) {
|
node.removeAllChildren();
|
String pid = "";
|
Object userObject = node.getUserObject();
|
if(!(userObject instanceof String)) {
|
PLActionCls pac = ((ClientPLActionCls) userObject).getPac();
|
pid = pac.id;
|
}
|
//添加子节点
|
for(PLActionCls plac : clses) {
|
if(plac.pid.equals(pid)) {
|
DefaultMutableTreeNode child = new DefaultMutableTreeNode(
|
new ClientPLActionCls(plac));
|
dtml.insertNodeInto(child, node, node.getChildCount());
|
addClsTreeNode(dtml, child, clses);
|
}
|
}
|
if(pid.equals("")) {
|
PLActionCls plac = new PLActionCls("", "未分类", "", "", "", System.currentTimeMillis(), (short)0);
|
DefaultMutableTreeNode child = new DefaultMutableTreeNode(
|
new ClientPLActionCls(plac));
|
dtml.insertNodeInto(child, node, node.getChildCount());
|
}
|
dtml.reload(node);
|
}
|
/**
|
* 树节点选择事件
|
* @param e
|
*/
|
private void clsTreeSelectionListener(TreeSelectionEvent e) {
|
TreePath tp = e.getPath();
|
DefaultMutableTreeNode node = (DefaultMutableTreeNode) tp.getLastPathComponent();
|
Object userObject = node.getUserObject();
|
if(userObject instanceof String) {
|
this.currentCls = null;
|
} else {
|
ClientPLActionCls pac = (ClientPLActionCls) userObject;
|
this.currentCls = pac.getPac();
|
}
|
refreshTableData();
|
}
|
/**
|
* 得到Action分类树面板
|
* @return
|
*/
|
private JPanel getTreePanel() {
|
JPanel panel = new JPanel(new BorderLayout());
|
|
//初始化树
|
DefaultMutableTreeNode root = new DefaultMutableTreeNode("Action分类");
|
DefaultTreeModel dtml = new DefaultTreeModel(root);
|
clsTree = new JTree(dtml);
|
clsTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
|
clsTree.addTreeSelectionListener(new TreeSelectionListener() {
|
public void valueChanged(TreeSelectionEvent e) {
|
clsTreeSelectionListener(e);
|
}
|
});
|
|
//添加树
|
panel.add(new JScrollPane(clsTree), BorderLayout.CENTER);
|
return panel;
|
}
|
private JPanel getRigthPanel() {
|
JPanel btnPanel = this.getBtnPanel();
|
tableModel = new MyTableModel();
|
table = new JTable(tableModel);
|
GridBagLayout g = new GridBagLayout();
|
g.rowHeights = new int[]{0, 0};
|
g.columnWidths = new int[]{0};
|
g.rowWeights = new double[]{Double.MIN_VALUE, 0.0};
|
g.columnWeights = new double[]{Double.MIN_VALUE};
|
JPanel rightPanel = new JPanel(g);
|
GridBagConstraints gbc = new GridBagConstraints();
|
gbc.fill = GridBagConstraints.BOTH;
|
gbc.insets = new Insets(5, 5, 5, 5);
|
gbc.gridx = 0;
|
gbc.gridy = 0;
|
rightPanel.add(new JScrollPane(table), gbc);
|
gbc.gridx = 0;
|
gbc.gridy = 1;
|
rightPanel.add(btnPanel, gbc);
|
return rightPanel;
|
}
|
private JPanel getBtnPanel() {
|
JPanel panel = new JPanel();
|
JButton addBtn = new JButton("保存");
|
addBtn.setActionCommand(ADD_COMMAND);
|
addBtn.addActionListener(this);
|
JButton delBtn = new JButton("取消");
|
delBtn.setActionCommand(DEL_COMMAND);
|
delBtn.addActionListener(this);
|
panel.add(addBtn);
|
panel.add(delBtn);
|
return panel;
|
}
|
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
String command = e.getActionCommand();
|
if(DEL_COMMAND.equals(command)){
|
selActions = null;
|
this.setVisible(false);
|
}else if(ADD_COMMAND.equals(command)){
|
int[] selRows = table.getSelectedRows();
|
selActions = new ArrayList<PLAction>();
|
for(int i : selRows){
|
PLAction selAction = tableModel.getRowAt(i);
|
selActions.add(selAction);
|
}
|
isOK = true;
|
this.setVisible(false);
|
}
|
}
|
public boolean isOK(){
|
return isOK;
|
}
|
public List<PLAction> getResult(){
|
return selActions;
|
}
|
|
private class MyTableModel extends AbstractTableModel{
|
|
private static final long serialVersionUID = 1L;
|
|
private String[] columns = new String[]{"序号", "编号", "名称", "类路径", "链接地址", "类型", "描述"};
|
private List<PLAction> data;
|
|
public List<PLAction> getData(){
|
return data;
|
}
|
public MyTableModel() {
|
this.data = new ArrayList<PLAction>();
|
}
|
public void setData(List<PLAction> data){
|
this.data = data;
|
fireTableDataChanged();
|
}
|
public void addRow(PLAction dataRule){
|
this.data.add(dataRule);
|
fireTableStructureChanged();
|
}
|
public PLAction getRowAt(int rowIndex){
|
if(rowIndex >= 0 && rowIndex<data.size()){
|
return data.get(rowIndex);
|
}
|
return null;
|
}
|
public void deleteRow(int[] selectedRows){
|
for (int i = selectedRows.length - 1; i >= 0; --i) {
|
this.data.remove(selectedRows[i]);
|
}
|
fireTableDataChanged();
|
}
|
|
@Override
|
public String getColumnName(int column) {
|
return columns[column];
|
}
|
@Override
|
public int getRowCount() {
|
if(data == null){
|
return 0;
|
}
|
return data.size();
|
}
|
|
@Override
|
public int getColumnCount() {
|
return this.columns.length;
|
}
|
|
@Override
|
public Object getValueAt(int rowIndex, int columnIndex) {
|
if(this.data == null){
|
return null;
|
}
|
PLAction plAction = this.data.get(rowIndex);
|
if(plAction == null){
|
return null;
|
}
|
switch(columnIndex){
|
case 0: return rowIndex + 1;
|
case 1: return plAction.plCode;
|
case 2: return plAction.plName;
|
case 3: return plAction.plCSClass;
|
case 4: return plAction.plBSUrl;
|
case 5: {
|
String plTypeType = plAction.plTypeType;
|
if (plTypeType.equals("business")) {
|
return "业务类型";
|
}else if (plTypeType.equals("link")) {
|
return "链接类型";
|
}
|
}
|
case 6: return plAction.plDesc;
|
}
|
return null;
|
}
|
|
// @Override
|
// public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
|
// PLAction plAction = this.data.get(rowIndex);
|
// String value = (String)aValue;
|
// switch(columnIndex){
|
// case 0: break;
|
// case 1: plAction.setName(value);break;
|
// case 2: plAction.setDesc(value);break;
|
// case 3: plAction.setDataName(value);break;
|
// case 4: plAction.setDataType(value);break;
|
// }
|
// }
|
}
|
}
|