Author: lgiessmann Date: Tue Sep 13 02:54:27 2011 New Revision: 884
Log: gdl-frontend: Widgets: refactred the update handler for http://textgrid.org/serviceregistry/model/types/Hash-Object
Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/CommitCallback.java branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/DeleteCallback.java
Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/CommitCallback.java ============================================================================== --- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/CommitCallback.java Tue Sep 13 02:28:13 2011 (r883) +++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/CommitCallback.java Tue Sep 13 02:54:27 2011 (r884) @@ -226,7 +226,17 @@ public void onResponseReceived(Request request, Response response) { if (200 == response.getStatusCode()) { if(edited){ - //TODO: implement + String delObj = response.getText(); + try{ + String url = URL.encode(CommitCallback.this.DELETE_REUQEST_URL); + RequestBuilder builder = new RequestBuilder(RequestBuilder.DELETE, url); + builder.setHeader("Content-type", "application/json"); + + builder.sendRequest(delObj, new HashObjectDeleteRequest(delObj, this.objectToBeSend)); + }catch(RequestException e){ + Window.alert("could not update the topic " + delObj); + //TODO: reset page + } } else { Window.alert("could not commit the topic with the psi " + psi + " since it already exists"); //TODO: reset page @@ -255,6 +265,47 @@ } } + + private class HashObjectDeleteRequest implements RequestCallback{ + private String objectToBeDeleted = null; + private String objectToBeSend = null; + + + @SuppressWarnings("unused") + private HashObjectDeleteRequest(){} + + + public HashObjectDeleteRequest(String objectToBeDeleted, String objectToBeSend){ + this.objectToBeDeleted = objectToBeDeleted; + this.objectToBeSend = objectToBeSend; + } + + + @Override + public void onResponseReceived(Request request, Response response) { + if (200 == response.getStatusCode()) { + try{ + String commitUrl = URL.encode(CommitCallback.this.COMMIT_REQUEST_URL); + RequestBuilder commitBuilder = new RequestBuilder(RequestBuilder.POST, commitUrl); + commitBuilder.setHeader("Content-type", "application/json"); + commitBuilder.sendRequest(this.objectToBeSend, new HashObjectCommitRequest(this.objectToBeSend)); + }catch(RequestException e){ + Window.alert("could not commit the data: " + this.objectToBeSend); + // TODO: reset web page + } + } else { + Window.alert("update operation of the object " + this.objectToBeDeleted + " failed: " + response.getStatusCode() + "(" + response.getStatusText() + ")\n" + response.getText()); + } + } + + + @Override + public void onError(Request request, Throwable exception) { + Window.alert("could not update the data: " + this.objectToBeDeleted); + // TODO: reset web page + } + } + private class HashObjectCommitRequest implements RequestCallback { private String objectToBeSend = null;
Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/DeleteCallback.java ============================================================================== --- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/DeleteCallback.java Tue Sep 13 02:28:13 2011 (r883) +++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/DeleteCallback.java Tue Sep 13 02:54:27 2011 (r884) @@ -53,7 +53,6 @@ RequestBuilder builder = new RequestBuilder(RequestBuilder.DELETE, url); builder.setHeader("Content-type", "application/json"); - //RootPanel.getBodyElement().setInnerText(delObj.toString()); // TODO: remove builder.sendRequest(delObj.toString(), new DeleteRequest(delObj, env)); }catch(RequestException e){ Window.alert("could not delete the topic: " + psi + ", because(" + e.getClass() + "): " + e.getMessage());