Author: lgiessmann Date: Tue Oct 25 09:29:07 2011 New Revision: 1020
Log: gdl-frontend: Widgets: updated the GDL-Schema => gdlt:Variant-Name-Scope and gdlt:Variant-Name-Reifier, so it is possible to select the corresponding topic types of these constraints directly in the schema instance
Modified: trunk/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlVisibleObject.java trunk/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TestClass.java trunk/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TmHelper.java
Modified: trunk/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlVisibleObject.java ============================================================================== --- trunk/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlVisibleObject.java Tue Oct 25 06:23:37 2011 (r1019) +++ trunk/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlVisibleObject.java Tue Oct 25 09:29:07 2011 (r1020) @@ -2003,8 +2003,14 @@ if(!(this.receivedData instanceof Topic)) throw new ExecutionException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to a Topic, but is: " + receivedData.getClass());
ArrayList<Variant> variants = TmHelper.getVariantsForConstraint((Topic)this.receivedData, this.getConstraint()); - if(variants.size() != 0) this.addSubItem(variants.get(0).getValue()); - else this.addSubItem(""); + if(variants.size() != 0){ + for (Variant variant : variants) { + this.addSubItem(variant.getValue()); + } + } + else{ + this.addSubItem(""); + } } else if (TmHelper.isInstanceOf(this.getConstraint(), PSIs.TMCL.tmclScopeConstraint)){ Topic type = TmHelper.getConstrainedStatement(this.getConstraint());
@@ -2547,6 +2553,19 @@ } + // handles the getContent call for item identifiers of variant-names + private void getVariantReifierContent(ArrayList<Pair<Object, TopicMapsTypes>> contents, boolean validate, Topic carrier, int selectedValueIndex) throws InvalidGdlSchemaException, InvalidContentException, ExecutionException{ + ArrayList<Variant> possibleVariants = TmHelper.getVariantsForConstraint(carrier, this.getRootConstraint()); + if(possibleVariants.size() != 0){ + Variant variant = possibleVariants.get(0); + Topic reifier = TmHelper.getTopicFromStringRepresentation(this.getSelectedValues().get(selectedValueIndex), this.getValueGroup()); + + if(reifier != null) variant.setReifier(reifier); + contents.add(new Pair<Object, TopicMapsTypes>(variant, TopicMapsTypes.Variant)); + } + } + + // handles the getContent call for occurrence and name values private void getTopicCharacteristicContent(ArrayList<Pair<Object, TopicMapsTypes>> contents, boolean validate, Topic carrier, int selectedValueIndex) throws InvalidGdlSchemaException, InvalidContentException, ExecutionException{ Topic characteristicType = TmHelper.getConstrainedStatement(this.getConstraint()); @@ -2621,7 +2640,8 @@ } else if (TmHelper.isInstanceOf(this.getConstraint(), PSIs.GDL.TopicType.gdlVariantNameScope)){ // TODO: implement } else if (TmHelper.isInstanceOf(this.getConstraint(), PSIs.GDL.TopicType.gdlVariantNameReifier)){ - // TODO: implement + if(!(localCarrier instanceof Topic)) throw new ExecutionException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to a Topic, but is: " + localCarrier.getClass()); + this.getVariantReifierContent(result, validate, (Topic)localCarrier, idx); } else if (TmHelper.isInstanceOf(this.getConstraint(), PSIs.GDL.TopicType.gdlVariantNameIdentifiers)){ if(!(localCarrier instanceof Topic)) throw new ExecutionException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to a Topic, but is: " + localCarrier.getClass()); this.getVariantIdentifierContent(result, validate, (Topic)localCarrier, idx);
Modified: trunk/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TestClass.java ============================================================================== --- trunk/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TestClass.java Tue Oct 25 06:23:37 2011 (r1019) +++ trunk/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TestClass.java Tue Oct 25 09:29:07 2011 (r1020) @@ -4,6 +4,7 @@ import us.isidor.gdl.anaToMia.TopicMaps.TmEngineModel.TmEngine; import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Occurrence; import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Name; +import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Variant; import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.TopicMapsTypes; import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Locator; import us.isidor.gdl.anaToMia.Widgets.environment.ICommitCallback; @@ -68,6 +69,8 @@ Window.alert(((Occurrence)construct.getFirst()).getValue() + " >> " + construct.getSecond()); } else if(construct.getSecond().equals(TopicMapsTypes.Name)){ Window.alert(((Name)construct.getFirst()).getValue() + " >> " + construct.getSecond()); + } else if(construct.getSecond().equals(TopicMapsTypes.Variant)){ + Window.alert(TmHelper.getAnyIdOfTopic(((Variant)construct.getFirst()).getReifier()) + " >> " + construct.getSecond()); } else { Window.alert(construct.getFirst() + " >> " + construct.getSecond()); }
Modified: trunk/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TmHelper.java ============================================================================== --- trunk/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TmHelper.java Tue Oct 25 06:23:37 2011 (r1019) +++ trunk/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TmHelper.java Tue Oct 25 09:29:07 2011 (r1020) @@ -1181,16 +1181,54 @@ // returns the topic that can be used to satisfy the passed variant-name-reifier-constraint. - public static ArrayList<Topic> getTmValuesForVariantNameReifierConstraint(Topic variantNameReifierConstraint) throws ExecutionException { - // TODO: implement - throw new ExecutionException("this mehtod is currently not implemented"); + public static ArrayList<Topic> getTmValuesForVariantNameReifierConstraint(Topic variantNameReifierConstraint) throws ExecutionException, InvalidGdlSchemaException { + ArrayList<Topic> result = new ArrayList<Topic>(); + if(variantNameReifierConstraint == null) return result; + + TopicMap tm = variantNameReifierConstraint.getTopicMap(); + Topic allowedRoleType = getTopicByPsi(PSIs.TMCL.tmclAllowed, tm); + Topic allowsRoleType = getTopicByPsi(PSIs.TMCL.tmclAllows, tm); + Topic allowedReifierAssocType = getTopicByPsi(PSIs.TMCL.tmclAllowedReifier, tm); + ArrayList<Topic> reifierTypeTopics = getOtherPlayerOfBinaryAssociation(variantNameReifierConstraint, allowsRoleType, allowedReifierAssocType, null, allowedRoleType); + + if(reifierTypeTopics.size() != 1){ + throw new InvalidGdlSchemaException("the constraint " + getAnyIdOfTopic(variantNameReifierConstraint) + " must be bound extactly once to a topic type, but is: " + reifierTypeTopics.size()); + } else { + // add the direct specified type + result.add(reifierTypeTopics.get(0)); + + // get subtypes of typeTopic + JsArray<Topic> allTopics = tm.getTopics(); + for(int i = 0; i != allTopics.length(); ++i) if(isSupertypeOf(allTopics.get(i), reifierTypeTopics.get(0))) result.add(allTopics.get(i)); + } + + return result; } // returns the topic that can be used to satisfy the passed variant-name-scope-constraint. - public static ArrayList<Topic> getTmValuesForVariantNameScopeConstraint(Topic variantNameScopeConstraint) throws ExecutionException{ - // TODO: implement - throw new ExecutionException("this method is currently not implemented"); + public static ArrayList<Topic> getTmValuesForVariantNameScopeConstraint(Topic variantNameScopeConstraint) throws ExecutionException, InvalidGdlSchemaException{ + ArrayList<Topic> result = new ArrayList<Topic>(); + if(variantNameScopeConstraint == null) return result; + + TopicMap tm = variantNameScopeConstraint.getTopicMap(); + Topic constraintRoleType = getTopicByPsi(PSIs.TMCL.tmclConstraint, tm); + Topic constrainedRoleType = getTopicByPsi(PSIs.TMCL.tmclConstrained, tm); + Topic constrainedScopeAssocType = getTopicByPsi(PSIs.TMCL.tmclConstrainedScope, tm); + ArrayList<Topic> scopeTypeTopics = getOtherPlayerOfBinaryAssociation(variantNameScopeConstraint, constraintRoleType, constrainedScopeAssocType, null, constrainedRoleType); + + if(scopeTypeTopics.size() != 1){ + throw new InvalidGdlSchemaException("the constraint " + getAnyIdOfTopic(variantNameScopeConstraint) + " must be bound extactly once to a topic type, but is: " + scopeTypeTopics.size()); + } else { + // add the direct specified type + result.add(scopeTypeTopics.get(0)); + + // get subtypes of typeTopic + JsArray<Topic> allTopics = tm.getTopics(); + for(int i = 0; i != allTopics.length(); ++i) if(isSupertypeOf(allTopics.get(i), scopeTypeTopics.get(0))) result.add(allTopics.get(i)); + } + + return result; }