[isidorus-cvs] r674 - branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base

lgiessmann at common-lisp.net lgiessmann at common-lisp.net
Wed Jul 27 08:28:58 UTC 2011


Author: lgiessmann
Date: Wed Jul 27 01:28:57 2011
New Revision: 674

Log:
gdl-frontend: Widgets: implemented some function in GdlVisibleObject nad TmHelper that set GdlActionButtons

Modified:
   branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/ButtonableObject.java
   branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlPsis.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

Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/ButtonableObject.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/ButtonableObject.java	Tue Jul 26 14:21:43 2011	(r673)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/ButtonableObject.java	Wed Jul 27 01:28:57 2011	(r674)
@@ -1,10 +1,14 @@
 package us.isidor.gdl.anaToMia.Widgets.base;
 
+import java.util.ArrayList;
+
+import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Topic;
 import us.isidor.gdl.anaToMia.Widgets.button.GdlActionButton;
 import us.isidor.gdl.anaToMia.Widgets.environment.ExecutionException;
 import com.google.gwt.user.client.ui.Composite;
 import com.google.gwt.user.client.ui.HorizontalPanel;
 import com.google.gwt.user.client.ui.Widget;
+import com.sun.corba.se.spi.orbutil.fsm.ActionBase;
 
 
 public class ButtonableObject extends Composite {
@@ -38,4 +42,32 @@
 			this.mainPanel.remove(this.mainPanel.getWidgetCount() - 1);
 		}
 	}
+	
+	
+	public boolean containsButton(Topic tmRepresentative){
+		for(int i = 0; i != this.mainPanel.getWidgetCount(); ++i)
+			if(((GdlActionButton)this.mainPanel.getWidget(i)).getTmRepresentative().equals(tmRepresentative)) return true;
+		
+		return false;
+	}
+	
+	
+	public boolean containsButton(GdlActionButton button){
+		for(int i = 0; i != this.mainPanel.getWidgetCount(); ++i)
+			if(this.mainPanel.getWidget(i).equals(button)) return true;
+		
+		return false;
+	}
+	
+	
+	public void removeObsoleteButtons(ArrayList<Topic> activeButtons){
+		if(activeButtons == null) return;
+		
+		ArrayList<GdlActionButton> buttonsToRemove = new ArrayList<GdlActionButton>();
+		for(int i = 0; i != this.mainPanel.getWidgetCount(); ++i)
+			if(!activeButtons.contains(this.mainPanel.getWidget(i))) buttonsToRemove.add((GdlActionButton)this.mainPanel.getWidget(i));
+		
+		for (GdlActionButton buttonToRemove : buttonsToRemove)
+			this.mainPanel.remove(buttonToRemove);
+	}
 }

Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlPsis.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlPsis.java	Tue Jul 26 14:21:43 2011	(r673)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlPsis.java	Wed Jul 27 01:28:57 2011	(r674)
@@ -202,6 +202,7 @@
 		public final static String gdlHiddenValue = gdl + "hidden-value";
 		public final static String gdlValueGroup = gdl + "value-group";
 		public final static String gdlTmValue = gdl + "tm-value";
+		public final static String gdlActionButton = gdl + "action-button";
 	}
 	
 	

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	Tue Jul 26 14:21:43 2011	(r673)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlVisibleObject.java	Wed Jul 27 01:28:57 2011	(r674)
@@ -4,9 +4,11 @@
 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.Widgets.button.GdlActionButton;
 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.MultipleHandlerRegistration;
@@ -67,6 +69,7 @@
 	protected ArrayList<Pair<String, String>> hoverCssNamesAndStyles = new ArrayList<Pair<String,String>>();
 	protected ArrayList<Widget> subElements = new ArrayList<Widget>();
 	protected ArrayList<Pair<Widget, ArrayList<EventHandler>>> eventHandlers = new ArrayList<Pair<Widget, ArrayList<EventHandler>>>();
+	protected ArrayList<Pair<Topic, Integer>> actionButtonsAndPositions = null;
 	
 
 	// some constructors
@@ -102,6 +105,30 @@
 		return btn;
 	}
 	
+	
+	// sets all buttons in the sub-elements that are specified by a
+	// gdl:button-position association
+	protected void setNthButtons() throws InvalidGdlSchemaException, ExecutionException {
+		if(this.actionButtonsAndPositions == null) this.actionButtonsAndPositions = TmHelper.topicContainsActionButtons(this.tmRepresentative);
+		
+		// walk though all sub elements
+		for(int i = 0; i != this.subElements.size(); ++i){
+			ButtonableObject parent = (ButtonableObject)this.subElements.get(i).getParent();
+			
+			// search all buttons for the current sub element
+			ArrayList<Topic> currentButtons = new ArrayList<Topic>();
+			for (Pair<Topic, Integer> pair : this.actionButtonsAndPositions)
+				if(pair.getSecond() == i || (i == this.subElements.size() -1 && pair.getSecond() == -1)) currentButtons.add(pair.getFirst());
+			
+			// remove buttons that do not belong to the current sub element anymore
+			parent.removeObsoleteButtons(currentButtons);
+			
+			// add buttons that are not bound to the current sub element, but belong to it
+			for (Topic currentButton : currentButtons)
+				if(!parent.containsButton(currentButton)) parent.addButton((GdlActionButton)GdlInstantiator.instantiate(currentButton));
+		}
+	}
+	
 
 	// a helper method that returns all occurrences of the type bound to the passed PSI
 	protected JsArray<Occurrence> getOccurrences(String occurrenceType){

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	Tue Jul 26 14:21:43 2011	(r673)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TmHelper.java	Wed Jul 27 01:28:57 2011	(r674)
@@ -272,7 +272,7 @@
 	}
 	
 	
-	// returns all topics that are instances if tm-value, which are also bound to this
+	// returns all topics that are instances of tm-value, which are also bound to this
 	// topic via a gdl:tm-binding association
 	public static ArrayList<Topic> getTmValues(Topic top){
 		ArrayList<Topic> result = new ArrayList<Topic>();
@@ -329,6 +329,57 @@
 	}
 	
 	
+	// Returns all pairs of topics and string that are of type gdl:Action-Button and are
+	// bound to the passed topic via a gdl:contains and via a gdl:button-position association.
+	// The topic is the gdl:Action-Button instance, whereas the string is the value of the
+	// instance of gdl:Nth-Element.
+	// The integer contains the index specified by the nth-value occurrence, a -1 indicates
+	// the value last.
+	public static ArrayList<Pair<Topic, Integer>> topicContainsActionButtons(Topic container) throws InvalidGdlSchemaException{
+		ArrayList<Pair<Topic, Integer>> result = new ArrayList<Pair<Topic,Integer>>();
+		if(container == null) return result;
+		
+		TopicMap tm = container.getTopicMap();
+		Topic containsAssocType = getTopicByPsi(GdlPsis.AssociationType.gdlContains, tm);
+		Topic containerRoleType = getTopicByPsi(GdlPsis.RoleType.gdlContainer, tm);
+		Topic actionButtonType = getTopicByPsi(GdlPsis.TopicType.gdlActionButton, tm);
+		Topic containeeRoleType = getTopicByPsi(GdlPsis.RoleType.gdlContainee, tm);
+		ArrayList<Topic> actionButtons = getOtherPlayerOfBinaryAssociation(container, containerRoleType, containsAssocType, null, actionButtonType, containeeRoleType);
+				
+		Topic actionButtonRoleType = getTopicByPsi(GdlPsis.RoleType.gdlActionButton, tm);
+		Topic buttonPosition = getTopicByPsi(GdlPsis.AssociationType.gdlButtonPosition, tm);
+		Topic nthElementType = getTopicByPsi(GdlPsis.TopicType.gdlNthElement, tm);
+		Topic nthElementRoleType = getTopicByPsi(GdlPsis.RoleType.gdlNthElement, tm);
+		Topic nthValueOccType = getTopicByPsi(GdlPsis.OccurrenceType.gdlNthValue, tm);
+		ArrayList<Pair<Topic, Topic>> rolePlayertypesAndTypes = new ArrayList<Pair<Topic,Topic>>();
+		rolePlayertypesAndTypes.add(new Pair<Topic, Topic>(nthElementType, nthElementRoleType));
+		for (Topic actionButton : actionButtons) {
+			ArrayList<Association> assocs = getAssociationsOfTopic(actionButton, actionButtonRoleType, buttonPosition, null, rolePlayertypesAndTypes);
+			if(assocs.size() == 0) continue;
+			if(assocs.size() > 1) throw new InvalidGdlSchemaException("the topic " + getAnyIdOfTopic(actionButton) + " must be bound none or once to a " + GdlPsis.AssociationType.gdlButtonPosition + " association, but is: " + assocs.size());
+			if(assocs.size() == 1) {
+				Topic nthElem = assocs.get(0).getRoles(nthElementRoleType).get(0).getPlayer();
+				JsArray<Occurrence> occs = nthElem.getOccurrences(nthValueOccType);
+				if(occs.length() != 1) throw new InvalidGdlSchemaException("the topic " + getAnyIdOfTopic(nthElem) + " must be bound exactly once to a " + GdlPsis.OccurrenceType.gdlNthValue + " occurrence, but is: " + occs.length());
+				int val = 0;
+				try{
+					if(occs.get(0).getValue().toLowerCase().equals("last")){
+						val = -1;
+					} else {
+						Integer.valueOf(occs.get(0).getValue());
+					}
+				}catch(NumberFormatException e){
+					throw new InvalidGdlSchemaException("The topic " + getAnyIdOfTopic(nthElem) + " must contain a value of the form <positive-integer>|\"last\" in the occurrence " + GdlPsis.OccurrenceType.gdlNthValue + ", but it contains: " + occs.get(0).getValue());
+				}
+				
+				result.add(new Pair<Topic, Integer>(actionButton, val));
+			}
+		}
+		
+		return result;
+	}
+	
+	
 	// returns an ordered list of the list items and their index stored in a pair instance
 	public static ArrayList<Pair<Topic, Integer>> listContains(Topic list) throws InvalidGdlSchemaException {
 		if(list == null) return new ArrayList<Pair<Topic,Integer>>();




More information about the Isidorus-cvs mailing list