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

lgiessmann at common-lisp.net lgiessmann at common-lisp.net
Fri Jul 15 07:55:20 UTC 2011


Author: lgiessmann
Date: Fri Jul 15 00:55:20 2011
New Revision: 623

Log:
gdl-frontend: Widgets: implemented GDL positioning in GdlUnit

Modified:
   branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/container/GdlUnit.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/container/GdlUnit.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/container/GdlUnit.java	Fri Jul 15 00:24:45 2011	(r622)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/container/GdlUnit.java	Fri Jul 15 00:55:20 2011	(r623)
@@ -28,6 +28,7 @@
 import com.google.gwt.user.client.ui.Widget;
 import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Occurrence;
 import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Topic;
+import us.isidor.gdl.anaToMia.Widgets.base.GdlPosition;
 import us.isidor.gdl.anaToMia.Widgets.base.GdlPsis;
 import us.isidor.gdl.anaToMia.Widgets.base.GdlVisibleObject;
 import us.isidor.gdl.anaToMia.Widgets.base.IGdlContainer;
@@ -35,6 +36,7 @@
 import us.isidor.gdl.anaToMia.Widgets.environment.ActiveStyleHandler;
 import us.isidor.gdl.anaToMia.Widgets.environment.ExecutionException;
 import us.isidor.gdl.anaToMia.Widgets.environment.FocusStyleHandler;
+import us.isidor.gdl.anaToMia.Widgets.environment.GdlInstantiator;
 import us.isidor.gdl.anaToMia.Widgets.environment.HoverStyleHandler;
 import us.isidor.gdl.anaToMia.Widgets.environment.InvalidGdlSchemaException;
 import us.isidor.gdl.anaToMia.Widgets.environment.Pair;
@@ -70,7 +72,6 @@
 	// creates a unit element or returns the one, if there is a unit element
 	// in the subElements array
 	private void createUnit() throws InvalidGdlSchemaException, ExecutionException{
-		// this object is able to own only one sub-element		
 		UnitWidget unit = new UnitWidget();
 		ActiveStyleHandler asHandler = new ActiveStyleHandler(this);
 		FocusStyleHandler fsHandler = new FocusStyleHandler(this);
@@ -86,6 +87,16 @@
 		unit.addBlurHandler(fsHandler);
 		super.addToContainerPanel(unit);
 		this.setGdlStyle(unit);
+		
+		// set the actual content of a unit
+		ArrayList<Topic> objectsContained = this.contains();
+		Topic currentTopic = this.getStartElement(objectsContained);
+		Topic lastTopic = super.getTmRepresentative();
+		while(currentTopic != null){
+			unit.append(lastTopic, currentTopic);
+			lastTopic = currentTopic;
+			currentTopic = TmHelper.getNextContainee(currentTopic, objectsContained);
+		}
 	}
 	
 	
@@ -1253,8 +1264,9 @@
 	
 	
 	@Override
+	@Deprecated
 	public GdlVisibleObject append(Topic ancestor, Topic current) throws InvalidGdlSchemaException, ExecutionException {
-		// TODO: implement
+		// do nothing this method has no effect on the mainpanle
 		return null;
 	}
 	
@@ -1264,7 +1276,15 @@
 	@Override
 	public ArrayList<Topic> contains() throws InvalidGdlSchemaException {
 		return TmHelper.topicContains(this.tmRepresentative);
-	} 
+	}
+	
+	
+	// Searches the topic that represents the first item that is placed within this view instance
+	// i.e. such an item must not have an association that is bound to it via a role of the type
+	// gdl:ancestor.
+	protected Topic getStartElement(ArrayList<Topic> containees) throws InvalidGdlSchemaException {
+		return TmHelper.getFirstContainee(super.getTmRepresentative(), containees);
+	}
 	
 		
 	// wraps a fieldset with a legend item that represent a group-element
@@ -1272,9 +1292,16 @@
 		private AbsolutePanel basePanel = new AbsolutePanel();
 		private Element fieldset = DOM.createFieldSet();
 		private Element legend = DOM.createLegend();
+		private ArrayList<Widget> subElements = new ArrayList<Widget>();
+		private Topic tmRepresentative = null;
+		
+		
+		private UnitWidget() {}
 		
 		
-		public UnitWidget(){
+		public UnitWidget(Topic tmRepresentative) throws ExecutionException{
+			if(tmRepresentative == null) throw new ExecutionException("tmRepresentative must be set");
+			this.tmRepresentative = tmRepresentative;
 			initWidget(this.basePanel);
 			this.fieldset.appendChild(this.legend);
 			this.basePanel.getElement().appendChild(this.fieldset);
@@ -1282,7 +1309,12 @@
 			DOM.setStyleAttribute(this.legend, "display", "none");
 			DOM.setStyleAttribute(this.legend, "marginLeft", "1em");
 			DOM.setStyleAttribute(this.legend, "marginRight", "1em");
-		}	
+		}
+		
+		
+		public Topic getTmRepresentative(){
+			return this.tmRepresentative;
+		}
 		
 		
 		// some css style setters
@@ -1494,8 +1526,34 @@
 		}
 		
 		
-		public void insert(GdlVisibleObject widget){
-			// TODO: implement, change signature => positioning
+		// appends a new element in form of a topic to this unit-widget
+		public GdlVisibleObject append(Topic ancestor, Topic current) throws ExecutionException, InvalidGdlSchemaException {
+			if(ancestor == null || current == null) throw new ExecutionException("to append \"" + TmHelper.getAnyIdOfTopic(current) + "\" on \"" + TmHelper.getAnyIdOfTopic(ancestor) + "\" both topics must be present");
+			GdlPosition position = new GdlPosition(TmHelper.getPositionOf(ancestor, current));
+			
+			GdlVisibleObject newObj = GdlInstantiator.instantiate(current);
+			GdlVisibleObject oldObj = null;
+			for (Widget widget : this.subElements){
+				if(((GdlVisibleObject)widget).getTmRepresentative().equals(ancestor)){
+					oldObj = (GdlVisibleObject)widget;
+					break;
+				}
+			}
+			
+			this.subElements.add(newObj);
+			if(this.getTmRepresentative().equals(ancestor)){
+				this.fieldset.appendChild(newObj.getElement());
+			}
+			else{
+				Element elemBefore = oldObj.getElement();
+				Element elemAfter = DOM.getNextSibling(elemBefore);
+				// insert before seems to be a more accepted and stable
+				// way of inserting new child elements than insertAfter
+				if(elemAfter == null) this.fieldset.appendChild(newObj.getElement());
+				else this.fieldset.insertBefore(newObj.getElement(), elemAfter);
+			}			
+			position.setAttributes(newObj);
+			return newObj;
 		}
 
 

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	Fri Jul 15 00:24:45 2011	(r622)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/view/GdlView.java	Fri Jul 15 00:55:20 2011	(r623)
@@ -1,11 +1,8 @@
 package us.isidor.gdl.anaToMia.Widgets.view;
 
 import java.util.ArrayList;
-
 import com.google.gwt.core.client.JsArray;
 import com.google.gwt.event.dom.client.ClickHandler;
-import com.google.gwt.user.client.DOM;
-import com.google.gwt.user.client.Window;
 import com.google.gwt.user.client.ui.Widget;
 import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Name;
 import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Topic;




More information about the Isidorus-cvs mailing list