catch up with branch daily

Signed-off-by: Ralf Mollik <ramollik@compex-commerce.com>
diff --git a/org.eclipse.osbp.autowireHelper/src/org/eclipse/osbp/autowirehelper/AutowireHelper.xtend b/org.eclipse.osbp.autowireHelper/src/org/eclipse/osbp/autowirehelper/AutowireHelper.xtend
index 18a4b51..20fa870 100644
--- a/org.eclipse.osbp.autowireHelper/src/org/eclipse/osbp/autowirehelper/AutowireHelper.xtend
+++ b/org.eclipse.osbp.autowireHelper/src/org/eclipse/osbp/autowirehelper/AutowireHelper.xtend
@@ -99,6 +99,7 @@
 import org.eclipse.xtext.util.concurrent.IUnitOfWork
 import org.eclipse.osbp.runtime.common.layouting.IPropertyConstants
 import org.eclipse.xtext.common.types.JvmField
+import org.eclipse.osbp.runtime.common.annotations.TargetEnumConstraints
 
 @SuppressWarnings("restriction")
 class AutowireHelper implements IAutowireDelegate {
@@ -904,12 +905,21 @@
 				val depth = toFilterDepth(info.field)
 				suspect.properties.put(IPropertyConstants.PROPERTY__FILTER_DEPTH, Integer.toString(depth))
 			}
-
+			
+			if(info.hasAnnotation(TargetEnumConstraints)) {
+				val containerType = info.field.eContainer as JvmGenericType
+				suspect.properties.put("TargetEnumRefClass", containerType.fullyQualifiedName.toString);
+				suspect.properties.put("TargetEnumRefField", info.field.simpleName);
+			}
+			
 			suspect.typeQualifiedName = type.qualifiedName
 			suspect.properties.put(IPropertyConstants.PROPERTY__ITEM_CAPTION, captionProperty)
 			suspect.properties.put(IPropertyConstants.PROPERTY__ITEM_DESCRIPTION, captionDescription)
 		}
 
+
+		
+
 		suspect
 	}
 
diff --git a/org.eclipse.osbp.autowireHelper/src/org/eclipse/osbp/autowirehelper/utils/AutowireUtil.xtend b/org.eclipse.osbp.autowireHelper/src/org/eclipse/osbp/autowirehelper/utils/AutowireUtil.xtend
index 5988a29..2b692f7 100644
--- a/org.eclipse.osbp.autowireHelper/src/org/eclipse/osbp/autowirehelper/utils/AutowireUtil.xtend
+++ b/org.eclipse.osbp.autowireHelper/src/org/eclipse/osbp/autowirehelper/utils/AutowireUtil.xtend
@@ -14,13 +14,14 @@
  * 
  * 
  *  This copyright notice shows up in the generated Java code
- *
+ * 
  */
- 
+
 package org.eclipse.osbp.autowirehelper.utils
 
 import java.util.List
 import java.util.Map
+import java.util.function.Function
 import javax.inject.Inject
 import org.apache.commons.lang.StringEscapeUtils
 import org.eclipse.osbp.dsl.semantic.common.types.LDataType
@@ -39,20 +40,24 @@
 import org.eclipse.osbp.ecview.semantic.uimodel.UiModel
 import org.eclipse.osbp.ecview.semantic.uimodel.UiView
 import org.eclipse.osbp.ecview.semantic.uimodel.impl.UiViewImpl
+import org.eclipse.osbp.runtime.common.annotations.CompareType
 import org.eclipse.osbp.runtime.common.annotations.DomainDescription
 import org.eclipse.osbp.runtime.common.annotations.DomainKey
+import org.eclipse.osbp.runtime.common.annotations.FilterDepth
 import org.eclipse.osbp.runtime.common.annotations.Properties
+import org.eclipse.osbp.runtime.common.annotations.TargetEnumConstraints
 import org.eclipse.osbp.utils.common.EntityUtils
 import org.eclipse.xtext.common.types.JvmAnnotationAnnotationValue
 import org.eclipse.xtext.common.types.JvmAnnotationReference
 import org.eclipse.xtext.common.types.JvmDeclaredType
+import org.eclipse.xtext.common.types.JvmEnumAnnotationValue
 import org.eclipse.xtext.common.types.JvmField
+import org.eclipse.xtext.common.types.JvmIntAnnotationValue
 import org.eclipse.xtext.common.types.JvmStringAnnotationValue
 import org.eclipse.xtext.common.types.JvmType
+import org.eclipse.xtext.common.types.JvmTypeAnnotationValue
 import org.eclipse.xtext.common.types.util.TypeReferences
 import org.eclipse.xtext.naming.IQualifiedNameProvider
-import org.eclipse.xtext.common.types.JvmIntAnnotationValue
-import org.eclipse.osbp.runtime.common.annotations.FilterDepth
 
 class AutowireUtil {
 	@Inject extension IQualifiedNameProvider
@@ -100,8 +105,8 @@
 	}
 
 	/**
-		 * Detects all the existing properties of the jvmtype corresponding attribute, the datatype of the attribute and references. 
-		 */
+	 * Detects all the existing properties of the jvmtype corresponding attribute, the datatype of the attribute and references. 
+	 */
 	public def List<Pair> toProperties(JvmDeclaredType type, String attributeName) {
 		val result = type.toFieldProperties.get(attributeName)
 		if (result != null) {
@@ -140,22 +145,60 @@
 
 		return propMap
 	}
-	
+
 	/**
 	 * Returns the depth of the filter for BeanReferenceFields
 	 */
 	public def int toFilterDepth(JvmField field) {
-			val ref = field.annotations.findFirst[ e |
-				val result = e.annotation.identifier.equals(typeof(FilterDepth).name)
-				return result
-			]
-			
-			if(ref === null) {
-				return 0
-			}
+		val ref = field.annotations.findFirst [ e |
+			val result = e.annotation.identifier.equals(typeof(FilterDepth).name)
+			return result
+		]
 
-			val JvmIntAnnotationValue depthVal = ref.values.get(0) as JvmIntAnnotationValue
-			return depthVal.values.get(0)
+		if (ref === null) {
+			return 0
+		}
+
+		val JvmIntAnnotationValue depthVal = ref.values.get(0) as JvmIntAnnotationValue
+		return depthVal.values.get(0)
+	}
+
+	/**
+	 * Returns info about the TargetEnumConstraints annotation.
+	 * 
+	 * usage:
+	 * 				
+				val targets = toEnumReferenceConstraint(info.field, [
+					return computer.loadClass(uiLayout?.eResource?.resourceSet, it.qualifiedName)
+				])
+	 
+	 * 
+	 * 
+	 */
+	public def List<TargetEnumProps> toEnumReferenceConstraint(JvmField jvmField,
+		Function<JvmType, Class<?>> typeProvider) {
+		val List<TargetEnumProps> targets = newArrayList;
+		jvmField.annotations.filter [ e |
+			val result = e.annotation.identifier.equals(typeof(TargetEnumConstraints).name)
+			return result
+		].forEach [
+			val JvmAnnotationReference ref = it;
+			ref.values.map[it as JvmAnnotationAnnotationValue].forEach [ av |
+				av.values.forEach [
+					val target = new TargetEnumProps
+					target.targetProperty = (it.values.get(0) as JvmStringAnnotationValue).values.get(0)
+					val enumClassJvmType = (it.values.get(1) as JvmTypeAnnotationValue).values.get(0)
+					target.enumClass = typeProvider.apply(enumClassJvmType.type)
+
+					target.enumLiteral = (it.values.get(2) as JvmStringAnnotationValue).values.get(0)
+					target.compareType = CompareType.valueOf(
+						(it.values.get(3) as JvmEnumAnnotationValue).values.get(0).simpleName)
+					targets += target
+				]
+			]
+		]
+
+		return targets
 	}
 
 	/**
@@ -224,7 +267,7 @@
 			} else if (uiBeanSlot.jvmType.type != null) {
 
 				// Temporary solution till final solution found.
-				//					eName = uiBeanSlot.jvmType.type.toString
+				// eName = uiBeanSlot.jvmType.type.toString
 				eName = ""
 			}
 		} else {
@@ -287,8 +330,8 @@
 				}
 			}
 		}
-		for (superType : type.superTypes){
-			if (superType.type instanceof JvmDeclaredType){
+		for (superType : type.superTypes) {
+			if (superType.type instanceof JvmDeclaredType) {
 				return isAnnotationOf((superType.type as JvmDeclaredType), clazz)
 			}
 		}
@@ -306,4 +349,35 @@
 
 	}
 
+	public static class TargetEnumProps {
+		/**
+		 * The property of the target type of the reference that must match the enum
+		 * literal.
+		 * 
+		 * @return the string
+		 */
+		String targetProperty;
+
+		/**
+		 * The enum class used to get the enum literal.
+		 * 
+		 * @return the class
+		 */
+		Class<?> enumClass;
+
+		/**
+		 * The name of the enum literal that is used as a filter.
+		 * 
+		 * @return the string
+		 */
+		String enumLiteral;
+
+		/**
+		 * The compareType used to execute the filter.
+		 * 
+		 * @return the compare type
+		 */
+		CompareType compareType = CompareType.EQUALS;
+	}
+
 }
diff --git a/org.eclipse.osbp.autowireHelper/xtend-gen/org/eclipse/osbp/autowirehelper/AutowireHelper.java b/org.eclipse.osbp.autowireHelper/xtend-gen/org/eclipse/osbp/autowirehelper/AutowireHelper.java
index 0e334b7..71da61e 100644
--- a/org.eclipse.osbp.autowireHelper/xtend-gen/org/eclipse/osbp/autowirehelper/AutowireHelper.java
+++ b/org.eclipse.osbp.autowireHelper/xtend-gen/org/eclipse/osbp/autowirehelper/AutowireHelper.java
@@ -96,6 +96,7 @@
 import org.eclipse.osbp.runtime.common.annotations.DomainKey;
 import org.eclipse.osbp.runtime.common.annotations.FilterDepth;
 import org.eclipse.osbp.runtime.common.annotations.OnKanbanCard;
+import org.eclipse.osbp.runtime.common.annotations.TargetEnumConstraints;
 import org.eclipse.osbp.runtime.common.annotations.UniqueEntry;
 import org.eclipse.osbp.runtime.common.layouting.IPropertyConstants;
 import org.eclipse.osbp.utils.functionnormalizer.api.FunctionTypingAPI;
@@ -1355,6 +1356,13 @@
           final int depth = this._autowireUtil.toFilterDepth(info.getField());
           suspect.getProperties().put(IPropertyConstants.PROPERTY__FILTER_DEPTH, Integer.toString(depth));
         }
+        boolean _hasAnnotation_1 = info.hasAnnotation(TargetEnumConstraints.class);
+        if (_hasAnnotation_1) {
+          EObject _eContainer = info.getField().eContainer();
+          final JvmGenericType containerType = ((JvmGenericType) _eContainer);
+          suspect.getProperties().put("TargetEnumRefClass", this._iQualifiedNameProvider.getFullyQualifiedName(containerType).toString());
+          suspect.getProperties().put("TargetEnumRefField", info.getField().getSimpleName());
+        }
         suspect.setTypeQualifiedName(type.getQualifiedName());
         suspect.getProperties().put(IPropertyConstants.PROPERTY__ITEM_CAPTION, captionProperty);
         suspect.getProperties().put(IPropertyConstants.PROPERTY__ITEM_DESCRIPTION, captionDescription);
diff --git a/org.eclipse.osbp.autowireHelper/xtend-gen/org/eclipse/osbp/autowirehelper/utils/AutowireUtil.java b/org.eclipse.osbp.autowireHelper/xtend-gen/org/eclipse/osbp/autowirehelper/utils/AutowireUtil.java
index aff31e3..bf71f19 100644
--- a/org.eclipse.osbp.autowireHelper/xtend-gen/org/eclipse/osbp/autowirehelper/utils/AutowireUtil.java
+++ b/org.eclipse.osbp.autowireHelper/xtend-gen/org/eclipse/osbp/autowirehelper/utils/AutowireUtil.java
@@ -21,6 +21,7 @@
 import java.util.List;
 import java.util.Map;
 import java.util.function.Consumer;
+import java.util.function.Function;
 import javax.inject.Inject;
 import org.apache.commons.lang.StringEscapeUtils;
 import org.eclipse.emf.common.util.EList;
@@ -42,21 +43,25 @@
 import org.eclipse.osbp.ecview.semantic.uimodel.UiModel;
 import org.eclipse.osbp.ecview.semantic.uimodel.UiView;
 import org.eclipse.osbp.ecview.semantic.uimodel.impl.UiViewImpl;
+import org.eclipse.osbp.runtime.common.annotations.CompareType;
 import org.eclipse.osbp.runtime.common.annotations.DomainDescription;
 import org.eclipse.osbp.runtime.common.annotations.DomainKey;
 import org.eclipse.osbp.runtime.common.annotations.FilterDepth;
 import org.eclipse.osbp.runtime.common.annotations.Properties;
+import org.eclipse.osbp.runtime.common.annotations.TargetEnumConstraints;
 import org.eclipse.osbp.utils.common.EntityUtils;
 import org.eclipse.xtend2.lib.StringConcatenation;
 import org.eclipse.xtext.common.types.JvmAnnotationAnnotationValue;
 import org.eclipse.xtext.common.types.JvmAnnotationReference;
 import org.eclipse.xtext.common.types.JvmAnnotationValue;
 import org.eclipse.xtext.common.types.JvmDeclaredType;
+import org.eclipse.xtext.common.types.JvmEnumAnnotationValue;
 import org.eclipse.xtext.common.types.JvmField;
 import org.eclipse.xtext.common.types.JvmIntAnnotationValue;
 import org.eclipse.xtext.common.types.JvmMember;
 import org.eclipse.xtext.common.types.JvmStringAnnotationValue;
 import org.eclipse.xtext.common.types.JvmType;
+import org.eclipse.xtext.common.types.JvmTypeAnnotationValue;
 import org.eclipse.xtext.common.types.JvmTypeReference;
 import org.eclipse.xtext.common.types.util.TypeReferences;
 import org.eclipse.xtext.naming.IQualifiedNameProvider;
@@ -80,6 +85,37 @@
     }
   }
   
+  public static class TargetEnumProps {
+    /**
+     * The property of the target type of the reference that must match the enum
+     * literal.
+     * 
+     * @return the string
+     */
+    private String targetProperty;
+    
+    /**
+     * The enum class used to get the enum literal.
+     * 
+     * @return the class
+     */
+    private Class<?> enumClass;
+    
+    /**
+     * The name of the enum literal that is used as a filter.
+     * 
+     * @return the string
+     */
+    private String enumLiteral;
+    
+    /**
+     * The compareType used to execute the filter.
+     * 
+     * @return the compare type
+     */
+    private CompareType compareType = CompareType.EQUALS;
+  }
+  
   @Inject
   @Extension
   private IQualifiedNameProvider _iQualifiedNameProvider;
@@ -241,6 +277,49 @@
   }
   
   /**
+   * Returns info about the TargetEnumConstraints annotation.
+   * 
+   * usage:
+   * 
+   * val targets = toEnumReferenceConstraint(info.field, [
+   * return computer.loadClass(uiLayout?.eResource?.resourceSet, it.qualifiedName)
+   * ])
+   */
+  public List<AutowireUtil.TargetEnumProps> toEnumReferenceConstraint(final JvmField jvmField, final Function<JvmType, Class<?>> typeProvider) {
+    final List<AutowireUtil.TargetEnumProps> targets = CollectionLiterals.<AutowireUtil.TargetEnumProps>newArrayList();
+    final Function1<JvmAnnotationReference, Boolean> _function = (JvmAnnotationReference e) -> {
+      final boolean result = e.getAnnotation().getIdentifier().equals(TargetEnumConstraints.class.getName());
+      return Boolean.valueOf(result);
+    };
+    final Consumer<JvmAnnotationReference> _function_1 = (JvmAnnotationReference it) -> {
+      final JvmAnnotationReference ref = it;
+      final Function1<JvmAnnotationValue, JvmAnnotationAnnotationValue> _function_2 = (JvmAnnotationValue it_1) -> {
+        return ((JvmAnnotationAnnotationValue) it_1);
+      };
+      final Consumer<JvmAnnotationAnnotationValue> _function_3 = (JvmAnnotationAnnotationValue av) -> {
+        final Consumer<JvmAnnotationReference> _function_4 = (JvmAnnotationReference it_1) -> {
+          final AutowireUtil.TargetEnumProps target = new AutowireUtil.TargetEnumProps();
+          JvmAnnotationValue _get = it_1.getValues().get(0);
+          target.targetProperty = ((JvmStringAnnotationValue) _get).getValues().get(0);
+          JvmAnnotationValue _get_1 = it_1.getValues().get(1);
+          final JvmTypeReference enumClassJvmType = ((JvmTypeAnnotationValue) _get_1).getValues().get(0);
+          target.enumClass = typeProvider.apply(enumClassJvmType.getType());
+          JvmAnnotationValue _get_2 = it_1.getValues().get(2);
+          target.enumLiteral = ((JvmStringAnnotationValue) _get_2).getValues().get(0);
+          JvmAnnotationValue _get_3 = it_1.getValues().get(3);
+          target.compareType = CompareType.valueOf(
+            ((JvmEnumAnnotationValue) _get_3).getValues().get(0).getSimpleName());
+          targets.add(target);
+        };
+        av.getValues().forEach(_function_4);
+      };
+      ListExtensions.<JvmAnnotationValue, JvmAnnotationAnnotationValue>map(ref.getValues(), _function_2).forEach(_function_3);
+    };
+    IterableExtensions.<JvmAnnotationReference>filter(jvmField.getAnnotations(), _function).forEach(_function_1);
+    return targets;
+  }
+  
+  /**
    * Detects all the existing properties of the jvmtype corresponding datatype of the attribute.
    */
   public LDataType toDataType(final JvmType type, final String attributeName) {