wangting
2025-01-13 20a1d1809d95d3395403bf2517e49c7def65fedd
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
/*******************************************************************************
 * @project: platform
 * @package: com.vci.platform.cs.workflow.editor.ui
 * @file: DecisionPanel.java
 * @author: yinww
 * @created: 2012-2-16
 * @purpose:
 * 
 * @version: 1.0
 * 
 * Revision History at the end of file.
 * 
 * Copyright 2012 vci-tech All rights reserved.
 ******************************************************************************/
 
package com.vci.client.workflow.editor.ui;
 
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.ArrayList;
import java.util.List;
 
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
 
import org.dom4j.Attribute;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
 
import com.mxgraph.util.mxResources;
import com.mxgraph.view.mxGraph;
import com.vci.client.ui.locale.LocaleDisplay;
import com.vci.client.workflow.delegate.EventConfClientDelegate;
import com.vci.client.workflow.editor.FlowConstants;
import com.vci.client.workflow.editor.FlowNode;
import com.vci.corba.common.VCIError;
 
public class DecisionPanel extends JPanel implements IProcessProperty {
    
    private static final long serialVersionUID = 3501576995209608346L;
    
    private JTextField nameField;
    private JTextField expressionField;
    private JComboBox decisionComboBox;
    private mxGraph graph;
    private FlowNode node;
 
    public DecisionPanel(mxGraph graph, FlowNode node) {
        this.graph = graph;
        this.node = node;
        
        GridBagLayout gridBagLayout = new GridBagLayout();
        gridBagLayout.columnWidths = new int[]{0, 0, 0};
        gridBagLayout.rowHeights = new int[]{0, 0, 0, 0};
        gridBagLayout.columnWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
        gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, Double.MIN_VALUE};
        setLayout(gridBagLayout);
        
        JLabel lblNewLabel = new JLabel("名称:");
        GridBagConstraints g = new GridBagConstraints();
        g.insets = new Insets(5, 0, 0, 5);
        g.anchor = GridBagConstraints.EAST;
        g.gridx = 0;
        g.gridy = 0;
        add(lblNewLabel, g);
        JLabel exprLabel = new JLabel("条件表达式:");
        g.gridy = 1;
        add(exprLabel, g);
        g.gridy = 2;
        JLabel dealClass = new JLabel("处理类:");
        add(dealClass, g);
        
        nameField = new JTextField();
        nameField.setText(node.getName());
        nameField.setEditable(false);
        expressionField = new JTextField();
        expressionField.setEditable(false);
        expressionField.setText("#{content}");
        g.fill = GridBagConstraints.HORIZONTAL;
        g.gridx = 1;
        g.gridy = 0;
        add(nameField, g);
        g.gridy = 1;
        add(expressionField, g);
        g.gridy = 2;
        decisionComboBox = new JComboBox(getEventTypes());
        add(decisionComboBox, g);
 
        DocumentListener documentListener = new DocumentListener() {
            public void removeUpdate(DocumentEvent e) {
                updateFlow();
            }
            public void insertUpdate(DocumentEvent e) {
                updateFlow();
            }
            public void changedUpdate(DocumentEvent e) {
                updateFlow();
            }
        };
        nameField.getDocument().addDocumentListener(documentListener);
//        decisionComboBox.addItemListener(new ItemListener() {
//            public void itemStateChanged(ItemEvent e) {
//                if(e.getStateChange() == ItemEvent.SELECTED && decisionComboBox.getSelectedIndex() > 0) {
//                    expressionField.setText("");
//                }else{
//                    expressionField.setText("#{content}");
//                }
//            }
//        });
        decisionComboBox.addActionListener(new ActionListener() {
            
            public void actionPerformed(ActionEvent arg0) {
                KeyValueInfoWrapper keyValueInfoWrapper = (KeyValueInfoWrapper)decisionComboBox.getSelectedItem();
                KeyValueInfo keyValue = keyValueInfoWrapper.getKeyValue();
                if(keyValue.getValue()!=null&&!"".equals(keyValue.getValue())) {
                    expressionField.setText("");
                }else{
                    expressionField.setText("#{content}");
                }
            }
        });
        expressionField.getDocument().addDocumentListener(new DocumentListener() {
            public void removeUpdate(DocumentEvent e) {
                updateDecision();
            }
            
            public void insertUpdate(DocumentEvent e) {
                updateDecision();
            }
            
            public void changedUpdate(DocumentEvent e) {
                updateDecision();
            }
        });
    }
 
    private void updateDecision() {
        if(expressionField.getText().trim().length() > 0 && decisionComboBox.getSelectedIndex() > 0) {
            decisionComboBox.setSelectedIndex(0);
        }
    }
    
    private KeyValueInfoWrapper[] getEventTypes() {
//        String decisionFlag = "workflow.decision.type";
//        String eventTypes = mxResources.get(decisionFlag);
        /*String[] types = EventProperties.getStringProperty("workflow.decision.type").split(",");*/
        //add by caill start 2016.4.8 通过corba连接服务端
        String[] types = null;
        try {
            types = new EventConfClientDelegate().getStringProperty("workflow.decision.type").split(",");
        } catch (VCIError e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        //add by caill end
//        if(types != null) {
//            String[] types = eventTypes.split(",");
            List<KeyValueInfoWrapper> taskTypes = new ArrayList<KeyValueInfoWrapper>();
            taskTypes.add(new KeyValueInfoWrapper("", ""));
            for (int i = 0; i < types.length; i++) {
//                taskTypes.add(new KeyValueInfoWrapper(types[i], mxResources.get(decisionFlag + "." + types[i])));
                /*taskTypes.add(new KeyValueInfoWrapper(types[i],
                        EventProperties.getStringProperty("workflow.decision.type" + "." + types[i])));*/
                //add by caill start 2016.4.8 通过corba连接服务端
                try {
                    taskTypes.add(new KeyValueInfoWrapper(types[i],
                            new EventConfClientDelegate().getStringProperty("workflow.decision.type" + "." + types[i])));
                } catch (VCIError e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                //add by caill end
                
            }
            return taskTypes.toArray(new KeyValueInfoWrapper[0]);
//        }
        
//        return new KeyValueInfoWrapper[0]; 
    }
 
    protected void updateFlow() {
        String name = this.toString();
        node.setName(name);
        graph.refresh();
    }
    
    @Override
    public String toString() {
        return nameField.getText().trim();
    }
 
    public String getNodeType() {
        return node.getType();
    }
 
    public void createAttribute(Element owner) {
        String name = toString();
        if(name.length() > 0) {
            Attribute nameAttribute = DocumentHelper.createAttribute(owner, FlowConstants.XMLNAME, nameField.getText());
            owner.add(nameAttribute);
        }
        
        String expr = expressionField.getText().trim();
        if(expr.length() > 0) {
            Attribute exprAttribute = DocumentHelper.createAttribute(owner, FlowConstants.EXPRESSION, expr);
            owner.add(exprAttribute);
        } else {
            KeyValueInfoWrapper selectedDecision = (KeyValueInfoWrapper) decisionComboBox.getSelectedItem();
            if(selectedDecision.toString().length() > 0) {
                Element handlerElement = owner.addElement(FlowConstants.HANDLER);
                /*String handlerClass = EventProperties.getStringProperty("workflow.decision.type" + "." + selectedDecision.getKey()+".class");*/
//                //add by caill start 2016.4.8 通过corba连接服务端
                String handlerClass = null;
                try {
                     handlerClass = new EventConfClientDelegate().getStringProperty("workflow.decision.type" + "." + selectedDecision.getKey()+".class");
                } catch (VCIError e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                //add by caill end
                mxResources.get("workflow.decision.type." + selectedDecision.getKey() + ".class");
                Attribute classAttribute = DocumentHelper.createAttribute(handlerElement, FlowConstants.EVENT_CLASS, handlerClass);
                handlerElement.add(classAttribute);
            }
        }
        
    }
 
    public void setValue(String text) {
        expressionField.setText(text);
    }
 
    public void setHandlerClass(String handlerClass) {
        if(handlerClass != null && handlerClass.trim().length() > 0) {
            int itemCount = decisionComboBox.getItemCount();
            for (int i = 0; i < itemCount; i++) {
                KeyValueInfoWrapper obj = (KeyValueInfoWrapper)decisionComboBox.getItemAt(i);
//                String property = mxResources.get("workflow.decision.type." + obj.getKey() + ".class");
                /*String property = EventProperties.getStringProperty("workflow.decision.type" + "." + obj.getKey()+".class");*/
                //add by caill start 2016.4.8 通过corba连接服务端
                String property = null;
                try {
                     property = new EventConfClientDelegate().getStringProperty("workflow.decision.type" + "." + obj.getKey()+".class");
                } catch (VCIError e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                //add by caill end
                if(property != null && property.equals(handlerClass)) {
                    decisionComboBox.setSelectedIndex(i);
                    break;
                }
            }
            
        }
    }
    
    private String getI18nForEvent(String key) {
        return LocaleDisplay.getI18nString(key, "RMIPWorkflow", getLocale());
    }
}
 
/*******************************************************************************
 * <B>Revision History</B><BR>
 * [type 'revision' and press Alt + / to insert revision block]<BR>
 * 
 * 
 * 
 * Copyright 2012 vci-tech All rights reserved.
 ******************************************************************************/