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

lgiessmann at common-lisp.net lgiessmann at common-lisp.net
Mon Sep 12 12:18:07 UTC 2011


Author: lgiessmann
Date: Mon Sep 12 05:18:04 2011
New Revision: 872

Log:
gdl-frontend: Widgets: add new functionality to the GdlCommitButton => after a commit of a created topic/association the carrier is reset

Modified:
   branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlPanel.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/button/GdlCreateButton.java
   branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/button/GdlDeleteButton.java
   branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/environment/ICommitCallback.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/view/GdlAssociationView.java
   branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/view/GdlDefaultCreatorTopicView.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/GdlPanel.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlPanel.java	Mon Sep 12 02:31:58 2011	(r871)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlPanel.java	Mon Sep 12 05:18:04 2011	(r872)
@@ -211,7 +211,7 @@
 			}
 			ArrayList<Pair<Construct, TopicMapsTypes>> data = new ArrayList<Pair<Construct,TopicMapsTypes>>();
 			data.add(new Pair<Construct, TopicMapsTypes>(this.requestedSchemaTm, TopicMapsTypes.TopicMap));
-			this.commitCallback.commitTmConstruct(data, this.tmEngine, null);
+			this.commitCallback.commitTmConstruct(data, null, this.tmEngine);
 		}catch(Exception e){
 			for (IOnErrorCallback handler : localOnErrorContainer) {
 				handler.onError(GdlErrorTypes.CommitError, e);
@@ -276,7 +276,6 @@
 	}
 
 	
-	
 	// Creates the actual view from the requested topic map
 	public void createView(){
 		try{

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	Mon Sep 12 02:31:58 2011	(r871)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/button/GdlCommitButton.java	Mon Sep 12 05:18:04 2011	(r872)
@@ -1,12 +1,15 @@
 package us.isidor.gdl.anaToMia.Widgets.button;
 
-import us.isidor.gdl.anaToMia.TopicMaps.TmEngineModel.TmEngine;
+
 import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Construct;
 import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Topic;
 import us.isidor.gdl.anaToMia.Widgets.base.GdlVisibleObject;
 import us.isidor.gdl.anaToMia.Widgets.environment.ExecutionException;
 import us.isidor.gdl.anaToMia.Widgets.environment.ICommitCallback;
 import us.isidor.gdl.anaToMia.Widgets.environment.InvalidGdlSchemaException;
+import us.isidor.gdl.anaToMia.Widgets.view.GdlAssociationView;
+import us.isidor.gdl.anaToMia.Widgets.view.GdlTopicView;
+
 import com.google.gwt.event.dom.client.ClickEvent;
 import com.google.gwt.event.dom.client.ClickHandler;
 import com.google.gwt.user.client.Window;
@@ -24,25 +27,34 @@
 	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));
+		this.getButton().addClickHandler(new CommitButtonClickHandler());
 	}
 	
 	
-	protected class CommitButtonClickHandler implements ClickHandler {
-		private GdlCommitButton owner = null; 
+	public void resetCarriers(){
+		GdlVisibleObject parent = this.getGdlParent();
 		
-		public CommitButtonClickHandler(GdlCommitButton owner){
-			this.owner = owner;
+		while(parent != null){
+			if(parent instanceof GdlTopicView)((GdlTopicView)parent).resetRepresentedTopic();
+			if(parent instanceof GdlAssociationView)((GdlAssociationView)parent).resetRepresentedAssociations();
+			parent = parent.getGdlParent();
 		}
+	}
+	
+	
+	protected class CommitButtonClickHandler implements ClickHandler {
+		private GdlCommitButton owner = null;
+		
+		
+		public CommitButtonClickHandler() { }
 		
 		
 		@Override
 		public void onClick(ClickEvent event) {
 			try{
-				TmEngine tmEngine = this.owner.getRoot().getTmEngine();
 				ICommitCallback callback = this.owner.getRoot().getCommitCallback();
 				
-				callback.commitTmConstruct(this.owner.getGdlParent().getContent(null, true), tmEngine, this.owner.getId());
+				callback.commitTmConstruct(this.owner.getGdlParent().getContent(null, true), GdlCommitButton.this, this.owner.getRoot().getTmEngine());
 			}catch(Exception e){
 				e.printStackTrace();
 				Window.alert("caught: " + e.getMessage());

Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/button/GdlCreateButton.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/button/GdlCreateButton.java	Mon Sep 12 02:31:58 2011	(r871)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/button/GdlCreateButton.java	Mon Sep 12 05:18:04 2011	(r872)
@@ -8,6 +8,7 @@
 import com.google.gwt.user.client.ui.Button;
 
 public class GdlCreateButton extends GdlActionButton {
+	// TOOD: is this class really necessary or is GdlCommitButton sufficient???
 	// TODO: implement
 	
 	protected GdlCreateButton(){

Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/button/GdlDeleteButton.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/button/GdlDeleteButton.java	Mon Sep 12 02:31:58 2011	(r871)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/button/GdlDeleteButton.java	Mon Sep 12 05:18:04 2011	(r872)
@@ -10,6 +10,8 @@
 import us.isidor.gdl.anaToMia.Widgets.environment.ExecutionException;
 import us.isidor.gdl.anaToMia.Widgets.environment.IDeleteCallback;
 import us.isidor.gdl.anaToMia.Widgets.environment.InvalidGdlSchemaException;
+import us.isidor.gdl.anaToMia.Widgets.view.GdlAssociationView;
+import us.isidor.gdl.anaToMia.Widgets.view.GdlTopicView;
 
 public class GdlDeleteButton extends GdlActionButton {
 	// TODO: implement
@@ -26,6 +28,17 @@
 	}
 	
 	
+	public void resetCarriers(){
+		GdlVisibleObject parent = this.getGdlParent();
+		
+		while(parent != null){
+			if(parent instanceof GdlTopicView)((GdlTopicView)parent).resetRepresentedTopic();
+			if(parent instanceof GdlAssociationView)((GdlAssociationView)parent).resetRepresentedAssociations();
+			parent = parent.getGdlParent();
+		}
+	}
+	
+	
 	protected class DeleteButtonClickHandler implements ClickHandler {
 		private GdlDeleteButton owner = null; 
 		

Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/environment/ICommitCallback.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/environment/ICommitCallback.java	Mon Sep 12 02:31:58 2011	(r871)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/environment/ICommitCallback.java	Mon Sep 12 05:18:04 2011	(r872)
@@ -1,11 +1,13 @@
 package us.isidor.gdl.anaToMia.Widgets.environment;
 
 import java.util.ArrayList;
+
 import us.isidor.gdl.anaToMia.TopicMaps.TmEngineModel.TmEngine;
 import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Construct;
 import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.TopicMapsTypes;
+import us.isidor.gdl.anaToMia.Widgets.button.GdlCommitButton;
 
 
 public interface ICommitCallback {
-	public void commitTmConstruct(ArrayList<Pair<Construct, TopicMapsTypes>> constructs, TmEngine tmengine, String buttonId);
+	public void commitTmConstruct(ArrayList<Pair<Construct, TopicMapsTypes>> constructs, GdlCommitButton sender, TmEngine tmEngine);
 }

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	Mon Sep 12 02:31:58 2011	(r871)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/CommitCallback.java	Mon Sep 12 05:18:04 2011	(r872)
@@ -3,6 +3,7 @@
 import java.util.ArrayList;
 import us.isidor.gdl.anaToMia.Widgets.base.PSIs;
 import us.isidor.gdl.anaToMia.Widgets.base.TmHelper;
+import us.isidor.gdl.anaToMia.Widgets.button.GdlCommitButton;
 import us.isidor.gdl.anaToMia.Widgets.environment.Pair;
 import com.google.gwt.core.client.JsArray;
 import com.google.gwt.http.client.Request;
@@ -37,20 +38,21 @@
 	
 	
 	@Override
-	public void commitTmConstruct(ArrayList<Pair<Construct, TopicMapsTypes>> constructs, TmEngine tmEngine, String buttonId) {
+	public void commitTmConstruct(ArrayList<Pair<Construct, TopicMapsTypes>> constructs, GdlCommitButton sender, TmEngine tmEngine) {
 		try{
+			String buttonId = sender == null ? null : sender.getId();
 			if("hash_object_commit_button_id".equals(buttonId)){
 				this.commitCreatedHashObject(constructs, tmEngine, "edited_hash_object_commit_button_id".equals(buttonId));
 			} else if("environment_commit_button_id".equals(buttonId)){
-				this.commitCreatedEnvironment(constructs, tmEngine);
+				this.commitCreatedEnvironment(constructs, sender, tmEngine);
 			}
-		}catch(ExporterException ee){
-			Window.alert("failed to commit the Topic Maps data, because: " + ee.getMessage());
+		}catch(Exception e){
+			Window.alert("failed to commit the Topic Maps data, because: " + e.getMessage());
 		}
 	}
 	
 	
-	private void commitCreatedEnvironment(ArrayList<Pair<Construct, TopicMapsTypes>> constructs, TmEngine tmEngine) throws ExporterException {
+	private void commitCreatedEnvironment(ArrayList<Pair<Construct, TopicMapsTypes>> constructs, GdlCommitButton sender, TmEngine tmEngine) throws ExporterException {
 		final String carrierPsi = PSIs.GDL.gdl + "environment_default_creator_topic_view_id";
 		ArrayList<Topic> topics = new ArrayList<Topic>();
 		ArrayList<TopicMap> topicMaps = new ArrayList<TopicMap>();
@@ -94,9 +96,7 @@
 		try{
 			// a check for an existing environment topic is not necessary,
 			// since it would be exactly the same topic.
-			
-			//Window.alert(jtm); // TODO: remove
-			builder.sendRequest(jtm, new EnvironmentCommitRequest(jtm));
+			builder.sendRequest(jtm, new EnvironmentCommitRequest(jtm, sender));
 		}catch(RequestException e){
 			Window.alert("could not commit the topic: " + jtm + ", because(" + e.getClass() + "): " + e.getMessage());
 		}
@@ -177,14 +177,16 @@
 	
 	private class EnvironmentCommitRequest implements RequestCallback {
 		private String objectToBeSend = null;
+		private GdlCommitButton sender = null;
 		
 		
 		@SuppressWarnings("unused")
 		private EnvironmentCommitRequest(){}
 		
 		
-		public EnvironmentCommitRequest(String objectToBeCommitted){
+		public EnvironmentCommitRequest(String objectToBeCommitted, GdlCommitButton sender){
 			this.objectToBeSend = objectToBeCommitted;
+			this.sender = sender;
 		}
 		
 		
@@ -192,6 +194,7 @@
 		public void onResponseReceived(Request request, Response response) {
 			if (200 == response.getStatusCode()) {
 				Window.alert("commit operation of the object " + this.objectToBeSend + " successed");
+				this.sender.resetCarriers();
 				// TODO: reset the web page
 			} else {
 				Window.alert("commit operation of the object " + this.objectToBeSend + " failed: " + response.getStatusCode() + "(" + response.getStatusText() + ")\n" + response.getText());

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	Mon Sep 12 02:31:58 2011	(r871)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/view/GdlAssociationView.java	Mon Sep 12 05:18:04 2011	(r872)
@@ -48,6 +48,16 @@
 	}
 	
 	
+	public void resetRepresentedAssociations(){
+		for (Widget ctrl : this.subElements) {
+			if(ctrl instanceof ButtonableObject){
+				if(((ButtonableObject)ctrl).getMainObject() instanceof AssociationItem){
+					((AssociationItem)((ButtonableObject)ctrl).getMainObject()).resetRepresentedAssociation();
+				}
+			}
+		}
+	}
+	
 	// content orientation has no effect on a view, so here must the original method
 	// defined in GdlVisibleObject implemented
 	@Override
@@ -221,11 +231,11 @@
 			
 			// TODO: implement
 			// reifier => topic-role
-			// item-identifeir => topic-role
+			// item-identifier => topic-role
 			// type => association-role
 			// reifier => association-role
 			// item-identifier => association-role
-			// scope => assocition-role
+			// scope => association-role
 		}
 		
 		return result;
@@ -238,12 +248,27 @@
 	// represented by this class
 	public class AssociationItem extends GdlView {
 		private int indexInParent = -1;
+		private Association representedAssociation = null;
 		
 		
 		@SuppressWarnings("unchecked")
 		public Association getRepresentedAssociation() throws InvalidGdlSchemaException{
-			if(this.receivedData != null) return (Association)this.receivedData;
-			else return this.tmRepresentative.getTopicMap().createAssociation(((GdlAssociationView)this.getGdlParent()).getAssociationType(), (JsArray<Topic>)JsArray.createArray());
+			if(this.receivedData != null){
+				return (Association)this.receivedData;
+			} else if (this.representedAssociation != null){
+				return this.representedAssociation;
+			} else{
+				this.representedAssociation = this.tmRepresentative.getTopicMap().createAssociation(((GdlAssociationView)this.getGdlParent()).getAssociationType(), (JsArray<Topic>)JsArray.createArray());
+				return this.representedAssociation;
+			}
+		}
+		
+		
+		// can be called to set the represented topic to null, e.g.
+		// if a created association was submitted and a new association is created,
+		// so the old carrier is reset as well
+		public void resetRepresentedAssociation(){
+			this.representedAssociation = null;
 		}
 		
 		

Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/view/GdlDefaultCreatorTopicView.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/view/GdlDefaultCreatorTopicView.java	Mon Sep 12 02:31:58 2011	(r871)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/view/GdlDefaultCreatorTopicView.java	Mon Sep 12 05:18:04 2011	(r872)
@@ -22,4 +22,12 @@
 	public GdlPanel getRoot(){
 		return this.rootPanel;
 	}
+	
+	
+	// removes and destroys the carrier topic that is created when the getContent
+	// method is invoked, so duplicate data entries are not produced!
+	public void resetCarrier(){
+		//TODO: implement => call for this instance and each child creator instance
+		
+	}
 }

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	Mon Sep 12 02:31:58 2011	(r871)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/view/GdlTopicView.java	Mon Sep 12 05:18:04 2011	(r872)
@@ -146,8 +146,7 @@
 	public ArrayList<Pair<Construct, TopicMapsTypes>> getContent(Construct carrier, boolean validate) throws InvalidGdlSchemaException, ExecutionException, InvalidContentException {
 		ArrayList<Pair<Construct, TopicMapsTypes>> result = new ArrayList<Pair<Construct,TopicMapsTypes>>();
 		
-		Topic localCarrier = (Topic)this.receivedData;
-		if(localCarrier == null) localCarrier = this.getRepresentedTopic();
+		Topic localCarrier = this.getRepresentedTopic();
 				
 		for (Widget ctrl : this.subElements) {
 			int i = 0;
@@ -225,4 +224,12 @@
 			return (Topic)this.receivedData;
 		}
 	}
+	
+	
+	// can be called to set the represented topic to null, e.g.
+	// if a created topic was submitted and a new topic is created,
+	// so the old carrier is reset as well
+	public void resetRepresentedTopic(){
+		this.representedTopic = null;
+	}
 }




More information about the Isidorus-cvs mailing list