Changeset 914 for branches/gdl-frontend/src/anaToMia
- Timestamp:
- 09/16/11 07:45:21 (14 years ago)
- Location:
- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/HashObjectUi.java ¶
r913 r914 1 1 package us.isidor.gdl.anaToMia.Widgets.isidorus; 2 2 3 4 import java.util.ArrayList;5 6 import us.isidor.gdl.anaToMia.TmEngine.jtmsBasedEngine.JtmsTmEngine;7 import us.isidor.gdl.anaToMia.Widgets.base.GdlPanel;8 import us.isidor.gdl.anaToMia.Widgets.environment.Pair;9 import us.isidor.gdl.anaToMia.Widgets.environment.TopicIdentifierTypes;10 3 import com.google.gwt.core.client.EntryPoint; 11 import com.google.gwt.dom.client.Element;12 import com.google.gwt.dom.client.TextAreaElement;13 import com.google.gwt.event.dom.client.ClickEvent;14 import com.google.gwt.event.dom.client.ClickHandler;15 import com.google.gwt.http.client.Request;16 import com.google.gwt.http.client.RequestBuilder;17 import com.google.gwt.http.client.RequestCallback;18 import com.google.gwt.http.client.RequestException;19 import com.google.gwt.http.client.Response;20 import com.google.gwt.http.client.URL;21 import com.google.gwt.json.client.JSONArray;22 import com.google.gwt.json.client.JSONParser;23 import com.google.gwt.json.client.JSONString;24 import com.google.gwt.json.client.JSONValue;25 import com.google.gwt.user.client.DOM;26 4 import com.google.gwt.user.client.Window; 27 import com.google.gwt.user.client.ui.Button;28 import com.google.gwt.user.client.ui.HorizontalPanel;29 import com.google.gwt.user.client.ui.Label;30 import com.google.gwt.user.client.ui.RootPanel;31 import com.google.gwt.user.client.ui.VerticalPanel;32 5 33 6 34 7 public class HashObjectUi implements EntryPoint { 35 private HorizontalPanel mainPanel = new HorizontalPanel();36 private VerticalPanel navigationPanel = new VerticalPanel();37 private Button createNewButton = new Button("create new");38 private PsiContainer psiContainer = null;39 private GdlPanel gdlPanel = null;40 private final String GDL_PANEL_STYLE_NAME = "gdl_panel";41 private final String CREATE_NEW_BUTTON_STYLE_NAME = "create_new_button";42 43 44 8 @Override 45 9 public void onModuleLoad() { 46 this.createNewButton.addStyleName(this.CREATE_NEW_BUTTON_STYLE_NAME);47 DOM.setStyleAttribute(this.createNewButton.getElement(), "marginBottom", "1em");48 10 try{ 49 GdlPanel.addClickHandler("hash_object_reset_button_id", new ResetClickHandler()); 50 this.psiContainer = new PsiContainer(new PsiClickHandler()); 51 this.createNewButton.addClickHandler(new CreateNewClickHandler()); 11 GdlWebPage page = new GdlWebPage(IsidorusConstants.HASH_OBJECT_PSI); 12 page.createWebPage(); 52 13 }catch(Exception e){ 53 Window.alert("could not create web page, becuase: (" + e.getClass() + ") " + e.getMessage()); 54 this.resetPage(); 55 } 56 57 RootPanel.get("GWT_Content").add(this.mainPanel); 58 mainPanel.add(this.navigationPanel); 59 mainPanel.setPixelSize(1024, 700); 60 navigationPanel.add(createNewButton); 61 this.requestHashObjectPsis(); 62 } 63 64 65 public void resetPage(){ 66 if(gdlPanel != null) this.gdlPanel.removeFromParent(); 67 if(this.psiContainer != null) this.psiContainer.removeFromParent(); 68 if(this.createNewButton != null) this.createNewButton.removeFromParent(); 69 70 try{ 71 this.psiContainer = new PsiContainer(new PsiClickHandler()); 72 }catch(Exception e){ 73 Window.alert("could not create web page, becuase: (" + e.getClass() + ") " + e.getMessage()); 74 this.resetPage(); 75 } 76 this.requestHashObjectPsis(); 77 } 78 79 80 private void requestHashObjectPsis(){ 81 String url = URL.encode(IsidorusConstants.GET_HASH_OBJECT_PSIS_URL); 82 RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url); 83 try{ 84 builder.sendRequest(null, new PsiRequest()); 85 }catch(RequestException e){ 86 e.printStackTrace(); 87 Window.alert("could not request existing instances of http://textgrid.org/serviceregistry/model/types/Hash-Object, because(" + e.getClass() + "): " + e.getMessage()); 88 HashObjectUi.this.resetPage(); 89 } 90 } 91 92 93 private class CreateNewClickHandler implements ClickHandler { 94 @Override 95 public void onClick(ClickEvent event) { 96 try{ 97 if(HashObjectUi.this.gdlPanel != null) HashObjectUi.this.gdlPanel.removeFromParent(); 98 ArrayList<Pair<String, TopicIdentifierTypes>> topicsToCreate = new ArrayList<Pair<String, TopicIdentifierTypes>>(); 99 topicsToCreate.add(new Pair<String, TopicIdentifierTypes>(IsidorusConstants.HASH_OBJECT_PSI, TopicIdentifierTypes.SubjectIdentifier)); 100 HashObjectUi.this.gdlPanel = new GdlPanel(null, topicsToCreate, 362, 160); 101 HashObjectUi.this.mainPanel.add(gdlPanel); 102 gdlPanel.setTmEngine(new JtmsTmEngine()); 103 gdlPanel.setLoadSchemaCallback(new LoadSchemaCallback()); 104 gdlPanel.setCommitCallback(new CommitCallback()); 105 gdlPanel.setDeleteCallback(new DeleteCallback()); 106 gdlPanel.addStyleName(HashObjectUi.this.GDL_PANEL_STYLE_NAME); 107 gdlPanel.loadSchema(); 108 }catch(Exception e){ 109 e.printStackTrace(); 110 Window.alert("could not instantiate the GdlPanel, because(" + e.getClass() + "): " + e.getMessage()); 111 HashObjectUi.this.resetPage(); 112 } 113 } 114 } 115 116 117 private class PsiClickHandler implements ClickHandler { 118 @Override 119 public void onClick(ClickEvent event) { 120 Object obj = event.getSource(); 121 if(obj instanceof Label){ 122 Label source = (Label)obj; 123 try{ 124 if(HashObjectUi.this.gdlPanel != null) HashObjectUi.this.gdlPanel.removeFromParent(); 125 HashObjectUi.this.gdlPanel = new GdlPanel(new Pair<String, TopicIdentifierTypes>(source.getText(), TopicIdentifierTypes.SubjectIdentifier), null, 362, 160); 126 HashObjectUi.this.mainPanel.add(gdlPanel); 127 gdlPanel.setTmEngine(new JtmsTmEngine()); 128 gdlPanel.setLoadSchemaCallback(new LoadSchemaCallback()); 129 gdlPanel.setCommitCallback(new CommitCallback()); 130 gdlPanel.setDeleteCallback(new DeleteCallback()); 131 gdlPanel.loadSchema(); 132 gdlPanel.addStyleName(HashObjectUi.this.GDL_PANEL_STYLE_NAME); 133 Window.scrollTo(0, 0); 134 }catch(Exception e){ 135 e.printStackTrace(); 136 Window.alert("could not instantiate the GdlPanel, because(" + e.getClass() + "): " + e.getMessage()); 137 HashObjectUi.this.resetPage(); 138 } 139 } 140 } 141 } 142 143 144 private class ResetClickHandler implements ClickHandler { 145 @Override 146 public void onClick(ClickEvent event) { 147 Element elem = DOM.getElementById("hash_object_text_key_id__GDL_0"); 148 ((TextAreaElement)elem).setValue(""); 149 elem = DOM.getElementById("hash_object_text_value_id__GDL_0"); 150 ((TextAreaElement)elem).setValue(""); 151 } 152 } 153 154 155 private class PsiRequest implements RequestCallback { 156 public PsiRequest(){} 157 158 159 @Override 160 public void onResponseReceived(Request request, Response response) { 161 if (200 == response.getStatusCode()) { 162 JSONValue psiVals = JSONParser.parseStrict(response.getText()); 163 JSONArray psis = null; 164 if(psiVals != null) psis = psiVals.isArray(); 165 if(psis == null){ 166 Window.alert("got bad json, an array of strings was expected, but got: " + response.getText()); 167 HashObjectUi.this.resetPage(); 168 } 169 for(int psisIdx = 0; psisIdx != psis.size(); ++psisIdx){ 170 JSONValue psiVal = psis.get(psisIdx); 171 JSONString psiString = null; 172 if(psiVal != null) psiString = psiVal.isString(); 173 HashObjectUi.this.psiContainer.addPsi(psiString); 174 } 175 176 HashObjectUi.this.psiContainer.insertIn(HashObjectUi.this.navigationPanel); 177 } else { 178 Window.alert("could not request existing instances of http://textgrid.org/serviceregistry/model/types/Hash-Object, because(" + response.getStatusCode() + "): " + response.getStatusText()); 179 HashObjectUi.this.resetPage(); 180 } 181 } 182 183 184 @Override 185 public void onError(Request request, Throwable exception) { 186 String message = null; 187 Class<? extends Throwable> eClass = null; 188 if(exception != null){ 189 message = exception.getMessage(); 190 eClass = exception.getClass(); 191 } 192 Window.alert("could not request existing instances of http://textgrid.org/serviceregistry/model/types/Hash-Object, because(" + eClass + "): " + message); 193 HashObjectUi.this.resetPage(); 14 Window.alert("could not create a web page, because: (" + e.getClass() + ") " + e.getMessage()); 194 15 } 195 16 } -
TabularUnified branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/IsidorusConstants.java ¶
r910 r914 19 19 public final static String GET_SCHEMA_REQUEST_URL = GWT.getModuleBaseURL() + "TextGrid_ServiceRegistry_required_TMCL_and_GDL_Schema_with_test_data.jtm"; 20 20 public final static String GET_HASH_OBJECT_PSIS_URL = GWT.getModuleBaseURL() + "HashObjectPsis.json"; 21 public final static String GET_ENVIRONMENT_PSIS_URL = GWT.getModuleBaseURL() + "EnvironmentPsis.json"; 21 22 public final static String TEXTGRID_LOGO_URL = GWT.getModuleBaseURL() + "textgrid_small.png"; 22 23 }
Note: See TracChangeset
for help on using the changeset viewer.