[isidorus-cvs] r605 - 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
Tue Jul 12 20:26:23 UTC 2011
Author: lgiessmann
Date: Tue Jul 12 13:26:22 2011
New Revision: 605
Log:
gdl-frontend: Widgets: implemted a mehtod that instantiates the default topic view, i.e. the entry point
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/environment/GdlInstantiator.java
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 Tue Jul 12 08:16:49 2011 (r604)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlPsis.java Tue Jul 12 13:26:22 2011 (r605)
@@ -2,8 +2,6 @@
import java.util.ArrayList;
import com.google.gwt.core.client.JsArray;
-
-import us.isidor.gdl.anaToMia.TopicMaps.TmEngineModel.TmEngine;
import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Association;
import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Construct;
import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Locator;
@@ -11,13 +9,28 @@
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.environment.GdlInstantiator;
import us.isidor.gdl.anaToMia.Widgets.environment.Pair;
import us.isidor.gdl.anaToMia.Widgets.environment.TopicIdentifierTypes;
+
public class GdlPsis {
public final static String gdl = "http://psi.isidor.us/gdl/";
+
+ // some psis of the TMDM
+ public class TMDM{
+ public final static String supertype = "http://psi.topicmaps.org/iso13250/model/supertype";
+ public final static String subtype = "http://psi.topicmaps.org/iso13250/model/subtype";
+ public final static String supertypeSubtype = "http://psi.topicmaps.org/iso13250/model/supertype-subtype";
+
+ }
+
+ // some psis of the TMCL
+ public class TMCL {
+ public final static String topictype = "http://psi.topicmaps.org/tmcl/topic-type";
+ }
+
+
// topic types
public class TopicType{
public final static String gdlSchema = gdl + "Schema";
@@ -333,26 +346,73 @@
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;
- // TODO: implement
- return null;
+ 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 assocition with two roles and the correct values
- public static ArrayList<Topic> getOtherPlayer(Topic thisTopic, Topic thisRoleType, Topic assocType, ArrayList<Topic> scope, Topic otherRoleType){
+ // 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(otherRoleType).length() == 1) result.add(parent.getRoles(otherRoleType).get(0).getPlayer());
+ 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){
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 Tue Jul 12 08:16:49 2011 (r604)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/environment/GdlInstantiator.java Tue Jul 12 13:26:22 2011 (r605)
@@ -123,6 +123,7 @@
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));
@@ -131,15 +132,69 @@
topsToDisplay.add(GdlPsis.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);
+ for (Topic topic : topsToDisplay) {
+ ArrayList<Topic> potentialTmValues = GdlPsis.getOtherPlayerOfBinaryAssociation(topic, tmConstruct, tmBinding, null, descriptor);
+ for (Topic potentialTmValue : potentialTmValues)
+ if(GdlPsis.isInstanceOf(potentialTmValue, TmValue)) tmValues.add(potentialTmValue);
+ }
- // TODO: implement
- // get tm-values for each topic
- // reduce tm-values to instances that are shared by all topics to display
- // filter shared tm-values for default-topic-view associations
- // return default-topic-view
+ // 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);
+ 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()){
+ invalidTmValues.add(value);
+ }
+ }
+ }
+ for (Topic invalid : invalidTmValues)tmValues.remove(invalid);
- return null;
+ // 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);
+ 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);
+ }
+
+ // return default-topic-view
+ if(defaultTopicViews.size() > 2){
+ String values = "";
+ for (Topic topic : topsToDisplay)values += ", " + GdlPsis.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(GdlPsis.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;
+ }
}
}
}
More information about the Isidorus-cvs
mailing list