/*******************************************************************************
|
* @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.
|
******************************************************************************/
|