[isidorus-cvs] r671 - 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
Tue Jul 26 15:20:23 UTC 2011


Author: lgiessmann
Date: Tue Jul 26 08:20:22 2011
New Revision: 671

Log:
gdl-frontend: Widgets: implemented ButtonableObject

Added:
   branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/ButtonableObject.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/GdlVisibleObject.java
   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/button/GdlActionButton.java
   branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/view/GdlView.java

Added: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/ButtonableObject.java
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/ButtonableObject.java	Tue Jul 26 08:20:22 2011	(r671)
@@ -0,0 +1,41 @@
+package us.isidor.gdl.anaToMia.Widgets.base;
+
+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;
+
+
+public class ButtonableObject extends Composite {
+	private HorizontalPanel mainPanel = new HorizontalPanel();
+	
+	
+	private ButtonableObject(){
+		initWidget(this.mainPanel);		
+	}
+	
+	
+	public ButtonableObject(Widget mainObject) throws ExecutionException {
+		this();
+		if(mainObject == null) throw new ExecutionException("mainObject must not be set to null!");
+		if(this.mainPanel != null) this.mainPanel.add(mainObject);
+	}
+	
+	
+	public void addButton(GdlActionButton button){
+		this.mainPanel.add(button);
+	}
+	
+	
+	public boolean removeButton(GdlActionButton button){
+		return this.mainPanel.remove(button);
+	}
+	
+	
+	public void removeAllButtons(){
+		while(this.mainPanel.getWidgetCount() > 1){
+			this.mainPanel.remove(this.mainPanel.getWidgetCount() - 1);
+		}
+	}
+}

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	Tue Jul 26 04:41:34 2011	(r670)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlPanel.java	Tue Jul 26 08:20:22 2011	(r671)
@@ -30,9 +30,6 @@
 	// GDL loading, GDL commit, GDL validate, GDL delete failed, but any other execution error also executes an
 	// error handler
 	private ArrayList<IOnErrorCallback> localOnErrorContainer = new ArrayList<IOnErrorCallback>();
-	// buttonCallbacks contains pairs of ClickHandlers and Strings that acts as IDs.
-	// The ClickHandlers will be registered on the buttons with the corresponding id attribute.
-	private ArrayList<Pair<ClickHandler, String>> buttonCallbacks = new ArrayList<Pair<ClickHandler, String>>();
 
 	// if any value is set in this array list, the requested view is a Default-Creator-Topic-View
 	private ArrayList<Pair<String, TopicIdentifierTypes>> requestedTopicsToCreate = new ArrayList<Pair<String,TopicIdentifierTypes>>();
@@ -55,6 +52,10 @@
 	private ICommitCallback commitCallback = null;
 	// callback instance for deleting the frontend data on the server
 	private IDeleteCallback deleteCallback = null;
+	
+	// contains all callbacks that are used as click handlers and the corresponding
+	// html element id of the button element
+	private ArrayList<Pair<String, ClickHandler>> buttonCallbacks = new ArrayList<Pair<String, ClickHandler>>();
 
 	
 	// some constructors
@@ -63,28 +64,42 @@
 	}
 	
 	
-	protected GdlPanel(Pair<String, TopicIdentifierTypes> topicToEdit, ArrayList<Pair<String, TopicIdentifierTypes>> topicToCreate) throws ExecutionException{
+	protected GdlPanel(Pair<String, TopicIdentifierTypes> topicToEdit, ArrayList<Pair<String, TopicIdentifierTypes>> topicToCreate, ArrayList<Pair<String, ClickHandler>> buttonCallbacks) throws ExecutionException{
 		this();
 		if(topicToEdit != null)this.requestedTopicToEdit = topicToEdit;
 		if(topicToCreate != null && topicToCreate.size() != 0)this.requestedTopicsToCreate = topicToCreate;
 		
 		if(this.requestedTopicsToCreate.size() != 0 && this.requestedTopicToEdit != null)
 			throw new ExecutionException("only one container can be set, i.e. either topics to create or a topic to edit");
+		
+		if(buttonCallbacks != null){
+			this.buttonCallbacks = buttonCallbacks;
+		}
 	}
 		
 	
-	public GdlPanel(Pair<String, TopicIdentifierTypes> topicToEdit, ArrayList<Pair<String, TopicIdentifierTypes>> topicToCreate, int width, int height) throws ExecutionException{
-		this(topicToEdit, topicToCreate);
+	public GdlPanel(Pair<String, TopicIdentifierTypes> topicToEdit, ArrayList<Pair<String, TopicIdentifierTypes>> topicToCreate, ArrayList<Pair<String, ClickHandler>> buttonCallbacks, int width, int height) throws ExecutionException{
+		this(topicToEdit, topicToCreate, buttonCallbacks);
 		this.setPixelSize(width, height);
 	}
 	
 	
-	public GdlPanel(Pair<String, TopicIdentifierTypes> topicToEdit, ArrayList<Pair<String, TopicIdentifierTypes>> topicToCreate, String width, String height) throws ExecutionException{
-		this(topicToEdit, topicToCreate);
+	public GdlPanel(Pair<String, TopicIdentifierTypes> topicToEdit, ArrayList<Pair<String, TopicIdentifierTypes>> topicToCreate, ArrayList<Pair<String, ClickHandler>> buttonCallbacks, String width, String height) throws ExecutionException{
+		this(topicToEdit, topicToCreate, buttonCallbacks);
 		this.setSize(width, height);
 	}
 
+	
+	public ClickHandler getclickHandler(String id){
+		if(id == null) return null;
+		
+		for (Pair<String, ClickHandler> pair : this.buttonCallbacks)
+			if(pair.getFirst().equals(id)) return pair.getSecond();
+		
+		return null;
+	}
 
+	
 	public void registerOnErrorHandler(String descriptorId, IOnErrorCallback handler){
 		if(!localOnErrorContainer.contains(handler)){
 			localOnErrorContainer.add(handler);
@@ -264,9 +279,6 @@
 			else if(this.requestedTopicToEdit != null)
 				this.view = GdlInstantiator.instantiateDefaultEditorTopicView(this.requestedTopicToEdit, this.requestedSchemaTm);
 			mainPanel.add(view);
-			for (Pair<ClickHandler, String> item : this.buttonCallbacks) {
-				view.registerButtonCallback(item.getFirst(), item.getSecond());
-			}
 		}catch(Exception e){
 			Window.alert("could not create a view (" + e.getClass() + "): " + e.getMessage());
 			e.printStackTrace();
@@ -275,50 +287,11 @@
 			}
 		}
 	}
-
-	
-	// this method is responsible for registering ClickHandlers of buttons 
-	// of the actual view element. If no view exist, the ClickHandlers and ids
-	// are stored until the creation of a view, finally they are registered on the
-	// created view
-	public void registerButtonCallback(ClickHandler handler, String id){
-		if(handler == null || id == null){
-			if(this.view == null){
-				this.buttonCallbacks.add(new Pair<ClickHandler, String>(handler, id));
-			} else {
-				this.view.registerButtonCallback(handler, id);
-			}
-		}
-	}
-	
-	
-	// this method is responsible for deregistering ClickHandlers of buttons
-	// of the actual view element. If no view exist, the ClickHandlers are removed
-	// from the private stored ClickHandler ArrayList and so they won't be
-	// added when a view is created
-	public void deregisterButtonCallback(ClickHandler handler, String id){
-		if(handler == null || id == null){
-			if(this.view == null){
-				ArrayList<Pair<ClickHandler, String>> toDelete = new ArrayList<Pair<ClickHandler,String>>();
-				for (Pair<ClickHandler, String> item : this.buttonCallbacks) {
-					if(item.getFirst().equals(handler) && item.getSecond().equals(id)){
-						toDelete.add(item);
-					}
-				}
-				
-				for(Pair<ClickHandler, String> item : toDelete) {
-					this.buttonCallbacks.remove(item);
-				}
-			} else {
-				this.view.deregisterButtonCallback(handler, id);
-			}
-		}
-	}
 	
 
 	// remove all content from the main panel
 	public void clear(){
 		this.mainPanel.clear();
-		this.buttonCallbacks = new ArrayList<Pair<ClickHandler,String>>();
+		this.buttonCallbacks = new ArrayList<Pair<String,ClickHandler>>();
 	}
 }

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 04:41:34 2011	(r670)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlVisibleObject.java	Tue Jul 26 08:20:22 2011	(r671)
@@ -91,21 +91,13 @@
 		return this.tmRepresentative;
 	}
 	
-	
-	public void registerButtonCallback(ClickHandler handler, String id){
-		// TODO: implement
-	}
-
-	
-	public void deregisterButtonCallback(ClickHandler handler, String id){
-		// TODO: implement
-	}
-
-	
+		
 	// this method should be invoked if a new sub-element is added to this instance
 	protected void addToContainerPanel(Widget widget) throws ExecutionException, InvalidGdlSchemaException{
 		this.setContentOrientation(this.getContentOrientation());
-				
+		
+		
+		
 		this.subElements.add(widget);
 		this.containerPanel.add(widget);
 	}

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	Tue Jul 26 04:41:34 2011	(r670)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TestClass.java	Tue Jul 26 08:20:22 2011	(r671)
@@ -30,7 +30,7 @@
 			ArrayList<Pair<String, TopicIdentifierTypes>> requestedTopicsToCreate = new ArrayList<Pair<String,TopicIdentifierTypes>>();
 			requestedTopicsToCreate.add(new Pair<String, TopicIdentifierTypes>("http://psi.test.org/gdl-test/Poet", TopicIdentifierTypes.SubjectIdentifier));
 			requestedTopicsToCreate.add(new Pair<String, TopicIdentifierTypes>("http://psi.test.org/gdl-test/Musician", TopicIdentifierTypes.SubjectIdentifier));
-			gdlPanel = new GdlPanel(null, requestedTopicsToCreate);
+			gdlPanel = new GdlPanel(null, requestedTopicsToCreate, 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/button/GdlActionButton.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/button/GdlActionButton.java	Tue Jul 26 04:41:34 2011	(r670)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/button/GdlActionButton.java	Tue Jul 26 08:20:22 2011	(r671)
@@ -37,6 +37,7 @@
 		this.subElements.add(btn);
 		this.mainPanel.add(btn);
 		this.setId(this.getId());
+		
 		return btn;
 	}
 	

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	Tue Jul 26 04:41:34 2011	(r670)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/view/GdlView.java	Tue Jul 26 08:20:22 2011	(r671)
@@ -66,16 +66,6 @@
 	}
 		
 	
-	public void registerButtonCallback(ClickHandler handler, String id){
-		for (Widget widget : this.subElements) ((GdlVisibleObject)widget).registerButtonCallback(handler, id);
-	}
-
-	
-	public void deregisterButtonCallback(ClickHandler handler, String id){
-		for (Widget widget : this.subElements) ((GdlVisibleObject)widget).deregisterButtonCallback(handler, id);
-	}
-	
-	
 	// 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.




More information about the Isidorus-cvs mailing list