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

lgiessmann at common-lisp.net lgiessmann at common-lisp.net
Mon Aug 29 15:22:42 UTC 2011


Author: lgiessmann
Date: Mon Aug 29 08:22:42 2011
New Revision: 801

Log:
gdl-frontend: Widgets: implemented the infrastructure for GdlVisibleObject.getContent(Construct carrier)

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/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/GdlDeleteButton.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/GdlDefaultTopicView.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 Aug 29 02:32:41 2011	(r800)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlPanel.java	Mon Aug 29 08:22:42 2011	(r801)
@@ -262,7 +262,7 @@
 	// data by using the view's getContent method.
 	public ArrayList<Pair<Construct, TopicMapsTypes>> getContent() throws Exception {
 		try{
-			return this.view.getContent();
+			return this.view.getContent(null);
 		}catch(Exception e){
 			for (IOnErrorCallback handler : localOnErrorContainer) {
 				handler.onError(GdlErrorTypes.TopicMapsGenerationError, e);

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	Mon Aug 29 02:32:41 2011	(r800)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlVisibleObject.java	Mon Aug 29 08:22:42 2011	(r801)
@@ -2208,12 +2208,77 @@
 	
 	
 	// returns the strings of the control that are entered/selected 
+	// returns the strings of the control that are entered/selected 
 	public abstract ArrayList<String> getSelectedValues();
 	
 	
 	// returns the actual data that is hold by this instance
-	public ArrayList<Pair<Construct, TopicMapsTypes>> getContent(){
-		// TODO: implement
-		return null;		
+	public ArrayList<Pair<Construct, TopicMapsTypes>> getContent(Construct carrier) throws InvalidGdlSchemaException, ExecutionException {
+		ArrayList<Pair<Construct, TopicMapsTypes>> result = new ArrayList<Pair<Construct,TopicMapsTypes>>();
+		if(carrier == null || this.getRootConstraint() == null) return result;
+		
+		//TODO: finalise
+		for (int idx = 0; idx != this.getSelectedValues().size(); ++idx){
+			if(TmHelper.isInstanceOf(this.getConstraint(), PSIs.TMCL.tmclItemIdentifierConstraint)){
+				
+			} else if (TmHelper.isInstanceOf(this.getRootConstraint(), PSIs.TMCL.tmclSubjectIdentifierConstraint)){
+				
+			} else if (TmHelper.isInstanceOf(this.getRootConstraint(), PSIs.TMCL.tmclSubjectLocatorConstraint)){
+				
+			} else if (TmHelper.isInstanceOf(this.getRootConstraint(), PSIs.TMCL.tmclTopicNameConstraint)){
+				
+			} else if (TmHelper.isInstanceOf(this.getRootConstraint(), PSIs.TMCL.tmclVariantNameConstraint)){
+				
+			} else if (TmHelper.isInstanceOf(this.getRootConstraint(), PSIs.TMCL.tmclTopicOccurrenceConstraint)){
+				if(!(carrier instanceof Topic)) throw new ExecutionException("the constraint " + TmHelper.getAnyIdOfTopic(this.getRootConstraint()) + " must be bound to a Topic, but is: " + carrier.getClass());
+				Topic occurrenceType = TmHelper.getConstrainedStatement(this.getConstraint());
+				JsArray<Occurrence> occurrences = ((Topic)carrier).getOccurrences(occurrenceType);
+
+				Occurrence changedOccurrence = null;
+				if(this.getRootConstraint().equals(this.getConstraint())){
+					if(occurrences.length() > idx){
+						changedOccurrence = occurrences.get(idx);
+						changedOccurrence.setValue(this.getSelectedValues().get(idx));
+					}else {
+						changedOccurrence = ((Topic)carrier).createOccurrence(occurrenceType, this.getSelectedValues().get(idx), null, null);
+					}
+				} // TODO: Type, Role-Player, ...
+				
+				result.add(new Pair<Construct, TopicMapsTypes>(changedOccurrence, TopicMapsTypes.Occurrence));
+			} else if (TmHelper.isInstanceOf(this.getRootConstraint(), PSIs.TMCL.tmclTopicRoleConstraint)){
+				if(!(carrier instanceof Association)) throw new ExecutionException("the constraint " + TmHelper.getAnyIdOfTopic(this.getRootConstraint()) + " must be bound to an Association, but is: " + carrier.getClass());
+				Pair<Topic, Topic> roleAndPlayerType = TmHelper.getConstrainedRoleAndPlayerTypeOfConstraint(this.getRootConstraint());
+				Topic roleType = roleAndPlayerType.getFirst();
+				Topic playerType = roleAndPlayerType.getSecond();
+				
+				JsArray<Role> typedRoles = ((Association)carrier).getRoles(roleType);
+				ArrayList<Role> roles = new ArrayList<Role>();
+				for(int i = 0; i != typedRoles.length(); ++i)
+					if(TmHelper.isInstanceOf(typedRoles.get(i).getPlayer(), playerType)) roles.add(typedRoles.get(i));
+				
+				Role changedRole = null;
+				if(TmHelper.isInstanceOf(this.getConstraint(), PSIs.TMCL.tmclReifierConstraint)){
+					// TODO: implement
+				} else if(TmHelper.isInstanceOf(this.getConstraint(), PSIs.TMCL.tmclItemIdentifierConstraint)){
+					// TODO: implement
+				} else if(TmHelper.isInstanceOf(this.getConstraint(), PSIs.GDL.TopicType.gdlRolePlayer)){
+					if(roles.size() > idx){
+						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()));
+					}
+				} else if(TmHelper.isInstanceOf(this.getConstraint(), PSIs.GDL.TopicType.gdlType)){
+					// TODO: implement
+				} else {
+					throw new InvalidGdlSchemaException("the root constraint must be bound to one of: " + PSIs.TMCL.tmclReifierConstraint + ", " + PSIs.TMCL.tmclItemIdentifierConstraint + ", " + PSIs.GDL.TopicType.gdlRolePlayer + ", " + PSIs.GDL.TopicType.gdlType + ", but is: " + TmHelper.getAnyIdOfTopic(this.getConstraint()));
+				}
+				result.add(new Pair<Construct, TopicMapsTypes>(changedRole, TopicMapsTypes.Role));
+			} else {
+				throw new InvalidGdlSchemaException("the constraint " + TmHelper.getAnyIdOfTopic(this.getRootConstraint()) + " is not supported");
+			}
+		}
+		
+		return result;
 	}
 }

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	Mon Aug 29 02:32:41 2011	(r800)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TmHelper.java	Mon Aug 29 08:22:42 2011	(r801)
@@ -1282,4 +1282,26 @@
 		
 		return result;
 	}
+
+	
+	// Returns the topic that is rperesentated by the passed string corresponding
+	// to the passed representationSchema
+	public static Topic getTopicFromStringRepresentation(String representation, Topic valueGroup) throws ExecutionException, InvalidGdlSchemaException {
+		if(representation == null || valueGroup == null) return null;
+		
+		ArrayList<Topic> tmValues = getTmValuesForConstraint(getConstraintOfValueGroup(valueGroup), valueGroup);
+		for (Topic tmValue : tmValues) {
+			if(getTopicRepresentation(tmValue, getDisplayByTopicOf(valueGroup), getPrefferedScopesForTopicOf(valueGroup)).equals(representation)) return tmValue;
+		}
+		
+		tmValues = getTmValues(valueGroup);
+		for (Topic tmValue : tmValues) {
+			ArrayList<Topic> rawValues = getValuesForTmValue(tmValue);
+			for (Topic rawValue : rawValues) {
+				if(getTopicRepresentation(tmValue, getDisplayByTopicOf(valueGroup), getPrefferedScopesForTopicOf(valueGroup)).equals(representation)) return rawValue;
+			}
+		}
+		
+		throw new ExecutionException("no topic found for the representation string: " + representation);
+	}
 }

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 Aug 29 02:32:41 2011	(r800)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/button/GdlDeleteButton.java	Mon Aug 29 08:22:42 2011	(r801)
@@ -1,11 +1,9 @@
 package us.isidor.gdl.anaToMia.Widgets.button;
 
-
 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;
-
 import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Construct;
 import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Topic;
 import us.isidor.gdl.anaToMia.Widgets.base.GdlVisibleObject;
@@ -37,7 +35,12 @@
 		
 		@Override
 		public void onClick(ClickEvent event) {
-				Window.alert("content: " + this.owner.getContent());
+			try{
+				Window.alert("content: " + this.owner.getGdlParent().getContent(null));
+				// TODO: implement
+			}catch(Exception e){
+				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	Mon Aug 29 02:32:41 2011	(r800)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/view/GdlAssociationView.java	Mon Aug 29 08:22:42 2011	(r801)
@@ -1,7 +1,6 @@
 package us.isidor.gdl.anaToMia.Widgets.view;
 
 import java.util.ArrayList;
-
 import com.google.gwt.core.client.JsArray;
 import com.google.gwt.user.client.ui.HorizontalPanel;
 import com.google.gwt.user.client.ui.VerticalPanel;
@@ -10,6 +9,7 @@
 import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Construct;
 import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Occurrence;
 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;
@@ -181,14 +181,25 @@
 			return this.validRoleCombinations;
 		}
 	}
-	
+
 	
 	@Override
-	public ArrayList<Pair<Construct, TopicMapsTypes>> getContent(){
-		// TODO: implement
-		return null;
+	public ArrayList<Pair<Construct, TopicMapsTypes>> getContent(Construct carrier) throws InvalidGdlSchemaException, ExecutionException {
+		ArrayList<Pair<Construct, TopicMapsTypes>> result = new ArrayList<Pair<Construct,TopicMapsTypes>>();
+		
+		for (Widget ctrl : this.subElements) {
+			if(ctrl instanceof ButtonableObject){
+				if(((ButtonableObject)ctrl).getMainObject() instanceof AssociationItem){
+					for (Pair<Construct, TopicMapsTypes> pair : ((AssociationItem)((ButtonableObject)ctrl).getMainObject()).getContent(null)) {
+						result.add(pair);
+					}
+				}
+			}
+		}
+		
+		return result;
 	}
-
+	
 
 	// This class represents a single association that is displayed.
 	// Further elements are created by caling the GdlInstantiator.instantiate
@@ -220,6 +231,27 @@
 		}
 		
 		
+		@SuppressWarnings("unchecked")
+		@Override
+		public ArrayList<Pair<Construct, TopicMapsTypes>> getContent(Construct carrier) throws InvalidGdlSchemaException, ExecutionException {
+			ArrayList<Pair<Construct, TopicMapsTypes>> result = new ArrayList<Pair<Construct,TopicMapsTypes>>();
+			
+			Association localCarrier = (Association)this.receivedData;
+			if(localCarrier == null){
+				TopicMap tm = this.tmRepresentative.getTopicMap();
+				localCarrier = tm.createAssociation(((GdlAssociationView)this.getGdlParent()).getAssociationType(), (JsArray<Topic>)JsArray.createArray());
+			}
+			
+			for (Widget ctrl : this.subElements) {
+				if(ctrl instanceof GdlVisibleObject){
+					((GdlVisibleObject)ctrl).getContent(localCarrier);
+				}
+			}
+			result.add(new Pair<Construct, TopicMapsTypes>(localCarrier, TopicMapsTypes.Association));
+			return result;
+		}
+		
+		
 		// this method should be invoked if a new sub-element is added to this instance.
 		// instances of GdlView does not organize their sub-elements in
 		// tables, sub-elements are placed directly on the mainpanel
@@ -294,12 +326,5 @@
 				this.setBackgroundColor(widget, this.getBackgroundColor(styleClass), styleClass);
 			}
 		}
-		
-		
-		@Override
-		public ArrayList<Pair<Construct, TopicMapsTypes>> getContent(){
-			// TODO: implement
-			return null;
-		}
 	}
 }

Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/view/GdlDefaultTopicView.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/view/GdlDefaultTopicView.java	Mon Aug 29 02:32:41 2011	(r800)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/view/GdlDefaultTopicView.java	Mon Aug 29 08:22:42 2011	(r801)
@@ -1,14 +1,11 @@
 package us.isidor.gdl.anaToMia.Widgets.view;
 
-import java.util.ArrayList;
 
-import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Construct;
 import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Topic;
-import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.TopicMapsTypes;
 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 us.isidor.gdl.anaToMia.Widgets.environment.Pair;
+
 
 public abstract class GdlDefaultTopicView extends GdlTopicView {
 
@@ -18,10 +15,4 @@
 	}
 	// TODO: implement
 	
-	
-	@Override
-	public ArrayList<Pair<Construct, TopicMapsTypes>> getContent(){
-		// TODO: implement
-		return null;
-	}
 }

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 Aug 29 02:32:41 2011	(r800)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/view/GdlTopicView.java	Mon Aug 29 08:22:42 2011	(r801)
@@ -1,10 +1,11 @@
 package us.isidor.gdl.anaToMia.Widgets.view;
 
+
 import java.util.ArrayList;
 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;
@@ -74,8 +75,24 @@
 	
 	
 	@Override
-	public ArrayList<Pair<Construct, TopicMapsTypes>> getContent(){
-		// TODO: implement
-		return null;
+	public ArrayList<Pair<Construct, TopicMapsTypes>> getContent(Construct carrier) throws InvalidGdlSchemaException, ExecutionException {
+		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()));
+		}
+				
+		for (Widget ctrl : this.subElements) {
+			if(this.receivedData == null) result.add(new Pair<Construct, TopicMapsTypes>(localCarrier, TopicMapsTypes.Topic));
+			if(ctrl instanceof GdlVisibleObject){
+				for (Pair<Construct, TopicMapsTypes> pair : ((GdlVisibleObject)ctrl).getContent(localCarrier)) {
+					if(this.receivedData != null)result.add(pair);
+				}
+			}
+		}
+		
+		return result;
 	}
 }




More information about the Isidorus-cvs mailing list