[isidorus-cvs] r610 - in branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets: base environment

lgiessmann at common-lisp.net lgiessmann at common-lisp.net
Wed Jul 13 15:18:43 UTC 2011


Author: lgiessmann
Date: Wed Jul 13 08:18:43 2011
New Revision: 610

Log:
gdl-frontend: Widgets: fixed some methods that instatiate GdlDefaultEditorTopicView from a Gdl Schema topic map

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/environment/GdlInstantiator.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	Wed Jul 13 07:45:55 2011	(r609)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TmHelper.java	Wed Jul 13 08:18:43 2011	(r610)
@@ -74,6 +74,21 @@
 	}
 	
 	
+	// a helper method to return an identifier string and a TopicIdentifierTypes instance
+	// of the topic contained in a Pair object
+	public static Pair<String, TopicIdentifierTypes> getAnyIdenditfierOfTopic(Topic topic){
+		if(topic.getSubjectIdentifiers().length() != 0){
+			return new Pair<String, TopicIdentifierTypes>(topic.getSubjectIdentifiers().get(0).getReference(), TopicIdentifierTypes.SubjectIdentifier);
+		}else if(topic.getSubjectLocators().length() != 0) {
+			return new Pair<String, TopicIdentifierTypes>(topic.getSubjectLocators().get(0).getReference(), TopicIdentifierTypes.SubjectLocator);
+		}if(topic.getItemIdentifiers().length() != 0){
+			return new Pair<String, TopicIdentifierTypes>(topic.getItemIdentifiers().get(0).getReference(), TopicIdentifierTypes.ItemIdentifier);
+		} else {
+			return null;
+		}
+	}
+	
+	
 	// returns all instances of the topic type
 	public static ArrayList<Topic> getInstanceOf(Topic type, boolean multipleTypesAllowed){
 		ArrayList<Topic> result = new ArrayList<Topic>();
@@ -179,6 +194,18 @@
 		}
 		return result;
 	}
+	
+	
+	// returns the other player of an association with two roles and the correct values
+	public static ArrayList<Topic> getOtherPlayerOfBinaryAssociation(Topic thisTopic, Topic thisRoleType, Topic assocType, ArrayList<Topic> scope, Topic otherPlayerType, Topic otherRoleType){
+		ArrayList<Topic> allPlayers = getOtherPlayerOfBinaryAssociation(thisTopic, thisRoleType, assocType, scope, otherRoleType);
+		if(otherRoleType == null) return allPlayers;
+		
+		ArrayList<Topic> result = new ArrayList<Topic>();
+		for (Topic player : allPlayers) if(isInstanceOf(player, otherPlayerType)) result.add(player);
+		
+		return result;
+	}
 
 	
 	// returns true if the instance topic is an instance of the topic bound to typeSubectIdentifier

Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/environment/GdlInstantiator.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/environment/GdlInstantiator.java	Wed Jul 13 07:45:55 2011	(r609)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/environment/GdlInstantiator.java	Wed Jul 13 08:18:43 2011	(r610)
@@ -32,7 +32,6 @@
 import us.isidor.gdl.anaToMia.Widgets.view.GdlCreatorAssociationView;
 import us.isidor.gdl.anaToMia.Widgets.view.GdlDefaultCreatorTopicView;
 import us.isidor.gdl.anaToMia.Widgets.view.GdlDefaultEditorTopicView;
-import us.isidor.gdl.anaToMia.Widgets.view.GdlDefaultTopicView;
 import us.isidor.gdl.anaToMia.Widgets.view.GdlEditorAssociationView;
 import us.isidor.gdl.anaToMia.Widgets.view.GdlSpecialCreatorTopicView;
 import us.isidor.gdl.anaToMia.Widgets.view.GdlSpecialEditorTopicView;
@@ -123,7 +122,7 @@
 			for (Topic top : views)
 				bindings += ", " + TmHelper.getAnyIdOfTopic(top);
 			bindings = bindings.substring(2);
-			throw new InvalidGdlSchemaException("the combination fo topics requested (" + values + ") must be bound exactly once to a " + GdlPsis.TopicType.gdlDefaultCreatorTopicView + " but is bound to " + bindings);
+			throw new InvalidGdlSchemaException("the combination of topics requested (" + values + ") must be bound exactly once to a " + GdlPsis.TopicType.gdlDefaultCreatorTopicView + " but is bound to " + bindings);
 		}
 		
 		return new GdlDefaultCreatorTopicView(views.get(0));
@@ -186,118 +185,59 @@
 	
 	
 	
-	public static GdlDefaultEditorTopicView instantiateDefaultEditorTopicView(Pair<String, TopicIdentifierTypes> requestedTopic, TopicMap schemaTm){
+	public static GdlDefaultEditorTopicView instantiateDefaultEditorTopicView(Pair<String, TopicIdentifierTypes> requestedTopic, TopicMap schemaTm) throws InvalidGdlSchemaException, ExecutionException{
 		if(requestedTopic == null || schemaTm == null) return null;
 		
 		
-		// TODO: search for a direct TM-Instance-Value binding if no one is found, search the types and call GdlDefaultCreatorTopicView
+		// request the topic that is passed by the user
+		Topic requestedTop = TmHelper.getTopicByAnyIdentifier(requestedTopic, schemaTm);
+		if(requestedTop == null) throw new InvalidGdlSchemaException("the topic " + requestedTopic.getFirst() + " was not found!");
 		
-		// 1. get the requested topic
-		// 2. get types of requested topic
-		// 3. get tm-values that are assiciated with exalty those topics that are requested => assert the tm-value type
-		// 4. search for a tm-instance-value binding
-		// 5. search the a default-creator-topic-view bound to the found tm-values
-		// 6. return the view or throw an error if no view or more than one view was found
-
+		// get all tm-instance-value topics bound to the requested topic
+		Topic tmConstruct = TmHelper.getTopicByPsi(GdlPsis.RoleType.gdlTmConstruct, schemaTm);
+		Topic tmBinding = TmHelper.getTopicByPsi(GdlPsis.AssociationType.gdlTmBinding, schemaTm);
+		Topic descriptor = TmHelper.getTopicByPsi(GdlPsis.RoleType.gdlDescriptor, schemaTm);
+		ArrayList<Topic> tmInstanceValues = TmHelper.getOtherPlayerOfBinaryAssociation(requestedTop, tmConstruct, tmBinding, null, descriptor);
 		
-		// TODO: implement
-		return null;
-	}
-	
-	
-	
-	
-	
-	
-	
-	
-	// returns a DefaultTopicView instance that represents the entry point of this topic map for one of
-	// instanceTopic of typeTopics, i.e. one of the must be null or empty
-	public static GdlDefaultTopicView instantiateDefaultEditorOrCreatorView(Pair<String, TopicIdentifierTypes> instanceTopic, ArrayList<Pair<String, TopicIdentifierTypes>> typeTopics, TopicMap tm) throws InvalidGdlSchemaException, ExecutionException{
-		if(tm == null) return null;
-		if(instanceTopic != null && (typeTopics != null && typeTopics.size() != 0)){
-			String values = instanceTopic.getFirst();
-			for (Pair<String, TopicIdentifierTypes> pair : typeTopics) if(values.length() != 0)values += ", " + pair.getFirst(); 
-			throw new ExecutionException("only one of topic is allowed to be set as the base topic for a " + GdlPsis.TopicType.gdlView + " but found: " + values);
+		// get all views bound to the found tm-instance-values
+		Topic defaultEditorTopicView = TmHelper.getTopicByPsi(GdlPsis.TopicType.gdlDefaultEditorTopicView, schemaTm);
+		Topic tmValue = TmHelper.getTopicByPsi(GdlPsis.RoleType.gdlTmValue, schemaTm);
+		Topic topicViewBinding = TmHelper.getTopicByPsi(GdlPsis.AssociationType.gdlTopicViewBinding, schemaTm);
+		ArrayList<Topic> views = new ArrayList<Topic>();
+		for (Topic tmInstanceValue : tmInstanceValues) {
+			ArrayList<Topic> tmpViews = TmHelper.getOtherPlayerOfBinaryAssociation(tmInstanceValue, tmValue, topicViewBinding, null, defaultEditorTopicView, descriptor);
+			for (Topic tmpView : tmpViews) if(!views.contains(tmpView))views.add(tmpView);
 		}
 		
-		Topic defaultCreatorTopicView = TmHelper.getTopicByPsi(GdlPsis.TopicType.gdlDefaultCreatorTopicView, tm);
-		Topic defaultEditorTopicView = TmHelper.getTopicByPsi(GdlPsis.TopicType.gdlDefaultEditorTopicView, tm);
-		if(defaultCreatorTopicView == null && defaultEditorTopicView == null){
-			throw new InvalidGdlSchemaException("the requested GDL schema does not have an entry point defined, either an instance of " + GdlPsis.TopicType.gdlDefaultCreatorTopicView + " or " + GdlPsis.TopicType.gdlDefaultEditorTopicView + " is necessary");
+		if(views.size() == 1){
+			return new GdlDefaultEditorTopicView(views.get(0));
+		}else if(views.size() > 1){
+			String bindings = "";
+			for (Topic top : views)
+				bindings += ", " + TmHelper.getAnyIdOfTopic(top);
+			bindings = bindings.substring(2);
+			throw new InvalidGdlSchemaException("the topic " + requestedTopic.getFirst() + " requested for editing must be bound to exaclty one " + GdlPsis.TopicType.gdlDefaultEditorTopicView + ", but is bound to " + bindings);
 		}else {
-			// all topics (types) that have to be displayed by a view
-			ArrayList<Topic> topsToDisplay = new ArrayList<Topic>();
-			if(instanceTopic != null){
-				topsToDisplay.add(TmHelper.getTopicByAnyIdentifier(instanceTopic, tm));
-			}else{
-				for (Pair<String, TopicIdentifierTypes> pair : typeTopics) {
-					topsToDisplay.add(TmHelper.getTopicByAnyIdentifier(pair, tm));
-				}
-			}
-
-			// get the TM-Value instance that is bound to the topic (type) and the view instance
-			ArrayList<Topic> tmValues = new ArrayList<Topic>();
-			Topic descriptor = TmHelper.getTopicByPsi(GdlPsis.RoleType.gdlDescriptor, tm);
-			Topic tmBinding = TmHelper.getTopicByPsi(GdlPsis.AssociationType.gdlTmBinding, tm);
-			Topic tmValue = TmHelper.getTopicByPsi(GdlPsis.RoleType.gdlTmValue, tm);
-			Topic TmValue = TmHelper.getTopicByPsi(GdlPsis.TopicType.gdlTmValue, tm);
-			Topic tmConstruct = TmHelper.getTopicByPsi(GdlPsis.RoleType.gdlTmConstruct, tm);
-			for (Topic topic : topsToDisplay) {
-				ArrayList<Topic> potentialTmValues = TmHelper.getOtherPlayerOfBinaryAssociation(topic, tmConstruct, tmBinding, null, descriptor);
-				for (Topic potentialTmValue : potentialTmValues)
-					if(TmHelper.isInstanceOf(potentialTmValue, TmValue)) tmValues.add(potentialTmValue);
-			}
-			
-			// get only the tm-value that binds all topics to be displayed to the current view
-			ArrayList<Topic> invalidTmValues = new ArrayList<Topic>();
-			Topic topictype = TmHelper.getTopicByPsi(GdlPsis.TMCL.topictype, tm);
-			for (Topic value : tmValues) {
-				for (Topic topToDisplay : topsToDisplay) {
-					ArrayList<Pair<Topic, Topic>> roles = new ArrayList<Pair<Topic,Topic>>();
-					roles.add(new Pair<Topic, Topic>(topictype, tmConstruct));
-					if(TmHelper.hasAssociation(topToDisplay, tmConstruct, tmBinding, value, descriptor) ||
-							TmHelper.getAssociationsOfTopic(value, descriptor, tmBinding, null, roles).size() != topsToDisplay.size()){
-						invalidTmValues.add(value);
-					}
-				}
-			}
 			
-			for (Topic invalid : invalidTmValues)tmValues.remove(invalid);			
-			
-			// get all default topic views that are bound to the existent tm-values
-			ArrayList<Topic> defaultTopicViews = new ArrayList<Topic>();
-			Topic defaultTopicView = TmHelper.getTopicByPsi(GdlPsis.TopicType.gdlDefaultTopicView, tm);
-			Topic topicViewBinding = TmHelper.getTopicByPsi(GdlPsis.AssociationType.gdlTopicViewBinding, tm);
-			for (Topic validTmValue : tmValues) {
-				ArrayList<Topic> views = TmHelper.getOtherPlayerOfBinaryAssociation(validTmValue, tmValue, topicViewBinding, null, descriptor);
-				for (Topic view : views) if(TmHelper.isInstanceOf(view, defaultTopicView)) defaultTopicViews.add(view);
-			}
+			ArrayList<Pair<String, TopicIdentifierTypes>> typesOfRequestedTopic = new ArrayList<Pair<String,TopicIdentifierTypes>>();
+			for(int i = 0; i != requestedTop.getTypes().length(); ++i)
+				typesOfRequestedTopic.add(TmHelper.getAnyIdenditfierOfTopic(requestedTop.getTypes().get(i)));
+						
+			views = getViewTopics(typesOfRequestedTopic, defaultEditorTopicView, schemaTm);
 			
-			// return default-topic-view
-			if(defaultTopicViews.size() > 2){
+			if(views.size() != 1){
 				String values = "";
-				for (Topic topic : topsToDisplay)values += ", " + TmHelper.getAnyIdOfTopic(topic);
-				if(values.length() >= 2) values = values.substring(2);
-				throw new InvalidGdlSchemaException("only one default editor or creator topic view can be bound to a topic, but found " + values);
-			} else if(defaultTopicViews.size() == 1){
-				return (GdlDefaultTopicView)instantiate(defaultTopicViews.get(0));
-			} else if(defaultTopicViews.size() == 2){ // one creator and one editor view
-				Topic creatorView = null;
-				Topic editorView = null;
-				if(TmHelper.isInstanceOf(defaultTopicViews.get(0), GdlPsis.TopicType.gdlDefaultCreatorTopicView)){
-					creatorView = defaultTopicViews.get(0);
-					editorView = defaultTopicViews.get(1);
-				}else {
-					creatorView = defaultTopicViews.get(1);
-					editorView = defaultTopicViews.get(0);
-				}
-				
-				if(instanceTopic != null)return new GdlDefaultEditorTopicView(editorView);
-				else return new GdlDefaultCreatorTopicView(creatorView);
-			} else {
-				return null;
+				for (Pair<String, TopicIdentifierTypes> pair : typesOfRequestedTopic)
+					values += ", " + pair.getFirst();
+				values = values.substring(2);
+				String bindings = "";
+				for (Topic top : views)
+					bindings += ", " + TmHelper.getAnyIdOfTopic(top);
+				bindings = bindings.substring(2);
+				throw new InvalidGdlSchemaException("the combination of topic types (" + values + ") for the requested topic " + requestedTopic.getFirst() + " must be bound exactly once to a " + GdlPsis.TopicType.gdlDefaultEditorTopicView + " but is bound to " + bindings);
 			}
+			
+			return new GdlDefaultEditorTopicView(views.get(0));
 		}
 	}
 }




More information about the Isidorus-cvs mailing list