[isidorus-cvs] r790 - branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base

lgiessmann at common-lisp.net lgiessmann at common-lisp.net
Fri Aug 26 07:06:26 UTC 2011


Author: lgiessmann
Date: Fri Aug 26 00:06:26 2011
New Revision: 790

Log:
gdl-frontend: Widgets: implemented the method "getVyluesforTmValue(Topic tmValue)" that returns all valid topics which are selected via the passed (Default-)TM-Value topic

Modified:
   branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TmHelper.java

Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TmHelper.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TmHelper.java	Thu Aug 25 15:05:01 2011	(r789)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TmHelper.java	Fri Aug 26 00:06:26 2011	(r790)
@@ -1192,4 +1192,62 @@
 			}
 		}
 	}
+
+
+	// returns the actual list of values for a TM-Value instance, i.e.
+	// *(Default-)TM-Type-Value: returns all topic instances that are
+	//		of the type bound to the TM-Type-Value topic
+	// *(Default-)TM-Single-Type-Value: returns all topics that are
+	//		of the type bound to the TM-Single-Type-Value and are not
+	//      of the type of any other topic
+	// *(Default-)TM-Multiple-Type-Value: returns all topics that are
+	//      instances of all types that are bound to the
+	//      TM-Multiple-Type-Value topic
+	// *(Default-)TM-Instance-Value: returns the topic that is bound
+	//		to the TM-Instance-Value topics
+	public static ArrayList<Topic> getValuesForTmValue(Topic tmValue) throws InvalidGdlSchemaException {
+		ArrayList<Topic> result = new ArrayList<Topic>();
+		if(tmValue == null) return result;
+				
+		TopicMap tm = tmValue.getTopicMap();
+		Topic descriptorRoleType = getTopicByPsi(PSIs.GDL.RoleType.gdlDescriptor, tm);
+		Topic tmBindingAssocType = getTopicByPsi(PSIs.GDL.AssociationType.gdlTmBinding, tm);
+		Topic tmConstructRoleType = getTopicByPsi(PSIs.GDL.RoleType.gdlTmConstruct, tm);
+		if(isInstanceOf(tmValue, PSIs.GDL.TopicType.gdlTmTypeValue) || isInstanceOf(tmValue, PSIs.GDL.TopicType.gdlDefaultTmTypeValue)){
+			ArrayList<Topic> topicTypes = getOtherPlayerOfBinaryAssociation(tmValue, descriptorRoleType, tmBindingAssocType, null, tmConstructRoleType);
+			if(topicTypes.size() != 1) throw new InvalidGdlSchemaException("the topic " + getAnyIdOfTopic(tmValue) + " must be bound exactly once to a topic type value via a " + PSIs.GDL.AssociationType.gdlTmBinding + " association, but is: " + topicTypes.size());
+			Topic topicType = topicTypes.get(0);
+			
+			JsArray<Topic> allTopics = tm.getTopics();
+			for(int i = 0; i != allTopics.length(); ++i)
+				if(isInstanceOf(allTopics.get(i), topicType)) result.add(allTopics.get(i));
+		} else if(isInstanceOf(tmValue, PSIs.GDL.TopicType.gdlTmSingleTypeValue) || isInstanceOf(tmValue, PSIs.GDL.TopicType.gdlDefaultTmSingleTypeValue)){
+			ArrayList<Topic> topicTypes = getOtherPlayerOfBinaryAssociation(tmValue, descriptorRoleType, tmBindingAssocType, null, tmConstructRoleType);
+			if(topicTypes.size() != 1) throw new InvalidGdlSchemaException("the topic " + getAnyIdOfTopic(tmValue) + " must be bound exactly once to a topic type value via a " + PSIs.GDL.AssociationType.gdlTmBinding + " association, but is: " + topicTypes.size());
+			Topic topicType = topicTypes.get(0);
+			
+			JsArray<Topic> allTopics = tm.getTopics();
+			for(int i = 0; i != allTopics.length(); ++i)
+				if(isInstanceOf(allTopics.get(i), topicType) && allTopics.get(i).getTypes().length() == 1) result.add(allTopics.get(i));
+		} else if(isInstanceOf(tmValue, PSIs.GDL.TopicType.gdlTmMultipleTypeValue) || isInstanceOf(tmValue, PSIs.GDL.TopicType.gdlDefaultTmMultipleTypeValue)){
+			ArrayList<Topic> topicTypes = getOtherPlayerOfBinaryAssociation(tmValue, descriptorRoleType, tmBindingAssocType, null, tmConstructRoleType);
+			if(topicTypes.size() == 0) throw new InvalidGdlSchemaException("the topic " + getAnyIdOfTopic(tmValue) + " must be bound at least once to a topic type value via a " + PSIs.GDL.AssociationType.gdlTmBinding + " association, but is: 0");
+			
+			JsArray<Topic> allTopics = tm.getTopics();
+			for(int i = 0; i != allTopics.length(); ++i){
+				int j = 0;
+				for( ; j != topicTypes.size(); ++j)
+					if(!isInstanceOf(allTopics.get(i), topicTypes.get(j)) || allTopics.get(i).getTypes().length() > topicTypes.size()) break;
+				
+				if(j == topicTypes.size()) result.add(allTopics.get(i));
+			}
+		} else if(isInstanceOf(tmValue, PSIs.GDL.TopicType.gdlTmInstanceValue) || isInstanceOf(tmValue, PSIs.GDL.TopicType.gdlDefaultTmInstanceValue)){
+			result = getOtherPlayerOfBinaryAssociation(tmValue, descriptorRoleType, tmBindingAssocType, null, tmConstructRoleType);
+			if(result.size() != 1) throw new InvalidGdlSchemaException("the topic " + getAnyIdOfTopic(tmValue) + " must be bound exactly once to a topic value via a " + PSIs.GDL.AssociationType.gdlTmBinding + " association, but is: " + result.size());
+		} else {
+			throw new InvalidGdlSchemaException("the topic " + getAnyIdOfTopic(tmValue) + " must be an instance of " + PSIs.GDL.TopicType.gdlTmValue);
+		}
+		
+		return result;
+	}
 }




More information about the Isidorus-cvs mailing list