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

lgiessmann at common-lisp.net lgiessmann at common-lisp.net
Fri Sep 16 07:45:22 UTC 2011


Author: lgiessmann
Date: Fri Sep 16 00:45:21 2011
New Revision: 914

Log:
gdl-frontend: Widgets: excluded the implementation that creates the gdl web page to the class GdlWebPage, so theat this instace create HashObjectUI and EnvironmentUi pages

Added:
   branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/GdlWebPage.java
Modified:
   branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/HashObjectUi.java
   branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/IsidorusConstants.java

Added: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/GdlWebPage.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/isidorus/GdlWebPage.java	Fri Sep 16 00:45:21 2011	(r914)
@@ -0,0 +1,207 @@
+package us.isidor.gdl.anaToMia.Widgets.isidorus;
+
+import java.util.ArrayList;
+import com.google.gwt.dom.client.Element;
+import com.google.gwt.dom.client.TextAreaElement;
+import com.google.gwt.event.dom.client.ClickEvent;
+import com.google.gwt.event.dom.client.ClickHandler;
+import com.google.gwt.http.client.Request;
+import com.google.gwt.http.client.RequestBuilder;
+import com.google.gwt.http.client.RequestCallback;
+import com.google.gwt.http.client.RequestException;
+import com.google.gwt.http.client.Response;
+import com.google.gwt.http.client.URL;
+import com.google.gwt.json.client.JSONArray;
+import com.google.gwt.json.client.JSONParser;
+import com.google.gwt.json.client.JSONString;
+import com.google.gwt.json.client.JSONValue;
+import com.google.gwt.user.client.DOM;
+import com.google.gwt.user.client.Window;
+import com.google.gwt.user.client.ui.Button;
+import com.google.gwt.user.client.ui.HorizontalPanel;
+import com.google.gwt.user.client.ui.Label;
+import com.google.gwt.user.client.ui.RootPanel;
+import com.google.gwt.user.client.ui.VerticalPanel;
+import us.isidor.gdl.anaToMia.TmEngine.jtmsBasedEngine.JtmsTmEngine;
+import us.isidor.gdl.anaToMia.Widgets.base.GdlPanel;
+import us.isidor.gdl.anaToMia.Widgets.environment.ExecutionException;
+import us.isidor.gdl.anaToMia.Widgets.environment.Pair;
+import us.isidor.gdl.anaToMia.Widgets.environment.TopicIdentifierTypes;
+
+
+public class GdlWebPage {
+	private String topicTypePsi = null;
+	private HorizontalPanel mainPanel = new HorizontalPanel();
+	private VerticalPanel navigationPanel = new VerticalPanel();
+	private Button createNewButton = new Button("create new");
+	private PsiContainer psiContainer = null;
+	private GdlPanel gdlPanel = null;
+	private final String GDL_PANEL_STYLE_NAME = "gdl_panel";
+	private final String CREATE_NEW_BUTTON_STYLE_NAME = "create_new_button";
+	
+	
+	public GdlWebPage(String topicTypePsi) throws ExecutionException{
+		if(topicTypePsi == null) throw new ExecutionException("topicTypePsi must not be null");
+		this.topicTypePsi = topicTypePsi;
+	}
+	
+	
+	public void createWebPage(){
+		this.createNewButton.addStyleName(this.CREATE_NEW_BUTTON_STYLE_NAME);
+		DOM.setStyleAttribute(this.createNewButton.getElement(), "marginBottom", "1em");
+		try{
+			GdlPanel.addClickHandler("hash_object_reset_button_id", new ResetClickHandler());
+			this.psiContainer = new PsiContainer(new PsiClickHandler());
+			this.createNewButton.addClickHandler(new CreateNewClickHandler());
+		}catch(Exception e){
+			Window.alert("could not create web page, because: (" + e.getClass() + ") " + e.getMessage());
+			this.resetPage();
+		}
+		
+		RootPanel.get("GWT_Content").add(this.mainPanel);
+		mainPanel.add(this.navigationPanel);
+		mainPanel.setPixelSize(1024, 700);
+		navigationPanel.add(createNewButton);
+		try{
+			this.requestHashObjectPsis();
+		} catch(ExecutionException e){
+			Window.alert("could not create web page, because: (" + e.getClass() + ") " + e.getMessage());
+			this.resetPage();
+		}
+	}
+	
+	
+	public void resetPage() {
+		if(gdlPanel != null) this.gdlPanel.removeFromParent();
+		if(this.psiContainer != null) this.psiContainer.removeFromParent();
+		if(this.createNewButton != null) this.createNewButton.removeFromParent();
+		
+		try{
+			this.psiContainer = new PsiContainer(new PsiClickHandler());
+			this.requestHashObjectPsis();
+		}catch(Exception e){
+			Window.alert("could not create web page, becuase: (" + e.getClass() + ") " + e.getMessage());
+		}
+	}
+	
+	
+	private void requestHashObjectPsis() throws ExecutionException {
+		String url = null;
+		if(IsidorusConstants.HASH_OBJECT_PSI.equals(GdlWebPage.this.topicTypePsi)) url = URL.encode(IsidorusConstants.GET_HASH_OBJECT_PSIS_URL);
+		else if(IsidorusConstants.ENVIRONMENT_PSI.equals(GdlWebPage.this.topicTypePsi)) url = URL.encode(IsidorusConstants.GET_ENVIRONMENT_PSIS_URL);
+		else throw new ExecutionException("the topic type PSI " + GdlWebPage.this.topicTypePsi + " is not supported!");
+		RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
+		try{
+			builder.sendRequest(null, new PsiRequest());
+		}catch(RequestException e){
+			e.printStackTrace();
+			Window.alert("could not request existing instances of http://textgrid.org/serviceregistry/model/types/Hash-Object, because(" + e.getClass() + "): " + e.getMessage());
+			GdlWebPage.this.resetPage();
+		}
+	}
+	
+	
+	private class CreateNewClickHandler implements ClickHandler {
+		@Override
+		public void onClick(ClickEvent event) {
+			try{
+				if(GdlWebPage.this.gdlPanel != null) GdlWebPage.this.gdlPanel.removeFromParent();
+				ArrayList<Pair<String, TopicIdentifierTypes>> topicsToCreate = new ArrayList<Pair<String, TopicIdentifierTypes>>();
+				topicsToCreate.add(new Pair<String, TopicIdentifierTypes>(IsidorusConstants.HASH_OBJECT_PSI, TopicIdentifierTypes.SubjectIdentifier));
+				GdlWebPage.this.gdlPanel = new GdlPanel(null, topicsToCreate, 362, 160);
+				GdlWebPage.this.mainPanel.add(gdlPanel);
+				gdlPanel.setTmEngine(new JtmsTmEngine());
+				gdlPanel.setLoadSchemaCallback(new LoadSchemaCallback());
+				gdlPanel.setCommitCallback(new CommitCallback());
+				gdlPanel.setDeleteCallback(new DeleteCallback());
+				gdlPanel.addStyleName(GdlWebPage.this.GDL_PANEL_STYLE_NAME);
+				gdlPanel.loadSchema();
+			}catch(Exception e){
+				e.printStackTrace();
+				Window.alert("could not instantiate the GdlPanel, because(" + e.getClass() + "): " + e.getMessage());
+				GdlWebPage.this.resetPage();	
+			}
+		}
+	}
+	
+	
+	private class PsiClickHandler implements ClickHandler {
+		@Override
+		public void onClick(ClickEvent event) {
+			Object obj = event.getSource();
+			if(obj instanceof Label){
+				Label source = (Label)obj;				
+				try{
+					if(GdlWebPage.this.gdlPanel != null) GdlWebPage.this.gdlPanel.removeFromParent();
+					GdlWebPage.this.gdlPanel = new GdlPanel(new Pair<String, TopicIdentifierTypes>(source.getText(), TopicIdentifierTypes.SubjectIdentifier), null, 362, 160);
+					GdlWebPage.this.mainPanel.add(gdlPanel);
+					gdlPanel.setTmEngine(new JtmsTmEngine());
+					gdlPanel.setLoadSchemaCallback(new LoadSchemaCallback());
+					gdlPanel.setCommitCallback(new CommitCallback());
+					gdlPanel.setDeleteCallback(new DeleteCallback());
+					gdlPanel.loadSchema();
+					gdlPanel.addStyleName(GdlWebPage.this.GDL_PANEL_STYLE_NAME);
+					Window.scrollTo(0, 0);
+				}catch(Exception e){
+					e.printStackTrace();
+					Window.alert("could not instantiate the GdlPanel, because(" + e.getClass() + "): " + e.getMessage());
+					GdlWebPage.this.resetPage();	
+				}
+			}
+		}
+	}
+	
+	
+	private class ResetClickHandler implements ClickHandler {
+		@Override
+		public void onClick(ClickEvent event) {
+			Element elem = DOM.getElementById("hash_object_text_key_id__GDL_0");
+			((TextAreaElement)elem).setValue("");
+			elem = DOM.getElementById("hash_object_text_value_id__GDL_0");
+			((TextAreaElement)elem).setValue("");
+		}
+	}
+	
+	
+	private class PsiRequest implements RequestCallback {
+		public PsiRequest(){}
+		
+
+		@Override
+		public void onResponseReceived(Request request, Response response) {
+			if (200 == response.getStatusCode()) {
+				JSONValue psiVals = JSONParser.parseStrict(response.getText());
+				JSONArray psis = null;
+				if(psiVals != null) psis = psiVals.isArray();
+				if(psis == null){
+					Window.alert("got bad json, an array of strings was expected, but got: " + response.getText());
+					GdlWebPage.this.resetPage();
+				}
+				for(int psisIdx = 0; psisIdx != psis.size(); ++psisIdx){
+					JSONValue psiVal = psis.get(psisIdx);
+					JSONString psiString = null;
+					if(psiVal != null) psiString = psiVal.isString();
+					GdlWebPage.this.psiContainer.addPsi(psiString);
+				}
+				
+				GdlWebPage.this.psiContainer.insertIn(GdlWebPage.this.navigationPanel);
+			} else {
+				Window.alert("could not request existing instances of http://textgrid.org/serviceregistry/model/types/Hash-Object, because(" + response.getStatusCode() + "): " + response.getStatusText());
+				GdlWebPage.this.resetPage();
+			}
+		}
+		
+
+		@Override
+		public void onError(Request request, Throwable exception) {
+			String message = null;
+			Class<? extends Throwable> eClass = null;
+			if(exception != null){
+				message = exception.getMessage();
+				eClass = exception.getClass();
+			}
+			Window.alert("could not request existing instances of http://textgrid.org/serviceregistry/model/types/Hash-Object, because(" + eClass + "): " + message);
+			GdlWebPage.this.resetPage();
+		}
+	}
+}

Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/HashObjectUi.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/HashObjectUi.java	Fri Sep 16 00:21:15 2011	(r913)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/HashObjectUi.java	Fri Sep 16 00:45:21 2011	(r914)
@@ -1,196 +1,17 @@
 package us.isidor.gdl.anaToMia.Widgets.isidorus;
 
-
-import java.util.ArrayList;
-
-import us.isidor.gdl.anaToMia.TmEngine.jtmsBasedEngine.JtmsTmEngine;
-import us.isidor.gdl.anaToMia.Widgets.base.GdlPanel;
-import us.isidor.gdl.anaToMia.Widgets.environment.Pair;
-import us.isidor.gdl.anaToMia.Widgets.environment.TopicIdentifierTypes;
 import com.google.gwt.core.client.EntryPoint;
-import com.google.gwt.dom.client.Element;
-import com.google.gwt.dom.client.TextAreaElement;
-import com.google.gwt.event.dom.client.ClickEvent;
-import com.google.gwt.event.dom.client.ClickHandler;
-import com.google.gwt.http.client.Request;
-import com.google.gwt.http.client.RequestBuilder;
-import com.google.gwt.http.client.RequestCallback;
-import com.google.gwt.http.client.RequestException;
-import com.google.gwt.http.client.Response;
-import com.google.gwt.http.client.URL;
-import com.google.gwt.json.client.JSONArray;
-import com.google.gwt.json.client.JSONParser;
-import com.google.gwt.json.client.JSONString;
-import com.google.gwt.json.client.JSONValue;
-import com.google.gwt.user.client.DOM;
 import com.google.gwt.user.client.Window;
-import com.google.gwt.user.client.ui.Button;
-import com.google.gwt.user.client.ui.HorizontalPanel;
-import com.google.gwt.user.client.ui.Label;
-import com.google.gwt.user.client.ui.RootPanel;
-import com.google.gwt.user.client.ui.VerticalPanel;
 
 
 public class HashObjectUi implements EntryPoint {
-	private HorizontalPanel mainPanel = new HorizontalPanel();
-	private VerticalPanel navigationPanel = new VerticalPanel();
-	private Button createNewButton = new Button("create new");
-	private PsiContainer psiContainer = null;
-	private GdlPanel gdlPanel = null;
-	private final String GDL_PANEL_STYLE_NAME = "gdl_panel";
-	private final String CREATE_NEW_BUTTON_STYLE_NAME = "create_new_button";
-	
-	
 	@Override
 	public void onModuleLoad() {
-		this.createNewButton.addStyleName(this.CREATE_NEW_BUTTON_STYLE_NAME);
-		DOM.setStyleAttribute(this.createNewButton.getElement(), "marginBottom", "1em");
-		try{
-			GdlPanel.addClickHandler("hash_object_reset_button_id", new ResetClickHandler());
-			this.psiContainer = new PsiContainer(new PsiClickHandler());
-			this.createNewButton.addClickHandler(new CreateNewClickHandler());
-		}catch(Exception e){
-			Window.alert("could not create web page, becuase: (" + e.getClass() + ") " + e.getMessage());
-			this.resetPage();
-		}
-		
-		RootPanel.get("GWT_Content").add(this.mainPanel);
-		mainPanel.add(this.navigationPanel);
-		mainPanel.setPixelSize(1024, 700);
-		navigationPanel.add(createNewButton);
-		this.requestHashObjectPsis();
-	}
-	
-	
-	public void resetPage(){
-		if(gdlPanel != null) this.gdlPanel.removeFromParent();
-		if(this.psiContainer != null) this.psiContainer.removeFromParent();
-		if(this.createNewButton != null) this.createNewButton.removeFromParent();
-		
 		try{
-			this.psiContainer = new PsiContainer(new PsiClickHandler());
+			GdlWebPage page = new GdlWebPage(IsidorusConstants.HASH_OBJECT_PSI);
+			page.createWebPage();
 		}catch(Exception e){
-			Window.alert("could not create web page, becuase: (" + e.getClass() + ") " + e.getMessage());
-			this.resetPage();
-		}
-		this.requestHashObjectPsis();
-	}
-	
-	
-	private void requestHashObjectPsis(){
-		String url = URL.encode(IsidorusConstants.GET_HASH_OBJECT_PSIS_URL);
-		RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
-		try{
-			builder.sendRequest(null, new PsiRequest());
-		}catch(RequestException e){
-			e.printStackTrace();
-			Window.alert("could not request existing instances of http://textgrid.org/serviceregistry/model/types/Hash-Object, because(" + e.getClass() + "): " + e.getMessage());
-			HashObjectUi.this.resetPage();
-		}
-	}
-	
-	
-	private class CreateNewClickHandler implements ClickHandler {
-		@Override
-		public void onClick(ClickEvent event) {
-			try{
-				if(HashObjectUi.this.gdlPanel != null) HashObjectUi.this.gdlPanel.removeFromParent();
-				ArrayList<Pair<String, TopicIdentifierTypes>> topicsToCreate = new ArrayList<Pair<String, TopicIdentifierTypes>>();
-				topicsToCreate.add(new Pair<String, TopicIdentifierTypes>(IsidorusConstants.HASH_OBJECT_PSI, TopicIdentifierTypes.SubjectIdentifier));
-				HashObjectUi.this.gdlPanel = new GdlPanel(null, topicsToCreate, 362, 160);
-				HashObjectUi.this.mainPanel.add(gdlPanel);
-				gdlPanel.setTmEngine(new JtmsTmEngine());
-				gdlPanel.setLoadSchemaCallback(new LoadSchemaCallback());
-				gdlPanel.setCommitCallback(new CommitCallback());
-				gdlPanel.setDeleteCallback(new DeleteCallback());
-				gdlPanel.addStyleName(HashObjectUi.this.GDL_PANEL_STYLE_NAME);
-				gdlPanel.loadSchema();
-			}catch(Exception e){
-				e.printStackTrace();
-				Window.alert("could not instantiate the GdlPanel, because(" + e.getClass() + "): " + e.getMessage());
-				HashObjectUi.this.resetPage();	
-			}
-		}
-	}
-	
-	
-	private class PsiClickHandler implements ClickHandler {
-		@Override
-		public void onClick(ClickEvent event) {
-			Object obj = event.getSource();
-			if(obj instanceof Label){
-				Label source = (Label)obj;				
-				try{
-					if(HashObjectUi.this.gdlPanel != null) HashObjectUi.this.gdlPanel.removeFromParent();
-					HashObjectUi.this.gdlPanel = new GdlPanel(new Pair<String, TopicIdentifierTypes>(source.getText(), TopicIdentifierTypes.SubjectIdentifier), null, 362, 160);
-					HashObjectUi.this.mainPanel.add(gdlPanel);
-					gdlPanel.setTmEngine(new JtmsTmEngine());
-					gdlPanel.setLoadSchemaCallback(new LoadSchemaCallback());
-					gdlPanel.setCommitCallback(new CommitCallback());
-					gdlPanel.setDeleteCallback(new DeleteCallback());
-					gdlPanel.loadSchema();
-					gdlPanel.addStyleName(HashObjectUi.this.GDL_PANEL_STYLE_NAME);
-					Window.scrollTo(0, 0);
-				}catch(Exception e){
-					e.printStackTrace();
-					Window.alert("could not instantiate the GdlPanel, because(" + e.getClass() + "): " + e.getMessage());
-					HashObjectUi.this.resetPage();	
-				}
-			}
-		}
-	}
-	
-	
-	private class ResetClickHandler implements ClickHandler {
-		@Override
-		public void onClick(ClickEvent event) {
-			Element elem = DOM.getElementById("hash_object_text_key_id__GDL_0");
-			((TextAreaElement)elem).setValue("");
-			elem = DOM.getElementById("hash_object_text_value_id__GDL_0");
-			((TextAreaElement)elem).setValue("");
-		}
-	}
-	
-	
-	private class PsiRequest implements RequestCallback {
-		public PsiRequest(){}
-		
-
-		@Override
-		public void onResponseReceived(Request request, Response response) {
-			if (200 == response.getStatusCode()) {
-				JSONValue psiVals = JSONParser.parseStrict(response.getText());
-				JSONArray psis = null;
-				if(psiVals != null) psis = psiVals.isArray();
-				if(psis == null){
-					Window.alert("got bad json, an array of strings was expected, but got: " + response.getText());
-					HashObjectUi.this.resetPage();
-				}
-				for(int psisIdx = 0; psisIdx != psis.size(); ++psisIdx){
-					JSONValue psiVal = psis.get(psisIdx);
-					JSONString psiString = null;
-					if(psiVal != null) psiString = psiVal.isString();
-					HashObjectUi.this.psiContainer.addPsi(psiString);
-				}
-				
-				HashObjectUi.this.psiContainer.insertIn(HashObjectUi.this.navigationPanel);
-			} else {
-				Window.alert("could not request existing instances of http://textgrid.org/serviceregistry/model/types/Hash-Object, because(" + response.getStatusCode() + "): " + response.getStatusText());
-				HashObjectUi.this.resetPage();
-			}
-		}
-		
-
-		@Override
-		public void onError(Request request, Throwable exception) {
-			String message = null;
-			Class<? extends Throwable> eClass = null;
-			if(exception != null){
-				message = exception.getMessage();
-				eClass = exception.getClass();
-			}
-			Window.alert("could not request existing instances of http://textgrid.org/serviceregistry/model/types/Hash-Object, because(" + eClass + "): " + message);
-			HashObjectUi.this.resetPage();
+			Window.alert("could not create a web page, because: (" + e.getClass() + ") " + e.getMessage());
 		}
 	}
 }

Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/IsidorusConstants.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/IsidorusConstants.java	Fri Sep 16 00:21:15 2011	(r913)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/IsidorusConstants.java	Fri Sep 16 00:45:21 2011	(r914)
@@ -18,5 +18,6 @@
 	//public final static String GET_SCHEMA_REQUEST_URL = Window.Location.getProtocol() + "//" + Window.Location.getHost() + "/gdl/schema";
 	public final static String GET_SCHEMA_REQUEST_URL = GWT.getModuleBaseURL() + "TextGrid_ServiceRegistry_required_TMCL_and_GDL_Schema_with_test_data.jtm";
 	public final static String GET_HASH_OBJECT_PSIS_URL = GWT.getModuleBaseURL() + "HashObjectPsis.json";
+	public final static String GET_ENVIRONMENT_PSIS_URL = GWT.getModuleBaseURL() + "EnvironmentPsis.json";
 	public final static String TEXTGRID_LOGO_URL = GWT.getModuleBaseURL() + "textgrid_small.png";
 }




More information about the Isidorus-cvs mailing list