package com.vci.client.portal.NewNewUI.actionmng;
|
|
import java.awt.BorderLayout;
|
import java.awt.FlowLayout;
|
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionListener;
|
import javax.swing.JButton;
|
import javax.swing.JDialog;
|
import javax.swing.JOptionPane;
|
import javax.swing.JPanel;
|
import javax.swing.JScrollPane;
|
import javax.swing.JTree;
|
import javax.swing.tree.DefaultMutableTreeNode;
|
import javax.swing.tree.DefaultTreeModel;
|
import javax.swing.tree.TreePath;
|
import javax.swing.tree.TreeSelectionModel;
|
|
import com.vci.client.portal.utility.UITools;
|
import com.vci.corba.common.VCIError;
|
import com.vci.corba.portal.data.PLActionCls;
|
import com.vci.mw.ClientContextVariable;
|
|
public class PLActionClsSelectDialog extends JDialog {
|
|
/**
|
* serialVersionUID
|
*/
|
private static final long serialVersionUID = -5667907302621398073L;
|
/**
|
* 分类树
|
*/
|
private JTree clsTree;
|
/**
|
* 选择的分类
|
*/
|
private PLActionCls currentCls;
|
/**
|
* 确定还是取消
|
*/
|
private boolean ok = false;
|
|
/**
|
* 构造器
|
* @param dialog
|
*/
|
public PLActionClsSelectDialog(JDialog dialog) {
|
super(dialog, "选择分类", true);
|
init();
|
this.setLocationRelativeTo(dialog);
|
this.setVisible(true);
|
}
|
|
/**
|
* 绘制
|
*/
|
private void init() {
|
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);
|
refreshClsTree(clsTree, clsTree.getPathForRow(0));
|
//添加树
|
JScrollPane scrollPane = new JScrollPane(clsTree);
|
panel.add(scrollPane, BorderLayout.CENTER);
|
|
JPanel btnPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
|
//创建分类按钮
|
JButton createBtn = new JButton("确定");
|
createBtn.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
okBtnAction();
|
}
|
});
|
//修改分类按钮
|
JButton editBtn = new JButton("取消");
|
editBtn.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
cancelBtnAction();
|
}
|
});
|
btnPanel.add(createBtn);
|
btnPanel.add(editBtn);
|
|
this.setLayout(new BorderLayout());
|
this.add(panel, BorderLayout.CENTER);
|
this.add(btnPanel, BorderLayout.SOUTH);
|
this.setSize(600, 400);
|
}
|
|
/**
|
* 确定事件
|
*/
|
private void okBtnAction() {
|
TreePath tp = clsTree.getSelectionPath();
|
DefaultMutableTreeNode node = (DefaultMutableTreeNode) tp.getLastPathComponent();
|
Object userObject = node.getUserObject();
|
if(userObject instanceof String) {
|
JOptionPane.showMessageDialog(
|
this, "不能选择根节点!", "系统提示", JOptionPane.INFORMATION_MESSAGE);
|
return;
|
} else {
|
ClientPLActionCls pac = (ClientPLActionCls) userObject;
|
this.currentCls = pac.getPac();
|
}
|
this.ok = true;
|
this.dispose();
|
}
|
|
/**
|
* 取消
|
*/
|
private void cancelBtnAction() {
|
this.currentCls = null;
|
this.ok = false;
|
this.dispose();
|
}
|
|
|
private void refreshClsTree(JTree clsTree, 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("", "未分类", "", "", "", 0, (short)0);
|
DefaultMutableTreeNode child = new DefaultMutableTreeNode(
|
new ClientPLActionCls(plac));
|
dtml.insertNodeInto(child, node, node.getChildCount());
|
}
|
dtml.reload(node);
|
}
|
|
public PLActionCls getCurrentCls() {
|
return currentCls;
|
}
|
|
public boolean isOk() {
|
return ok;
|
}
|
}
|