package com.vci.client.portal.UI.v3;
|
|
import java.awt.BorderLayout;
|
import java.awt.Component;
|
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.Arrays;
|
import java.util.Comparator;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
import javax.swing.ButtonGroup;
|
import javax.swing.JScrollPane;
|
import javax.swing.JTree;
|
import javax.swing.event.TreeSelectionListener;
|
import javax.swing.tree.TreePath;
|
|
import com.vci.client.framework.rightConfig.modelConfig.ModuleTreeCellRenderer;
|
import com.vci.client.omd.btm.ui.BtmClient;
|
import com.vci.client.omd.linktype.LinkTypeStart;
|
import com.vci.client.ui.swing.VCISwingUtil;
|
import com.vci.client.ui.swing.components.VCIJButton;
|
import com.vci.client.ui.swing.components.VCIJDialog;
|
import com.vci.client.ui.swing.components.VCIJLabel;
|
import com.vci.client.ui.swing.components.VCIJPanel;
|
import com.vci.client.ui.swing.components.VCIJRadioButton;
|
import com.vci.client.ui.swing.components.VCIJTextField;
|
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;
|
import com.vci.corba.omd.btm.BtmItem;
|
import com.vci.corba.omd.ltm.LinkType;
|
import com.vci.mw.ClientContextVariable;
|
|
/**
|
* 业务类型&链接类型树Panel
|
*
|
* <p>Title: </p>
|
* <p>Description: </p>
|
* <p>Copyright: Copyright (c) 2016</p>
|
* <p>Company: VCI</p>
|
* @author xiongchao
|
* @time 2017-2-15
|
* @version 1.0
|
*/
|
public class BtmLinkTypeTreePanel extends VCIJPanel {
|
|
/**
|
*
|
*/
|
private static final long serialVersionUID = 3357669516630770059L;
|
private boolean showBtmLinkTypeRadioButton = false;
|
private boolean onlyLinkType = false;
|
public BtmLinkTypeTreePanel(){
|
|
}
|
|
public void buildUI(){
|
init();
|
}
|
private void init(){
|
initUI();
|
}
|
private void initUI(){
|
setLayout(new BorderLayout());
|
add(getNorthPanel(), BorderLayout.NORTH);
|
add(new JScrollPane(getCenterTreePanel()), BorderLayout.CENTER);
|
}
|
private VCIJLabel lblSearch = new VCIJLabel("查找:");
|
private VCIJTextField txtSearch = new VCIJTextField("", false);
|
private VCIJButton btnSearch = VCISwingUtil.createVCIJButton("search", "", "", "search.gif", new ActionListener() {
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
search_exec();
|
}
|
});
|
private VCIJButton btnRefresh = VCISwingUtil.createVCIJButton("refresh", "", "", "pagination_refresh.png", new ActionListener() {
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
refresh_exec();
|
}
|
});
|
private VCIJRadioButton rbtnBtmType = new VCIJRadioButton("业务类型", true);
|
private VCIJRadioButton rbtnLinkType = new VCIJRadioButton("链接类型", false);
|
private VCIJPanel getNorthPanel(){
|
VCIJPanel pal = new VCIJPanel();
|
pal.setLayout(new GridBagLayout());
|
pal.add(lblSearch, getGBC(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, 1));
|
pal.add(txtSearch, getGBC(1, 0, 2, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, 1));
|
pal.add(btnSearch, getGBC(3, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, 1));
|
pal.add(btnRefresh, getGBC(4, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, 1));
|
rbtnBtmType.addActionListener(new ActionListener() {
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
rbtn_change(rbtnBtmType.getText());
|
}
|
});
|
rbtnLinkType.addActionListener(new ActionListener() {
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
rbtn_change(rbtnLinkType.getText());
|
}
|
});
|
if(isShowBtmLinkTypeRadioButton() && !isOnlyLinkType()){
|
ButtonGroup rbtnGroup = new ButtonGroup();
|
rbtnGroup.add(rbtnBtmType);
|
rbtnGroup.add(rbtnLinkType);
|
pal.add(rbtnBtmType, getGBC(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, 1));
|
pal.add(rbtnLinkType, getGBC(2, 1, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, 1));
|
}
|
return pal;
|
}
|
|
private VCIBaseTreeNode rootNode = null;
|
private VCIBaseTreeModel treeModel = null;
|
private VCIBaseTree tree = null;
|
private VCIBaseTree getCenterTreePanel(){
|
VCIBaseTree res = null;
|
rootNode = new VCIBaseTreeNode("", "root");
|
treeModel = new VCIBaseTreeModel(rootNode);
|
updateRootNodeInfo();
|
reloadTreeData();
|
tree = new VCIBaseTree(treeModel, new ModuleTreeCellRenderer(){
|
private static final long serialVersionUID = 6253740682089786968L;
|
@Override
|
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus){
|
Component compt = super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
|
VCIBaseTreeNode node = null;
|
if(value instanceof VCIBaseTreeNode){
|
node = (VCIBaseTreeNode)value;
|
}
|
if(node != null){
|
if(node.isRoot()){
|
setIcon(VCISwingUtil.createImageIcon("house.png"));
|
}
|
if(node.getObj() instanceof BtmItem){
|
setIcon(VCISwingUtil.createImageIcon("folder.png"));
|
} else if(node.getObj() instanceof LinkType){
|
setIcon(VCISwingUtil.createImageIcon("folder_link.png"));
|
}
|
}
|
return compt;
|
}
|
});
|
res = tree;
|
return res;
|
}
|
private String getRootNodeShowLabel(){
|
String res = rbtnBtmType.getText();
|
if(isShowBtmLinkTypeRadioButton()){
|
if(rbtnLinkType.isSelected()){
|
res = rbtnLinkType.getText();
|
}
|
}
|
if(isOnlyLinkType()){
|
res = rbtnLinkType.getText();
|
rbtnLinkType.setSelected(isOnlyLinkType());
|
rbtnBtmType.setSelected(!isOnlyLinkType());
|
}
|
return res;
|
}
|
private void search_exec(){
|
searchedTreeNodeList.clear();
|
String text = txtSearch.getText().trim();
|
if("".equals(text)) return;
|
searchInTree(rootNode, searchedTreeNodeList, text);
|
|
if(searchedTreeNodeList.size() < 0){
|
return;
|
}
|
if(searchedTreeNodeList.size() == 1){
|
VCIBaseTreeNode treeNode = searchedTreeNodeList.get(0);
|
selectedTreeNodeToTree(treeNode);
|
return;
|
}
|
showSearchResultDialg(searchedTreeNodeList);
|
}
|
|
private void selectedTreeNodeToTree(VCIBaseTreeNode treeNode){
|
tree.clearSelection();
|
TreePath navToTreePath = new TreePath(treeNode.getPath());
|
tree.setSelectionPath(navToTreePath);
|
tree.scrollPathToVisible(navToTreePath);
|
tree.updateUI();
|
tree.validate();
|
}
|
|
private int index = -1;
|
private List<VCIBaseTreeNode> searchedTreeNodeList = new ArrayList<VCIBaseTreeNode>();
|
private VCIJDialog dialog = new VCIJDialog(ClientContextVariable.getFrame(), true);
|
private VCIJButton btnPrev = VCISwingUtil.createVCIJButton("prev", "上一个", "上一个", "pagination_previous.png", new ActionListener() {
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
index = index - 1;
|
prevOrNext(index);
|
}
|
});
|
private VCIJButton btnNext = VCISwingUtil.createVCIJButton("next", "下一个", "下一个", "pagination_next.png", new ActionListener() {
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
index = index + 1;
|
prevOrNext(index);
|
}
|
});
|
private VCIJButton btnClose = VCISwingUtil.createVCIJButton("close", "关闭", "关闭", "close.png", new ActionListener() {
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
dialog.setVisible(false);
|
dialog.dispose();
|
}
|
});
|
private VCIJLabel lblSearchInfo = new VCIJLabel("", null, VCIJLabel.LEADING);
|
private void showSearchResultDialg(List<VCIBaseTreeNode> list){
|
index = -1;
|
btnPrev.setEnabled(false);
|
btnNext.setEnabled(true);
|
|
VCIJPanel pal = new VCIJPanel(new FlowLayout(FlowLayout.LEADING));
|
lblSearchInfo.setText("" +
|
"<html>" +
|
"<p>共查找到 " + String.valueOf(searchedTreeNodeList.size()) + " 个结果</p>" +
|
"<p> </p>" +
|
"<p> </p>" +
|
"</html>" +
|
"");
|
pal.add(lblSearchInfo);
|
|
dialog.setTitle("查找结果");
|
dialog.setSize(300, 125);
|
dialog.setLocationRelativeTo(ClientContextVariable.getFrame());
|
VCIJPanel palBtn = new VCIJPanel(new FlowLayout());
|
|
palBtn.add(btnPrev);
|
palBtn.add(btnNext);
|
palBtn.add(btnClose);
|
VCIJPanel palContent = new VCIJPanel(new BorderLayout());
|
palContent.add(pal, BorderLayout.CENTER);
|
palContent.add(palBtn, BorderLayout.SOUTH);
|
dialog.setContentPane(palContent);
|
dialog.setVisible(true);
|
}
|
|
private void prevOrNext(int index){
|
VCIBaseTreeNode treeNode = searchedTreeNodeList.get(index);
|
selectedTreeNodeToTree(treeNode);
|
|
btnPrev.setEnabled(index > 0);
|
btnNext.setEnabled(index < searchedTreeNodeList.size() - 1);
|
|
lblSearchInfo.setText("" +
|
"<html>" +
|
"<p>共查找到 " + String.valueOf(searchedTreeNodeList.size()) + " 个结果,当前显示</p>" +
|
"<p>第 " + String.valueOf(index + 1) + " 个 : " + treeNode.getUserObject() + "</p>" +
|
"<p> </p>" +
|
"</html>" +
|
"");
|
lblSearchInfo.updateUI();
|
updateUI();
|
}
|
|
|
private void searchInTree(VCIBaseTreeNode parentTreeNode, List<VCIBaseTreeNode> list, String text){
|
int childCount = parentTreeNode.getChildCount();
|
for (int i = 0; i < childCount; i++) {
|
VCIBaseTreeNode treeNode = (VCIBaseTreeNode) parentTreeNode.getChildAt(i);
|
Object obj = treeNode.getObj();
|
if(isOnlyLinkType() ||
|
(isShowBtmLinkTypeRadioButton() && rbtnLinkType.isSelected())){
|
if(obj instanceof LinkType){
|
LinkType lt = (LinkType)obj;
|
if(lt.name.contains(text) || lt.tag.contains(text)){
|
list.add(treeNode);
|
}
|
}
|
} else if(rbtnBtmType.isSelected()){
|
if(obj instanceof BtmItem){
|
BtmItem bi = (BtmItem)obj;
|
if(bi.name.contains(text) || bi.label.contains(text)){
|
list.add(treeNode);
|
}
|
}
|
}
|
searchInTree(treeNode, list, text);
|
}
|
}
|
|
private void refresh_exec(){
|
btmItemMap.clear();
|
linkTypeMap.clear();
|
reloadTreeData();
|
}
|
private String lastRbtnText = rbtnBtmType.getText();
|
private void rbtn_change(String text){
|
if(text.equals(lastRbtnText)){
|
return;
|
}
|
lastRbtnText = text;
|
reloadTreeData();
|
updateRootNodeInfo();
|
updateUI();
|
}
|
private void updateRootNodeInfo(){
|
rootNode.setUserObject(getRootNodeShowLabel());
|
}
|
private void reloadTreeData(){
|
loadTreeData(rootNode, treeModel);
|
}
|
private Map<String, BtmItem[]> btmItemMap = new HashMap<String, BtmItem[]>();
|
private Map<String, LinkType[]> linkTypeMap = new HashMap<String, LinkType[]>();
|
private void loadTreeData(VCIBaseTreeNode parentTreeNode, VCIBaseTreeModel treeModel) {
|
try{
|
parentTreeNode.removeAllChildren();
|
if(rbtnBtmType.isSelected()){
|
BtmItem[] bis = new BtmItem[0];
|
String name = "";
|
if(!btmItemMap.containsKey(name)){
|
bis = BtmClient.getService().getAllBtmItem(name);
|
btmItemMap.put(name, bis);
|
} else {
|
bis = btmItemMap.get(name);
|
}
|
addBtmItemToTreeNode(bis, parentTreeNode);
|
} else {
|
LinkType[] lts = new LinkType[0];
|
String name = "all";
|
if(!linkTypeMap.containsKey("")){
|
lts = LinkTypeStart.getService().getLinkTypes();
|
linkTypeMap.put(name, lts);
|
}else {
|
lts = linkTypeMap.put(name, lts);
|
}
|
addLinkTypeToTreeNode(lts, parentTreeNode);
|
}
|
treeModel.reload();
|
}catch(Exception e){
|
e.printStackTrace();
|
}
|
}
|
private void addBtmItemToTreeNode(BtmItem[] btmItems, VCIBaseTreeNode parentTreeNode) throws VCIError{
|
Arrays.sort(btmItems, btmItemComparator);
|
for (BtmItem btmItem : btmItems) {
|
String nodeName = btmItem.name + " " + btmItem.label;
|
VCIBaseTreeNode treeNode = new VCIBaseTreeNode(nodeName, btmItem);
|
treeNode.setExpand(true);
|
treeNode.setLeaf(true);
|
treeModel.insertNodeInto(treeNode, parentTreeNode, treeModel.getChildCount(parentTreeNode));
|
BtmItem[] childBtmItems = new BtmItem[0];
|
String name = btmItem.name;
|
if(!btmItemMap.containsKey(name)){
|
childBtmItems = BtmClient.getService().getChildrenBtms(name);
|
btmItemMap.put(name, childBtmItems);
|
} else {
|
childBtmItems = btmItemMap.get(name);
|
}
|
addBtmItemToTreeNode(childBtmItems, treeNode);
|
}
|
}
|
private void addLinkTypeToTreeNode(LinkType[] linkTypes, VCIBaseTreeNode parentTreeNode){
|
Arrays.sort(linkTypes, linkTypeComparator);
|
for (LinkType linkType : linkTypes) {
|
String nodeName = linkType.name + " " + linkType.tag;
|
VCIBaseTreeNode treeNode = new VCIBaseTreeNode(nodeName, linkType);
|
treeNode.setLeaf(true);
|
treeNode.setExpand(true);
|
treeModel.insertNodeInto(treeNode, parentTreeNode, treeModel.getChildCount(parentTreeNode));
|
}
|
}
|
private Comparator<BtmItem> btmItemComparator = new Comparator<BtmItem>(){
|
@Override
|
public int compare(BtmItem o1, BtmItem o2) {
|
return o1.name.compareTo(o2.name);
|
}
|
};
|
private Comparator<LinkType> linkTypeComparator = new Comparator<LinkType>(){
|
@Override
|
public int compare(LinkType o1, LinkType o2) {
|
return o1.name.compareTo(o2.name);
|
}
|
};
|
private GridBagConstraints getGBC(int gridx, int gridy, int gridwidth, int gridheight, double weightx, double weighty, int anchor, int fill, int padxy) {
|
return new GridBagConstraints(gridx, gridy, gridwidth, gridheight, weightx, weighty, anchor, fill, new Insets(padxy, padxy, padxy, padxy), padxy, padxy);
|
}
|
|
public boolean isShowBtmLinkTypeRadioButton() {
|
return showBtmLinkTypeRadioButton;
|
}
|
|
public boolean isOnlyLinkType() {
|
return onlyLinkType;
|
}
|
/**
|
* 设置是否显示 业务类型 链接类型 单选按钮
|
* <p>显示后 可以切换显示 业务类型 或 链接类型</p>
|
* <p>默认值为false,此时按只显示 业务类型进行处理 </p>
|
* @param showBtmLinkTypeRadioButton
|
*/
|
public void setShowBtmLinkTypeRadioButton(boolean showBtmLinkTypeRadioButton) {
|
this.showBtmLinkTypeRadioButton = showBtmLinkTypeRadioButton;
|
}
|
/**
|
* 设置是否只显示链接类型(只显示链接类型时,没有 业务类型 链接类型 切换的单选按钮)
|
* @param onlyLinkType
|
*/
|
public void setOnlyLinkType(boolean onlyLinkType) {
|
this.onlyLinkType = onlyLinkType;
|
}
|
/**
|
* 添加树节点选择后的事件处理
|
* @param tsl 树节点选择后的事件处理程序 TreeSelectionListener
|
*/
|
public void addTreeSelectionListener(TreeSelectionListener tsl) {
|
tree.addTreeSelectionListener(tsl);
|
}
|
/**
|
* 返回当前选择的业务类型列表
|
* @return 当前选择的业务类型列表 List<BtmItem>
|
*/
|
public List<BtmItem> getSelectedBtmItems(){
|
List<BtmItem> list = new ArrayList<BtmItem>();
|
if(isShowBtmLinkTypeRadioButton() && rbtnBtmType.isSelected()){
|
TreePath[] treePaths = tree.getSelectionPaths();
|
for (TreePath treePath : treePaths) {
|
Object pathObj = treePath.getLastPathComponent();
|
if(pathObj != null && pathObj instanceof VCIBaseTreeNode){
|
VCIBaseTreeNode treeNode = (VCIBaseTreeNode)pathObj;
|
Object obj = treeNode.getObj();
|
if(obj instanceof BtmItem){
|
list.add(((BtmItem)obj));
|
}
|
}
|
}
|
}
|
return list;
|
}
|
/**
|
* 返回当前选择的链接类型列表
|
* @return 当前选择的链接类型列表 List<LinkType>
|
*/
|
public List<LinkType> getSelectedLinkTypes(){
|
List<LinkType> list = new ArrayList<LinkType>();
|
if(!isOnlyLinkType() && rbtnLinkType.isSelected()){
|
TreePath[] treePaths = tree.getSelectionPaths();
|
for (TreePath treePath : treePaths) {
|
Object pathObj = treePath.getLastPathComponent();
|
if(pathObj != null && pathObj instanceof VCIBaseTreeNode){
|
VCIBaseTreeNode treeNode = (VCIBaseTreeNode)pathObj;
|
Object obj = treeNode.getObj();
|
if(obj instanceof LinkType){
|
list.add(((LinkType)obj));
|
}
|
}
|
}
|
}
|
return list;
|
}
|
}
|