package com.vci.client.framework.appConfig; import java.awt.BorderLayout; import java.awt.Component; import javax.swing.JPanel; import javax.swing.JTree; import javax.swing.event.TreeSelectionEvent; import javax.swing.event.TreeSelectionListener; import javax.swing.tree.DefaultTreeCellRenderer; import javax.swing.tree.TreePath; import com.vci.client.LogonApplication; import com.vci.client.framework.appConfig.object.AppConfigCategoryObject; import com.vci.client.framework.delegate.AppConfigCategoryClientDelegate; import com.vci.client.ui.exception.VCIException; import com.vci.client.ui.swing.VCISwingUtil; import com.vci.client.ui.swing.components.VCIJPanel; import com.vci.client.ui.swing.components.VCIJScrollPane; import com.vci.client.ui.swing.components.VCIJSplitPane; import com.vci.client.ui.tree.VCIBaseTree; import com.vci.client.ui.tree.VCIBaseTreeModel; import com.vci.client.ui.tree.VCIBaseTreeNode; public class AppConfigModulePanel extends VCIJPanel { /** * */ private static final long serialVersionUID = 7786534649775071284L; private VCIBaseTreeNode rootNode = new VCIBaseTreeNode("系统配置分类", "root"); private VCIBaseTree treeOption = null; private VCIBaseTreeModel treeModel = null; private VCIJSplitPane jsplitPane = null; private JPanel curPanel = null; private AppConfigCategoryPanel categoryPanel = null; private AppConfigDetailPanel2 detailPanel = null; public AppConfigModulePanel() { init(); } public void refrashTree() { initContents(); } private void init(){ initComponents(); initContents(); } private void initComponents(){ setLayout(new BorderLayout()); jsplitPane = new VCIJSplitPane(VCIJSplitPane.HORIZONTAL_SPLIT, getLeftCategoryTreePane(), new VCIJPanel()); jsplitPane.setDividerSize(6); jsplitPane.setContinuousLayout(true); jsplitPane.setOneTouchExpandable(true); jsplitPane.setDividerLocation(200); add(jsplitPane, BorderLayout.CENTER); categoryPanel = new AppConfigCategoryPanel(this); //categoryPanel. detailPanel = new AppConfigDetailPanel2(); treeOption.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { treeSelectionChange_valueChanged(e); } }); } private VCIJScrollPane getLeftCategoryTreePane(){ VCIJScrollPane jsp = new VCIJScrollPane(); treeModel = new VCIBaseTreeModel(rootNode); treeOption = new VCIBaseTree(treeModel); treeOption.setCellRenderer(new DefaultTreeCellRenderer() { /** * */ private static final long serialVersionUID = 9104143041307538008L; @Override public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { Component compt = super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus); if(value instanceof VCIBaseTreeNode){ VCIBaseTreeNode node = (VCIBaseTreeNode) value; if(node.getObj() instanceof String && node.getObj().toString().equals("root")){ setIcon(VCISwingUtil.createImageIcon("options.png")); } else{ setIcon(VCISwingUtil.createImageIcon("folder.png")); } } return compt; } }); jsp.getViewport().add(treeOption); return jsp; } private void initContents(){ rootNode.removeAllChildren(); //TODO AppConfigCategoryClientDelegate delegate = new AppConfigCategoryClientDelegate(LogonApplication.getUserEntityObject()); try { AppConfigCategoryObject[] objs = delegate.getAppConfigCategorys(); for(AppConfigCategoryObject obj : objs){ VCIBaseTreeNode node = new VCIBaseTreeNode(obj.getName(), obj); rootNode.add(node); rootNode.setExpand(true); node.setExpand(true); node.setLeaf(true); } treeOption.updateUI(); TreePath path = new TreePath(rootNode.getPath()); treeOption.setSelectionPath(path); } catch (VCIException e) { // TODO Auto-generated catch block e.printStackTrace(); } } private void treeSelectionChange_valueChanged(TreeSelectionEvent e) { TreePath treePath = e.getPath(); VCIBaseTreeNode selectNode = (VCIBaseTreeNode) treePath.getLastPathComponent(); Object object = selectNode.getObj(); if (object.equals("root")) { if (curPanel == categoryPanel) return; curPanel = categoryPanel; } else if (object instanceof AppConfigCategoryObject) { detailPanel.refreshCategory((AppConfigCategoryObject)object); if (curPanel == detailPanel) return; curPanel = detailPanel; } jsplitPane.setRightComponent(curPanel); int location = jsplitPane.getDividerLocation(); jsplitPane.setDividerLocation(location); } }