田源
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
package com.vci.client.workflow.template;
 
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.Locale;
import java.util.Map;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;
 
import com.vci.client.LogonApplication;
import com.vci.client.common.VCIBasePanel;
import com.vci.client.framework.rightConfig.object.FunctionObject;
import com.vci.client.framework.util.RightControlUtil;
import com.vci.client.ui.exception.VCIException;
import com.vci.client.ui.locale.LocaleDisplay;
import com.vci.client.ui.swing.VCIOptionPane;
import com.vci.client.ui.swing.VCISwingUtil;
import com.vci.client.ui.swing.components.VCIJButton;
import com.vci.client.ui.swing.components.VCIJPanel;
import com.vci.client.ui.swing.components.table.AbstractVCIJTableDataProvider;
import com.vci.client.ui.swing.components.table.VCIJTableNode;
import com.vci.client.ui.swing.components.table.VCIJTablePanel;
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;
 
public class ProcessCustomTypePanel extends VCIBasePanel{
    private static final long serialVersionUID = 1L;
    
    private VCIJButton addButton = VCISwingUtil.createVCIJButton("","增加" ,"增加" , "create.gif",null);
    private VCIJButton editButton = VCISwingUtil.createVCIJButton("","修改" ,"修改" , "modify.gif",null);
    private VCIJButton deleteButton = VCISwingUtil.createVCIJButton("","删除" ,"删除", "delete.gif" ,null);
   
    
    private String userName = LogonApplication.getUserEntityObject().getUserName();
    private LinkedList<VCIJButton> selfCustomButtons = new LinkedList<VCIJButton>();
    {
        selfCustomButtons.add(addButton);
        selfCustomButtons.add(editButton);
        selfCustomButtons.add(deleteButton);
    }
    
    public ProcessCustomTypePanel(FunctionObject funcObj){
        super(funcObj);
        init();
        checkPermission();
    }
    private void init() {
        LogonApplication.getUserEntityObject().setModules(this.getClass().getName());
        initComponents();
        initAction();//初始化按钮点击事件
    }
    private void initComponents() {
        setLayout(new BorderLayout());
        add(initTablePanel(), BorderLayout.CENTER);
    }
    
    private void checkPermission(){
        checkRight(RightControlUtil.CREATE, addButton);
        checkRight(RightControlUtil.UPDATE, editButton);
        checkRight(RightControlUtil.DELETE, deleteButton);
    }
    
    class MyDataProvider extends AbstractVCIJTableDataProvider<ProcessCategoryObject>{
 
        public ProcessCategoryObject[] getDatas(int arg0, int arg1) {
            ProcessCategoryObject[] processCategories = null;
            ProcessCategoryObject[] processCategoriesCount = null;
            try {
                ProcessCustomClientDelegate delSrv = new ProcessCustomClientDelegate(LogonApplication.getUserEntityObject());
                processCategoriesCount = delSrv.getProcessCategories("root");
                processCategories = delSrv.getProcessCategoriesByPage("root",arg1,arg0);
                this.total = processCategoriesCount.length;
            } catch (VCIException e) {
                e.printStackTrace();
            }
            return processCategories;
        }
 
        public VCIJTableNode<ProcessCategoryObject> getNewRowNode(ProcessCategoryObject dataObj) {
            VCIJTableNode<ProcessCategoryObject> node = new VCIJTableNode<ProcessCategoryObject>(dataObj);
            node.setPropertyValue(getSpecialColumns()[0], dataObj.getName());
            node.setPropertyValue(getSpecialColumns()[1], dataObj.getDesc());
            return node;
        }
 
        public String[] getSpecialColumns() {
            return "分类名称, 描述".split(",");
        }
 
        public int getTotal() {
            return this.total;
        }
        
    }
    
    MyDataProvider dataProvider = new MyDataProvider();
    VCIJTablePanel<ProcessCategoryObject> tablePanel = new VCIJTablePanel<ProcessCategoryObject>(dataProvider);
    private VCIJPanel tablePanel(){
        int startIndex = dataProvider.getDataColumnStartIndex();
        LinkedHashMap<Integer, Integer> widthMaps = new LinkedHashMap<Integer, Integer>();
        widthMaps.put(startIndex++, 250);widthMaps.put(startIndex++, 250);widthMaps.put(startIndex++, 250);
        tablePanel.setColumnWidthMaps(widthMaps);
        tablePanel.setCustomButtonFlowAlign(FlowLayout.CENTER);
        tablePanel.setPageButtonFlowAlign(FlowLayout.CENTER);
        tablePanel.setCustomButtons(selfCustomButtons);
        tablePanel.setShowPaging(false);
        tablePanel.setShowExport(false);
        tablePanel.buildTablePanel();
        tablePanel.refreshTableData();
        return tablePanel;
    }
 
    
    public JPanel initTablePanel(){
        
        JPanel pal = new JPanel();
        pal.setLayout(new BorderLayout());
        pal.setBorder(new TitledBorder("流程分类定义"));
        pal.add(tablePanel(), BorderLayout.CENTER);
        pal.setVisible(true);
        return pal;
    }
    
    /**
     * 事件
     */
    private void initAction(){
        addButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(ActionEvent e) {
                addButton_conform();
            }
        });
        
         editButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    editButton_conform();
                }
         });
         
         deleteButton.addActionListener(new java.awt.event.ActionListener() {
             public void actionPerformed(ActionEvent e) {
                 deleteButton_conform();
             }
         });
    }
    
    /**
     * 添加事件
     */
    private void addButton_conform(){
        showCreateDialog();
        tablePanel.refreshTableData();
    }
    
    private void showCreateDialog() {
        showProcessCategoryDialog("create",null);
    }
 
    private void showProcessCategoryDialog(String optType,ProcessCategoryObject obj) {
        try {
            ProcessCategoryTypeDialog dialog = new ProcessCategoryTypeDialog("",optType,obj,funcObj);
            dialog.setVisible(true);
        } catch (VCIException exp) {
            VCIOptionPane.showError(LogonApplication.frame, "RMIPWorkflow", exp);
        }
    }
    /**
     * 修改事件
     */
    private void editButton_conform(){
        
        int len = tablePanel.getSelectedRowIndexs().length;
        if(len == 0){
            VCIOptionPane.showMessage(this, 
                    "请选择数据再进行修改操作!");
            return;
        }
        if (len > 1){
            VCIOptionPane.showMessage(this, 
                    LocaleDisplay.getI18nString("rmip.stafforg.operate.deptedit2", "RMIPFramework", getLocale()));
            return;
        }
        ProcessCategoryObject obj = tablePanel.getSelectedRowObjects().get(0);
        showProcessCategoryDialog("modify", (ProcessCategoryObject) obj);
        tablePanel.refreshTableData();
    }
    /**
     * 删除事件
     */
    private void deleteButton_conform(){
        int len = tablePanel.getSelectedRowIndexs().length;
        if(len == 0){
            VCIOptionPane.showMessage(this, 
                    "请选择要删除的对象!");
            return;
        }
        String[] puids = new String[len];
 
        Map<String, String> map = new HashMap<String, String>();
        for (int i = 0; i < len; i++) {
            ProcessCategoryObject roleInfo = tablePanel.getSelectedRowObjects().get(i);
            puids[i] = roleInfo.getId();
            map.put(roleInfo.getId(), roleInfo.getName());
        }
        
        int ok=VCIOptionPane.showQuestion(LogonApplication.frame, ClientHelper
                .getI18nStringForWorkflow(this.getClass().getName() + "."
                        + "deleteProcessCategoryConfirmMessage",
                        getLocale()));
       
        if (ok == 0) {
            boolean rs=true;
            try {
//                ProcessCustomClientDelegate delegate = new ProcessCustomClientDelegate(LogonApplication.frame.getUserEntityObject());
//                rs = delegate.deleteProcessCategory(puids[0]);
                for(String id : puids){
                    ProcessCustomClientDelegate delegate = new ProcessCustomClientDelegate(LogonApplication.getUserEntityObject());
                    ProcessDefinitionObject[] processDefinitions = new ProcessCustomClientDelegate(LogonApplication.getUserEntityObject()).getProcessDefinitions(id);
                    if(processDefinitions.length>0){
                        VCIOptionPane.showMessage(LogonApplication.frame, "分类下有模板,请先删除模版!");
                        return;
                    }else{
                        rs = delegate.deleteProcessCategory(id);
                    }
                }
            } catch (VCIException e) {
                VCIOptionPane.showError(LogonApplication.frame, "RMIPWorkflow", e);
                e.printStackTrace();
            }
            if (!rs) {
                return;
            }
        }else{
            return;
        }
        tablePanel.refreshTableData();
    }
    
    private String getI18nString(String spCode){
        return ClientHelper.getI18nStringForWorkflow(this.getClass().getName() + "." + spCode, Locale.getDefault());
    }
}