package com.vci.client.omd.btm.ui;
|
|
import java.awt.BorderLayout;
|
import java.awt.Dimension;
|
import java.awt.GridBagConstraints;
|
import java.awt.GridBagLayout;
|
import java.awt.Toolkit;
|
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionListener;
|
import java.util.ArrayList;
|
import java.util.Enumeration;
|
import java.util.HashMap;
|
|
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.TreeSelectionModel;
|
|
import com.vci.corba.omd.btm.BtmItem;
|
import com.vci.corba.common.VCIError;
|
|
public class FNameSelectDialog extends JDialog{
|
|
/**
|
*
|
*/
|
private static final long serialVersionUID = -8277560177280192479L;
|
private static FNameSelectDialog fNameSelectDialog = null;
|
private JTree btmTree;
|
private String fName = "";
|
private String btmName = "";
|
private JPanel centerPanel;
|
private JPanel southPanel;
|
private JButton btnOK;
|
private JButton btnCancel;
|
private BtmItem[] btmArray;
|
private HashMap<String, ArrayList<String>> btmNameListMap;
|
private DefaultMutableTreeNode rootNode;
|
|
private FNameSelectDialog(){
|
initUI();
|
initBtmTree();
|
addListener();
|
}
|
|
public static FNameSelectDialog getInstance(){
|
if(fNameSelectDialog == null){
|
fNameSelectDialog = new FNameSelectDialog();
|
}
|
return fNameSelectDialog;
|
}
|
|
private void initUI(){
|
this.setTitle("业务类型");
|
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
this.setSize(screenSize.width/4, screenSize.height/2);
|
this.setModal(true);
|
this.setLocationRelativeTo(null);
|
this.setResizable(false);
|
|
this.setLayout(new BorderLayout(5, 5));
|
|
//树
|
centerPanel = new JPanel();
|
//确定,取消按钮
|
southPanel = new JPanel();
|
this.add(centerPanel, BorderLayout.CENTER);
|
this.add(southPanel, BorderLayout.SOUTH);
|
|
centerPanel.setLayout(new GridBagLayout());
|
GridBagConstraints g = new GridBagConstraints();
|
g.gridx = 0;
|
g.gridy = 0;
|
g.weightx = 1.0;
|
g.weighty = 1.0;
|
g.fill = GridBagConstraints.BOTH;
|
rootNode = new DefaultMutableTreeNode("业务类型树");
|
btmTree = new JTree(rootNode);
|
btmTree.setAutoscrolls(true);
|
//设置单选模式
|
btmTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
|
centerPanel.add(new JScrollPane(btmTree), g);
|
|
btnOK = new JButton("确定");
|
btnCancel = new JButton("取消");
|
southPanel.add(btnOK);
|
southPanel.add(btnCancel);
|
}
|
|
private void initBtmTree(){
|
try {
|
|
btmArray = BtmClient.getService().getAllBtmItem("");
|
btmNameListMap = new HashMap<String, ArrayList<String>>();
|
BtmItem BtmItem = null;
|
rootNode = (DefaultMutableTreeNode) btmTree.getModel().getRoot();
|
if(!rootNode.isLeaf()){
|
rootNode.removeAllChildren();
|
}
|
for(int i = 0; i < btmArray.length; i++){
|
BtmItem = btmArray[i];
|
if(BtmItem.fName.equals("")){
|
rootNode.add(new DefaultMutableTreeNode(BtmItem.name));
|
}else{
|
if(btmNameListMap.get(BtmItem.fName) == null){
|
ArrayList<String> btmList = new ArrayList<String>();
|
btmList.add(BtmItem.name);
|
btmNameListMap.put(BtmItem.fName, btmList);
|
}else{
|
btmNameListMap.get(BtmItem.fName).add(BtmItem.name);
|
}
|
}
|
}
|
//也许这段可以加到上面的if中
|
for(Enumeration e = rootNode.children(); e.hasMoreElements();){
|
DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement();
|
if(node.isLeaf()){
|
addBtmNodeToTree(node);
|
}
|
}
|
} catch (VCIError e) {
|
e.printStackTrace();
|
}
|
}
|
|
private void addListener(){
|
btnOK.addActionListener(new ActionListener() {
|
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
DefaultMutableTreeNode seletionNode = (DefaultMutableTreeNode) btmTree.getLastSelectedPathComponent();
|
if(seletionNode == null){
|
JOptionPane.showMessageDialog(null, "请选择业务类型", "无业务类型", JOptionPane.WARNING_MESSAGE);
|
return;
|
}
|
String fName_ = (String)seletionNode.getUserObject();
|
if(fName_.equals(btmName)){
|
JOptionPane.showMessageDialog(null, "业务类型不能继承自己", "选择业务类型", JOptionPane.WARNING_MESSAGE);
|
return;
|
}
|
fName = fName_;
|
JOptionPane.showMessageDialog(null, "继承类型修改成功", "修改成功", JOptionPane.WARNING_MESSAGE);
|
dispose();
|
}
|
});
|
btnCancel.addActionListener(new ActionListener() {
|
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
dispose();
|
}
|
});
|
}
|
/**
|
* 由叶子节点去btmListMap中查找子节点
|
* @param node
|
*/
|
private void addBtmNodeToTree(DefaultMutableTreeNode node){
|
String btmName = (String)node.getUserObject();
|
if(btmNameListMap.get(btmName) == null){
|
return;
|
}else{
|
ArrayList<String> btmNameList = null;
|
String btmName_ = null;
|
DefaultMutableTreeNode node_ = null;
|
btmNameList = btmNameListMap.get(btmName);
|
for(int i = 0; i < btmNameList.size(); i++){
|
btmName_ = btmNameList.get(i);
|
node_ = new DefaultMutableTreeNode(btmName_);
|
node.add(node_);
|
addBtmNodeToTree(node_);
|
}
|
}
|
|
}
|
|
|
public String getFName(){
|
return fName;
|
}
|
|
public void setBtmName(String btmName){
|
this.btmName = btmName;
|
}
|
}
|