package com.vci.client.workflow.editor.ui;
|
|
import java.awt.BorderLayout;
|
import java.awt.GridBagConstraints;
|
import java.awt.GridBagLayout;
|
import java.awt.Insets;
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
import javax.swing.JComponent;
|
import javax.swing.JLabel;
|
import javax.swing.JPanel;
|
import javax.swing.JTabbedPane;
|
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.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;
|
import com.vci.corba.workflow.data.ProcessTaskInfo;
|
import com.vci.corba.workflow.data.PropertyInfo;
|
|
/**
|
* 路由功能类
|
* @author liudi
|
*
|
* 2013-4-27
|
*/
|
public class TransitionPanel extends JTabbedPane implements IProcessProperty {
|
|
private static final long serialVersionUID = 1724948299848339422L;
|
|
private JTextField nameField;
|
private mxGraph graph;
|
private FlowNode node;
|
|
private TaskEventPanel transitionInitEventPropertyPanel;
|
private EventPanel transitionEndEventPropertyPanel;
|
|
public PropertyInfo[] transmTrainsitionInfo_start;
|
public PropertyInfo[] transmTrainsitionInfo_end;
|
public String transTrainsitionEnevtType_Start;
|
public String transTrainsitionEnevtType_End;
|
private TrainsitionDescPanel trainsitionDescPanel;
|
|
private static Map<String,PropertyObject[]> eventTypes=new HashMap<String,PropertyObject[]>();
|
public TransitionPanel(mxGraph graph, FlowNode node) throws VCIError {
|
super(JTabbedPane.LEFT);
|
this.graph = graph;
|
this.node = node;
|
|
addTab("基本属性", getGeneralPanel(node));
|
addTab("事件", getEventPanel());
|
addTab("业务功能", getTaskDesPanel());
|
|
//2013-4-27 添加自定义路由事件
|
// GridBagConstraints gbc_eventPanel = new GridBagConstraints();
|
// gbc_eventPanel.fill = GridBagConstraints.BOTH;
|
// gbc_eventPanel.gridx = 0;
|
// gbc_eventPanel.gridy = 1;
|
// gbc_eventPanel.weightx = 2;
|
// gbc_eventPanel.gridwidth = 2;
|
// gbc_eventPanel.gridheight=10;
|
// add(getEventPanel(), gbc_eventPanel);
|
|
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);
|
}
|
|
private JComponent getGeneralPanel(FlowNode node) {
|
JPanel generalPanel = new JPanel(new GridBagLayout());
|
GridBagLayout gridBagLayout = new GridBagLayout();
|
gridBagLayout.columnWidths = new int[]{0, 0, 0};
|
gridBagLayout.rowHeights = new int[]{0, 0};
|
gridBagLayout.columnWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
|
gridBagLayout.rowWeights = new double[]{0.0, Double.MIN_VALUE};
|
generalPanel.setLayout(gridBagLayout);
|
|
JLabel lblNewLabel = new JLabel("名称:");
|
GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
|
gbc_lblNewLabel.insets = new Insets(0, 0, 0, 5);
|
gbc_lblNewLabel.anchor = GridBagConstraints.EAST;
|
gbc_lblNewLabel.gridx = 0;
|
gbc_lblNewLabel.gridy = 0;
|
generalPanel.add(lblNewLabel, gbc_lblNewLabel);
|
|
nameField = new JTextField();
|
nameField.setText(node.getName());
|
GridBagConstraints gbc_textField = new GridBagConstraints();
|
gbc_textField.fill = GridBagConstraints.HORIZONTAL;
|
gbc_textField.gridx = 1;
|
gbc_textField.gridy = 0;
|
generalPanel.add(nameField, gbc_textField);
|
|
JPanel resultPanel = new JPanel(new BorderLayout());
|
resultPanel.add(generalPanel, BorderLayout.NORTH);
|
return resultPanel;
|
}
|
|
private JPanel getTaskDesPanel() {
|
trainsitionDescPanel = new TrainsitionDescPanel();
|
return trainsitionDescPanel;
|
}
|
|
protected void updateFlow() {
|
graph.refresh();
|
}
|
|
@Override
|
public String toString() {
|
return nameField.getText().trim();
|
}
|
|
public String getNodeType() {
|
return node.getType();
|
}
|
|
public void createAttribute(Element owner) throws VCIError {
|
// Attribute attributeName = DocumentHelper.createAttribute(owner, FlowConstants.XMLNAME, nameField.getText());
|
// owner.add(attributeName);
|
|
getTrainsitionXml(owner, transitionInitEventPropertyPanel,"trainsition");
|
|
createTransitionEventXml(owner,
|
transmTrainsitionInfo_start,
|
FlowConstants.TRANSITION_EVENT);
|
|
String urlText = trainsitionDescPanel.getUrlTextArea().getText().trim();
|
if(urlText!=null&&!"".equals(urlText)){
|
Attribute attributeKey = DocumentHelper.createAttribute(owner, FlowConstants.URL_PATH, urlText);
|
owner.add(attributeKey);
|
}
|
}
|
|
public void setValue(String text) {
|
nameField.setText(text);
|
}
|
|
/**
|
* 2013-4-27 添加自定义路由事件
|
* @return
|
* @throws VCIError
|
*/
|
private JComponent getEventPanel() throws VCIError {
|
// JTabbedPane eventPanel = new JTabbedPane();
|
transitionInitEventPropertyPanel = new TaskEventPanel("事件", getEventTypes("trainsition"),"trainsition");
|
// eventPanel.add("事件", transitionInitEventPropertyPanel);
|
return transitionInitEventPropertyPanel;
|
}
|
|
private PropertyObject[] getEventTypes(String eventType) throws VCIError {
|
/*String[] types = EventProperties.getStringProperty("workflow.event.type."+eventType).split(",");*/
|
//add by caill start 2016.4.8 通过corba连接服务端
|
if(eventTypes.get(eventType)!=null){
|
return eventTypes.get(eventType);
|
}else{
|
String[] types = null;
|
try {
|
types = new EventConfClientDelegate().getStringProperty("workflow.event.type."+eventType).split(",");
|
} catch (VCIError e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
throw e;
|
}
|
//add by caill end
|
List<PropertyObject> taskTypes = new ArrayList<PropertyObject>();
|
taskTypes.add(new PropertyObject("", ""));
|
for (int i = 0; i < types.length; i++) {
|
/*taskTypes.add(new PropertyObject(types[i], EventProperties.getStringProperty("workflow.event.type." + types[i])));*/
|
//add by caill start 2016.4.8 通过corba连接服务端
|
try {
|
taskTypes.add(new PropertyObject(types[i], new EventConfClientDelegate().getStringProperty("workflow.event.type." + types[i])));
|
} catch (VCIError e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
throw e;
|
}
|
//add by caill end
|
}
|
eventTypes.put(eventType, taskTypes.toArray(new PropertyObject[0]));
|
return taskTypes.toArray(new PropertyObject[0]);
|
}
|
}
|
|
private String getI18nForEvent(String key){
|
return LocaleDisplay.getI18nString(key, "RMIPWorkflow", getLocale());
|
}
|
|
private void getTrainsitionXml(Element owner, TaskEventPanel eventPanel, String eventType) {
|
PropertyInfo[] customClassInfo = eventPanel.getCustomInfos();
|
if (customClassInfo.length > 0) {
|
transmTrainsitionInfo_start = customClassInfo;
|
}else{
|
transmTrainsitionInfo_start = new PropertyInfo[0];
|
}
|
}
|
public void setEventInfo(ProcessTaskInfo processTaskInfo, String eventType) {
|
updateTransitionType(processTaskInfo);
|
transitionInitEventPropertyPanel.setProcessTaskInfo(processTaskInfo);
|
}
|
public void setCustomClassInfo( String eventType,PropertyInfo[] customInfos) throws VCIError{
|
int length = getEventTypes("trainsition").length;
|
PropertyInfo[] res = new PropertyInfo[customInfos.length];
|
for(int j = 0;j<customInfos.length;j++){
|
for(int i=0;i<length;i++){
|
PropertyObject propertyObject = getEventTypes("trainsition")[i];
|
PropertyInfo propertyInfo = new PropertyInfo();
|
/*String eventClass = EventProperties.getStringProperty("workflow.event.type."
|
+ propertyObject.getProperty() + ".class");*/
|
//add by caill start 2016.4.8 通过corba连接服务端
|
String eventClass = null;
|
try {
|
eventClass = new EventConfClientDelegate().getStringProperty("workflow.event.type."
|
+ propertyObject.getProperty() + ".class");
|
} catch (VCIError e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
}
|
//add by caill end
|
if(eventClass.equals(customInfos[j].property)){
|
propertyInfo.property = propertyObject.getValue();
|
res[j] = propertyInfo;
|
}
|
}
|
}
|
transitionInitEventPropertyPanel.setCustomInfos(res);
|
}
|
|
private void updateTransitionType(ProcessTaskInfo processTaskInfo) {
|
/*String[] types = EventProperties.getStringProperty("workflow.event.type").split(",");*/
|
//add by caill start 2016.4.8 通过corba连接服务端
|
String[] types = null;
|
try {
|
types = new EventConfClientDelegate().getStringProperty("workflow.event.type").split(",");
|
} catch (VCIError e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
}
|
//add by caill end
|
for (int i = 0; i < types.length; i++) {
|
/*String eventClass = EventProperties.getStringProperty("workflow.event.type." + types[i] + ".class");*/
|
//add by caill start 2016.4.8 通过corba连接服务端
|
String eventClass = null;
|
try {
|
eventClass = new EventConfClientDelegate().getStringProperty("workflow.event.type." + types[i] + ".class");
|
} catch (VCIError e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
}
|
//add by caill end
|
if(processTaskInfo.taskType.equals(eventClass)){
|
processTaskInfo.taskType = types[i];
|
return;
|
}
|
}
|
|
}
|
|
/**
|
* 添加路由事件 2013-4-27
|
*
|
* @param owner
|
* @param transmTrainsitionInfo
|
* @param eventType
|
* @throws VCIError
|
*/
|
private void createTransitionEventXml(Element owner,
|
PropertyInfo[] transmTrainsitionInfo, String eventType) throws VCIError {
|
// Element onElement = owner.addElement(FlowConstants.EVENT_ON);
|
// Attribute startAttribute = DocumentHelper.createAttribute(owner,
|
// FlowConstants.EVENT, eventType);
|
// onElement.add(startAttribute);
|
|
String result = "";
|
if(transmTrainsitionInfo==null){
|
return;
|
}
|
PropertyObject[] eventTypes=getEventTypes("trainsition");
|
for (int k = 0; k < transmTrainsitionInfo.length; k++) {
|
for (int j = 0; j < eventTypes.length; j++) {
|
String className = transmTrainsitionInfo[k].property;
|
String classValue = "";
|
if (eventTypes[j].getValue().equals(className)) {
|
classValue = eventTypes[j].getProperty();
|
Map<String, Map<String, ArrayList<PropertyInfo>>> resultMap = transitionInitEventPropertyPanel.getResultMap();
|
Map<String, ArrayList<PropertyInfo>> eventAndParamMap = resultMap.get("trainsition");
|
/*String initEventClass = EventProperties.getStringProperty("workflow.event.type."
|
+ classValue + ".class");*/
|
//add by caill start 2016.4.8 通过corba连接服务端
|
String initEventClass = null;
|
try {
|
initEventClass = new EventConfClientDelegate().getStringProperty("workflow.event.type."
|
+ classValue + ".class");
|
} catch (VCIError e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
}
|
//add by caill end
|
ArrayList<PropertyInfo> paramList = new ArrayList<PropertyInfo>();
|
if(eventAndParamMap!=null){
|
paramList = eventAndParamMap.get(initEventClass);
|
}
|
Element listenerElement = owner
|
.addElement(FlowConstants.EVENT_LISTENER);
|
Attribute classAttribute = DocumentHelper.createAttribute(
|
owner, FlowConstants.EVENT_CLASS, initEventClass);
|
listenerElement.add(classAttribute);
|
if(paramList!=null){
|
for (int p = 0; p < paramList.size(); p++) {
|
Element fieldElement = listenerElement.addElement(FlowConstants.EVENT_FIELD);
|
Attribute nameAttribute = DocumentHelper.createAttribute(owner, FlowConstants.XMLNAME, paramList.get(p).property);
|
fieldElement.add(nameAttribute);
|
|
Element stringElement = fieldElement.addElement(FlowConstants.EVENT_STRING);
|
Attribute valueAttribute = DocumentHelper.createAttribute(owner, FlowConstants.EVENT_VALUE, paramList.get(p).value);
|
stringElement.add(valueAttribute);
|
}
|
}
|
}
|
}
|
}
|
}
|
|
private Map<String,ArrayList<PropertyInfo>> taskeventMap ;
|
private Map<String ,Map<String,ArrayList<PropertyInfo>>> resultMap ;
|
public Map<String, ArrayList<PropertyInfo>> getTaskeventMap() {
|
return taskeventMap;
|
}
|
|
public void setTaskeventMap(Map<String, ArrayList<PropertyInfo>> taskeventMap) {
|
this.taskeventMap = taskeventMap;
|
}
|
|
public Map<String, Map<String, ArrayList<PropertyInfo>>> getResultMap() {
|
return resultMap;
|
}
|
|
public void setResultMap(String eventType,
|
Map<String, Map<String, ArrayList<PropertyInfo>>> resultMap) {
|
this.resultMap = resultMap;
|
transitionInitEventPropertyPanel.setTaskeventMap(resultMap.get("trainsition"));
|
}
|
|
/**
|
* @param taskDesc
|
*/
|
public void setTrainsitionDescPanel(String urlTextArea) {
|
// trainsitionDescPanel.setTaskDesArea(taskDesc);
|
trainsitionDescPanel.setUrlTextArea(urlTextArea);
|
}
|
}
|