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

lgiessmann at common-lisp.net lgiessmann at common-lisp.net
Mon Aug 22 17:53:48 UTC 2011


Author: lgiessmann
Date: Mon Aug 22 10:53:48 2011
New Revision: 773

Log:
gdl-frontend: Widgets: implemented filtering for GdlAssociationView, so only associations that are valid to the defined constraints of the GdlAssociationView are represented by this view, currently role-combination-constraints are not examined

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/Utils.java
   branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/view/GdlAssociationView.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	Mon Aug 22 09:00:17 2011	(r772)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TmHelper.java	Mon Aug 22 10:53:48 2011	(r773)
@@ -633,7 +633,7 @@
 
 	
 	// returns the constrained role-types of the passed constraint
-	public static Topic getConstraintRolesOfConstraint(Topic topicRoleOrAssociationRoleConstraint) throws InvalidGdlSchemaException {
+	public static Topic getConstraintRoleOfConstraint(Topic topicRoleOrAssociationRoleConstraint) throws InvalidGdlSchemaException {
 		if(topicRoleOrAssociationRoleConstraint == null) return null;
 		
 		TopicMap tm = topicRoleOrAssociationRoleConstraint.getTopicMap();
@@ -648,6 +648,22 @@
 	}
 	
 	
+	// returns the constrained role and player types of the passed constraint
+	public static Pair<Topic, Topic> getConstraintRoleAndPlayerTypeOfConstraint(Topic topicRoleConstraint) throws InvalidGdlSchemaException {
+		if(topicRoleConstraint == null) return null;
+		
+		TopicMap tm = topicRoleConstraint.getTopicMap();
+		Topic constraintRoleType = getTopicByPsi(PSIs.TMCL.tmclConstraint, tm);
+		Topic constrainedTopicTypeAssocType = getTopicByPsi(PSIs.TMCL.tmclConstrainedTopicType, tm);
+		Topic constrainedRoleType = getTopicByPsi(PSIs.TMCL.tmclConstrained, tm);
+		Topic topicType = getTopicByPsi(PSIs.TMCL.tmclTopictype, tm);
+		ArrayList<Topic> result = getOtherPlayerOfBinaryAssociation(topicRoleConstraint, constraintRoleType, constrainedTopicTypeAssocType, null, topicType, constrainedRoleType);
+		
+		if(result.size() != 1) throw new InvalidGdlSchemaException("the topic " + getAnyIdOfTopic(topicRoleConstraint) + " must be bound exactly once to a topic-type via a " + PSIs.TMCL.tmclConstrainedTopicType + " association, but is bound: " + result.size());
+		else return new Pair<Topic, Topic>(getConstraintRoleOfConstraint(topicRoleConstraint), result.get(0));
+	}
+	
+	
 	// returns the topic that plays the role of tmcl:constrained in an association
 	// of the type tmcl:constrained-statement that is bound to the passed topic
 	// constrinatTopic that plays the role of tmcl:constraint

Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/Utils.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/Utils.java	Mon Aug 22 09:00:17 2011	(r772)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/Utils.java	Mon Aug 22 10:53:48 2011	(r773)
@@ -7,7 +7,6 @@
 import com.google.gwt.dom.client.Element;
 
 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;

Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/view/GdlAssociationView.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/view/GdlAssociationView.java	Mon Aug 22 09:00:17 2011	(r772)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/view/GdlAssociationView.java	Mon Aug 22 10:53:48 2011	(r773)
@@ -2,45 +2,44 @@
 
 import java.util.ArrayList;
 
+import com.google.gwt.core.client.JsArray;
 import com.google.gwt.user.client.Window;
-
 import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Association;
+import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Role;
 import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Topic;
-import us.isidor.gdl.anaToMia.Widgets.base.PSIs;
 import us.isidor.gdl.anaToMia.Widgets.base.TmHelper;
-import us.isidor.gdl.anaToMia.Widgets.base.Utils;
 import us.isidor.gdl.anaToMia.Widgets.environment.ExecutionException;
 import us.isidor.gdl.anaToMia.Widgets.environment.InvalidGdlSchemaException;
+import us.isidor.gdl.anaToMia.Widgets.environment.Pair;
 
 
 public abstract class GdlAssociationView extends GdlView {
 	protected ArrayList<Association> associationsToRepresent = null;
+	protected boolean associationsToRepresentSet = false;
 	private ArrayList<Topic> associationRoleConstraints = new ArrayList<Topic>();
-	private boolean associationRoleconstraintsSet = false;
+	private boolean associationRoleConstraintsSet = false;
 	private ArrayList<Topic> topicRoleConstraints = new ArrayList<Topic>();
 	private boolean topicRoleConstraintsSet = false;
 	private Topic associationType = null;
 	private boolean associationTypeSet = false;
-	private ArrayList<Topic> roleTypes = new ArrayList<Topic>();
-	private boolean roleTypesSet = false;
+	private ArrayList<Pair<Topic, Topic>> roleAndPlayerTypes = new ArrayList<Pair<Topic, Topic>>();
+	private boolean roleAndPlayerTypesSet = false;
 	private ArrayList<Topic> roleCombinationConstraints = new ArrayList<Topic>();
 	private boolean roleCombinationConstraintsSet = false;
 	
 
 	public GdlAssociationView(Topic tmRepresentative, Topic receivedData) throws InvalidGdlSchemaException, ExecutionException {
 		super(tmRepresentative, receivedData);
-		Window.alert("constraints: " +this.getRoleTypes().size() + " >> " + (this instanceof GdlEditorAssociationView));
-		
 		if(this instanceof GdlEditorAssociationView) this.associationsToRepresent = this.filterAssociations();
 	}
 	
 	
 	// Return the association-role-constraints this view is bound to
 	public ArrayList<Topic> getAssociationRoleConstraints() throws InvalidGdlSchemaException {
-		if(this.associationRoleconstraintsSet){
+		if(this.associationRoleConstraintsSet){
 			return this.associationRoleConstraints;
 		} else {
-			this.associationRoleconstraintsSet = true;
+			this.associationRoleConstraintsSet = true;
 			this.associationRoleConstraints = TmHelper.getAssociationRoleConstraintsForView(this.tmRepresentative);
 			return this.associationRoleConstraints;
 		}
@@ -75,24 +74,30 @@
 	
 	// returns the role-types that are valid to be used
 	// in associations of the type that is bound to this view
-	public ArrayList<Topic> getRoleTypes() throws InvalidGdlSchemaException {
-		if(this.roleTypesSet){
-			return this.roleTypes;
+	public ArrayList<Pair<Topic, Topic>> getRoleAndPlayerTypes() throws InvalidGdlSchemaException {
+		if(this.roleAndPlayerTypesSet){
+			return this.roleAndPlayerTypes;
 		} else {
-			this.roleTypesSet = true;
+			this.roleAndPlayerTypesSet = true;
 			ArrayList<Topic> roleTypesOfAssociationRoleConstraints = new ArrayList<Topic>();
 			for (Topic constraint : this.getAssociationRoleConstraints()){
-				Topic top = TmHelper.getConstraintRolesOfConstraint(constraint);
+				Topic top = TmHelper.getConstraintRoleOfConstraint(constraint);
 				if(!roleTypesOfAssociationRoleConstraints.contains(top)) roleTypesOfAssociationRoleConstraints.add(top);
 			}
 			
-			ArrayList<Topic> roleTypesOfTopicRoleConstraints = new ArrayList<Topic>();
+			ArrayList<Pair<Topic, Topic>> roleTypesOfTopicRoleConstraints = new ArrayList<Pair<Topic, Topic>>();
 			for (Topic constraint : this.getTopicRoleConstraints()){
-				Topic top = TmHelper.getConstraintRolesOfConstraint(constraint);
-				if(!roleTypesOfTopicRoleConstraints.contains(top)) roleTypesOfTopicRoleConstraints.add(top);
+				Pair<Topic, Topic> roleAndPlayerType = TmHelper.getConstraintRoleAndPlayerTypeOfConstraint(constraint);
+				if(!roleTypesOfTopicRoleConstraints.contains(roleAndPlayerType)) roleTypesOfTopicRoleConstraints.add(roleAndPlayerType);
+			}
+			
+			ArrayList<Pair<Topic, Topic>> result = new ArrayList<Pair<Topic,Topic>>();
+			for (Pair<Topic, Topic> roleAndPlayerType : roleTypesOfTopicRoleConstraints) {
+				if(roleTypesOfAssociationRoleConstraints.contains(roleAndPlayerType.getFirst())) result.add(roleAndPlayerType);
 			}
 			
-			return Utils.union(roleTypesOfAssociationRoleConstraints, roleTypesOfTopicRoleConstraints);
+			this.roleAndPlayerTypes = result;
+			return this.roleAndPlayerTypes;
 		}
 	}
 	
@@ -130,10 +135,76 @@
 	}
 	
 	
+	// returns all associations of the received topicthat have a
+	// correct type determined by this association-view
+	private ArrayList<Association> filterAssociationsByType() throws InvalidGdlSchemaException {
+		ArrayList<Association> allAssociations = new ArrayList<Association>();
+		if(this.receivedData != null)
+			for(int i = 0; i != ((Topic)this.receivedData).getRolesPlayed().length(); ++i)
+				allAssociations.add(((Topic)this.receivedData).getRolesPlayed().get(i).getParent());
+		
+		// collect only the associations that match the correct association type
+		ArrayList<Association> filteredAssociationsByType = new ArrayList<Association>();
+		for (Association assoc : allAssociations)
+			if(assoc.getType().equals(this.getAssociationType())) filteredAssociationsByType.add(assoc);
+		
+		return filteredAssociationsByType;
+	}
+	
+	
+	// returns all associations contained in the ArrayList allAssociations
+	// that have the only permitted role types
+	private ArrayList<Association> filterAssociationsByRoleAndPlayerTypes(ArrayList<Association> allAssociations) throws InvalidGdlSchemaException {
+		if(allAssociations == null) return new ArrayList<Association>();
+		
+		ArrayList<Association> filteredAssociationsByAssociationRoleConstraints = new ArrayList<Association>();
+		for (Association assoc : allAssociations){
+			JsArray<Role> roles = assoc.getRoles();
+			int i = 0;
+			for( ; i != roles.length(); ++i){
+				Topic rt = roles.get(i).getType();
+				Topic rp = roles.get(i).getPlayer();
+
+				int j = 0;
+				for( ; j != this.getRoleAndPlayerTypes().size(); ++j){
+					Pair<Topic, Topic> pair = this.getRoleAndPlayerTypes().get(j);
+					if(pair.getFirst().equals(rt) && TmHelper.isInstanceOf(rp, pair.getSecond())) break;
+				}
+
+				if(j == this.getRoleAndPlayerTypes().size()) break;
+			}
+			
+			if(i == roles.length())filteredAssociationsByAssociationRoleConstraints.add(assoc);
+		}
+		
+		return filteredAssociationsByAssociationRoleConstraints; 
+	}
+
 	
-	public ArrayList<Association> filterAssociations(){
-		// TODO: implement => returns an array with associations that
-		//       must be represetned by this association view
+	// returns all associations contained in the ArrayList allAssociations
+	// that are valid to the role-combination-constraints that belongs to this view
+	private ArrayList<Association> filterAssociationsByRoleCombinations(ArrayList<Association> allAssociations) throws InvalidGdlSchemaException {
+		// TODO: implement
 		return null;
 	}
+	
+		
+	// returns an array with associations that
+	// must be represented by this association view
+	private ArrayList<Association> filterAssociations() throws InvalidGdlSchemaException {
+		ArrayList<Association> filteredAssociations = this.filterAssociationsByType();
+		filteredAssociations = filterAssociationsByRoleAndPlayerTypes(filteredAssociations);
+		filteredAssociations = filterAssociationsByRoleCombinations(filteredAssociations);
+		
+		this.associationsToRepresent = filteredAssociations;
+		this.associationsToRepresentSet = true;
+		return this.associationsToRepresent;
+	}
+	
+	
+	// Returns the associations that are represented by this associaton-view
+	public ArrayList<Association> getAssociationsToRepresent() throws InvalidGdlSchemaException {
+		if(this.associationsToRepresentSet) return this.associationsToRepresent;
+		else return this.filterAssociations();
+	}
 }




More information about the Isidorus-cvs mailing list