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 * *
Title:
*Description:
*Copyright: Copyright (c) 2016
*Company: VCI
* @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共查找到 " + String.valueOf(searchedTreeNodeList.size()) + " 个结果
" + "" + "
" + "" + ""); 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("" + "" + "
共查找到 " + String.valueOf(searchedTreeNodeList.size()) + " 个结果,当前显示
" + "第 " + String.valueOf(index + 1) + " 个 : " + treeNode.getUserObject() + "
" + "" + "" + ""); lblSearchInfo.updateUI(); updateUI(); } private void searchInTree(VCIBaseTreeNode parentTreeNode, List
显示后 可以切换显示 业务类型 或 链接类型
*默认值为false,此时按只显示 业务类型进行处理
* @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