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

lgiessmann at common-lisp.net lgiessmann at common-lisp.net
Thu Sep 8 14:47:57 UTC 2011


Author: lgiessmann
Date: Thu Sep  8 07:47:55 2011
New Revision: 857

Log:
gdl-frontend: Widgets: implemented the handling of GdlHiddenValue when set to an tmcl:topic-occurrence-constraint

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/TestClass.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/base/Utils.java
   branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/CommitCallback.java
   branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/DeleteCallback.java
   branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/IsidorusConstants.java
   branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/LoadSchemaCallback.java
   branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/view/GdlTopicView.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	Thu Sep  8 07:02:36 2011	(r856)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlHiddenValue.java	Thu Sep  8 07:47:55 2011	(r857)
@@ -1,6 +1,7 @@
 package us.isidor.gdl.anaToMia.Widgets.base;
 
 
+import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Occurrence;
 import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Topic;
 import us.isidor.gdl.anaToMia.Widgets.environment.ExecutionException;
 import us.isidor.gdl.anaToMia.Widgets.environment.InvalidGdlSchemaException;
@@ -89,6 +90,17 @@
 	}
 	
 	
+	// returns the actual literal value that is set for this hidden value
+	// to be used
+	public String getRawDefaultLiteralValue() throws InvalidGdlSchemaException {
+		if(this.getDefaultLiteralValue() == null) return null;
+		
+		Occurrence occurrence = TmHelper.getSingleOccurrence(this.getDefaultLiteralValue(), TmHelper.getTopicByPsi(PSIs.GDL.OccurrenceType.gdlLiteralValue, this.tmRepresentative.getTopicMap()));
+		if(occurrence == null) throw new InvalidGdlSchemaException("the topic " + TmHelper.getAnyIdOfTopic(this.getDefaultLiteralValue()) + " must be bound to exactly one occurrence of the type: " + PSIs.GDL.OccurrenceType.gdlLiteralValue + ", but is: unbound");
+		else return occurrence.getValue();
+	}
+	
+	
 	// 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 {
@@ -98,7 +110,7 @@
 	}
 
 
-	//returns the actual values represetned by the tmValues 
+	//returns the actual values represented by the tmValues 
 	public Topic getRawTmValue() throws InvalidGdlSchemaException{
 		if(this.rawTmValuesSet){
 			return this.rawTmValue;

Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TestClass.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TestClass.java	Thu Sep  8 07:02:36 2011	(r856)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TestClass.java	Thu Sep  8 07:47:55 2011	(r857)
@@ -31,12 +31,12 @@
 			mainPanel.setPixelSize(1000, 600);
 			
 			ArrayList<Pair<String, TopicIdentifierTypes>> requestedTopicsToCreate = new ArrayList<Pair<String,TopicIdentifierTypes>>();
-			//requestedTopicsToCreate.add(new Pair<String, TopicIdentifierTypes>("http://textgrid.org/serviceregistry/model/types/Hash-Object", TopicIdentifierTypes.SubjectIdentifier));
-			requestedTopicsToCreate.add(new Pair<String, TopicIdentifierTypes>("http://textgrid.org/serviceregistry/model/types/Environment", TopicIdentifierTypes.SubjectIdentifier));
+			requestedTopicsToCreate.add(new Pair<String, TopicIdentifierTypes>("http://textgrid.org/serviceregistry/model/types/Hash-Object", TopicIdentifierTypes.SubjectIdentifier));
+			//requestedTopicsToCreate.add(new Pair<String, TopicIdentifierTypes>("http://textgrid.org/serviceregistry/model/types/Environment", TopicIdentifierTypes.SubjectIdentifier));
 			//requestedTopicsToCreate.add(new Pair<String, TopicIdentifierTypes>("http://psi.test.org/gdl-test/Poet", TopicIdentifierTypes.SubjectIdentifier));
 			//requestedTopicsToCreate.add(new Pair<String, TopicIdentifierTypes>("http://psi.test.org/gdl-test/Musician", TopicIdentifierTypes.SubjectIdentifier));
 			
-			Pair<String, TopicIdentifierTypes> requestedTopicToEdit = new Pair<String, TopicIdentifierTypes>("http://textgrid.org/serviceregistry/test-env-1", TopicIdentifierTypes.SubjectIdentifier);
+			//Pair<String, TopicIdentifierTypes> requestedTopicToEdit = new Pair<String, TopicIdentifierTypes>("http://textgrid.org/serviceregistry/test-env-1", TopicIdentifierTypes.SubjectIdentifier);
 			//Pair<String, TopicIdentifierTypes> requestedTopicToEdit = new Pair<String, TopicIdentifierTypes>("http://textgrid.org/serviceregistry/test-hash-2", TopicIdentifierTypes.SubjectIdentifier);
 			GdlPanel.addClickHandler("hash_object_reset_button_id", new ClickHandler() {
 				@Override
@@ -46,7 +46,7 @@
 				}
 			});
 			
-			gdlPanel = new GdlPanel(requestedTopicToEdit, null);
+			gdlPanel = new GdlPanel(null, requestedTopicsToCreate);
 			mainPanel.add(gdlPanel);
 			gdlPanel.setTmEngine(new JtmsTmEngine());
 			gdlPanel.setLoadSchemaCallback(new LoadSchemaCallback());

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	Thu Sep  8 07:02:36 2011	(r856)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TmHelper.java	Thu Sep  8 07:47:55 2011	(r857)
@@ -687,10 +687,10 @@
 		
 		TopicMap tm = hiddenValue.getTopicMap();
 		Topic valueBindingAssocTopic = getTopicByPsi(PSIs.GDL.AssociationType.gdlValueBinding, tm);
-		Topic valueGroupRoleType = getTopicByPsi(PSIs.GDL.RoleType.gdlValueGroup, tm);
+		Topic hiddenValueRoleType = getTopicByPsi(PSIs.GDL.RoleType.gdlHiddenValue, 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);
+		ArrayList<Topic> defaultTmValues = getOtherPlayerOfBinaryAssociation(hiddenValue, hiddenValueRoleType, valueBindingAssocTopic, null, defaultLiteralValueType, valueRoleType);
 
 		if(defaultTmValues.size() == 1) return defaultTmValues.get(0);
 		else if(defaultTmValues.size() == 0) return null;

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	Thu Sep  8 07:02:36 2011	(r856)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/Utils.java	Thu Sep  8 07:47:55 2011	(r857)
@@ -3,12 +3,37 @@
 import java.util.ArrayList;
 import com.google.gwt.core.client.JavaScriptObject;
 
+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.environment.Pattern;
 import com.google.gwt.core.client.JsArray;
 import com.google.gwt.dom.client.Element;
 
 public class Utils {
+	
+	// returns a string of the form:
+	// {
+	// association-type: psi
+	// roles: [type: psi, player: psi]
+	// [type: psi, player: psi]...
+	// }
+	// this method is only defined for debugging purpose
+	public static String toString(Association association){
+		if(association == null) return "{ }";
+		
+		String result = "{\ntype: ";
+		result += TmHelper.getAnyIdOfTopic(association.getType());
+		result += "\n\nroles:\n";
+		
+		JsArray<Role> roles = association.getRoles();
+		for(int i = 0; i != roles.length(); ++i)
+			result += "[type: " + TmHelper.getAnyIdOfTopic(roles.get(i).getType()) + "\nplayer: " + TmHelper.getAnyIdOfTopic(roles.get(i).getPlayer()) + "]\n\n";
+			
+		return result.substring(0, result.length() - 1) + "\n}";
+	}
+	
+	
 	// returns a string of the form [item1, item2, ... ] for all
 	// items of an ArrayList
 	public static <T> String arrayToString(ArrayList<T> data){

Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/CommitCallback.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/CommitCallback.java	Thu Sep  8 07:02:36 2011	(r856)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/CommitCallback.java	Thu Sep  8 07:47:55 2011	(r857)
@@ -31,7 +31,7 @@
 
 
 public class CommitCallback implements ICommitCallback{
-	public final String DELETE_REUQEST_URL = IsidorusConstants.DELETE_REUQEST_URL;
+	public final String DELETE_REUQEST_URL = IsidorusConstants.DELETE_REQUEST_URL;
 	public final String COMMIT_REQUEST_URL = IsidorusConstants.COMMIT_REQUEST_URL;
 	public final String GET_REQUEST_URL = IsidorusConstants.GET_FRAGMENT_REQUEST_URL;
 	
@@ -95,7 +95,7 @@
 			// a check for an existing environment topic is not necessary,
 			// since it would be exactly the same topic.
 			
-			//RootPanel.getBodyElement().setInnerText(jtm); // TODO: remove
+			//Window.alert(jtm); // TODO: remove
 			builder.sendRequest(null, new EnvironmentCommitRequest(jtm));
 		}catch(RequestException e){
 			Window.alert("could not commit the topic: " + jtm + ", because(" + e.getClass() + "): " + e.getMessage());
@@ -164,7 +164,7 @@
 			commitBuilder.setHeader("Content-type", "application/json");
 			RequestBuilder getBuilder = new RequestBuilder(RequestBuilder.GET, getUrl);
 			try{
-				//RootPanel.getBodyElement().setInnerText(jtm); //TODO: remove
+				Window.alert(jtm); //TODO: remove
 				
 				if(edited)getBuilder.sendRequest(null, new EditedHashObjectCommitRequest(null, jtm, false));
 				else commitBuilder.sendRequest(jtm, new HashObjectCommitRequest(jtm));

Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/DeleteCallback.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/DeleteCallback.java	Thu Sep  8 07:02:36 2011	(r856)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/DeleteCallback.java	Thu Sep  8 07:47:55 2011	(r857)
@@ -23,7 +23,7 @@
 
 
 public class DeleteCallback implements IDeleteCallback {
-	public final String REUQEST_URL = IsidorusConstants.DELETE_REUQEST_URL;
+	public final String REUQEST_URL = IsidorusConstants.DELETE_REQUEST_URL;
 	
 
 	@Override

Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/IsidorusConstants.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/IsidorusConstants.java	Thu Sep  8 07:02:36 2011	(r856)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/IsidorusConstants.java	Thu Sep  8 07:47:55 2011	(r857)
@@ -1,12 +1,14 @@
 package us.isidor.gdl.anaToMia.Widgets.isidorus;
 
 
+import com.google.gwt.core.client.GWT;
 import com.google.gwt.user.client.Window;
 
 
 public class IsidorusConstants {
-	public final static String DELETE_REUQEST_URL = Window.Location.getProtocol() + "//" + Window.Location.getHost() + "/gdl/delete";
+	public final static String DELETE_REQUEST_URL = Window.Location.getProtocol() + "//" + Window.Location.getHost() + "/gdl/delete";
 	public final static String COMMIT_REQUEST_URL = Window.Location.getProtocol() + "//" + Window.Location.getHost() + "/gdl/commit";
 	public final static String GET_FRAGMENT_REQUEST_URL = Window.Location.getProtocol() + "//" + Window.Location.getHost() + "/gdl/fragment/";
-	public final static String GET_SCHEMA_REQUEST_URL = Window.Location.getProtocol() + "//" + Window.Location.getHost() + "/gdl/schema"; //GWT.getModuleBaseURL() + "TextGrid_ServiceRegistry_required_TMCL_and_GDL_Schema_with_test_data.jtm";
+	//public final static String GET_SCHEMA_REQUEST_URL = Window.Location.getProtocol() + "//" + Window.Location.getHost() + "/gdl/schema";
+	public final static String GET_SCHEMA_REQUEST_URL = GWT.getModuleBaseURL() + "TextGrid_ServiceRegistry_required_TMCL_and_GDL_Schema_with_test_data.jtm";
 }

Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/LoadSchemaCallback.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/LoadSchemaCallback.java	Thu Sep  8 07:02:36 2011	(r856)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/LoadSchemaCallback.java	Thu Sep  8 07:47:55 2011	(r857)
@@ -35,7 +35,6 @@
 	public void loadSchema(GdlPanel panel, Pair<String, TopicIdentifierTypes> requestedTopicToEdit , ArrayList<Pair<String, TopicIdentifierTypes>> requestedTopicsToCreate)throws RequestException {
 		this.requestedTopicsToCreate = requestedTopicsToCreate;
 		this.requestedTopicToEdit = requestedTopicToEdit;
-		Window.alert("request address >> " + isidorusUrl); //TODO: remove
 		requestBuilder.sendRequest(null, new RequestCallbackImpl(panel));
 	}
 

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	Thu Sep  8 07:02:36 2011	(r856)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/view/GdlTopicView.java	Thu Sep  8 07:47:55 2011	(r857)
@@ -13,6 +13,7 @@
 import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.TopicMapsTypes;
 import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Variant;
 import us.isidor.gdl.anaToMia.Widgets.base.ButtonableObject;
+import us.isidor.gdl.anaToMia.Widgets.base.GdlHiddenValue;
 import us.isidor.gdl.anaToMia.Widgets.base.GdlVisibleObject;
 import us.isidor.gdl.anaToMia.Widgets.base.PSIs;
 import us.isidor.gdl.anaToMia.Widgets.base.TmHelper;
@@ -140,6 +141,7 @@
 	}
 	
 	
+	@SuppressWarnings("unchecked")
 	@Override
 	public ArrayList<Pair<Construct, TopicMapsTypes>> getContent(Construct carrier, boolean validate) throws InvalidGdlSchemaException, ExecutionException, InvalidContentException {
 		ArrayList<Pair<Construct, TopicMapsTypes>> result = new ArrayList<Pair<Construct,TopicMapsTypes>>();
@@ -159,14 +161,36 @@
 			}
 		}
 		
-		for (@SuppressWarnings("unused") Topic hd : this.getHiddenValues()) {
+		
+		for (Topic hd : this.getHiddenValues()) {
+			GdlHiddenValue hdv = new GdlHiddenValue(hd, this);
+			if(TmHelper.isInstanceOf(hdv.getConstraint(), PSIs.TMCL.tmclTopicOccurrenceConstraint)){
+				if(!hdv.getConstraint().equals(hdv.getRootConstraint())) throw new InvalidGdlSchemaException("the constraint " + TmHelper.getAnyIdOfTopic(hdv.getConstraint()) + " must not be bound to another constraint, but is bound to:  " + TmHelper.getAnyIdOfTopic(hdv.getRootConstraint()));
+				Topic top = this.getRepresentedTopic();
+				Topic occurrenceType = TmHelper.getConstrainedStatement(hdv.getConstraint());
+				if(occurrenceType == null) throw new InvalidContentException("the constraint " + TmHelper.getAnyIdOfTopic(hdv.getConstraint()) + " must be bound to an occurrence type via a " + PSIs.TMCL.tmclConstrainedStatement + " association");
+				String value = hdv.getRawDefaultLiteralValue();
+				if(value == null) throw new InvalidGdlSchemaException("the topic " + TmHelper.getAnyIdOfTopic(hdv.getTmRepresentative()) + " must be bound to an instance of " + PSIs.GDL.TopicType.gdlHiddenValue + ", but is unbound");
+				JsArray<Occurrence> occurrences = top.getOccurrences(occurrenceType);
+				// set the occurrence value only if it does not exist - don't override an existing occurrence
+				int i = 0;
+				for( ; i != occurrences.length(); ++i) if(occurrences.get(i).getValue().equals(value)) break;
+				
+				if(i == occurrences.length()){
+					Occurrence occ = top.createOccurrence(occurrenceType, value, (JsArray<Topic>)JsArray.createArray());
+					Pair<Construct, TopicMapsTypes> newItem = new Pair<Construct, TopicMapsTypes>(occ, TopicMapsTypes.Occurrence);
+					if(!this.indirectlyContained(newItem, result)) result.add(newItem);
+				}
+			}
+			
+			
 			// TODO: process hidden values
 			// subject-identifier
 			// subject-locator
 			// item-identifier
 			// topic-name
 			// variant-name
-			// topic-occurrence
+			// *topic-occurrence
 			// type => topic-name
 			// type => topic-occurrence
 			// datatype => topic-occurrence




More information about the Isidorus-cvs mailing list