/machinelearning/5.0.x/drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/flow/ruleflow/core/SubProcessWrapper.java

https://github.com/droolsjbpm/droolsjbpm-contributed-experiments · Java · 135 lines · 102 code · 13 blank · 20 comment · 30 complexity · 40f5def1247a06aa85e2838cbbfcaf4e MD5 · raw file

  1. package org.drools.eclipse.flow.ruleflow.core;
  2. /*
  3. * Copyright 2005 JBoss Inc
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. import java.util.HashMap;
  18. import java.util.Map;
  19. import org.drools.eclipse.flow.common.editor.core.ElementConnection;
  20. import org.drools.eclipse.flow.common.editor.core.ElementWrapper;
  21. import org.drools.eclipse.flow.ruleflow.view.property.subprocess.SubProcessParameterInMappingPropertyDescriptor;
  22. import org.drools.eclipse.flow.ruleflow.view.property.subprocess.SubProcessParameterOutMappingPropertyDescriptor;
  23. import org.drools.workflow.core.node.SubProcessNode;
  24. import org.eclipse.ui.views.properties.ComboBoxPropertyDescriptor;
  25. import org.eclipse.ui.views.properties.IPropertyDescriptor;
  26. import org.eclipse.ui.views.properties.TextPropertyDescriptor;
  27. /**
  28. * Wrapper for a SubFlow node.
  29. *
  30. * @author <a href="mailto:kris_verlaenen@hotmail.com">Kris Verlaenen</a>
  31. */
  32. public class SubProcessWrapper extends EventBasedNodeWrapper {
  33. private static final long serialVersionUID = 3668348577732020324L;
  34. public static final String PROCESS_ID = "ProcessId";
  35. public static final String WAIT_FOR_COMPLETION = "WaitForCompletion";
  36. public static final String INDEPENDENT = "Independent";
  37. public static final String PARAMETER_IN_MAPPING = "ParameterInMapping";
  38. public static final String PARAMETER_OUT_MAPPING = "ParameterOutMapping";
  39. public SubProcessWrapper() {
  40. setNode(new SubProcessNode());
  41. getSubProcessNode().setName("SubProcess");
  42. }
  43. protected void initDescriptors() {
  44. super.initDescriptors();
  45. IPropertyDescriptor[] oldDescriptors = descriptors;
  46. descriptors = new IPropertyDescriptor[oldDescriptors.length + 7];
  47. System.arraycopy(oldDescriptors, 0, descriptors, 0, oldDescriptors.length);
  48. descriptors[descriptors.length - 7] = getOnEntryPropertyDescriptor();
  49. descriptors[descriptors.length - 6] = getOnExitPropertyDescriptor();
  50. descriptors[descriptors.length - 5] =
  51. new SubProcessParameterInMappingPropertyDescriptor(PARAMETER_IN_MAPPING, "Parameter In Mapping", getSubProcessNode());
  52. descriptors[descriptors.length - 4] =
  53. new SubProcessParameterOutMappingPropertyDescriptor(PARAMETER_OUT_MAPPING, "Parameter Out Mapping", getSubProcessNode());
  54. descriptors[descriptors.length - 3] =
  55. new ComboBoxPropertyDescriptor(INDEPENDENT, "Independent", new String[] {"true", "false"});
  56. descriptors[descriptors.length - 2] =
  57. new TextPropertyDescriptor(PROCESS_ID, "ProcessId");
  58. descriptors[descriptors.length - 1] =
  59. new ComboBoxPropertyDescriptor(WAIT_FOR_COMPLETION, "Wait for completion", new String[] {"true", "false"});
  60. }
  61. public SubProcessNode getSubProcessNode() {
  62. return (SubProcessNode) getNode();
  63. }
  64. public boolean acceptsIncomingConnection(ElementConnection connection, ElementWrapper source) {
  65. return super.acceptsIncomingConnection(connection, source)
  66. && getIncomingConnections().isEmpty();
  67. }
  68. public boolean acceptsOutgoingConnection(ElementConnection connection, ElementWrapper target) {
  69. return super.acceptsOutgoingConnection(connection, target)
  70. && getOutgoingConnections().isEmpty();
  71. }
  72. public Object getPropertyValue(Object id) {
  73. if (PROCESS_ID.equals(id)) {
  74. String processId = getSubProcessNode().getProcessId();
  75. return processId == null ? "" : processId;
  76. }
  77. if (WAIT_FOR_COMPLETION.equals(id)) {
  78. return getSubProcessNode().isWaitForCompletion() ? new Integer(0) : new Integer(1);
  79. }
  80. if (INDEPENDENT.equals(id)) {
  81. return getSubProcessNode().isIndependent() ? new Integer(0) : new Integer(1);
  82. }
  83. if (PARAMETER_IN_MAPPING.equals(id)) {
  84. return getSubProcessNode().getInMappings();
  85. }
  86. if (PARAMETER_OUT_MAPPING.equals(id)) {
  87. return getSubProcessNode().getOutMappings();
  88. }
  89. return super.getPropertyValue(id);
  90. }
  91. public void resetPropertyValue(Object id) {
  92. if (PROCESS_ID.equals(id)) {
  93. getSubProcessNode().setProcessId("");
  94. } else if (WAIT_FOR_COMPLETION.equals(id)) {
  95. getSubProcessNode().setWaitForCompletion(true);
  96. } else if (INDEPENDENT.equals(id)) {
  97. getSubProcessNode().setIndependent(true);
  98. } else if (PARAMETER_IN_MAPPING.equals(id)) {
  99. getSubProcessNode().setInMappings(new HashMap<String, String>());
  100. } else if (PARAMETER_OUT_MAPPING.equals(id)) {
  101. getSubProcessNode().setOutMappings(new HashMap<String, String>());
  102. } else {
  103. super.resetPropertyValue(id);
  104. }
  105. }
  106. @SuppressWarnings("unchecked")
  107. public void setPropertyValue(Object id, Object value) {
  108. if (PROCESS_ID.equals(id)) {
  109. getSubProcessNode().setProcessId((String) value);
  110. } else if (WAIT_FOR_COMPLETION.equals(id)) {
  111. getSubProcessNode().setWaitForCompletion(((Integer) value).intValue() == 0);
  112. } else if (INDEPENDENT.equals(id)) {
  113. getSubProcessNode().setIndependent(((Integer) value).intValue() == 0);
  114. } else if (PARAMETER_IN_MAPPING.equals(id)) {
  115. getSubProcessNode().setInMappings((Map<String, String>) value);
  116. } else if (PARAMETER_OUT_MAPPING.equals(id)) {
  117. getSubProcessNode().setOutMappings((Map<String, String>) value);
  118. } else {
  119. super.setPropertyValue(id, value);
  120. }
  121. }
  122. }