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

lgiessmann at common-lisp.net lgiessmann at common-lisp.net
Fri Aug 19 11:09:15 UTC 2011


Author: lgiessmann
Date: Fri Aug 19 04:09:15 2011
New Revision: 761

Log:
gdl-frontend: Widgets: implemeneted the handling of Gdl-Default-Literal-Values

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/isidorus/LoadSchemaCallback.java
   branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/text/GdlText.java

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	Fri Aug 19 04:08:27 2011	(r760)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TestClass.java	Fri Aug 19 04:09:15 2011	(r761)
@@ -1,7 +1,6 @@
 package us.isidor.gdl.anaToMia.Widgets.base;
 
 
-import java.util.ArrayList;
 import us.isidor.gdl.anaToMia.TmEngine.jtmsBasedEngine.JtmsTmEngine;
 import us.isidor.gdl.anaToMia.Widgets.environment.Pair;
 import us.isidor.gdl.anaToMia.Widgets.environment.TopicIdentifierTypes;
@@ -26,7 +25,7 @@
 			mainPanel.setBorderWidth(1);
 			mainPanel.setPixelSize(1000, 600);
 			
-			ArrayList<Pair<String, TopicIdentifierTypes>> requestedTopicsToCreate = new ArrayList<Pair<String,TopicIdentifierTypes>>();
+			//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://psi.test.org/gdl-test/Poet", TopicIdentifierTypes.SubjectIdentifier));
@@ -34,14 +33,14 @@
 			
 			//Pair<String, TopicIdentifierTypes> requestedTopicToEdit = new Pair<String, TopicIdentifierTypes>("http://textgrid.org/serviceregistry/model/types/test-env", TopicIdentifierTypes.SubjectIdentifier);
 			//Pair<String, TopicIdentifierTypes> requestedTopicToEdit = new Pair<String, TopicIdentifierTypes>("http://textgrid.org/serviceregistry/model/types/test-hash", TopicIdentifierTypes.SubjectIdentifier);
-			Pair<String, TopicIdentifierTypes> requestedTopicToEdit = new Pair<String, TopicIdentifierTypes>("http://textgrid.org/serviceregistry/test-hash-1", TopicIdentifierTypes.SubjectIdentifier);
+			Pair<String, TopicIdentifierTypes> requestedTopicToEdit = new Pair<String, TopicIdentifierTypes>("http://textgrid.org/serviceregistry/test-hash-2", TopicIdentifierTypes.SubjectIdentifier);
 			GdlPanel.addClickHandler("unit_1_text_create_button_id", new ClickHandler() {
 				@Override
 				public void onClick(ClickEvent event) {
 					Window.alert("you clicked " + ((Button)event.getSource()).getText());
 				}
 			});
-			gdlPanel = new GdlPanel(requestedTopicToEdit, requestedTopicsToCreate);
+			gdlPanel = new GdlPanel(requestedTopicToEdit, null);
 			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/isidorus/LoadSchemaCallback.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/LoadSchemaCallback.java	Fri Aug 19 04:08:27 2011	(r760)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/LoadSchemaCallback.java	Fri Aug 19 04:09:15 2011	(r761)
@@ -23,7 +23,7 @@
 // this class can be used as a callback that requests the Topic Map data
 // addressable by the URI isidorusUrl
 public class LoadSchemaCallback implements ILoadSchemaCallback{
-	private final String isidorusUrl = URL.encode(GWT.getModuleBaseURL() + "TextGrid_ServiceRegistry_required_TMCL_and_GDL_Schema_with_test_data.jtm"); //"test.gdl.jtm"); // TODO: replace with the correct URL
+	private final String isidorusUrl = URL.encode(GWT.getModuleBaseURL() + "TextGrid_ServiceRegistry_required_TMCL_and_GDL_Schema_with_test_data.jtm"); // TODO: replace with the correct URL
 	private ArrayList<Pair<String, TopicIdentifierTypes>> requestedTopicsToCreate = new ArrayList<Pair<String,TopicIdentifierTypes>>(); 
 	private Pair<String, TopicIdentifierTypes> requestedTopicToEdit = null;
 	private RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, isidorusUrl);

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	Fri Aug 19 04:08:27 2011	(r760)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/text/GdlText.java	Fri Aug 19 04:09:15 2011	(r761)
@@ -1,6 +1,8 @@
 package us.isidor.gdl.anaToMia.Widgets.text;
 
 import java.util.ArrayList;
+
+import com.google.gwt.core.client.JsArray;
 import com.google.gwt.event.dom.client.BlurEvent;
 import com.google.gwt.event.dom.client.KeyPressEvent;
 import com.google.gwt.event.dom.client.KeyPressHandler;
@@ -17,6 +19,7 @@
 import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Reifiable;
 import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.ReifiableStub;
 import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Topic;
+import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.TopicMap;
 import us.isidor.gdl.anaToMia.Widgets.base.ButtonableObject;
 import us.isidor.gdl.anaToMia.Widgets.base.PSIs;
 import us.isidor.gdl.anaToMia.Widgets.base.IGdlHasValueGroup;
@@ -63,60 +66,85 @@
 	
 	public GdlText(Topic tmRepresentative, Construct receivedData) throws InvalidGdlSchemaException, ExecutionException{
 		super(tmRepresentative, receivedData);
-		// TODO: create a text element for each TM-elem, at least one empty elem
-		this.createNewTextArea().setText("Text"); // TODO: remove only for debugging
 		
+		// If the receivedData is set and the tmRepresentative is bound to a value-group
+		// that is bound to a constraint, the received data is consumed.
+		// Otherwise, the default values are consumped, since no set constraint means
+		// that no data of the received construct is determined to be set by this Widget.
+		if(receivedData != null && this.getConstraint() != null) this.setReceivedData();
+		else this.setDefaultValue();
+
+		this.setNthButtons();
+	}
+	
+	
+	// sets the fields for the received data
+	protected void setReceivedData() throws InvalidGdlSchemaException, ExecutionException {
+		if(receivedData == null) return;
 		
-		// TODO: move to GdlVisibleObject
-		if(receivedData != null){
-			if(TmHelper.isInstanceOf(this.getConstraint(), PSIs.TMCL.tmclSubjectIdentifierConstraint)){
-				if(!(receivedData instanceof Topic)) throw new ExecutionException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to a Topic, but is: " + receivedData.getClass());
-				
-				Pattern rex = new Pattern(this.getLiteralValueForConstraint());
-				for(int i = 0; i != ((Topic)receivedData).getSubjectIdentifiers().length(); ++i){
-					String psi = ((Topic)receivedData).getSubjectIdentifiers().get(i).getReference();
-					if(rex.matches(psi)){
-						this.createNewTextArea().setText(psi);
-					}
+		if(TmHelper.isInstanceOf(this.getConstraint(), PSIs.TMCL.tmclSubjectIdentifierConstraint)){
+			if(!(receivedData instanceof Topic)) throw new ExecutionException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to a Topic, but is: " + receivedData.getClass());
+			
+			Pattern rex = new Pattern(this.getLiteralValueForConstraint());
+			for(int i = 0; i != ((Topic)receivedData).getSubjectIdentifiers().length(); ++i){
+				String psi = ((Topic)receivedData).getSubjectIdentifiers().get(i).getReference();
+				if(rex.matches(psi)){
+					this.createNewTextArea().setText(psi);
 				}
-			} else if(TmHelper.isInstanceOf(this.getConstraint(), PSIs.TMCL.tmclSubjectLocatorConstraint)){
-				if(!(receivedData instanceof Topic)) throw new ExecutionException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to a Topic, but is: " + receivedData.getClass());
-				
-				Pattern rex = new Pattern(this.getLiteralValueForConstraint());
-				for(int i = 0; i != ((Topic)receivedData).getSubjectLocators().length(); ++i){
-					String sl = ((Topic)receivedData).getSubjectLocators().get(i).getReference();
-					if(rex.matches(sl)){
-						this.createNewTextArea().setText(sl);
-					}
+			}
+		} else if(TmHelper.isInstanceOf(this.getConstraint(), PSIs.TMCL.tmclSubjectLocatorConstraint)){
+			if(!(receivedData instanceof Topic)) throw new ExecutionException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to a Topic, but is: " + receivedData.getClass());
+			
+			Pattern rex = new Pattern(this.getLiteralValueForConstraint());
+			for(int i = 0; i != ((Topic)receivedData).getSubjectLocators().length(); ++i){
+				String sl = ((Topic)receivedData).getSubjectLocators().get(i).getReference();
+				if(rex.matches(sl)){
+					this.createNewTextArea().setText(sl);
 				}
-			} else if(TmHelper.isInstanceOf(this.getConstraint(), PSIs.TMCL.tmclItemIdentifierConstraint)){
-				if(!(this.receivedData instanceof Reifiable)) throw new ExecutionException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to a Reifiable, but is: " + receivedData.getClass());
-				
-				Pattern rex = new Pattern(this.getLiteralValueForConstraint());
-				for(int i = 0; i != ((ReifiableStub)receivedData).getItemIdentifiers().length(); ++i){
-					String ii = ((Topic)receivedData).getItemIdentifiers().get(i).getReference();
-					if(rex.matches(ii)){
-						this.createNewTextArea().setText(ii);
-					}
+			}
+		} else if(TmHelper.isInstanceOf(this.getConstraint(), PSIs.TMCL.tmclItemIdentifierConstraint)){
+			if(!(this.receivedData instanceof Reifiable)) throw new ExecutionException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to a Reifiable, but is: " + receivedData.getClass());
+			
+			Pattern rex = new Pattern(this.getLiteralValueForConstraint());
+			for(int i = 0; i != ((ReifiableStub)receivedData).getItemIdentifiers().length(); ++i){
+				String ii = ((Topic)receivedData).getItemIdentifiers().get(i).getReference();
+				if(rex.matches(ii)){
+					this.createNewTextArea().setText(ii);
 				}
-			} else if(TmHelper.isInstanceOf(this.getConstraint(), PSIs.TMCL.tmclTopicNameConstraint)){
-				if(!(receivedData instanceof Topic)) throw new ExecutionException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to a Topic, but is: " + receivedData.getClass());
-				
-				Topic nameType = TmHelper.getConstrainedStatement(this.getConstraint());
-				for(int i = 0; i != ((Topic)this.receivedData).getNames(nameType).length(); ++i)
-					this.createNewTextArea().setText(((Topic)this.receivedData).getNames(nameType).get(i).getValue());
-			} else if(TmHelper.isInstanceOf(this.getConstraint(), PSIs.TMCL.tmclTopicOccurrenceConstraint)){
-				if(!(receivedData instanceof Topic)) throw new ExecutionException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to a Topic, but is: " + receivedData.getClass());
-				
-				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());
 			}
-			// TODO: implement type, variant, datatype, ... constraints
+		} else if(TmHelper.isInstanceOf(this.getConstraint(), PSIs.TMCL.tmclTopicNameConstraint)){
+			if(!(receivedData instanceof Topic)) throw new ExecutionException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to a Topic, but is: " + receivedData.getClass());
+			
+			Topic nameType = TmHelper.getConstrainedStatement(this.getConstraint());
+			for(int i = 0; i != ((Topic)this.receivedData).getNames(nameType).length(); ++i)
+				this.createNewTextArea().setText(((Topic)this.receivedData).getNames(nameType).get(i).getValue());
+		} else if(TmHelper.isInstanceOf(this.getConstraint(), PSIs.TMCL.tmclTopicOccurrenceConstraint)){
+			if(!(receivedData instanceof Topic)) throw new ExecutionException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to a Topic, but is: " + receivedData.getClass());
+			
+			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());
+		}
+		// TODO: implement type, variant, datatype, association, ... constraints
+	}
+	
+	
+	// sets the field for the set default value or sets at least one empty field
+	public 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){
+			TopicMap tm = this.getDefaultLiteralValue().getTopicMap();
+			Topic occType = TmHelper.getTopicByPsi(PSIs.OccurrenceType.gdlLiteralValue, tm);
+			JsArray<Occurrence> vals = this.getDefaultLiteralValue().getOccurrences(occType);
+			if(vals.length() != 1) throw new InvalidGdlSchemaException("the topic " + TmHelper.getAnyIdOfTopic(this.getDefaultLiteralValue()) + " must be bound exactly once to a " + PSIs.OccurrenceType.gdlLiteralValue + " occurrence, but is: " + vals.length());
+			
+			this.createNewTextArea().setText(vals.get(0).getValue());
+		} else if(this.getDefaultTmValue() != null){
+			// TODO: set default-tm-value
 		} else {
-			// TODO: implement: set default values or generate at least one field
+			this.createNewTextArea();
 		}
-		this.setNthButtons();
 	}
 	
 	




More information about the Isidorus-cvs mailing list