dangsn
2024-12-26 4e9ff2ce6a830bb2340d7c8612c72eea0c5a553e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
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);
    }
}