Author: lgiessmann Date: Tue Aug 23 11:06:14 2011 New Revision: 776
Log: gdl-frontend: Widgets: implemented the topic representation => gdl:display-by + gdl:preferred-scope
Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/IGdlHasValueGroup.java branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/PSIs.java 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/text/GdlText.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/IGdlHasValueGroup.java ============================================================================== --- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/IGdlHasValueGroup.java Tue Aug 23 09:03:08 2011 (r775) +++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/IGdlHasValueGroup.java Tue Aug 23 11:06:14 2011 (r776) @@ -58,7 +58,22 @@ // returns all topics of a topic map that can be used for a defined constraint public ArrayList<Topic> getTmValuesForConstraint() throws InvalidGdlSchemaException, ExecutionException; + // returns a regular expression that must be satisfied to satisfy the // constraint, that is bound to the element's value group instance public String getLiteralValueForConstraint() throws InvalidGdlSchemaException; + + + // returns the Topic that represents the constraint, which is used to + // determine the topic's display-schema + public Topic getDisplayByConstraintOfValueGroup() throws InvalidGdlSchemaException; + + + // Returns a list of topics that represent the topic's preferred scope(s) + public ArrayList<Topic> getPreferredScopeOfValueGroup() throws InvalidGdlSchemaException; + + + // Returns a string that represents the topic as a string corresponding + // to the defined display-by and preferred-scope topics + public String getTopicRepresentation(Topic topicToRepresent, Topic displayBy, ArrayList<Topic> preferredScopes) throws InvalidGdlSchemaException; }
Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/PSIs.java ============================================================================== --- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/PSIs.java Tue Aug 23 09:03:08 2011 (r775) +++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/PSIs.java Tue Aug 23 11:06:14 2011 (r776) @@ -222,6 +222,8 @@ public final static String gdlTopicViewBinding = gdl + "topic-view-binding"; public final static String gdlAssociationViewBinding = gdl + "association-view-binding"; public final static String gdlValueBinding = gdl + "value-binding"; + public final static String gdlDisplayBy = gdl + "display-by"; + public final static String gdlPrefferedScope = gdl + "preferred-scope"; }
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 Tue Aug 23 09:03:08 2011 (r775) +++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TmHelper.java Tue Aug 23 11:06:14 2011 (r776) @@ -5,6 +5,7 @@ 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.Name; import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Occurrence; import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Role; import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.ScopedStub; @@ -13,6 +14,7 @@ import us.isidor.gdl.anaToMia.Widgets.environment.ExecutionException; import us.isidor.gdl.anaToMia.Widgets.environment.InvalidGdlSchemaException; import us.isidor.gdl.anaToMia.Widgets.environment.Pair; +import us.isidor.gdl.anaToMia.Widgets.environment.Pattern; import us.isidor.gdl.anaToMia.Widgets.environment.TopicIdentifierTypes; import com.google.gwt.core.client.JsArray;
@@ -1058,4 +1060,106 @@ else if(occs.length() == 0) return null; else return occs.get(0); } + + + // Returns an array of topics that represent the preffered scope that is set + // to a tm-value or value-group instance + public static ArrayList<Topic> getPrefferedScopesForTopicOf(Topic tmValueOrValueGroup){ + if(tmValueOrValueGroup == null) return new ArrayList<Topic>(); + + TopicMap tm = tmValueOrValueGroup.getTopicMap(); + Topic descriptorRoleType = getTopicByPsi(PSIs.RoleType.gdlDescriptor, tm); + Topic preferredScopeAssocType = getTopicByPsi(PSIs.AssociationType.gdlPrefferedScope, tm); + Topic tmConstructRoleType = getTopicByPsi(PSIs.RoleType.gdlTmConstruct, tm); + return getOtherPlayerOfBinaryAssociation(tmValueOrValueGroup, descriptorRoleType, preferredScopeAssocType, null, tmConstructRoleType); + } + + + // Returns the topic that is bound to the passed tm-value or value-group topic + // and represents the representation schema of the topics that must be displayed + public static Topic getDisplayByTopicOf(Topic tmValueOrvalueGroup) throws InvalidGdlSchemaException{ + if(tmValueOrvalueGroup == null) return null; + + TopicMap tm = tmValueOrvalueGroup.getTopicMap(); + Topic displayByAssocType = getTopicByPsi(PSIs.AssociationType.gdlDisplayBy, tm); + Topic descriptorRoleType = getTopicByPsi(PSIs.RoleType.gdlDescriptor, tm); + Topic tmConstruct = getTopicByPsi(PSIs.RoleType.gdlTmConstruct, tm); + Topic subjectIdentifierConstraintType = getTopicByPsi(PSIs.TMCL.tmclSubjectIdentifierConstraint, tm); + Topic subjectLocatorConstraintType = getTopicByPsi(PSIs.TMCL.tmclSubjectLocatorConstraint, tm); + Topic itemIdentifierConstraintType = getTopicByPsi(PSIs.TMCL.tmclItemIdentifierConstraint, tm); + Topic topicNameConstraintType = getTopicByPsi(PSIs.TMCL.tmclTopicNameConstraint, tm); + ArrayList<Topic> resultPsi = getOtherPlayerOfBinaryAssociation(tmValueOrvalueGroup, descriptorRoleType, displayByAssocType, null, tmConstruct, subjectIdentifierConstraintType); + ArrayList<Topic> resultSl = getOtherPlayerOfBinaryAssociation(tmValueOrvalueGroup, descriptorRoleType, displayByAssocType, null, tmConstruct, subjectLocatorConstraintType); + ArrayList<Topic> resultIi = getOtherPlayerOfBinaryAssociation(tmValueOrvalueGroup, descriptorRoleType, displayByAssocType, null, tmConstruct, itemIdentifierConstraintType); + ArrayList<Topic> resultName = getOtherPlayerOfBinaryAssociation(tmValueOrvalueGroup, descriptorRoleType, displayByAssocType, null, tmConstruct, topicNameConstraintType); + + ArrayList<Topic> result = Utils.merge(Utils.merge(Utils.merge(resultPsi, resultSl), resultIi), resultName); + + if(result.size() > 1) throw new InvalidGdlSchemaException("the topic " + getAnyIdOfTopic(tmValueOrvalueGroup) + " must be bound none or once to a tmcl:constraint via a " + PSIs.AssociationType.gdlDisplayBy + " assciation, but is: " + result.size()); + else if(result.size() == 1) return result.get(0); + else return null; + } + + + // Returns a string that represents the topic. The returned string must + // correspond to the passed diplayBy and preferredScopes data. + public static String getTopicRepresentation(Topic topicToRepresent, Topic displayBy, ArrayList<Topic> preferredScopes) throws InvalidGdlSchemaException { + if(topicToRepresent == null) return null; + + if(displayBy == null){ + if(topicToRepresent.getSubjectIdentifiers().length() == 0) throw new InvalidGdlSchemaException("the topic " + getAnyIdOfTopic(topicToRepresent) + " is not bound to a " + PSIs.AssociationType.gdlDisplayBy + " association and is not bound to a Subject-Identifier - but one of them must be set"); + else return topicToRepresent.getSubjectIdentifiers().get(0).getReference(); + } else { + TopicMap tm = topicToRepresent.getTopicMap(); + Topic subjectIdentifierConstraint = getTopicByPsi(PSIs.TMCL.tmclSubjectIdentifierConstraint, tm); + Topic subjectLocatorConstraint = getTopicByPsi(PSIs.TMCL.tmclSubjectLocatorConstraint, tm); + Topic itemIdentifierConstraint = getTopicByPsi(PSIs.TMCL.tmclItemIdentifierConstraint, tm); + Topic topicNameConstraint = getTopicByPsi(PSIs.TMCL.tmclTopicNameConstraint, tm); + + String result = null; + if(isInstanceOf(displayBy, topicNameConstraint)){ + Topic nameType = TmHelper.getConstrainedStatement(displayBy); + ArrayList<Name> names = new ArrayList<Name>(); + for(int i = 0; i != topicToRepresent.getNames(nameType).length(); ++i) + names.add(topicToRepresent.getNames(nameType).get(i)); + + if(preferredScopes != null && preferredScopes.size() != 0){ + // TODO: implement + } + if(names.size() != 0) result = names.get(0).getValue(); + } else if(isInstanceOf(displayBy, subjectIdentifierConstraint)){ + Pattern rex = new Pattern(TmHelper.getLiteralValueForConstraint(displayBy)); + for(int i = 0; i != topicToRepresent.getSubjectIdentifiers().length(); ++i){ + String psi = topicToRepresent.getSubjectIdentifiers().get(i).getReference(); + if(rex.matches(psi)){ + result = psi; + break; + } + } + } else if(isInstanceOf(displayBy, subjectLocatorConstraint)){ + Pattern rex = new Pattern(TmHelper.getLiteralValueForConstraint(displayBy)); + for(int i = 0; i != topicToRepresent.getSubjectLocators().length(); ++i){ + String psi = topicToRepresent.getSubjectLocators().get(i).getReference(); + if(rex.matches(psi)){ + result = psi; + break; + } + } + } else if(isInstanceOf(displayBy, itemIdentifierConstraint)){ + Pattern rex = new Pattern(TmHelper.getLiteralValueForConstraint(displayBy)); + for(int i = 0; i != topicToRepresent.getItemIdentifiers().length(); ++i){ + String psi = topicToRepresent.getItemIdentifiers().get(i).getReference(); + if(rex.matches(psi)){ + result = psi; + break; + } + } + } else { + throw new InvalidGdlSchemaException("the topic " + getAnyIdOfTopic(displayBy) + " is not a valid representation schema type"); + } + + if(result == null) throw new InvalidGdlSchemaException(""); + else return result; + } + } }
Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/text/GdlText.java ============================================================================== --- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/text/GdlText.java Tue Aug 23 09:03:08 2011 (r775) +++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/text/GdlText.java Tue Aug 23 11:06:14 2011 (r776) @@ -57,6 +57,11 @@ protected boolean tmValueTopicsSet = false; protected ArrayList<Topic> literalValueTopics = new ArrayList<Topic>(); protected boolean literalValueTopicsSet = false; + protected ArrayList<Topic> preferredScopes = new ArrayList<Topic>(); + protected boolean prefferedScopesSet = false; + protected Topic displayByConstraint = null; + protected boolean displayByConstraintSet = false; + // some constructors protected GdlText() throws InvalidGdlSchemaException, ExecutionException { @@ -124,13 +129,15 @@ Topic occurrenceType = TmHelper.getConstrainedStatement(this.getConstraint()); for(int i = 0; i != ((Topic)this.receivedData).getOccurrences(occurrenceType).length(); ++i) this.createNewTextArea().setText(((Topic)this.receivedData).getOccurrences(occurrenceType).get(i).getValue()); + } else if(TmHelper.isInstanceOf(this.getConstraint(), PSIs.TopicType.gdlRolePlayer)){ + this.createNewTextArea().setText("gdl:Role-Player instance"); } - // TODO: implement type, variant, datatype, association, ... constraints + // TODO: implement type, variant, datatype, associations, roles, ... constraints } // sets the field for the set default value or sets at least one empty field - public void setDefaultValue() throws InvalidGdlSchemaException, ExecutionException { + protected void setDefaultValue() throws InvalidGdlSchemaException, ExecutionException { if(this.getDefaultLiteralValue() != null && this.getDefaultTmValue() != null) throw new InvalidGdlSchemaException("the topic " + TmHelper.getAnyIdOfTopic(this.getValueGroup()) + " must be bound to maximal one " + PSIs.TopicType.gdlDefaultValue + ", but is: 2"); if(this.getDefaultLiteralValue() != null){ @@ -1040,4 +1047,34 @@ public String getLiteralValueForConstraint() throws InvalidGdlSchemaException { return TmHelper.getLiteralValueForConstraint(this.getConstraint()); } + + + @Override + public Topic getDisplayByConstraintOfValueGroup() throws InvalidGdlSchemaException { + if(this.displayByConstraintSet){ + return this.displayByConstraint; + } else { + this.displayByConstraintSet = true; + this.displayByConstraint = TmHelper.getDisplayByTopicOf(this.getValueGroup()); + return this.displayByConstraint; + } + } + + + @Override + public ArrayList<Topic> getPreferredScopeOfValueGroup() throws InvalidGdlSchemaException { + if(this.prefferedScopesSet){ + return this.preferredScopes; + } else { + this.prefferedScopesSet = true; + this.preferredScopes = TmHelper.getPrefferedScopesForTopicOf(this.getValueGroup()); + return this.preferredScopes; + } + } + + + @Override + public String getTopicRepresentation(Topic topicToRepresent, Topic displayBy, ArrayList<Topic> preferredScopes) throws InvalidGdlSchemaException { + return TmHelper.getTopicRepresentation(topicToRepresent, displayBy, preferredScopes); + } }
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 Tue Aug 23 09:03:08 2011 (r775) +++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/view/GdlAssociationView.java Tue Aug 23 11:06:14 2011 (r776) @@ -1,7 +1,6 @@ package us.isidor.gdl.anaToMia.Widgets.view;
import java.util.ArrayList; - import com.google.gwt.core.client.JsArray; import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Association; import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Role; @@ -28,10 +27,30 @@ private ArrayList<Pair<Pair<Topic, Topic>, Pair<Topic, Topic>>> validRoleCombinations = new ArrayList<Pair<Pair<Topic,Topic>,Pair<Topic,Topic>>>(); private boolean validRoleCombinationsSet = false; + + protected GdlAssociationView(){ + super(); + } +
public GdlAssociationView(Topic tmRepresentative, Topic receivedData) throws InvalidGdlSchemaException, ExecutionException { - super(tmRepresentative, receivedData); + this(); + this.tmRepresentative = tmRepresentative; + this.tm = this.tmRepresentative.getTopicMap(); + this.receivedData = receivedData; + this.setId(this.getId()); + this.setGdlStyle(); if(this instanceof GdlEditorAssociationView) this.associationsToRepresent = this.filterAssociations(); + + ArrayList<Topic> objectsContained = this.contains(); + + Topic currentTopic = this.getStartElement(objectsContained); + Topic lastTopic = super.getTmRepresentative(); + while(currentTopic != null){ + this.append(lastTopic, currentTopic); + lastTopic = currentTopic; + currentTopic = TmHelper.getNextContainee(currentTopic, objectsContained); + } }