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

lgiessmann at common-lisp.net lgiessmann at common-lisp.net
Wed Jul 13 14:45:56 UTC 2011


Author: lgiessmann
Date: Wed Jul 13 07:45:55 2011
New Revision: 609

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

Added:
   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/Utils.java
Modified:
   branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlPanel.java
   branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlPsis.java
   branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlVisibleObject.java
   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/ILoadSchemaCallback.java
   branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/LoadSchemaCallback.java
   branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/view/GdlView.java

Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlPanel.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlPanel.java	Wed Jul 13 05:38:00 2011	(r608)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlPanel.java	Wed Jul 13 07:45:55 2011	(r609)
@@ -37,7 +37,7 @@
 	// if any value is set in this array list, the requested view is a Default-Creator-Topic-View
 	private ArrayList<Pair<String, TopicIdentifierTypes>> requestedTopicsToCreate = new ArrayList<Pair<String,TopicIdentifierTypes>>();
 	// if any value is set in this array list, the requested view is a Default-Editor-Topic-View
-	private ArrayList<Pair<String, TopicIdentifierTypes>> requestedTopicsToEdit = new ArrayList<Pair<String,TopicIdentifierTypes>>();
+	private Pair<String, TopicIdentifierTypes> requestedTopicToEdit = null;
 	
 	// the GWT base for this panel 
 	private AbsolutePanel mainPanel = new AbsolutePanel();
@@ -63,24 +63,24 @@
 	}
 	
 	
-	protected GdlPanel(ArrayList<Pair<String, TopicIdentifierTypes>> topicsToEdit, ArrayList<Pair<String, TopicIdentifierTypes>> topicToCreate) throws ExecutionException{
+	protected GdlPanel(Pair<String, TopicIdentifierTypes> topicToEdit, ArrayList<Pair<String, TopicIdentifierTypes>> topicToCreate) throws ExecutionException{
 		this();
-		if(topicsToEdit != null && topicsToEdit.size() != 0)this.requestedTopicsToEdit = topicsToEdit;
+		if(topicToEdit != null)this.requestedTopicToEdit = topicToEdit;
 		if(topicToCreate != null && topicToCreate.size() != 0)this.requestedTopicsToCreate = topicToCreate;
 		
-		if(this.requestedTopicsToCreate.size() != 0 && this.requestedTopicsToEdit.size() != 0)
-			throw new ExecutionException("only one container can be set, i.e. either topics to create or topics to edit");
+		if(this.requestedTopicsToCreate.size() != 0 && this.requestedTopicToEdit != null)
+			throw new ExecutionException("only one container can be set, i.e. either topics to create or a topic to edit");
 	}
 		
 	
-	public GdlPanel(ArrayList<Pair<String, TopicIdentifierTypes>> topicsToEdit, ArrayList<Pair<String, TopicIdentifierTypes>> topicToCreate, int width, int height) throws ExecutionException{
-		this(topicsToEdit, topicToCreate);
+	public GdlPanel(Pair<String, TopicIdentifierTypes> topicToEdit, ArrayList<Pair<String, TopicIdentifierTypes>> topicToCreate, int width, int height) throws ExecutionException{
+		this(topicToEdit, topicToCreate);
 		this.setPixelSize(width, height);
 	}
 	
 	
-	public GdlPanel(ArrayList<Pair<String, TopicIdentifierTypes>> topicsToEdit, ArrayList<Pair<String, TopicIdentifierTypes>> topicToCreate, String width, String height) throws ExecutionException{
-		this(topicsToEdit, topicToCreate);
+	public GdlPanel(Pair<String, TopicIdentifierTypes> topicToEdit, ArrayList<Pair<String, TopicIdentifierTypes>> topicToCreate, String width, String height) throws ExecutionException{
+		this(topicToEdit, topicToCreate);
 		this.setSize(width, height);
 	}
 
@@ -168,7 +168,7 @@
 			if(this.loadSchemaCallback == null){
 				throw new ExecutionException("No LoadSchemaCallback was set yet");
 			}
-			this.loadSchemaCallback.loadSchema(this, this.requestedTopicsToEdit, this.requestedTopicsToCreate);
+			this.loadSchemaCallback.loadSchema(this, this.requestedTopicToEdit, this.requestedTopicsToCreate);
 		}catch(Exception e){
 			for (IOnErrorCallback handler : localOnErrorContainer) {
 				handler.onError(GdlErrorTypes.LoadError, e);
@@ -258,8 +258,10 @@
 	// Creates the actual view from the requested topic map
 	public void createView(){
 		try{
-			//view = GdlInstantiator.instantiateDefaultEditorOrCreatorView(requestedTopicsTo, requestedTopicToCreat, this.requestedSchemaTm);
-			//TODO: implement
+			if(this.requestedTopicsToCreate != null && this.requestedTopicsToCreate.size() != 0)
+				this.view = GdlInstantiator.instantiateDefaultCreatorTopicView(this.requestedTopicsToCreate, this.requestedSchemaTm);
+			else if(this.requestedTopicToEdit != null)
+				this.view = GdlInstantiator.instantiateDefaultEditorTopicView(this.requestedTopicToEdit, this.requestedSchemaTm);
 			mainPanel.add(view);
 			for (Pair<ClickHandler, String> item : this.buttonCallbacks) {
 				view.registerButtonCallback(item.getFirst(), item.getSecond());

Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlPsis.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlPsis.java	Wed Jul 13 05:38:00 2011	(r608)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlPsis.java	Wed Jul 13 07:45:55 2011	(r609)
@@ -252,247 +252,5 @@
 		public final static String gdlFocus = gdl + "focus";
 		public final static String gdlActive = gdl + "active";
 	}
-	
-	
-	// a helper that returns the topic bound to the identifier via a subject identifier
-	public static Topic getTopicByPsi(String subjectIdentifier, TopicMap tm){
-		if(subjectIdentifier == null || tm == null) return null;
-		
-		Locator loc = tm.createLocator(subjectIdentifier);
-		return tm.getTopicBySubjectIdentifier(loc);
-	}
-	
-	
-	// a helper that returns the topic bound to the identifier via a subject locator
-	public static Topic getTopicBySl(String subjectLocator, TopicMap tm){
-		if(subjectLocator == null || tm == null) return null;
-		
-		Locator loc = tm.createLocator(subjectLocator);
-		return tm.getTopicBySubjectLocator(loc);
-	}
-	
-	
-	// a helper that returns the topic bound to the identifier via an item identifier
-	public static Topic getTopicByIi(String itemIdentifier, TopicMap tm){
-		if(itemIdentifier == null || tm == null) return null;
-		
-		Locator loc = tm.createLocator(itemIdentifier);
-		return (Topic)tm.getConstructByItemIdentifier(loc);
-	}
-	
-	
-	// returns a topic that is identified by ref
-	public static Topic getTopicByAnyIdentifier(Pair<String, TopicIdentifierTypes> ref, TopicMap tm){
-		if(ref.getSecond() == TopicIdentifierTypes.ItemIdentifier){
-			return getTopicByIi(ref.getFirst(), tm);
-		}else if(ref.getSecond() == TopicIdentifierTypes.SubjectLocator){
-			return getTopicBySl(ref.getFirst(), tm);
-		}else {
-			return getTopicByPsi(ref.getFirst(), tm);
-		}
-	}	
-	
-	
-	// a helper method to return any identifier string of the topic
-	public static String getAnyIdOfTopic(Topic topic){
-		if(topic.getSubjectIdentifiers().length() != 0){
-			return topic.getSubjectIdentifiers().get(0).getReference();
-		}else if(topic.getSubjectLocators().length() != 0) {
-			return topic.getSubjectLocators().get(0).getReference();
-		}if(topic.getItemIdentifiers().length() != 0){
-			return topic.getItemIdentifiers().get(0).getReference();
-		} 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>();
-		TopicMap tm = type.getTopicMap();
-		
-		for(int i = 0; i != tm.getTopics().length(); ++i){
-			if(multipleTypesAllowed){
-				if(isInstanceOf(tm.getTopics().get(i), type)) result.add(tm.getTopics().get(i));
-			} else {
-				if(isInstanceOf(tm.getTopics().get(i), type) && tm.getTopics().get(i).getTypes().length() == 1) result.add(tm.getTopics().get(i));
-			}
-		}
-		
-		return result;
-	}
-	
-	
-	// returns true if the topic instance if an instance of the topic type
-	public static boolean isInstanceOf(Topic instance, Topic type){
-		if(instance == null || type == null) return false;
 
-		JsArray<Topic> types = instance.getTypes();
-		for(int i = 0; i != types.length(); ++i){
-			ArrayList<Topic> superTypes = getAllSuperTypes(types.get(i), null);
-			superTypes.add(types.get(i));
-			if(superTypes.contains(type)) return true;
-		}
-
-		return false;
-	}
-	
-	
-	// returns an array list with all direct and indirect supertypes of top
-	public static ArrayList<Topic> getAllSuperTypes(Topic top, ArrayList<Topic> collectedSupertypes){
-		if(top == null) return new ArrayList<Topic>();
-		
-		ArrayList<Topic> localCollectedSuperTypes = new ArrayList<Topic>();
-		if(collectedSupertypes != null) localCollectedSuperTypes = collectedSupertypes;
-		
-		ArrayList<Topic> direcSupertypes = getDirectSuperTypes(top);
-		for (Topic topic : localCollectedSuperTypes) direcSupertypes.remove(topic); //avoid duplicates
-		for (Topic topic : direcSupertypes)localCollectedSuperTypes.add(topic);
-		
-		for (Topic topic : direcSupertypes){
-			ArrayList<Topic> tmp = getAllSuperTypes(topic, localCollectedSuperTypes);
-			for (Topic tmpTopic : tmp) localCollectedSuperTypes.add(tmpTopic);
-		}
-		return localCollectedSuperTypes;
-	}
-	
-	
-	// returns the direct supertypes of the passed topic
-	public static ArrayList<Topic> getDirectSuperTypes(Topic top){
-		ArrayList<Topic> result = new ArrayList<Topic>();
-		if(top == null) return result;
-		TopicMap tm = top.getTopicMap();
-		Topic subtype = getTopicByPsi(TMDM.subtype, tm);
-		Topic supertype = getTopicByPsi(TMDM.supertype, tm);
-		Topic supertypeSubtype = getTopicByPsi(TMDM.supertypeSubtype, tm);
-		
-		if(subtype == null || supertype == null || supertypeSubtype == null) return result;
-		
-		JsArray<Role> validRoles = top.getRolesPlayed(subtype, supertypeSubtype);
-		for(int i = 0; i != validRoles.length(); ++i){
-			Association parent = validRoles.get(i).getParent();
-			if(parent.getRoles().length() == 2 && parent.getRoles(supertype).length() == 1)result.add(parent.getRoles(supertypeSubtype).get(0).getPlayer());
-		}
-		return result;
-	}
-	
-	
-	// returns true if a corresponding association exists
-	public static boolean hasAssociation(Topic thisTopic, Topic thisRoleType, Topic assocType, Topic otherPlayer, Topic otherRoleType){
-		if(thisTopic == null || thisRoleType == null || assocType == null || otherPlayer == null || otherRoleType == null) return false;
-		
-		JsArray<Role> roles = thisTopic.getRolesPlayed(thisRoleType, assocType);
-		for(int i = 0; i != roles.length(); ++i){
-			Association parent = roles.get(i).getParent();
-			JsArray<Role> otherRoles = parent.getRoles(otherRoleType);
-			for(int j = 0; j != otherRoles.length(); ++j)
-				if(otherRoles.get(j).getPlayer().equals(otherPlayer)) return true;
-		}
-		
-		return false;
-	}
-	
-	
-	// 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 otherRoleType){
-		ArrayList<Topic> result = new ArrayList<Topic>();
-		if(thisTopic == null || thisRoleType == null || assocType == null || otherRoleType == null) return result;
-		
-		JsArray<Role> roles = thisTopic.getRolesPlayed(thisRoleType, assocType);
-		for(int i = 0; i != roles.length(); ++i){
-			Association parent = roles.get(i).getParent();
-			if(parent.getRoles().length() != 2) return result;
-			if(thisRoleType.equals(otherRoleType) && parent.getRoles(thisTopic).length() == 2){
-				if(parent.getRoles(thisRoleType).get(0).getPlayer().equals(thisTopic)) result.add(parent.getRoles(thisRoleType).get(1).getPlayer()); 
-				else result.add(parent.getRoles(thisRoleType).get(0).getPlayer()); 
-			}else if(parent.getRoles(otherRoleType).length() == 1){
-				result.add(parent.getRoles(otherRoleType).get(0).getPlayer());
-			}
-		}
-		return result;
-	}
-
-	
-	// returns true if the instance topic is an instance of the topic bound to typeSubectIdentifier
-	public static boolean isInstanceOf(Topic instance, String typeSubjectIdentifier){
-		TopicMap tm = instance.getTopicMap();
-		Topic type = tm.getTopicBySubjectIdentifier(tm.createLocator(typeSubjectIdentifier));
-		return isInstanceOf(instance, type);
-	}
-	
-	
-	// returns true if the passed association has exactly the corresponding roles to
-	// the array list rolePlayersAndTypes
-	public static boolean hasRoles(Association assoc, ArrayList<Pair<Topic, Topic>> rolePlayertypesAndTypes){
-		if(assoc == null) return false;
-		if(assoc.getRoles().length() == 0 && rolePlayertypesAndTypes == null) return true;
-		if(assoc.getRoles().length() != rolePlayertypesAndTypes.size()) return false;
-		
-		for (Pair<Topic, Topic> pair : rolePlayertypesAndTypes) {
-			JsArray<Role> selection = assoc.getRoles(pair.getSecond());
-			int i = 0;
-			for(; i != selection.length(); ++i){
-				if(isInstanceOf(selection.get(i).getPlayer(), pair.getFirst())) break;
-			}
-			
-			if(i == selection.length()) return false;
-		}
-		
-		return true;
-	}
-	
-	
-	// returns true if the topics of themes are all equal to the scope of construct
-	public static boolean hasThemes(Construct construct, ArrayList<Topic> themes){
-		if(construct == null) return false;
-		
-		ScopedStub scoped = (ScopedStub)construct;
-		if(scoped.getScope().length() != 0 && (themes == null || themes.size() == 0)) return false;
-		if(scoped.getScope().length() != themes.size()) return false;
-		
-		for(int i = 0; i != scoped.getScope().length(); ++i){
-			if(!themes.contains(scoped.getScope().get(i))) return false;
-		}
-		
-		return true;
-	}
-	
-	
-	// returns all topics that are instances if tm-value, which are also bound to this
-	// topic via a gdl:tm-binding association
-	public static ArrayList<Topic> getTmValues(Topic top){
-		ArrayList<Topic> result = new ArrayList<Topic>();
-		if(top == null) return result;
-		TopicMap tm = top.getTopicMap();
-		Topic descriptor = getTopicByPsi(RoleType.gdlDescriptor, tm);
-		Topic tmBinding = getTopicByPsi(AssociationType.gdlTmBinding, tm);
-		Topic tmValue = getTopicByPsi(TopicType.gdlTmValue, tm);
-		
-		JsArray<Role> roles = top.getRolesPlayed(descriptor, tmBinding);
-		for(int i = 0; i != roles.length(); ++i){
-			Association parent = roles.get(i).getParent();
-			if(parent.getRoles().length() == 2 && parent.getRoles(descriptor).length() == 1 &&
-					isInstanceOf(parent.getRoles(descriptor).get(0).getPlayer(), tmValue))
-				result.add(parent.getRoles(descriptor).get(0).getPlayer());
-		}
-		return result;
-	}
-	
-	
-	// returns the associations that are bound to the topic "topic" and have the passed scope and roles
-	public static ArrayList<Association> getAssociationsOfTopic(Topic topic, Topic roleType, Topic assocType, ArrayList<Topic> scope, ArrayList<Pair<Topic, Topic>> rolePlayertypesAndTypes){
-		ArrayList<Association> result = new ArrayList<Association>();
-		if(topic == null || assocType == null || rolePlayertypesAndTypes == null || rolePlayertypesAndTypes.size() == 0) return result;
-		
-		ArrayList<Association> allPotentialAssocs = new ArrayList<Association>();
-		for(int i = 0; i != topic.getRolesPlayed(roleType, assocType).length(); ++i) allPotentialAssocs.add(topic.getRolesPlayed(roleType, assocType).get(i).getParent());
-		
-		ArrayList<Association> assocsWoScope = new ArrayList<Association>();
-		for (Association assoc : allPotentialAssocs) if(hasRoles(assoc, rolePlayertypesAndTypes)) assocsWoScope.add(assoc);
-		
-		for (Association assoc : assocsWoScope) if(hasThemes(assoc, scope)) result.add(assoc);
-		
-		return result;
-	}
 }

Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlVisibleObject.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlVisibleObject.java	Wed Jul 13 05:38:00 2011	(r608)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlVisibleObject.java	Wed Jul 13 07:45:55 2011	(r609)
@@ -142,7 +142,7 @@
 		}
 
 		if(unscopedOccs.size() > 1){
-			throw new InvalidGdlSchemaException("The topic " + GdlPsis.getAnyIdOfTopic(this.tmRepresentative) + " must be bound to none or one unscoped occurrence of the type " + occurrenceType + ", but is bound " + unscopedOccs.size() + " times to it");
+			throw new InvalidGdlSchemaException("The topic " + TmHelper.getAnyIdOfTopic(this.tmRepresentative) + " must be bound to none or one unscoped occurrence of the type " + occurrenceType + ", but is bound " + unscopedOccs.size() + " times to it");
 		} else if(unscopedOccs.size() == 1){
 			return unscopedOccs.get(0);
 		} else {
@@ -170,7 +170,7 @@
 			}
 
 			if(matchedOccurrences.size() > 1){
-				throw new InvalidGdlSchemaException("The topic " + GdlPsis.getAnyIdOfTopic(this.tmRepresentative) + "must be bound to none or one occurrence of the type " + occurrenceType + " and the scope " + theme + " but is bound " + matchedOccurrences.size() + " times to it");
+				throw new InvalidGdlSchemaException("The topic " + TmHelper.getAnyIdOfTopic(this.tmRepresentative) + "must be bound to none or one occurrence of the type " + occurrenceType + " and the scope " + theme + " but is bound " + matchedOccurrences.size() + " times to it");
 			} else if(matchedOccurrences.size() == 1){
 				return matchedOccurrences.get(0);
 			} else {
@@ -184,7 +184,7 @@
 	public String getId() throws InvalidGdlSchemaException {
 		JsArray<Occurrence> idOccs = getOccurrences(GdlPsis.OccurrenceType.gdlId);
 		if(idOccs.length() != 1){
-			throw new InvalidGdlSchemaException("The topic " + GdlPsis.getAnyIdOfTopic(this.tmRepresentative) + " must be bound to exactly one occurrence of the type " + GdlPsis.OccurrenceType.gdlId + ", but is bound " + idOccs.length() + " times to it");
+			throw new InvalidGdlSchemaException("The topic " + TmHelper.getAnyIdOfTopic(this.tmRepresentative) + " must be bound to exactly one occurrence of the type " + GdlPsis.OccurrenceType.gdlId + ", but is bound " + idOccs.length() + " times to it");
 		} else {
 			return idOccs.get(0).getValue();
 		}

Added: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TmHelper.java
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TmHelper.java	Wed Jul 13 07:45:55 2011	(r609)
@@ -0,0 +1,265 @@
+package us.isidor.gdl.anaToMia.Widgets.base;
+
+import java.util.ArrayList;
+
+import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Association;
+import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Construct;
+import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Locator;
+import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Role;
+import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.ScopedStub;
+import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Topic;
+import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.TopicMap;
+import us.isidor.gdl.anaToMia.Widgets.base.GdlPsis.AssociationType;
+import us.isidor.gdl.anaToMia.Widgets.base.GdlPsis.RoleType;
+import us.isidor.gdl.anaToMia.Widgets.base.GdlPsis.TMDM;
+import us.isidor.gdl.anaToMia.Widgets.base.GdlPsis.TopicType;
+import us.isidor.gdl.anaToMia.Widgets.environment.Pair;
+import us.isidor.gdl.anaToMia.Widgets.environment.TopicIdentifierTypes;
+
+import com.google.gwt.core.client.JsArray;
+
+public class TmHelper {
+	
+	
+	// a helper that returns the topic bound to the identifier via a subject identifier
+	public static Topic getTopicByPsi(String subjectIdentifier, TopicMap tm){
+		if(subjectIdentifier == null || tm == null) return null;
+		
+		Locator loc = tm.createLocator(subjectIdentifier);
+		return tm.getTopicBySubjectIdentifier(loc);
+	}
+	
+	
+	// a helper that returns the topic bound to the identifier via a subject locator
+	public static Topic getTopicBySl(String subjectLocator, TopicMap tm){
+		if(subjectLocator == null || tm == null) return null;
+		
+		Locator loc = tm.createLocator(subjectLocator);
+		return tm.getTopicBySubjectLocator(loc);
+	}
+	
+	
+	// a helper that returns the topic bound to the identifier via an item identifier
+	public static Topic getTopicByIi(String itemIdentifier, TopicMap tm){
+		if(itemIdentifier == null || tm == null) return null;
+		
+		Locator loc = tm.createLocator(itemIdentifier);
+		return (Topic)tm.getConstructByItemIdentifier(loc);
+	}
+	
+	
+	// returns a topic that is identified by ref
+	public static Topic getTopicByAnyIdentifier(Pair<String, TopicIdentifierTypes> ref, TopicMap tm){
+		if(ref.getSecond() == TopicIdentifierTypes.ItemIdentifier){
+			return getTopicByIi(ref.getFirst(), tm);
+		}else if(ref.getSecond() == TopicIdentifierTypes.SubjectLocator){
+			return getTopicBySl(ref.getFirst(), tm);
+		}else {
+			return getTopicByPsi(ref.getFirst(), tm);
+		}
+	}	
+	
+	
+	// a helper method to return any identifier string of the topic
+	public static String getAnyIdOfTopic(Topic topic){
+		if(topic.getSubjectIdentifiers().length() != 0){
+			return topic.getSubjectIdentifiers().get(0).getReference();
+		}else if(topic.getSubjectLocators().length() != 0) {
+			return topic.getSubjectLocators().get(0).getReference();
+		}if(topic.getItemIdentifiers().length() != 0){
+			return topic.getItemIdentifiers().get(0).getReference();
+		} 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>();
+		TopicMap tm = type.getTopicMap();
+		
+		for(int i = 0; i != tm.getTopics().length(); ++i){
+			if(multipleTypesAllowed){
+				if(isInstanceOf(tm.getTopics().get(i), type)) result.add(tm.getTopics().get(i));
+			} else {
+				if(isInstanceOf(tm.getTopics().get(i), type) && tm.getTopics().get(i).getTypes().length() == 1) result.add(tm.getTopics().get(i));
+			}
+		}
+		
+		return result;
+	}
+	
+	
+	// returns true if the topic instance if an instance of the topic type
+	public static boolean isInstanceOf(Topic instance, Topic type){
+		if(instance == null || type == null) return false;
+
+		JsArray<Topic> types = instance.getTypes();
+		for(int i = 0; i != types.length(); ++i){
+			ArrayList<Topic> superTypes = getAllSuperTypes(types.get(i), null);
+			superTypes.add(types.get(i));
+			if(superTypes.contains(type)) return true;
+		}
+
+		return false;
+	}
+	
+	
+	// returns an array list with all direct and indirect supertypes of top
+	public static ArrayList<Topic> getAllSuperTypes(Topic top, ArrayList<Topic> collectedSupertypes){
+		if(top == null) return new ArrayList<Topic>();
+		
+		ArrayList<Topic> localCollectedSuperTypes = new ArrayList<Topic>();
+		if(collectedSupertypes != null) localCollectedSuperTypes = collectedSupertypes;
+		
+		ArrayList<Topic> direcSupertypes = getDirectSuperTypes(top);
+		for (Topic topic : localCollectedSuperTypes) direcSupertypes.remove(topic); //avoid duplicates
+		for (Topic topic : direcSupertypes)localCollectedSuperTypes.add(topic);
+		
+		for (Topic topic : direcSupertypes){
+			ArrayList<Topic> tmp = getAllSuperTypes(topic, localCollectedSuperTypes);
+			for (Topic tmpTopic : tmp) localCollectedSuperTypes.add(tmpTopic);
+		}
+		return localCollectedSuperTypes;
+	}
+	
+	
+	// returns the direct supertypes of the passed topic
+	public static ArrayList<Topic> getDirectSuperTypes(Topic top){
+		ArrayList<Topic> result = new ArrayList<Topic>();
+		if(top == null) return result;
+		TopicMap tm = top.getTopicMap();
+		Topic subtype = getTopicByPsi(TMDM.subtype, tm);
+		Topic supertype = getTopicByPsi(TMDM.supertype, tm);
+		Topic supertypeSubtype = getTopicByPsi(TMDM.supertypeSubtype, tm);
+		
+		if(subtype == null || supertype == null || supertypeSubtype == null) return result;
+		
+		JsArray<Role> validRoles = top.getRolesPlayed(subtype, supertypeSubtype);
+		for(int i = 0; i != validRoles.length(); ++i){
+			Association parent = validRoles.get(i).getParent();
+			if(parent.getRoles().length() == 2 && parent.getRoles(supertype).length() == 1)result.add(parent.getRoles(supertypeSubtype).get(0).getPlayer());
+		}
+		return result;
+	}
+	
+	
+	// returns true if a corresponding association exists
+	public static boolean hasAssociation(Topic thisTopic, Topic thisRoleType, Topic assocType, Topic otherPlayer, Topic otherRoleType){
+		if(thisTopic == null || thisRoleType == null || assocType == null || otherPlayer == null || otherRoleType == null) return false;
+		
+		JsArray<Role> roles = thisTopic.getRolesPlayed(thisRoleType, assocType);
+		for(int i = 0; i != roles.length(); ++i){
+			Association parent = roles.get(i).getParent();
+			JsArray<Role> otherRoles = parent.getRoles(otherRoleType);
+			for(int j = 0; j != otherRoles.length(); ++j)
+				if(otherRoles.get(j).getPlayer().equals(otherPlayer)) return true;
+		}
+		
+		return false;
+	}
+	
+	
+	// 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 otherRoleType){
+		ArrayList<Topic> result = new ArrayList<Topic>();
+		if(thisTopic == null || thisRoleType == null || assocType == null || otherRoleType == null) return result;
+		
+		JsArray<Role> roles = thisTopic.getRolesPlayed(thisRoleType, assocType);
+		for(int i = 0; i != roles.length(); ++i){
+			Association parent = roles.get(i).getParent();
+			if(parent.getRoles().length() != 2) return result;
+			if(thisRoleType.equals(otherRoleType) && parent.getRoles(thisTopic).length() == 2){
+				if(parent.getRoles(thisRoleType).get(0).getPlayer().equals(thisTopic)) result.add(parent.getRoles(thisRoleType).get(1).getPlayer()); 
+				else result.add(parent.getRoles(thisRoleType).get(0).getPlayer()); 
+			}else if(parent.getRoles(otherRoleType).length() == 1){
+				result.add(parent.getRoles(otherRoleType).get(0).getPlayer());
+			}
+		}
+		return result;
+	}
+
+	
+	// returns true if the instance topic is an instance of the topic bound to typeSubectIdentifier
+	public static boolean isInstanceOf(Topic instance, String typeSubjectIdentifier){
+		TopicMap tm = instance.getTopicMap();
+		Topic type = tm.getTopicBySubjectIdentifier(tm.createLocator(typeSubjectIdentifier));
+		return isInstanceOf(instance, type);
+	}
+	
+	
+	// returns true if the passed association has exactly the corresponding roles to
+	// the array list rolePlayersAndTypes
+	public static boolean hasRoles(Association assoc, ArrayList<Pair<Topic, Topic>> rolePlayertypesAndTypes){
+		if(assoc == null) return false;
+		if(assoc.getRoles().length() == 0 && rolePlayertypesAndTypes == null) return true;
+		if(assoc.getRoles().length() != rolePlayertypesAndTypes.size()) return false;
+		
+		for (Pair<Topic, Topic> pair : rolePlayertypesAndTypes) {
+			JsArray<Role> selection = assoc.getRoles(pair.getSecond());
+			int i = 0;
+			for(; i != selection.length(); ++i){
+				if(isInstanceOf(selection.get(i).getPlayer(), pair.getFirst())) break;
+			}
+			
+			if(i == selection.length()) return false;
+		}
+		
+		return true;
+	}
+	
+	
+	// returns true if the topics of themes are all equal to the scope of construct
+	public static boolean hasThemes(Construct construct, ArrayList<Topic> themes){
+		if(construct == null) return false;
+		
+		ScopedStub scoped = (ScopedStub)construct;
+		if(scoped.getScope().length() != 0 && (themes == null || themes.size() == 0)) return false;
+		if(scoped.getScope().length() != themes.size()) return false;
+		
+		for(int i = 0; i != scoped.getScope().length(); ++i){
+			if(!themes.contains(scoped.getScope().get(i))) return false;
+		}
+		
+		return true;
+	}
+	
+	
+	// returns all topics that are instances if tm-value, which are also bound to this
+	// topic via a gdl:tm-binding association
+	public static ArrayList<Topic> getTmValues(Topic top){
+		ArrayList<Topic> result = new ArrayList<Topic>();
+		if(top == null) return result;
+		TopicMap tm = top.getTopicMap();
+		Topic descriptor = getTopicByPsi(RoleType.gdlDescriptor, tm);
+		Topic tmBinding = getTopicByPsi(AssociationType.gdlTmBinding, tm);
+		Topic tmValue = getTopicByPsi(TopicType.gdlTmValue, tm);
+		
+		JsArray<Role> roles = top.getRolesPlayed(descriptor, tmBinding);
+		for(int i = 0; i != roles.length(); ++i){
+			Association parent = roles.get(i).getParent();
+			if(parent.getRoles().length() == 2 && parent.getRoles(descriptor).length() == 1 &&
+					isInstanceOf(parent.getRoles(descriptor).get(0).getPlayer(), tmValue))
+				result.add(parent.getRoles(descriptor).get(0).getPlayer());
+		}
+		return result;
+	}
+	
+	
+	// returns the associations that are bound to the topic "topic" and have the passed scope and roles
+	public static ArrayList<Association> getAssociationsOfTopic(Topic topic, Topic roleType, Topic assocType, ArrayList<Topic> scope, ArrayList<Pair<Topic, Topic>> rolePlayertypesAndTypes){
+		ArrayList<Association> result = new ArrayList<Association>();
+		if(topic == null || assocType == null || rolePlayertypesAndTypes == null || rolePlayertypesAndTypes.size() == 0) return result;
+		
+		ArrayList<Association> allPotentialAssocs = new ArrayList<Association>();
+		for(int i = 0; i != topic.getRolesPlayed(roleType, assocType).length(); ++i) allPotentialAssocs.add(topic.getRolesPlayed(roleType, assocType).get(i).getParent());
+		
+		ArrayList<Association> assocsWoScope = new ArrayList<Association>();
+		for (Association assoc : allPotentialAssocs) if(hasRoles(assoc, rolePlayertypesAndTypes)) assocsWoScope.add(assoc);
+		
+		for (Association assoc : assocsWoScope) if(hasThemes(assoc, scope)) result.add(assoc);
+		
+		return result;
+	}
+}

Added: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/Utils.java
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/Utils.java	Wed Jul 13 07:45:55 2011	(r609)
@@ -0,0 +1,20 @@
+package us.isidor.gdl.anaToMia.Widgets.base;
+
+import java.util.ArrayList;
+
+public class Utils {
+	
+	// returns true if both arrays have the same items
+	public static <T> boolean compareLists(ArrayList<T> lft, ArrayList<T> rgt){
+		if(lft == null && rgt == null) return true;
+		if(lft == null || rgt == null) return false;
+		if(lft.size() != rgt.size()) return false;
+		
+		for(Object obj : lft) if(!rgt.contains(obj))return false;
+		
+		// because of duplicate values the reverse comparison must also be done
+		for(Object obj : rgt) if(!lft.contains(obj))return false;
+			
+		return true;
+	}
+}

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 05:38:00 2011	(r608)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/environment/GdlInstantiator.java	Wed Jul 13 07:45:55 2011	(r609)
@@ -7,6 +7,8 @@
 import us.isidor.gdl.anaToMia.Widgets.base.GdlLineBreak;
 import us.isidor.gdl.anaToMia.Widgets.base.GdlPsis;
 import us.isidor.gdl.anaToMia.Widgets.base.GdlVisibleObject;
+import us.isidor.gdl.anaToMia.Widgets.base.TmHelper;
+import us.isidor.gdl.anaToMia.Widgets.base.Utils;
 import us.isidor.gdl.anaToMia.Widgets.button.GdlActionButton;
 import us.isidor.gdl.anaToMia.Widgets.button.GdlCheckBox;
 import us.isidor.gdl.anaToMia.Widgets.button.GdlCommitButton;
@@ -40,74 +42,175 @@
 	// returns a java instance of a GdlVisibleObject that corresponds to the
 	// set topic type of the passed topic instance
 	public static GdlVisibleObject instantiate(Topic tmRepresentative) throws InvalidGdlSchemaException, ExecutionException{
-		if(GdlPsis.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlLineBreak)){
+		if(TmHelper.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlLineBreak)){
 			return new GdlLineBreak(tmRepresentative);
-		}else if(GdlPsis.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlInfo)){
+		}else if(TmHelper.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlInfo)){
 			return new GdlInfo(tmRepresentative);
-		}else if(GdlPsis.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlTitle)){
+		}else if(TmHelper.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlTitle)){
 			return new GdlTitle(tmRepresentative);
-		}else if(GdlPsis.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlReference)){
+		}else if(TmHelper.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlReference)){
 			return new GdlReference(tmRepresentative);
-		}else if(GdlPsis.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlRadioButton)){
+		}else if(TmHelper.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlRadioButton)){
 			return new GdlRadioButton(tmRepresentative);
-		}else if(GdlPsis.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlCheckBox)){
+		}else if(TmHelper.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlCheckBox)){
 			return new GdlCheckBox(tmRepresentative);
-		}else if(GdlPsis.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlActionButton)){
+		}else if(TmHelper.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlActionButton)){
 			return new GdlActionButton(tmRepresentative);
-		}else if(GdlPsis.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlValidateButton)){
+		}else if(TmHelper.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlValidateButton)){
 			return new GdlValidateButton(tmRepresentative);
-		}else if(GdlPsis.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlCreateButton)){
+		}else if(TmHelper.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlCreateButton)){
 			return new GdlCreateButton(tmRepresentative);
-		}else if(GdlPsis.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlDeleteButton)){
+		}else if(TmHelper.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlDeleteButton)){
 			return new GdlDeleteButton(tmRepresentative);
-		}else if(GdlPsis.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlCommitButton)){
+		}else if(TmHelper.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlCommitButton)){
 			return new GdlCommitButton(tmRepresentative);
-		}else if(GdlPsis.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlImage)){
+		}else if(TmHelper.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlImage)){
 			return new GdlImage(tmRepresentative);
-		}else if(GdlPsis.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlVideo)){
+		}else if(TmHelper.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlVideo)){
 			return new GdlVideo(tmRepresentative);
-		}else if(GdlPsis.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlAudio)){
+		}else if(TmHelper.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlAudio)){
 			return new GdlAudio(tmRepresentative);
-		}else if(GdlPsis.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlDatePicker)){
+		}else if(TmHelper.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlDatePicker)){
 			return new GdlDatePicker(tmRepresentative);
-		}else if(GdlPsis.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlTimePicker)){
+		}else if(TmHelper.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlTimePicker)){
 			return new GdlTimePicker(tmRepresentative);
-		}else if(GdlPsis.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlDateTimePicker)){
+		}else if(TmHelper.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlDateTimePicker)){
 			return new GdlDateTimePicker(tmRepresentative);
-		}else if(GdlPsis.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlUnit)){
+		}else if(TmHelper.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlUnit)){
 			return new GdlUnit(tmRepresentative);
-		}else if(GdlPsis.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlText)){
+		}else if(TmHelper.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlText)){
 			return new GdlText(tmRepresentative);
-		}else if(GdlPsis.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlList)){
+		}else if(TmHelper.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlList)){
 			return new GdlList(tmRepresentative);
-		}else if(GdlPsis.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlListBox)){
+		}else if(TmHelper.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlListBox)){
 			return new GdlListBox(tmRepresentative);
-		}else if(GdlPsis.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlDefaultCreatorTopicView)){
+		}else if(TmHelper.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlDefaultCreatorTopicView)){
 			return new GdlDefaultCreatorTopicView(tmRepresentative);
-		}else if(GdlPsis.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlDefaultEditorTopicView)){
+		}else if(TmHelper.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlDefaultEditorTopicView)){
 			return new GdlDefaultEditorTopicView(tmRepresentative);
-		}else if(GdlPsis.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlSpecialCreatorTopicView)){
+		}else if(TmHelper.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlSpecialCreatorTopicView)){
 			return new GdlSpecialCreatorTopicView(tmRepresentative);
-		}else if(GdlPsis.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlSpecialEditorTopicView)){
+		}else if(TmHelper.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlSpecialEditorTopicView)){
 			return new GdlSpecialEditorTopicView(tmRepresentative);
-		}else if(GdlPsis.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlCreatorAssociationview)){
+		}else if(TmHelper.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlCreatorAssociationview)){
 			return new GdlCreatorAssociationView(tmRepresentative);
-		}else if(GdlPsis.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlEditorAssociationView)){
+		}else if(TmHelper.isInstanceOf(tmRepresentative, GdlPsis.TopicType.gdlEditorAssociationView)){
 			return new GdlEditorAssociationView(tmRepresentative);
 		}else{
 			String values = "";
 			for(int i = 0; i != tmRepresentative.getTypes().length(); ++i){
 				if(i != tmRepresentative.getTypes().length() - 1){
-					values += GdlPsis.getAnyIdOfTopic(tmRepresentative.getTypes().get(i)) + ", ";
+					values += TmHelper.getAnyIdOfTopic(tmRepresentative.getTypes().get(i)) + ", ";
 				}else {
-					values += GdlPsis.getAnyIdOfTopic(tmRepresentative.getTypes().get(i));	
+					values += TmHelper.getAnyIdOfTopic(tmRepresentative.getTypes().get(i));	
 				}
 			}
-			throw new InvalidGdlSchemaException("the topic " + GdlPsis.getAnyIdOfTopic(tmRepresentative) + " is an instance of an unsupported visible topic type or an abstract topic type: " + values);
+			throw new InvalidGdlSchemaException("the topic " + TmHelper.getAnyIdOfTopic(tmRepresentative) + " is an instance of an unsupported visible topic type or an abstract topic type: " + values);
 		}
 	}
 
+	
+	// returns a GdlDefaultCreatorTopicView tha corresponds to the passed arguements
+	public static GdlDefaultCreatorTopicView instantiateDefaultCreatorTopicView(ArrayList<Pair<String, TopicIdentifierTypes>> requestedTopics, TopicMap schemaTm) throws InvalidGdlSchemaException, ExecutionException{
+		ArrayList<Topic> views = getViewTopics(requestedTopics, TmHelper.getTopicByPsi(GdlPsis.TopicType.gdlDefaultCreatorTopicView, schemaTm), schemaTm);
+		
+		if(views.size() != 1){
+			String values = "";
+			for (Pair<String, TopicIdentifierTypes> pair : requestedTopics)
+				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 fo topics requested (" + values + ") must be bound exactly once to a " + GdlPsis.TopicType.gdlDefaultCreatorTopicView + " but is bound to " + bindings);
+		}
+		
+		return new GdlDefaultCreatorTopicView(views.get(0));
+	}
+	
+	
+	// returns the topics that are bound to the corresponding user topics and corresponds to the
+	// given view super type. Note only topics that are bound to TM-Single-Type-Value and
+	// TM-Multiple-Type-Value are taken into account.
+	public static ArrayList<Topic> getViewTopics(ArrayList<Pair<String, TopicIdentifierTypes>> requestedTopics, Topic viewSupertype, TopicMap schemaTm) throws InvalidGdlSchemaException{
+	if(requestedTopics == null || requestedTopics.size() == 0 || schemaTm == null) return null;
+		
+		// request all topics that are passed by the user
+		ArrayList<Topic> requestedTops = new ArrayList<Topic>();
+		for (Pair<String, TopicIdentifierTypes> topId : requestedTopics){
+			Topic top = TmHelper.getTopicByAnyIdentifier(topId, schemaTm);
+			if(top == null) throw new InvalidGdlSchemaException("the topic " + topId.getFirst() + " was not found!");
+			if(!requestedTops.contains(top)) requestedTops.add(top);
+		}
+		
+		// get all TM-Values, i.e. TM-Multiple-Type-Value and TM-Single-Type-Value (only if requstedTops.sie() == 1)
+		ArrayList<Topic> tmValues = new ArrayList<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);
+		Topic tmMultipleTypeValue = TmHelper.getTopicByPsi(GdlPsis.TopicType.gdlTmMultipleTypeValue, schemaTm);
+		Topic tmSingleTypeValue = TmHelper.getTopicByPsi(GdlPsis.TopicType.gdlTmSingleTypeValue, schemaTm);
+		for (Topic requestedTopic : requestedTops) {
+			ArrayList<Topic> allTmValues = TmHelper.getOtherPlayerOfBinaryAssociation(requestedTopic, tmConstruct, tmBinding, null, descriptor);
+			// filter only the valid tm-values for this scenario 
+			for (Topic tmValue : allTmValues){
+				if(TmHelper.isInstanceOf(tmValue, tmMultipleTypeValue) || (requestedTops.size() == 1 && TmHelper.isInstanceOf(tmValue, tmSingleTypeValue))){
+					// check all user topics that are associated with the tmValue, i.e. a tmValue is only valid
+					// if exactly those topics are associated to it through a tm-binding association, which are
+					// requested by the user
+					ArrayList<Topic> allInstanceValues = TmHelper.getOtherPlayerOfBinaryAssociation(tmValue, descriptor, tmBinding, null, tmConstruct);
+					if(Utils.compareLists(allInstanceValues, requestedTops) && !tmValues.contains(tmValue)) tmValues.add(tmValue);
+				}
+			}
+		}
+		
+		// get all views that are bound to the found tm-values
+		ArrayList<Topic> views = new ArrayList<Topic>();
+		Topic tmValueRoleType = TmHelper.getTopicByPsi(GdlPsis.RoleType.gdlTmValue, schemaTm);
+		Topic topicViewBinding = TmHelper.getTopicByPsi(GdlPsis.AssociationType.gdlTopicViewBinding, schemaTm);
+		for (Topic tmValue : tmValues) {
+			ArrayList<Topic> allViews = TmHelper.getOtherPlayerOfBinaryAssociation(tmValue, tmValueRoleType, topicViewBinding, null, descriptor);
+			// filter for allViews
+			if(viewSupertype == null){
+				for (Topic view : allViews)
+					if(!views.contains(view))views.add(view);
+			} else {
+				for (Topic view : allViews)
+					if(!views.contains(view) && TmHelper.isInstanceOf(view, viewSupertype)) views.add(view);
+			}
+		}
+		
+		return views;
+	}
+	
+	
+	
+	public static GdlDefaultEditorTopicView instantiateDefaultEditorTopicView(Pair<String, TopicIdentifierTypes> requestedTopic, TopicMap schemaTm){
+		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
+		
+		// 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
 
+		
+		// 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{
@@ -118,43 +221,43 @@
 			throw new ExecutionException("only one of topic is allowed to be set as the base topic for a " + GdlPsis.TopicType.gdlView + " but found: " + values);
 		}
 		
-		Topic defaultCreatorTopicView = GdlPsis.getTopicByPsi(GdlPsis.TopicType.gdlDefaultCreatorTopicView, tm);
-		Topic defaultEditorTopicView = GdlPsis.getTopicByPsi(GdlPsis.TopicType.gdlDefaultEditorTopicView, tm);
+		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");
 		}else {
 			// all topics (types) that have to be displayed by a view
 			ArrayList<Topic> topsToDisplay = new ArrayList<Topic>();
 			if(instanceTopic != null){
-				topsToDisplay.add(GdlPsis.getTopicByAnyIdentifier(instanceTopic, tm));
+				topsToDisplay.add(TmHelper.getTopicByAnyIdentifier(instanceTopic, tm));
 			}else{
 				for (Pair<String, TopicIdentifierTypes> pair : typeTopics) {
-					topsToDisplay.add(GdlPsis.getTopicByAnyIdentifier(pair, tm));
+					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 = GdlPsis.getTopicByPsi(GdlPsis.RoleType.gdlDescriptor, tm);
-			Topic tmBinding = GdlPsis.getTopicByPsi(GdlPsis.AssociationType.gdlTmBinding, tm);
-			Topic tmValue = GdlPsis.getTopicByPsi(GdlPsis.RoleType.gdlTmValue, tm);
-			Topic TmValue = GdlPsis.getTopicByPsi(GdlPsis.TopicType.gdlTmValue, tm);
-			Topic tmConstruct = GdlPsis.getTopicByPsi(GdlPsis.RoleType.gdlTmConstruct, tm);
+			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 = GdlPsis.getOtherPlayerOfBinaryAssociation(topic, tmConstruct, tmBinding, null, descriptor);
+				ArrayList<Topic> potentialTmValues = TmHelper.getOtherPlayerOfBinaryAssociation(topic, tmConstruct, tmBinding, null, descriptor);
 				for (Topic potentialTmValue : potentialTmValues)
-					if(GdlPsis.isInstanceOf(potentialTmValue, TmValue)) tmValues.add(potentialTmValue);
+					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 = GdlPsis.getTopicByPsi(GdlPsis.TMCL.topictype, tm);
+			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(GdlPsis.hasAssociation(topToDisplay, tmConstruct, tmBinding, value, descriptor) ||
-							GdlPsis.getAssociationsOfTopic(value, descriptor, tmBinding, null, roles).size() != topsToDisplay.size()){
+					if(TmHelper.hasAssociation(topToDisplay, tmConstruct, tmBinding, value, descriptor) ||
+							TmHelper.getAssociationsOfTopic(value, descriptor, tmBinding, null, roles).size() != topsToDisplay.size()){
 						invalidTmValues.add(value);
 					}
 				}
@@ -164,17 +267,17 @@
 			
 			// get all default topic views that are bound to the existent tm-values
 			ArrayList<Topic> defaultTopicViews = new ArrayList<Topic>();
-			Topic defaultTopicView = GdlPsis.getTopicByPsi(GdlPsis.TopicType.gdlDefaultTopicView, tm);
-			Topic topicViewBinding = GdlPsis.getTopicByPsi(GdlPsis.AssociationType.gdlTopicViewBinding, tm);
+			Topic defaultTopicView = TmHelper.getTopicByPsi(GdlPsis.TopicType.gdlDefaultTopicView, tm);
+			Topic topicViewBinding = TmHelper.getTopicByPsi(GdlPsis.AssociationType.gdlTopicViewBinding, tm);
 			for (Topic validTmValue : tmValues) {
-				ArrayList<Topic> views = GdlPsis.getOtherPlayerOfBinaryAssociation(validTmValue, tmValue, topicViewBinding, null, descriptor);
-				for (Topic view : views) if(GdlPsis.isInstanceOf(view, defaultTopicView)) defaultTopicViews.add(view);
+				ArrayList<Topic> views = TmHelper.getOtherPlayerOfBinaryAssociation(validTmValue, tmValue, topicViewBinding, null, descriptor);
+				for (Topic view : views) if(TmHelper.isInstanceOf(view, defaultTopicView)) defaultTopicViews.add(view);
 			}
 			
 			// return default-topic-view
 			if(defaultTopicViews.size() > 2){
 				String values = "";
-				for (Topic topic : topsToDisplay)values += ", " + GdlPsis.getAnyIdOfTopic(topic);
+				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){
@@ -182,7 +285,7 @@
 			} else if(defaultTopicViews.size() == 2){ // one creator and one editor view
 				Topic creatorView = null;
 				Topic editorView = null;
-				if(GdlPsis.isInstanceOf(defaultTopicViews.get(0), GdlPsis.TopicType.gdlDefaultCreatorTopicView)){
+				if(TmHelper.isInstanceOf(defaultTopicViews.get(0), GdlPsis.TopicType.gdlDefaultCreatorTopicView)){
 					creatorView = defaultTopicViews.get(0);
 					editorView = defaultTopicViews.get(1);
 				}else {

Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/environment/ILoadSchemaCallback.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/environment/ILoadSchemaCallback.java	Wed Jul 13 05:38:00 2011	(r608)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/environment/ILoadSchemaCallback.java	Wed Jul 13 07:45:55 2011	(r609)
@@ -6,5 +6,5 @@
 import us.isidor.gdl.anaToMia.Widgets.base.GdlPanel;
 
 public interface ILoadSchemaCallback {
-	public void loadSchema(GdlPanel panel, ArrayList<Pair<String, TopicIdentifierTypes>> requestedTopicsToEdit, ArrayList<Pair<String, TopicIdentifierTypes>> requestedTopicsToCreate)throws RequestException;
+	public void loadSchema(GdlPanel panel, Pair<String, TopicIdentifierTypes> requestedTopicToEdit, ArrayList<Pair<String, TopicIdentifierTypes>> requestedTopicsToCreate)throws RequestException;
 }

Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/LoadSchemaCallback.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/LoadSchemaCallback.java	Wed Jul 13 05:38:00 2011	(r608)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/LoadSchemaCallback.java	Wed Jul 13 07:45:55 2011	(r609)
@@ -25,7 +25,7 @@
 public class LoadSchemaCallback implements ILoadSchemaCallback{
 	private final String isidorusUrl = URL.encode(GWT.getModuleBaseURL() + "test.gdl.jtm"); // TODO: replace with the correct URL
 	private ArrayList<Pair<String, TopicIdentifierTypes>> requestedTopicsToCreate = new ArrayList<Pair<String,TopicIdentifierTypes>>(); 
-	private ArrayList<Pair<String, TopicIdentifierTypes>> requestedTopicsToEdit = new ArrayList<Pair<String,TopicIdentifierTypes>>(); 
+	private Pair<String, TopicIdentifierTypes> requestedTopicToEdit = null;
 	private RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, isidorusUrl);
 	
 	
@@ -34,9 +34,9 @@
 	
 	// this method is invoked as a callback method
 	@Override
-	public void loadSchema(GdlPanel panel, ArrayList<Pair<String, TopicIdentifierTypes>> requestedTopicsToEdit , ArrayList<Pair<String, TopicIdentifierTypes>> requestedTopicsToCreate)throws RequestException {
+	public void loadSchema(GdlPanel panel, Pair<String, TopicIdentifierTypes> requestedTopicToEdit , ArrayList<Pair<String, TopicIdentifierTypes>> requestedTopicsToCreate)throws RequestException {
 		this.requestedTopicsToCreate = requestedTopicsToCreate;
-		this.requestedTopicsToEdit = requestedTopicsToEdit;
+		this.requestedTopicToEdit = requestedTopicToEdit;
 		requestBuilder.sendRequest(null, new RequestCallbackImpl(panel));
 	}
 
@@ -75,7 +75,7 @@
 					public void onClick(ClickEvent event) {
 						dialog.hide();
 						try{
-							loadSchema(panel, LoadSchemaCallback.this.requestedTopicsToEdit, LoadSchemaCallback.this.requestedTopicsToCreate);
+							loadSchema(panel, LoadSchemaCallback.this.requestedTopicToEdit, LoadSchemaCallback.this.requestedTopicsToCreate);
 						}catch(Exception e){
 							Window.alert("connection to : " + isidorusUrl + " failed: " + e.getMessage());
 						}
@@ -102,7 +102,7 @@
 				public void onClick(ClickEvent event) {
 					dialog.hide();
 					try{
-						loadSchema(panel, LoadSchemaCallback.this.requestedTopicsToEdit, LoadSchemaCallback.this.requestedTopicsToCreate);
+						loadSchema(panel, LoadSchemaCallback.this.requestedTopicToEdit, LoadSchemaCallback.this.requestedTopicsToCreate);
 					}catch(Exception e){
 						Window.alert("connection to : " + isidorusUrl + " failed: " + e.getMessage());
 					}

Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/view/GdlView.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/view/GdlView.java	Wed Jul 13 05:38:00 2011	(r608)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/view/GdlView.java	Wed Jul 13 07:45:55 2011	(r609)
@@ -14,6 +14,7 @@
 import us.isidor.gdl.anaToMia.Widgets.base.GdlVisibleObject;
 import us.isidor.gdl.anaToMia.Widgets.base.IGdlContainer;
 import us.isidor.gdl.anaToMia.Widgets.base.IGdlHasValue;
+import us.isidor.gdl.anaToMia.Widgets.base.TmHelper;
 import us.isidor.gdl.anaToMia.Widgets.environment.ExecutionException;
 import us.isidor.gdl.anaToMia.Widgets.environment.InvalidGdlSchemaException;
 
@@ -68,7 +69,7 @@
 			if(topsWithoutAncestorPosAssoc.size() > 1){
 				String foundTops = "";
 				for (Topic topic : topsWithoutAncestorPosAssoc) {
-					foundTops += GdlPsis.getAnyIdOfTopic(topic) + ", ";
+					foundTops += TmHelper.getAnyIdOfTopic(topic) + ", ";
 				}
 				if(foundTops.length() >= 2)foundTops = foundTops.substring(0, foundTops.length() - 2);
 				throw new InvalidGdlSchemaException("A " + GdlPsis.TopicType.gdlView + " must have maximal one item that is desiganted to tbe the first item in this view, i.e. there must be zero or one items without being bound to a " + GdlPsis.RoleType.gdlAncestor + " but found: " + foundTops);




More information about the Isidorus-cvs mailing list