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
package com.vci.client.workflow.template;
 
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Toolkit;
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 com.vci.client.LogonApplication;
import com.vci.client.common.IconSelectDialog;
import com.vci.client.framework.rightConfig.object.FunctionObject;
import com.vci.client.logon.base.BaseJDialog;
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.workflow.commom.ClientHelper;
import com.vci.client.workflow.delegate.ProcessCustomClientDelegate;
import com.vci.client.workflow.template.object.ProcessCategoryObject;
import com.vci.corba.common.VCIError;
 
public class ProcessCategoryTypeDialog extends BaseJDialog {
    
    private static final long serialVersionUID = 8564910826301969195L;
    
    private KJButton okBtn = new KJButton("确定", "ok.gif");
    private KJButton cancelBtn = new KJButton("取消", "cancel.gif");
    private KJButton selectIconBtn = new KJButton("选择", "newresourcetypes.gif");
    private KTextField nameField = new KTextField();
    private JTextArea descArea;
    
    private String optType = null;
    private ProcessCategoryObject processCategoryObject = null;
 
    private ProcessCustomClientDelegate preferLibraryDelegate;
    FunctionObject funcObj = new FunctionObject();
    public ProcessCategoryTypeDialog(String title, 
            String optType, ProcessCategoryObject processCategoryObject) throws VCIException {
        super(LogonApplication.frame, title, true);
        preferLibraryDelegate = new ProcessCustomClientDelegate(LogonApplication.getUserEntityObject());
        this.optType = optType;
        this.processCategoryObject = processCategoryObject;
        
        init();
//        checkPermission();
    }
    
    public ProcessCategoryTypeDialog(String title,String optType,ProcessCategoryObject processCategoryObject,FunctionObject funcObj) throws VCIException {
        super(LogonApplication.frame, title, true);
        preferLibraryDelegate = new ProcessCustomClientDelegate(LogonApplication.getUserEntityObject());
        this.optType = optType;
        this.funcObj = funcObj;
        this.processCategoryObject = processCategoryObject;
        
        init();
//        checkPermission();
    }
    
    private void init() throws VCIException {
        initPanelContent();
        if (optType.equals("create")) {
            this.setTitle("创建模板分类");
        } else if (optType.equals("modify")) {
            this.setTitle("编辑模板分类");
            this.setUIContent();
        }
        addListener();
        setSize(340, 280);
        centerToScreen();
    }
    
    /**
     * <p>Description: 初始所有UI元素</p>
     */
    private void initPanelContent() {
        JPanel panel = new JPanel();
        getContentPane().add(panel, BorderLayout.CENTER);
        GridBagLayout gbl_panel = new GridBagLayout();
        panel.setLayout(gbl_panel);
        
        JLabel lblNewLabel = new JLabel("名称");
        GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
        gbc_lblNewLabel.anchor = GridBagConstraints.EAST;
        gbc_lblNewLabel.insets = new Insets(0, 0, 5, 5);
        gbc_lblNewLabel.gridx = 0;
        gbc_lblNewLabel.gridy = 0;
        panel.add(lblNewLabel, gbc_lblNewLabel);
        
        GridBagConstraints gbc_textField = new GridBagConstraints();
        gbc_textField.insets = new Insets(0, 0, 5, 0);
        gbc_textField.fill = GridBagConstraints.HORIZONTAL;
        gbc_textField.gridx = 1;
        gbc_textField.gridy = 0;
        panel.add(nameField, gbc_textField);
        
//        JLabel lblNewLabel_2 = new JLabel("选择图标");
//        GridBagConstraints gbc_lblNewLabel_2 = new GridBagConstraints();
//        gbc_lblNewLabel_2.anchor = GridBagConstraints.EAST;
//        gbc_lblNewLabel_2.insets = new Insets(0, 0, 5, 5);
//        gbc_lblNewLabel_2.gridx = 0;
//        gbc_lblNewLabel_2.gridy = 1;
//        panel.add(lblNewLabel_2, gbc_lblNewLabel_2);
        
//        GridBagConstraints gbc_textField_2 = new GridBagConstraints();
//        gbc_textField_2.insets = new Insets(0, 0, 5, 0);
//        gbc_textField_2.fill = GridBagConstraints.HORIZONTAL;
//        gbc_textField_2.gridx = 1;
//        gbc_textField_2.gridy = 1;
//        panel.add(selectIconBtn, gbc_textField_2);
        
        JLabel descLabel = new JLabel("描述");
        GridBagConstraints descLabelGbc = new GridBagConstraints();
        descLabelGbc.anchor = GridBagConstraints.NORTHEAST;
        descLabelGbc.insets = new Insets(0, 0, 0, 5);
        descLabelGbc.gridx = 0;
        descLabelGbc.gridy = 1;
        panel.add(descLabel, descLabelGbc);
 
        descArea = new JTextArea(5, 20);
        JScrollPane scrollPane = new JScrollPane(descArea);
        GridBagConstraints gbc_scrollPane = new GridBagConstraints();
        gbc_scrollPane.fill = GridBagConstraints.BOTH;
        gbc_scrollPane.gridx = 1;
        gbc_scrollPane.gridy = 1;
        panel.add(scrollPane, gbc_scrollPane);
        
        JPanel btnPanel = new JPanel();
        btnPanel.add(okBtn);
        btnPanel.add(cancelBtn);
        getContentPane().add(btnPanel, BorderLayout.SOUTH);
    }
    
    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);
    }
    
    /**
     * <p>Description: 初始化所有按钮关联的操作监听</p>
     */
    private void addListener() {
        selectIconBtn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                selectIcon();
            }
        });
 
        okBtn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                ok();
            }
        });
 
        cancelBtn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                close();
            }
        });
    }
    
    private void selectIcon() {
        String title = getI18nString("lblIcon");
        IconSelectDialog iconDialog = new IconSelectDialog(title, true, optType, selectIconBtn);
        iconDialog.setVisible(true);
    }
 
    private void ok() {
        if(optType.equalsIgnoreCase("create")){
            ProcessCategoryObject object = getCreateProcessCategory();
            if (!checkProcessCategoryData(object)) {
                return;
            }
            String parentId = "root";
//            Object currentSelectedObject = getOperate().getToolBar().getMainPanel().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);
//                operate.getToolBar().getMainPanel().addNewObjectToTree(object);
                close();
            } 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 = getOperate().getToolBar().getMainPanel().getCurrentSelectedObject();
//            if (currentSelectedObject instanceof ProcessCategoryObject) {
//                parentId = ((ProcessCategoryObject)currentSelectedObject).getParentId();
//            };
            object.setParentId(parentId);
            try {
                if(!checkNameExisted(object)) return;
                preferLibraryDelegate.updateProcessCategory(object);
//                operate.getToolBar().getMainPanel().refreshModifyObjectToTree(object);
                close();
            } 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());
        }
        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;
    }
    
    private void close() {
        this.dispose();
        this.setVisible(false);
    }
 
    public ProcessCategoryObject getCreateProcessCategory() {
        return getProcessCategoryFromUIControl();
    }
    
    public ProcessCategoryObject getModifyProcessCategory() {
        ProcessCategoryObject obj = getProcessCategoryFromUIControl();
        if (this.processCategoryObject != null) {
            obj.setId(this.processCategoryObject.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() {
        this.nameField.setText(this.processCategoryObject.getName());
        this.descArea.setText(this.processCategoryObject.getDesc());
        String icon = this.processCategoryObject.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());
    }
}