ludc
2025-01-16 986aa62ed00bee39363bab41b4eeb8259d446efd
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
package com.vci.client.workflow.template;
 
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
 
import javax.swing.JComponent;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.event.TreeExpansionEvent;
import javax.swing.event.TreeExpansionListener;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
 
import com.vci.client.LogonApplication;
import com.vci.client.common.VCIBasePanel;
import com.vci.client.framework.rightConfig.object.FunctionObject;
import com.vci.client.ui.exception.VCIException;
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.object.ProcessCategoryObject;
import com.vci.client.workflow.template.object.ProcessDefinitionObject;
import com.vci.client.workflow.template.object.RMTypeObject;
 
public class ProcessCustomPanel extends VCIBasePanel {
 
    private static final long serialVersionUID = 3053694281232264263L;
 
    private VCIBaseTree leftTree = null;
    private VCIBaseTreeModel treeModel = null;
    private VCIBaseTreeNode rootNode = null;
 
    private ProcessCustomToolBar toolBar = null;
    JComponent rightPanel = null;
    JPanel rightEmptyPanel = new JPanel();
 
    private JSplitPane splitPane;
 
    private JPopupMenu popupMenu = new JPopupMenu();// 弹出式菜单
    private JMenuItem menuitem_cute = new JMenuItem("剪切");
    private JMenuItem menuitem_past = new JMenuItem("粘贴");
    private Set<TreePath> movePath;
 
    // 保存剪切和粘贴的临时数据
    private List<VCIBaseTreeNode> tempTreeNode = new ArrayList<VCIBaseTreeNode>();
 
    FunctionObject object = new FunctionObject();
 
    public void setLeftTree(VCIBaseTree leftTree) {
        this.leftTree = leftTree;
    }
 
    public ProcessCustomPanel(FunctionObject object) {
        super(object);
        this.object = object;
//        LogonApplication.frame.getUserEntityObject().setModules(this.getClass().getName());
        init();
    }
 
    private void init() {
        JScrollPane leftScrPane = new JScrollPane();
        splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftScrPane, rightEmptyPanel);
        splitPane.setDividerSize(10);
        splitPane.setContinuousLayout(true);
        splitPane.setOneTouchExpandable(true);
        splitPane.setDividerLocation(200);
        this.setLayout(new BorderLayout());
        this.add(splitPane, BorderLayout.CENTER);
        initLeftPanel(leftScrPane);
    }
 
    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);
 
        popupMenu.add(menuitem_cute);
        popupMenu.add(menuitem_past);
 
        leftTree.addTreeSelectionListener(new TreeSelectionListener() {
            public void valueChanged(TreeSelectionEvent e) {
                treeValueChanged(e);
            }
        });
        leftTree.addTreeExpansionListener(new TreeExpansionListener() {
            public void treeExpanded(TreeExpansionEvent event) {
                TreePath treePath = event.getPath();
                VCIBaseTreeNode selectNode = (VCIBaseTreeNode) treePath.getLastPathComponent();
                if (!selectNode.isExpand() && !selectNode.getObj().equals("root")) {
                    selectNode.removeAllChildren();
                    getExpandTreeData(selectNode);
                }
            }
 
            public void treeCollapsed(TreeExpansionEvent event) {
            }
        });
        leftTree.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                super.mouseClicked(e);
//                TreePath treePath = leftTree.getPathForLocation(e.getX(), e.getY());
                TreePath[] treePath = leftTree.getSelectionPaths();
                VCIBaseTreeNode node = (VCIBaseTreeNode) leftTree.getSelectionPath().getLastPathComponent();
 
                if (!(node.getObj() instanceof String)) {
                    movePath = new HashSet<TreePath>();
                    for (TreePath tp : treePath) {
                        movePath.add(tp);
                    }
                }
            };
 
            @Override
            public void mouseReleased(MouseEvent e) {
                super.mouseReleased(e);
                TreePath treePath = leftTree.getPathForLocation(e.getX(), e.getY());
                if (treePath == null) {
                    return;
                }
                VCIBaseTreeNode node = (VCIBaseTreeNode) treePath.getLastPathComponent();
                Object obj = node.getObj();
                if (e.isPopupTrigger()) {
                    if (obj instanceof ProcessCategoryObject) {
                        menuitem_cute.setEnabled(false);
                        menuitem_past.setEnabled(true);
                    } else if (obj instanceof ProcessDefinitionObject) {
                        menuitem_cute.setEnabled(true);
                        menuitem_past.setEnabled(false);
                    }
                    popupMenu.show(leftTree, e.getX(), e.getY());
                }
            }
        });
        // 剪切事件
        menuitem_cute.addActionListener(new ActionListener() {
 
            public void actionPerformed(ActionEvent e) {
                for (TreePath tp : movePath) {
                    VCIBaseTreeNode node = (VCIBaseTreeNode) tp.getLastPathComponent();
                    if (node != null) {
                        tempTreeNode.add(node);
                    }
                }
            }
        });
        // 粘贴事件
        menuitem_past.addActionListener(new ActionListener() {
 
            public void actionPerformed(ActionEvent e) {
                if (tempTreeNode == null) {
                    return;
                }
                // 分类id
                String categoryId = "";
                // 模板id
                String deploymentId = "";
                VCIBaseTreeNode expendNode = null;
                for (TreePath tp : movePath) {
                    VCIBaseTreeNode parentNode = (VCIBaseTreeNode) tp.getLastPathComponent();
                    Object obj = parentNode.getObj();
                    if (obj instanceof ProcessCategoryObject) {
                        categoryId = ((ProcessCategoryObject) obj).getId();
                        for (VCIBaseTreeNode nd : tempTreeNode) {
                            if (nd.getObj() instanceof ProcessDefinitionObject) {
                                ProcessDefinitionObject definitionObj = (ProcessDefinitionObject) nd.getObj();
                                deploymentId = definitionObj.getJbpmDeploymentId();
//                                if(nd.isExpand()){
                                treeModel.insertNodeInto(nd, parentNode, parentNode.getChildCount());
//                                }
                                parentNode.setExpand(true);
                                ProcessCustomClientDelegate delegate = new ProcessCustomClientDelegate(
                                        LogonApplication.getUserEntityObject());
                                try {
                                    delegate.moveDefinition(deploymentId, categoryId);
                                } catch (VCIException e1) {
                                    e1.printStackTrace();
                                }
                            }
                        }
                    }
                }
                tempTreeNode = new ArrayList<VCIBaseTreeNode>();
                movePath = new HashSet<TreePath>();
                leftTree.updateUI();
 
            }
        });
 
        leftJsp.getViewport().add(leftTree);
        initLeftTree(rootNode);
    }
 
    protected void treeValueChanged(TreeSelectionEvent e) {
        TreePath treePath = e.getPath();
        if (treePath == null) {
            splitPane.setRightComponent(rightEmptyPanel);
            return;
        }
 
        VCIBaseTreeNode selectNode = (VCIBaseTreeNode) treePath.getLastPathComponent();
        Object object = selectNode.getObj();
        ProcessDefinitionObject processDefinitionObject = null;
 
        if (object instanceof ProcessDefinitionObject) {
            processDefinitionObject = (ProcessDefinitionObject) object;
            if (rightPanel == null) {
                rightPanel = new ProcessDefinitionPanel();
            }
            ((ProcessDefinitionPanel) rightPanel).setObject(processDefinitionObject);
            splitPane.setRightComponent(rightPanel);
        } else {
            splitPane.setRightComponent(rightEmptyPanel);
        }
        int location = splitPane.getDividerLocation();
        splitPane.setDividerLocation(location);
    }
 
    public ProcessCustomToolBar getSpecialToolBar() {
        if (toolBar == null) {
            toolBar = new ProcessCustomToolBar(LogonApplication.frame, this);
        }
        return toolBar;
    }
 
    /**
     * 返回当前选中的树节点
     * 
     * @return
     */
    public VCIBaseTreeNode getCurrentSelectedTreeNode() {
        return (VCIBaseTreeNode) this.leftTree.getLastSelectedPathComponent();
    }
 
    public Object getCurrentSelectedObject() {
        return this.getCurrentSelectedTreeNode().getObj();
    }
 
    /**
     * toolbar上的刷新按钮会调用该方法
     */
    public void updateTree() {
        ((VCIBaseTreeNode) this.leftTree.getLastSelectedPathComponent()).removeAllChildren();
        getExpandTreeData(((VCIBaseTreeNode) this.leftTree.getLastSelectedPathComponent()));
        this.leftTree.updateUI();
    }
 
    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();
                } else if (nodeObject instanceof RMTypeObject) {
                    TreeNode[] treeNodes = treeNode.getPath();
                    processCategoryId = ((ProcessCategoryObject) (((VCIBaseTreeNode) treeNodes[1]).getObj())).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);
                if (processDefinitions != null && processDefinitions.length > 0) {
                    for (ProcessDefinitionObject processDefinitionObject : processDefinitions) {
                        String nodeName = processDefinitionObject.toString();
                        VCIBaseTreeNode node = new VCIBaseTreeNode(nodeName, processDefinitionObject);
                        node.setLeaf(true);
                        treeModel.insertNodeInto(node, treeNode, treeNode.getChildCount());
                    }
                    treeNode.setExpand(true);
                }
            }
        } catch (VCIException ex) {
            VCIOptionPane.showError(LogonApplication.frame, "RMIPWorkflow", ex);
        }
    }
 
    public void initLeftTree() {
        initLeftTree(this.rootNode);
    }
 
    public 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, "RMIPWorkflow", e);
            return;
        }
    }
 
    public void setEmptyPanel() {
        splitPane.setRightComponent(rightEmptyPanel);
        int location = splitPane.getDividerLocation();
        splitPane.setDividerLocation(location);
    }
 
    public void addNewObjectToTree(ProcessCategoryObject object) {
        VCIBaseTreeNode newNode = new VCIBaseTreeNode(object.getName(), object);
        this.treeModel.insertNodeInto(newNode, getCurrentSelectedTreeNode(),
                getCurrentSelectedTreeNode().getChildCount());
        this.leftTree.setSelectionPath(new TreePath(newNode.getPath()));
        this.leftTree.updateUI();
    }
 
    public void refreshModifyObjectToTree(ProcessCategoryObject object) {
        VCIBaseTreeNode modifyNode = getCurrentSelectedTreeNode();
        modifyNode.setUserObject(object.getName());
        modifyNode.setObj(object);
        this.leftTree.setSelectionPath(new TreePath(modifyNode.getPath()));
        this.leftTree.updateUI();
    }
 
    public void removeNode(VCIBaseTreeNode treeNode) {
        treeNode.removeFromParent();
        this.leftTree.updateUI();
    }
 
    public VCIBaseTree getLeftTree() {
        return leftTree;
    }
 
    private String getI18nString(String spCode) {
        return ClientHelper.getI18nStringForWorkflow(this.getClass().getName() + "." + spCode, this.getLocale());
    }
}