wangting
2024-12-30 306a9c4fde94c54d91aee5a69d59b993c7c707a1
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
package com.vci.client.workflow.template;
 
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.LinkedHashMap;
import java.util.Map;
 
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.event.TreeExpansionEvent;
import javax.swing.event.TreeExpansionListener;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
import javax.swing.tree.TreeSelectionModel;
 
import com.vci.client.LogonApplication;
import com.vci.client.logon.base.BaseJDialog;
import com.vci.client.ui.exception.VCIException;
import com.vci.client.ui.swing.KJButton;
import com.vci.client.ui.swing.VCIOptionPane;
import com.vci.client.ui.tree.VCIBaseTree;
import com.vci.client.ui.tree.VCIBaseTreeModel;
import com.vci.client.ui.tree.VCIBaseTreeNode;
import com.vci.client.workflow.commom.ClientHelper;
import com.vci.client.workflow.delegate.ProcessCustomClientDelegate;
import com.vci.client.workflow.template.ProcessCategoryTreeCellRender;
import com.vci.client.workflow.template.object.NodeHideObject;
import com.vci.client.workflow.template.object.ProcessCategoryObject;
import com.vci.client.workflow.template.object.ProcessDefinitionObject;
import com.vci.corba.common.VCIError;
 
public class AssignProcessDialog extends BaseJDialog {
 
    private static final long serialVersionUID = 4257732186259993713L;
    
    private VCIBaseTree leftTree = null;
    private VCIBaseTreeModel treeModel = null;
    private VCIBaseTreeNode rootNode = null;
    
    private KJButton okBtn = new KJButton(this.getI18nString("btnOk"), "ok.gif");
    private KJButton cancelBtn = new KJButton(this.getI18nString("btnCancel"), "cancel.gif");
 
    private ProcessDefinitionObject processDefinitionObject;
    private boolean isOk = false;
    
    public AssignProcessDialog(Frame parent) {
        super(parent, true);
        setTitle(getI18nString("selectProcess"));
        initUI();
        addListener();
        setSize(280, 320);
        centerToScreen();
    }
 
    private void initUI() {
        JPanel assignPanel = new JPanel(new BorderLayout());
        JScrollPane leftScrPane = new JScrollPane();
        initLeftPanel(leftScrPane);
        assignPanel.add(leftScrPane);
        
        JPanel btnPanel = new JPanel();
        btnPanel.add(okBtn);
        btnPanel.add(cancelBtn);
        getContentPane().add(assignPanel);
        getContentPane().add(btnPanel, BorderLayout.SOUTH);
    }
    
    private void initLeftPanel(JScrollPane leftJsp) {
        String rootObj = "root";
        rootNode = new VCIBaseTreeNode(this.getI18nString("treeRootNodeName"), rootObj);
        treeModel = new VCIBaseTreeModel(rootNode);
        leftTree = new VCIBaseTree(treeModel, new ProcessCategoryTreeCellRender());
        leftTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
        leftTree.addTreeExpansionListener(new TreeExpansionListener() {
            public void treeExpanded(TreeExpansionEvent event) {
                TreePath treePath = event.getPath();
                VCIBaseTreeNode selectNode = (VCIBaseTreeNode) treePath.getLastPathComponent();
                if(!selectNode.isExpand()){
                    selectNode.removeAllChildren();
                    getExpandTreeData(selectNode);
                }
            }
 
            public void treeCollapsed(TreeExpansionEvent event) {
            }
        });
        leftJsp.getViewport().add(leftTree);
        initLeftTree(rootNode);
    }
    private void getExpandTreeData(VCIBaseTreeNode treeNode) {
        try{
            String processCategoryId = "";
            Object nodeObject = treeNode.getObj();
            if(nodeObject instanceof String && nodeObject.toString().equals("root")){
                initLeftTree(rootNode);
            }else{
                if (nodeObject instanceof ProcessCategoryObject) {
                    processCategoryId = ((ProcessCategoryObject)nodeObject).getId();
                } 
                //refresh tree from db
                ProcessCategoryObject[] processCategories = new ProcessCustomClientDelegate(LogonApplication.getUserEntityObject()).getProcessCategories(processCategoryId);
                for (ProcessCategoryObject obj : processCategories) {
                    VCIBaseTreeNode node = new VCIBaseTreeNode(obj.getName(), obj);
                    treeModel.insertNodeInto(node, treeNode, treeNode.getChildCount());
                    treeNode.setExpand(true);
                }
                
                ProcessDefinitionObject[] processDefinitions = new ProcessCustomClientDelegate(LogonApplication.getUserEntityObject()).getProcessDefinitions(processCategoryId);
                Map<String, String> hideMap = getHideNodeMap();
                /**
                 * 为模板配置流程时,隐藏的流程模板不显示
                 * 2012-11-28  wangxl 
                 */
                for (ProcessDefinitionObject processDefinitionObject : processDefinitions) {
                    if(!hideMap.containsKey(processDefinitionObject.getJbpmDeploymentId())) {
                        String nodeName = processDefinitionObject.toString();
                        VCIBaseTreeNode node = new VCIBaseTreeNode(nodeName, processDefinitionObject);
                        treeModel.insertNodeInto(node, treeNode, treeNode.getChildCount());
                        treeNode.setExpand(true);
                    }
                }
            }
        }catch(VCIException ex){
            VCIOptionPane.showError(LogonApplication.frame, "RMIPRm", ex);
        }
    }
    
    private Map<String, String> getHideNodeMap() {
        Map<String, String> map = new LinkedHashMap<String, String>();
        ProcessCustomClientDelegate pccd = new ProcessCustomClientDelegate(LogonApplication.getUserEntityObject());
        try {
            NodeHideObject[] nh = pccd.getNodeHideDeploymentId();
            for(NodeHideObject node : nh) {
                map.put(node.getDeploymentId(), "Y");
            }
        } catch (VCIError e) {
            e.printStackTrace();
        }
        return map;
    }
    
    private void initLeftTree(VCIBaseTreeNode treeNode) {
        try{
            ProcessCustomClientDelegate delSrv = new ProcessCustomClientDelegate(LogonApplication.getUserEntityObject());
            ProcessCategoryObject[] processCategories = delSrv.getProcessCategories("root");
            treeNode.removeAllChildren();
            for(ProcessCategoryObject obj : processCategories){
                VCIBaseTreeNode node = new VCIBaseTreeNode(obj.getName(), obj);
                treeNode.add(node);
            }
            this.leftTree.setSelectionPath(new TreePath(treeNode));
            this.leftTree.updateUI();
        } catch (VCIException e) {
            VCIOptionPane.showError(LogonApplication.frame, "RMIPRm", e);
            return;
        }
    }
 
    private void addListener() {
        okBtn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                ok();
            }
        });
        
        cancelBtn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                close();
            }
        });
    }
 
    private ProcessDefinitionObject getSelectProcessDefinition() {
        ProcessDefinitionObject result = null;
        Object node = leftTree.getLastSelectedPathComponent();
        if(node != null) {
            Object obj = ((VCIBaseTreeNode)node).getObj();
            if(obj instanceof ProcessDefinitionObject) {
                result = (ProcessDefinitionObject) obj;
            }
        }
        return result;
    }
    
    private void ok() {
        processDefinitionObject = getSelectProcessDefinition();
        if(processDefinitionObject == null){
            JOptionPane.showMessageDialog(this, getI18nString("plsSelectProcessDefinition"));
            return;
        }
        isOk = true;
        close();
    }
 
    private void close() {
        this.dispose();
        this.setVisible(false);
    }
    
    public ProcessDefinitionObject getProcessDefinitionObject() {
        return processDefinitionObject;
    }
 
    private void centerToScreen() {
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension componentSize = getSize();
        if (componentSize.height > screenSize.height) {
            componentSize.height = screenSize.height;
        }
 
        if (componentSize.width > screenSize.width) {
            componentSize.width = screenSize.width;
        }
 
        this.setLocation((screenSize.width - componentSize.width) / 2,
                (screenSize.height - componentSize.height) / 2);
    }
 
    public boolean isOk() {
        return isOk;
    }
    
    private String getI18nString(String code){
        return ClientHelper.getI18nStringForWorkflow(this.getClass().getName() + "." + code, this.getLocale());
    }
}