Author: lgiessmann
Date: Tue Aug 30 04:22:52 2011
New Revision: 809
Log:
gdl-frontend: Widgets: implemented the class GdlHiddenValue
Modified:
branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlHiddenValue.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/base/TmHelper.java
branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/button/GdlCommitButton.java
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/GdlTopicView.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/GdlHiddenValue.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlHiddenValue.java Tue Aug 30 03:22:19 2011 (r808)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlHiddenValue.java Tue Aug 30 04:22:52 2011 (r809)
@@ -1,6 +1,8 @@
package us.isidor.gdl.anaToMia.Widgets.base;
import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Topic;
+import us.isidor.gdl.anaToMia.Widgets.environment.ExecutionException;
+import us.isidor.gdl.anaToMia.Widgets.environment.InvalidGdlSchemaException;
public class GdlHiddenValue {
protected Topic constraintTopic = null;
@@ -11,8 +13,81 @@
protected boolean defaultTmValueTopicSet = false;
protected Topic defaultLiteralValueTopic = null;
protected boolean defaultLiteralValueTopicSet = false;
+ protected Topic tmRepresentative = null;
+ @SuppressWarnings("unused")
+ private GdlHiddenValue(){}
+ public GdlHiddenValue(Topic tmRepresentative) throws ExecutionException{
+ if(tmRepresentative == null) throw new ExecutionException("tmRepresentative must no be null");
+ this.tmRepresentative = tmRepresentative;
+ }
+
+
+ public Topic getTmRepresentative(){
+ return this.tmRepresentative;
+ }
+
+
+ // returns the direct (first) constraint that is bound to the value-group
+ // of this element - or null if it is unbound
+ public Topic getConstraint() throws InvalidGdlSchemaException {
+ if(this.constraintTopicSet){
+ return this.constraintTopic;
+ } else {
+ this.constraintTopic = TmHelper.getConstraintOfHiddenValue(this.getTmRepresentative());
+ this.constraintTopicSet = true;
+ return this.constraintTopic;
+ }
+ }
+
+
+ // returns the root (last) constraint that is bound to the value-group
+ // of this element - or null if it is unbound
+ public Topic getRootConstraint() throws InvalidGdlSchemaException {
+ if(this.rootConstraintTopicSet){
+ return this.rootConstraintTopic;
+ } else {
+ this.rootConstraintTopic = TmHelper.getRootConstraintOfHiddenValue(this.getTmRepresentative(), this.getConstraint());
+ this.rootConstraintTopicSet = true;
+ return this.rootConstraintTopic;
+ }
+ }
+
+
+ // returns the topic that represents the default topic maps value of
+ // the value-group that is bound to this element - null if it is unbound
+ public Topic getDefaultTmValue() throws InvalidGdlSchemaException {
+ if(this.defaultTmValueTopicSet){
+ return this.defaultTmValueTopic;
+ } else {
+ this.defaultTmValueTopic = TmHelper.getDefaultTmValueOfHiddenValue(this.getTmRepresentative());
+ this.defaultTmValueTopicSet = true;
+ return this.defaultTmValueTopic;
+ }
+ }
+
+
+ // returns the topic that represents the default literal value of the
+ // value-group that is bound to this element - or null if it is unbound
+ public Topic getDefaultLiteralValue() throws InvalidGdlSchemaException {
+ if(this.defaultLiteralValueTopicSet){
+ return this.defaultLiteralValueTopic;
+ } else {
+ this.defaultLiteralValueTopic = TmHelper.getDefaultLiteralValueOfHiddenValue(this.getTmRepresentative());
+ this.defaultLiteralValueTopicSet = true;
+ return this.defaultLiteralValueTopic;
+ }
+ }
+
+
+ // returns the topic that represents the default value of
+ // the value-group that is bound to this element - null if it is unbound
+ public Topic getDefaultValue() throws InvalidGdlSchemaException {
+ if(this.getDefaultLiteralValue() != null && this.getDefaultTmValue() != null) throw new InvalidGdlSchemaException("the topic " + TmHelper.getAnyIdOfTopic(this.getTmRepresentative()) + " must be bound to maximal one " + PSIs.GDL.TopicType.gdlDefaultValue + ", but is: 2");
+ else if(this.getDefaultLiteralValue() != null) return this.getDefaultLiteralValue();
+ else return this.getDefaultTmValue();
+ }
}
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 Tue Aug 30 03:22:19 2011 (r808)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlVisibleObject.java Tue Aug 30 04:22:52 2011 (r809)
@@ -2266,7 +2266,7 @@
changedRole = roles.get(idx);
changedRole.setPlayer(TmHelper.getTopicFromStringRepresentation(this.getSelectedValues().get(idx), this.getValueGroup()));
} else {
- changedRole = ((Association)carrier).createRole(roleType, TmHelper.getTopicFromStringRepresentation(this.getSelectedValues().get(idx), this.getDisplayByOfValueGroup()));
+ changedRole = ((Association)carrier).createRole(roleType, TmHelper.getTopicFromStringRepresentation(this.getSelectedValues().get(idx), this.getValueGroup()));
}
} else if(TmHelper.isInstanceOf(this.getConstraint(), PSIs.GDL.TopicType.gdlType)){
// TODO: implement
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 30 03:22:19 2011 (r808)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TmHelper.java Tue Aug 30 04:22:52 2011 (r809)
@@ -16,6 +16,7 @@
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 us.isidor.gdl.anaToMia.Widgets.view.GdlTopicView;
import com.google.gwt.core.client.JsArray;
@@ -593,6 +594,126 @@
}
+ // returns the hidden values that are bound to the representative
+ // of a GdlView instance
+ public static ArrayList<Topic> getHiddenValueOf(Topic viewTopic) {
+ ArrayList<Topic> result = new ArrayList<Topic>();
+ if(viewTopic == null) return result;
+
+ TopicMap tm = viewTopic.getTopicMap();
+ Topic containerRoleType = getTopicByPsi(PSIs.GDL.RoleType.gdlContainer, tm);
+ Topic containeeRoleType = getTopicByPsi(PSIs.GDL.RoleType.gdlContainee, tm);
+ Topic containsAssocType = getTopicByPsi(PSIs.GDL.AssociationType.gdlContains, tm);
+ Topic hiddenValueType = getTopicByPsi(PSIs.GDL.TopicType.gdlHiddenValue, tm);
+ return getOtherPlayerOfBinaryAssociation(viewTopic, containerRoleType, containsAssocType, null, hiddenValueType, containeeRoleType);
+ }
+
+
+ // returns the first constraint of the passed hidden value topic
+ public static Topic getConstraintOfHiddenValue(Topic hiddenValue) throws InvalidGdlSchemaException {
+ if(hiddenValue == null) return null;
+
+ TopicMap tm = hiddenValue.getTopicMap();
+ Topic hiddenValueRoleType = getTopicByPsi(PSIs.GDL.RoleType.gdlHiddenValue, tm);
+ Topic descriptorType = getTopicByPsi(PSIs.GDL.TopicType.gdlDescriptor, tm);
+ Topic tmBindingAssocType = getTopicByPsi(PSIs.GDL.AssociationType.gdlTmBinding, tm);
+ Topic tmclConstraintType = getTopicByPsi(PSIs.TMCL.tmclConstraint, tm);
+ Topic tmConstructRoleType = getTopicByPsi(PSIs.GDL.RoleType.gdlTmConstruct, tm);
+ ArrayList<Topic> tmclConstraints = getOtherPlayerOfBinaryAssociation(hiddenValue, hiddenValueRoleType, tmBindingAssocType, null, tmclConstraintType, tmConstructRoleType);
+
+ ArrayList<Topic> gdlConstraints = getOtherPlayerOfBinaryAssociation(hiddenValue, hiddenValueRoleType, tmBindingAssocType, null, descriptorType, tmConstructRoleType);
+
+ if(tmclConstraints.size() > 1 || gdlConstraints.size() > 1 || (tmclConstraints.size() == 1 && gdlConstraints.size() == 1))
+ throw new InvalidGdlSchemaException("the topic " + getAnyIdOfTopic(hiddenValue) + " can be bound only to one constraint, but is " + (tmclConstraints.size() + gdlConstraints.size()));
+
+ if(tmclConstraints.size() == 1) return tmclConstraints.get(0);
+ else if (gdlConstraints.size() == 1) return gdlConstraints.get(0);
+ else return null;
+ }
+
+
+ // returns the last/root constraint that is bound to the passed
+ // hidden value topic
+ public static Topic getRootConstraintOfHiddenValue(Topic hiddenValue, Topic currentConstraint) throws InvalidGdlSchemaException {
+ if(hiddenValue == null) return null;
+
+ Topic localCurrentConstraint = currentConstraint == null ? getConstraintOfHiddenValue(hiddenValue) : currentConstraint;
+ TopicMap tm = hiddenValue.getTopicMap();
+ Topic tmclConstraintType = getTopicByPsi(PSIs.TMCL.tmclConstraint, tm);
+
+ if(isInstanceOf(localCurrentConstraint, tmclConstraintType)) return localCurrentConstraint;
+ else {
+ // get next constraint and invoke this method recursively
+ Topic descriptorRoleType = getTopicByPsi(PSIs.GDL.RoleType.gdlDescriptor, tm);
+ Topic tmBindingAssocType = getTopicByPsi(PSIs.GDL.AssociationType.gdlTmBinding, tm);
+ Topic tmConstructRoleType = getTopicByPsi(PSIs.GDL.RoleType.gdlTmConstruct, tm);
+ Topic gdlDescriptor = getTopicByPsi(PSIs.GDL.TopicType.gdlDescriptor, tm);
+
+ ArrayList<Topic> nextTmclConstraints = getOtherPlayerOfBinaryAssociation(localCurrentConstraint, descriptorRoleType, tmBindingAssocType, null, tmclConstraintType, tmConstructRoleType);
+ ArrayList<Topic> nextGdlConstraints = getOtherPlayerOfBinaryAssociation(localCurrentConstraint, descriptorRoleType, tmBindingAssocType, null, gdlDescriptor, tmConstructRoleType);
+
+ if(nextTmclConstraints.size() > 1 || nextGdlConstraints.size() > 1 || (nextTmclConstraints.size() == 1 && nextGdlConstraints.size() == 1))
+ throw new InvalidGdlSchemaException("the topic " + getAnyIdOfTopic(localCurrentConstraint) + " can be bound only to one constraint, but is " + (nextTmclConstraints.size() + nextGdlConstraints.size()));
+
+ if(nextTmclConstraints.size() == 1) return nextTmclConstraints.get(0);
+ else if(nextGdlConstraints.size() == 1) return getRootConstraintOfValueGroup(hiddenValue, nextGdlConstraints.get(0));
+ else throw new InvalidGdlSchemaException("the hidden value " + getAnyIdOfTopic(hiddenValue) + " must be bound to exaclty one root constraint of the type " + PSIs.TMCL.tmclConstraint + " but is unbound");
+ }
+ }
+
+
+ // returns the default value of a hidden value, i.e. the actual value representative
+ public static Topic getDefaultTmValueOfHiddenValue(Topic hiddenValue) throws InvalidGdlSchemaException {
+ if(hiddenValue == null) return null;
+
+ TopicMap tm = hiddenValue.getTopicMap();
+ Topic valueBindingAssocTopic = getTopicByPsi(PSIs.GDL.AssociationType.gdlValueBinding, tm);
+ Topic hiddenValueRoleType = getTopicByPsi(PSIs.GDL.RoleType.gdlHiddenValue, tm);
+ Topic valueRoleType = getTopicByPsi(PSIs.GDL.RoleType.gdlValue, tm);
+ Topic defaultTmValueType = getTopicByPsi(PSIs.GDL.TopicType.gdlDefaultTmValue, tm);
+
+ ArrayList<Topic> defaultTmValues = getOtherPlayerOfBinaryAssociation(hiddenValue, hiddenValueRoleType, valueBindingAssocTopic, null, defaultTmValueType, valueRoleType);
+
+ if(defaultTmValues.size() == 1) return defaultTmValues.get(0);
+ else if(defaultTmValues.size() == 0) return null;
+ else throw new InvalidGdlSchemaException("the topic " + getAnyIdOfTopic(hiddenValue) + " must be bound none or once to a " + PSIs.GDL.TopicType.gdlDefaultTmValue + ", but is: " + defaultTmValues.size());
+ }
+
+
+ // returns the default literal value representative of the hidden value
+ public static Topic getDefaultLiteralValueOfHiddenValue(Topic hiddenValue) throws InvalidGdlSchemaException {
+ if(hiddenValue == null) return null;
+
+ TopicMap tm = hiddenValue.getTopicMap();
+ Topic valueBindingAssocTopic = getTopicByPsi(PSIs.GDL.AssociationType.gdlValueBinding, tm);
+ Topic valueGroupRoleType = getTopicByPsi(PSIs.GDL.RoleType.gdlValueGroup, tm);
+ Topic valueRoleType = getTopicByPsi(PSIs.GDL.RoleType.gdlValue, tm);
+ Topic defaultLiteralValueType = getTopicByPsi(PSIs.GDL.TopicType.gdlDefaultLiteralValue, tm);
+ ArrayList<Topic> defaultTmValues = getOtherPlayerOfBinaryAssociation(hiddenValue, valueGroupRoleType, valueBindingAssocTopic, null, defaultLiteralValueType, valueRoleType);
+
+ if(defaultTmValues.size() == 1) return defaultTmValues.get(0);
+ else if(defaultTmValues.size() == 0) return null;
+ else throw new InvalidGdlSchemaException("the topic " + getAnyIdOfTopic(hiddenValue) + " must be bound none or once to a " + PSIs.GDL.TopicType.gdlDefaultLiteralValue + ", but is: " + defaultTmValues.size());
+ }
+
+
+ // returns a topic that is represented by the nearest instance of GdlTopicView
+ public static Topic getNearestTopic(GdlVisibleObject elem){
+ if(elem == null) return null;
+
+ GdlTopicView view = null;
+ GdlVisibleObject parent = elem;
+
+ do{
+ if(parent instanceof GdlTopicView) view = (GdlTopicView)parent;
+ else parent = parent.getGdlParent();
+ }while(view == null && parent != null);
+
+ if(view == null) return null;
+ else return view.getRepresentedTopic();
+ }
+
+
// returns the topic that represents the value group that is bound to the passed
// topic via a gdl:view-binding association
public static Topic getValueGroupOf(Topic visibleElement) throws InvalidGdlSchemaException{
@@ -741,7 +862,7 @@
Topic tmConstructRoleType = getTopicByPsi(PSIs.GDL.RoleType.gdlTmConstruct, tm);
Topic associationRoleConstraintType = getTopicByPsi(PSIs.TMCL.tmclAssociationRoleConstraint, tm);
ArrayList<Topic> result = getOtherPlayerOfBinaryAssociation(viewRepresentative, descriptorRoleType, associationViewBindingAssocType, null, associationRoleConstraintType, tmConstructRoleType);
-
+
if(result.size() == 0) throw new InvalidGdlSchemaException("the topic " + getAnyIdOfTopic(viewRepresentative) + " must be bound to at least one " + PSIs.TMCL.tmclAssociationRoleConstraint + ", but is unbound");
else return result;
}
Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/button/GdlCommitButton.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/button/GdlCommitButton.java Tue Aug 30 03:22:19 2011 (r808)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/button/GdlCommitButton.java Tue Aug 30 04:22:52 2011 (r809)
@@ -5,8 +5,12 @@
import us.isidor.gdl.anaToMia.Widgets.base.GdlVisibleObject;
import us.isidor.gdl.anaToMia.Widgets.environment.ExecutionException;
import us.isidor.gdl.anaToMia.Widgets.environment.InvalidGdlSchemaException;
+import com.google.gwt.event.dom.client.ClickEvent;
+import com.google.gwt.event.dom.client.ClickHandler;
+import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
+
public class GdlCommitButton extends GdlActionButton {
// TODO: implement
@@ -18,5 +22,28 @@
public GdlCommitButton(Topic tmRepresentative, Construct receivedData, GdlVisibleObject parent) throws InvalidGdlSchemaException, ExecutionException{
super(tmRepresentative, receivedData, parent);
((Button)this.subElements.get(0)).setText("commit");
+ this.getButton().addClickHandler(new CommitButtonClickHandler(this));
+ }
+
+
+ protected class CommitButtonClickHandler implements ClickHandler {
+ private GdlCommitButton owner = null;
+
+ public CommitButtonClickHandler(GdlCommitButton owner){
+ this.owner = owner;
+ }
+
+
+ @Override
+ public void onClick(ClickEvent event) {
+ try{
+ this.owner.getGdlParent().getContent(null);
+
+ // TODO: implement
+ }catch(Exception e){
+ e.printStackTrace();
+ Window.alert("caught: " + e.getMessage());
+ }
+ }
}
}
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 30 03:22:19 2011 (r808)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/view/GdlAssociationView.java Tue Aug 30 04:22:52 2011 (r809)
@@ -197,6 +197,8 @@
}
}
+ // TODO: process hidden values
+
return result;
}
Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/view/GdlTopicView.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/view/GdlTopicView.java Tue Aug 30 03:22:19 2011 (r808)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/view/GdlTopicView.java Tue Aug 30 04:22:52 2011 (r809)
@@ -5,7 +5,6 @@
import com.google.gwt.user.client.ui.Widget;
import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Construct;
import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Topic;
-import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.TopicMap;
import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.TopicMapsTypes;
import us.isidor.gdl.anaToMia.Widgets.base.ButtonableObject;
import us.isidor.gdl.anaToMia.Widgets.base.GdlVisibleObject;
@@ -17,6 +16,8 @@
public abstract class GdlTopicView extends GdlView {
+ protected Topic representedTopic = null;
+
public GdlTopicView(Topic tmRepresentative, Topic receivedData, GdlVisibleObject gdlParent) throws InvalidGdlSchemaException, ExecutionException{
super(tmRepresentative, receivedData, gdlParent);
@@ -79,10 +80,7 @@
ArrayList<Pair<Construct, TopicMapsTypes>> result = new ArrayList<Pair<Construct,TopicMapsTypes>>();
Topic localCarrier = (Topic)this.receivedData;
- if(localCarrier == null){
- TopicMap tm = this.tmRepresentative.getTopicMap();
- localCarrier = tm.createTopicBySubjectIdentifier(tm.createLocator(this.getId()));
- }
+ if(localCarrier == null) localCarrier = this.getRepresentedTopic();
for (Widget ctrl : this.subElements) {
if(this.receivedData == null) result.add(new Pair<Construct, TopicMapsTypes>(localCarrier, TopicMapsTypes.Topic));
@@ -93,6 +91,22 @@
}
}
+ // TODO: process hidden values
+
return result;
}
+
+
+ public Topic getRepresentedTopic(){
+ if(this.receivedData ==null){
+ if(this.representedTopic == null){
+ this.representedTopic = this.tmRepresentative.getTopicMap().createTopic();
+ return this.representedTopic;
+ } else {
+ return this.representedTopic;
+ }
+ } else {
+ return (Topic)this.receivedData;
+ }
+ }
}
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 Tue Aug 30 03:22:19 2011 (r808)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/view/GdlView.java Tue Aug 30 04:22:52 2011 (r809)
@@ -19,6 +19,10 @@
public abstract class GdlView extends GdlVisibleObject implements IGdlContainer {
+ protected boolean hiddenValuesSet = false;
+ protected ArrayList<Topic> hiddenValues = new ArrayList<Topic>();
+
+
protected GdlView(){
super();
}
@@ -109,4 +113,16 @@
public ArrayList<Topic> contains() throws InvalidGdlSchemaException{
return TmHelper.topicContains(this.tmRepresentative);
}
+
+
+ // returns all hidden values that are bound to this view
+ public ArrayList<Topic> getHiddenValues() throws InvalidGdlSchemaException {
+ if(this.hiddenValuesSet) {
+ return this.hiddenValues;
+ } else {
+ this.hiddenValuesSet = true;
+ this.hiddenValues = TmHelper.getHiddenValueOf(this.tmRepresentative);
+ return this.hiddenValues;
+ }
+ }
}
\ No newline at end of file