田源
2025-01-09 8a166a60cfd1a2e593ffa103d10c0dc224fc8628
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
363
364
365
package com.vci.client.workflow.template;
 
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
 
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.tree.TreePath;
 
import com.vci.client.LogonApplication;
import com.vci.client.common.IconSelectDialog;
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.image.BundleImage;
import com.vci.client.ui.locale.LocaleDisplay;
import com.vci.client.ui.swing.KJButton;
import com.vci.client.ui.swing.KTextField;
import com.vci.client.ui.swing.VCIOptionPane;
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.corba.common.VCIError;
 
 
 
/**
 * @author liudi
 *
 * 2012-5-21
 */
public class ProcessCategoryPanel extends VCIBasePanel {
    
    private static final long serialVersionUID = 8564910826301969195L;
    
    private KJButton okBtn = new KJButton(this.getI18nString("btnOk"), "ok.gif");
    private KJButton cancelBtn = new KJButton(this.getI18nString("btnCancel"), "cancel.gif");
    private KJButton selectIconBtn = new KJButton(this.getI18nString("btnChooseIcon"), "process_edit.gif");
    private KTextField nameField = new KTextField();
    private JTextArea descArea = new JTextArea();
    
    private String optType = null;
    private ProcessCustomOperate operate = null;
    private ProcessCategoryObject processCategoryObject = null;
 
    private ProcessCustomClientDelegate preferLibraryDelegate ;
    
    KJButton addBtn = new KJButton("新建", "add.png");
    KJButton editBtn = new KJButton("修改", "edit.png");
    KJButton delBtn = new KJButton("删除", "delete.png");
    
    ProcessCustomPanel panel;
    public ProcessCategoryPanel(ProcessCustomPanel panel,FunctionObject object) throws VCIException{
        super(object);
        preferLibraryDelegate = new ProcessCustomClientDelegate(LogonApplication.getUserEntityObject());
//        this.processCategoryObject = processCategoryObject;
        this.panel = panel;
        init();
    }
    public ProcessCategoryPanel(String optType, ProcessCategoryObject processCategoryObject,FunctionObject object) throws VCIException {
        super(object);
        preferLibraryDelegate = new ProcessCustomClientDelegate(LogonApplication.getUserEntityObject());
        this.optType = optType;
        this.processCategoryObject = processCategoryObject;
        
        init();
//        checkPermission();
    }
    
    private void init() throws VCIException {
        initPanelContent();
//        if (optType.equals("create")) {
//            this.setTitle(this.getI18nString("createTitle"));
//        } else if (optType.equals("modify")) {
//            this.setTitle(this.getI18nString("modifyTitle"));
        this.setUIContent();
//        }
        addListener();
    }
    
    /**
     * <p>Description: 初始所有UI元素</p>
     */
    private void initPanelContent() {
        JPanel panel = new JPanel();
        BorderLayout thisLayout = new BorderLayout();
        setLayout(thisLayout);
        panel.setLayout(null);
        
        JLabel lblNewLabel = new JLabel(this.getI18nString("lblName"));
        lblNewLabel.setBounds(222, 60, 60, 25);
        panel.add(lblNewLabel);
        
        nameField.setBounds(260, 60, 300, 25);
        panel.add(nameField);
        
        JLabel descLabel = new JLabel(getI18nString("lblDesc"));
        descLabel.setBounds(222, 120, 60, 25);
        panel.add(descLabel);
 
        JScrollPane scrollPane = new JScrollPane();
        scrollPane.getViewport().add(descArea);
        scrollPane.setBounds(260, 120, 300, 120);
        panel.add(scrollPane);
        add(panel,BorderLayout.CENTER);
        
        JPanel btnPanel = new JPanel();
        btnPanel.add(addBtn);
        btnPanel.add(editBtn);
        btnPanel.add(delBtn);
        add(btnPanel,BorderLayout.SOUTH);
//        panel.setPreferredSize(new java.awt.Dimension(205, 142));
    }
    
    /**
     * <p>Description: 初始化所有按钮关联的操作监听</p>
     */
    private void addListener() {
        selectIconBtn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                selectIcon();
            }
        });
 
        addBtn.addActionListener(new ActionListener() {
            
            public void actionPerformed(ActionEvent e) {
                ok("create");
            }
 
        });
        editBtn.addActionListener(new ActionListener() {
            
            public void actionPerformed(ActionEvent e) {
                ok("edit") ;
            }
        });
        delBtn.addActionListener(new ActionListener() {
            
            public void actionPerformed(ActionEvent e) {
//                ok();
                deleteProcessCategory();
            }
        });
//        okBtn.addActionListener(new ActionListener() {
//            public void actionPerformed(ActionEvent e) {
//                ok();
//            }
//        });
//
//        cancelBtn.addActionListener(new ActionListener() {
//            public void actionPerformed(ActionEvent e) {
//            }
//        });
    }
    public void deleteProcessCategory() {
//        ProcessCustomPanel mainPanel = panel;
        Object selectedObject = panel.getCurrentSelectedObject();
        if (selectedObject instanceof ProcessCategoryObject) {
            if (VCIOptionPane.showQuestion(LogonApplication.frame, ClientHelper
                    .getI18nStringForWorkflow(this.getClass().getName() + "."
                            + "deleteProcessCategoryConfirmMessage",
                            panel.getLocale())) != 0) {
                return;
            }
            ProcessCategoryObject object = (ProcessCategoryObject) selectedObject;
            deleteProcessCategoryClassify(object.getId());
        } else {
            VCIOptionPane.showError(LogonApplication.frame, ClientHelper
                    .getI18nStringForWorkflow(this.getClass().getName() + "."
                            + "pleaseChooseTreeNode", panel.getLocale()));
        }
    }
 
    private void deleteProcessCategoryClassify(String id) {
        try {
            ProcessCustomClientDelegate delegate = new ProcessCustomClientDelegate(LogonApplication.getUserEntityObject());
            ProcessDefinitionObject[] processDefinitions = new ProcessCustomClientDelegate(LogonApplication.getUserEntityObject()).getProcessDefinitions(id);
            if(processDefinitions.length>0){
                VCIOptionPane.showMessage(LogonApplication.frame, "分类下有模板,请先删除模版!");
                return;
            }else{
                boolean rs = delegate.deleteProcessCategory(id);
                if (rs) {
                    VCIBaseTreeNode node = panel.getCurrentSelectedTreeNode();
                    panel.removeNode(node);
                    panel.getLeftTree().setSelectionPath(new TreePath(panel.getRootPane()));
                    panel.setEmptyPanel();
                }
            }
        } catch (VCIException exp) {
            VCIOptionPane.showError(LogonApplication.frame, "RMIPWorkflow", exp);
        }
    }
    private void selectIcon() {
        String title = getI18nString("lblIcon");
        IconSelectDialog iconDialog = new IconSelectDialog(title, true, optType, selectIconBtn);
        iconDialog.setVisible(true);
    }
 
    private void ok(String opertype) {
        if(opertype.equalsIgnoreCase("create")){
            ProcessCategoryObject object = getCreateProcessCategory();
            if (!checkProcessCategoryData(object)) {
                return;
            }
            String parentId = "root";
//            Object currentSelectedObject = getOperate().getToolBar().getMainPanel().getCurrentSelectedObject();
            Object currentSelectedObject = panel.getCurrentSelectedObject();
            if (currentSelectedObject instanceof ProcessCategoryObject) {
                parentId = ((ProcessCategoryObject)currentSelectedObject).getId();
            };
            object.setParentId(parentId);
 
            try {
                if(!checkNameExisted(object)) return;
                String id = preferLibraryDelegate.saveProcessCategory(object);
                object.setId(id);
                panel.addNewObjectToTree(object);
            } catch (VCIError ex) {
                VCIOptionPane.showError(this,
                        LocaleDisplay.getI18nString(String.valueOf(ex.code), "RMIPWorkflow", getLocale()));
            }
        }else{
            ProcessCategoryObject object = getModifyPreferLibrary();
            if (!checkProcessCategoryData(object)) {
                return;
            }
            String parentId = "root";
            Object currentSelectedObject = panel.getCurrentSelectedObject();
            if (currentSelectedObject instanceof ProcessCategoryObject) {
                parentId = ((ProcessCategoryObject)currentSelectedObject).getParentId();
            };
            object.setParentId(parentId);
            try {
                if(!checkNameExisted(object)) return;
                preferLibraryDelegate.updateProcessCategory(object);
                panel.refreshModifyObjectToTree(object);
            } catch (VCIError ex) {
                VCIOptionPane.showError(LogonApplication.frame,
                        LocaleDisplay.getI18nString(String.valueOf(ex.code), "RMIPWorkflow", getLocale()));
            }
        }
    }
 
    private ProcessCategoryObject getModifyPreferLibrary() {
        ProcessCategoryObject obj = getProcessCategoryFromUIControl();
//        if (this.processCategoryObject != null) {
//            obj.setId(this.processCategoryObject.getId());
//        }
        Object object = panel.getCurrentSelectedObject();
        if(object instanceof ProcessCategoryObject){
            ProcessCategoryObject pcObject = (ProcessCategoryObject) object;
            if(pcObject!=null){
                obj.setId(pcObject.getId());
            }
        }
        return obj;
    }
 
    private boolean checkNameExisted(ProcessCategoryObject object) throws VCIError{
        boolean res = true;
        //判断是否存在相同名称的模板分类
        if(preferLibraryDelegate.existProcessCategory(object.getId(), object.getName())){
            VCIOptionPane.showError(LogonApplication.frame, getI18nString("nameDuplicated"));
            nameField.requestFocus();
            nameField.selectAll();
            return false;
        }
        return res;
    }
    
    public ProcessCategoryObject getCreateProcessCategory() {
        return getProcessCategoryFromUIControl();
    }
    
    public ProcessCategoryObject getModifyProcessCategory() {
        ProcessCategoryObject obj = getProcessCategoryFromUIControl();
        Object object = panel.getCurrentSelectedObject();
        if(object instanceof ProcessCategoryObject){
            ProcessCategoryObject pcObject = (ProcessCategoryObject) object;
            if(pcObject!=null){
                obj.setId(pcObject.getId());
            }
        }
        return obj;
    }
    
    /**
     * <p>Description: 获取页面填写内容,并将其构建成集成任务对象</p>
     */
    private ProcessCategoryObject getProcessCategoryFromUIControl() {
        ProcessCategoryObject obj = new ProcessCategoryObject();
        obj.setName(this.nameField.getText());
        obj.setIcon(getIconFromIconButton());
        obj.setDesc(this.descArea.getText());
        obj.setCreateUser(LogonApplication.getUserEntityObject().getUserName());
        obj.setModifyUser(LogonApplication.getUserEntityObject().getUserName());
        return obj;
    }
    
    /**
     * <p>Description: 根据被修改对象的内容初始化编辑对话框</p>
     */
    private void setUIContent() {
        Object object = panel.getCurrentSelectedObject();
        if(object instanceof ProcessCategoryObject){
            ProcessCategoryObject pcObject = (ProcessCategoryObject) object;
            
            this.nameField.setText(pcObject.getName());
            this.descArea.setText(pcObject.getDesc());
            String icon = pcObject.getIcon(); 
            if(!icon.equals("")){
                selectIconBtn.setIcon(new BundleImage().createImageIcon(icon));
            }
        }
    }
    
    /**
     * 检查优选库数据
     * @param object
     * @return
     */
    public boolean checkProcessCategoryData(ProcessCategoryObject object){
        boolean res = false;
        if(object.getName().equals("")){
            VCIOptionPane.showMessage(this, getI18nString("nameIsNotNull"));
        }else{
            res = true;
        }
        return res;
    }
    
    /**
     * <p>Description: 获取去图标按钮选择的图片</p>
     */
    private String getIconFromIconButton(){
        String icon = this.selectIconBtn.getIcon().toString();
        return icon.substring(icon.lastIndexOf("/") + 1);
    }
    
    private String getI18nString(String code){
        return ClientHelper.getI18nStringForWorkflow(this.getClass().getName() + "." + code, this.getLocale());
    }
    
    public ProcessCustomOperate getOperate() {
        return this.operate;
    }
    
    private void initGUI() {
        try {
            {
                this.setPreferredSize(new java.awt.Dimension(265, 159));
            }
        } catch(Exception e) {
            e.printStackTrace();
        }
    }
 
}