Author: lgiessmann Date: Wed Sep 21 02:37:02 2011 New Revision: 948
Log: gdl-frontend: Widgets: added a request that gets all psis of hash-object instances for a particular environment topic
Added: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/HashObjectPsiContainer.java 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/GdlWebPage.java branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/IsidorusConstants.java
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 Wed Sep 21 01:23:59 2011 (r947) +++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/DeleteCallback.java Wed Sep 21 02:37:02 2011 (r948) @@ -26,6 +26,7 @@
public class DeleteCallback implements IDeleteCallback { private final String REUQEST_URL = IsidorusConstants.DELETE_REQUEST_URL; + private final String TM_SPARQL_URL = IsidorusConstants.TM_SPARQL_ENDPOINT; private final String TM_SPARQL_QUERY_PART_1 = "PREFIX types:http://textgrid.org/serviceregistry/model/types/\n" + "PREFIX model:http://textgrid.org/serviceregistry/model/\n" + "PREFIX env:http://textgrid.org/serviceregistry/environment/\n" + @@ -33,6 +34,17 @@ "?topics a types:Hash-Object.\n" + "?topics model:environment env:"; private final String TM_SPARQL_QUERY_PART_2 = ".\n}"; + private GdlWebPage gdlWebPage = null; + private HashObjectPsiContainer hashObjectPsiContainer = new HashObjectPsiContainer(null); + + + @SuppressWarnings("unused") + private DeleteCallback(){} + + + public DeleteCallback(GdlWebPage gdlWebPage){ + this.gdlWebPage = gdlWebPage; + }
@Override @@ -55,19 +67,82 @@ private String createTmSparqlQuery(Topic environment){ - String psi = environment.getSubjectLocators().get(0).getReference(); + String psi = environment.getSubjectIdentifiers().get(0).getReference(); String psiSuffix = Utils.splitUriByLastFragment(psi)[1]; return this.TM_SPARQL_QUERY_PART_1 + psiSuffix + this.TM_SPARQL_QUERY_PART_2; } private void deleteEnvironmentTopic(Topic env){ - Window.alert(this.createTmSparqlQuery(env)); - // TODO: get all associated hash-objects - // TODO: create a list for the user - // TODO: check the user's input - // TODO: delete all hash-objects - // TODO: delete the environment + String url = URL.encode(this.TM_SPARQL_URL); + RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url); + try{ + DeleteCallback.this.gdlWebPage.createLoadScreenPanel("Wating for Data", "Requesting all PSIs of instances of " + IsidorusConstants.HASH_OBJECT_PSI + " that are associated with " + env.getSubjectIdentifiers().get(0).getReference() + " from " + url); + builder.sendRequest(this.createTmSparqlQuery(env), new GetHashObjectPsisRequest()); + }catch(RequestException e){ + e.printStackTrace(); + Window.alert("could not request existing instances of " + IsidorusConstants.HASH_OBJECT_PSI + ", because(" + e.getClass() + "): " + e.getMessage()); + DeleteCallback.this.gdlWebPage.resetPage(); + } + } + + + private class GetHashObjectPsisRequest implements RequestCallback { + public GetHashObjectPsisRequest(){} + + + @Override + public void onResponseReceived(Request request, Response response) { + if (200 == response.getStatusCode()) { + JSONValue psiVals = JSONParser.parseStrict(response.getText()); + JSONObject resultObject = psiVals.isObject(); + if(resultObject == null) Window.alert("got bad json, a query result object was expected, but got: " + response.getText()); + + JSONValue content = resultObject.get("topics"); + if(content == null) Window.alert("got bad json, a query result object was expected, but got: " + response.getText()); + + JSONArray psis = null; + if(psiVals != null) psis = content.isArray(); + if(psis != null){ + for(int psisIdx = 0; psisIdx != psis.size(); ++psisIdx){ + JSONValue psiVal = psis.get(psisIdx); + JSONString psiString = null; + if(psiVal != null) psiString = psiVal.isString(); + String psiValue = null; + if(psiString != null){ + psiValue = psiString.stringValue(); + if(psiValue.startsWith("<")) psiValue = psiValue.substring(1); + if(psiValue.endsWith(">")) psiValue = psiValue.substring(0, psiValue.length() - 1); + } + DeleteCallback.this.hashObjectPsiContainer.addHashObjectPsi(psiValue); + } + } + + DeleteCallback.this.gdlWebPage.setHashObjectPsiContainer(DeleteCallback.this.hashObjectPsiContainer); + } else { + Window.alert("could not request existing instances of " + IsidorusConstants.HASH_OBJECT_PSI + ", because(" + response.getStatusCode() + "): " + response.getStatusText()); + } + DeleteCallback.this.gdlWebPage.removeLoadScreenPanel(); + + + + // TODO: check the user's input + // TODO: delete all hash-objects + // TODO: delete the environment + } + + + @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 " + IsidorusConstants.HASH_OBJECT_PSI + ", because(" + eClass + "): " + message); + DeleteCallback.this.gdlWebPage.resetPage(); + } }
Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/GdlWebPage.java ============================================================================== --- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/GdlWebPage.java Wed Sep 21 01:23:59 2011 (r947) +++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/GdlWebPage.java Wed Sep 21 02:37:02 2011 (r948) @@ -34,12 +34,14 @@ private String topicTypePsi = null; private HorizontalPanel mainPanel = new HorizontalPanel(); private VerticalPanel navigationPanel = new VerticalPanel(); + private VerticalPanel contentPanel = new VerticalPanel(); private Button createNewButton = new Button("create new"); private PsiContainer psiContainer = null; private GdlPanel gdlPanel = null; private LoadScreenPanel loadScreenPanel = null; private final String GDL_PANEL_STYLE_NAME = "gdl_panel"; private final String CREATE_NEW_BUTTON_STYLE_NAME = "create_new_button"; + private HashObjectPsiContainer hashObjectPsicontainer = null; public GdlWebPage(String topicTypePsi) throws ExecutionException{ @@ -62,6 +64,7 @@ RootPanel.get("GWT_Content").add(this.mainPanel); this.mainPanel.add(this.navigationPanel); + this.mainPanel.add(this.contentPanel); this.mainPanel.setPixelSize(1024, 700); this.navigationPanel.add(this.createNewButton); try{ @@ -89,6 +92,20 @@ } + public void setHashObjectPsiContainer(HashObjectPsiContainer psiContainer){ + if(this.hashObjectPsicontainer != null) this.hashObjectPsicontainer.removeFromParent(); + this.hashObjectPsicontainer = psiContainer; + if(this.hashObjectPsicontainer != null) this.contentPanel.insert(this.hashObjectPsicontainer, this.contentPanel.getWidgetCount()); + } + + + public void setGdlPanel(GdlPanel gdlPanel){ + if(this.gdlPanel != null) this.gdlPanel.removeFromParent(); + this.gdlPanel = gdlPanel; + if(this.gdlPanel != null) this.contentPanel.add(this.gdlPanel); + } + + public void removeLoadScreenPanel(){ if(this.loadScreenPanel != null) this.loadScreenPanel.removeFromParent(); } @@ -138,16 +155,15 @@ @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>(GdlWebPage.this.topicTypePsi, TopicIdentifierTypes.SubjectIdentifier)); - GdlWebPage.this.gdlPanel = new GdlPanel(null, topicsToCreate, 362, 160); - GdlWebPage.this.mainPanel.add(gdlPanel); + GdlPanel gdlPanel = new GdlPanel(null, topicsToCreate, 362, 160); gdlPanel.setTmEngine(new JtmsTmEngine()); gdlPanel.setLoadSchemaCallback(new LoadSchemaCallback(GdlWebPage.this)); gdlPanel.setCommitCallback(new CommitCallback()); - gdlPanel.setDeleteCallback(new DeleteCallback()); + gdlPanel.setDeleteCallback(new DeleteCallback(GdlWebPage.this)); gdlPanel.addStyleName(GdlWebPage.this.GDL_PANEL_STYLE_NAME); + GdlWebPage.this.setGdlPanel(gdlPanel); gdlPanel.loadSchema(); }catch(Exception e){ e.printStackTrace(); @@ -165,13 +181,12 @@ 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 gdlPanel = new GdlPanel(new Pair<String, TopicIdentifierTypes>(source.getText(), TopicIdentifierTypes.SubjectIdentifier), null, 362, 160); gdlPanel.setTmEngine(new JtmsTmEngine()); gdlPanel.setLoadSchemaCallback(new LoadSchemaCallback(GdlWebPage.this)); gdlPanel.setCommitCallback(new CommitCallback()); - gdlPanel.setDeleteCallback(new DeleteCallback()); + gdlPanel.setDeleteCallback(new DeleteCallback(GdlWebPage.this)); + GdlWebPage.this.setGdlPanel(gdlPanel); gdlPanel.loadSchema(); gdlPanel.addStyleName(GdlWebPage.this.GDL_PANEL_STYLE_NAME); Window.scrollTo(0, 0);
Added: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/HashObjectPsiContainer.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/HashObjectPsiContainer.java Wed Sep 21 02:37:02 2011 (r948) @@ -0,0 +1,53 @@ +package us.isidor.gdl.anaToMia.Widgets.isidorus; + + + +import java.util.ArrayList; +import com.google.gwt.event.dom.client.ClickHandler; +import com.google.gwt.user.client.ui.Button; +import com.google.gwt.user.client.ui.CheckBox; +import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.Label; +import com.google.gwt.user.client.ui.VerticalPanel; +import com.google.gwt.user.client.ui.Widget; + + +public class HashObjectPsiContainer extends Composite { + private ArrayList<CheckBox> psiCheckBoxes = new ArrayList<CheckBox>(); + private VerticalPanel containerPanel = new VerticalPanel(); + private Button commitButton = new Button("delete"); + + + private HashObjectPsiContainer(){ + this.initWidget(this.containerPanel); + this.containerPanel.add(this.commitButton); + } + + + public HashObjectPsiContainer(ClickHandler buttonClikcHandler){ + this(); + + if(buttonClikcHandler != null) this.commitButton.addClickHandler(buttonClikcHandler); + } + + + public void addHashObjectPsi(String psi){ + if(psi == null) return; + + this.commitButton.removeFromParent(); + CheckBox cbx = new CheckBox(psi); + this.psiCheckBoxes.add(cbx); + + int widgetIdx = 0; + for( ; widgetIdx != this.containerPanel.getWidgetCount(); ++widgetIdx){ + Widget wdgt = this.containerPanel.getWidget(widgetIdx); + if((wdgt instanceof Label) && ((Label)wdgt).getText().compareTo(psi) >= 0){ + this.containerPanel.insert(cbx, widgetIdx); + break; + } + } + + if(widgetIdx == this.containerPanel.getWidgetCount()) this.containerPanel.add(cbx); + this.containerPanel.insert(this.commitButton, this.containerPanel.getWidgetCount()); + } +}
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 Wed Sep 21 01:23:59 2011 (r947) +++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/IsidorusConstants.java Wed Sep 21 02:37:02 2011 (r948) @@ -10,13 +10,14 @@ public final static String HASH_OBJECT_PSI = "http://textgrid.org/serviceregistry/model/types/Hash-Object"; public final static String ENVIRONMENT_PSI = "http://textgrid.org/serviceregistry/model/types/Environment"; public final static String HASH_VALUE_OCCURRENCE_TYPE = "http://textgrid.org/serviceregistry/model/value"; + public final static String TM_SPARQL_ENDPOINT = Window.Location.getProtocol() + "//" + Window.Location.getHost() + "/gdl/tm-sparql"; public final static String DELETE_REQUEST_URL = Window.Location.getProtocol() + "//" + Window.Location.getHost() + "/gdl/delete"; public final static String COMMIT_REQUEST_URL = Window.Location.getProtocol() + "//" + Window.Location.getHost() + "/gdl/commit"; public final static String GET_FRAGMENT_REQUEST_URL = Window.Location.getProtocol() + "//" + Window.Location.getHost() + "/gdl/fragment/"; 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_full_TMCL_and_GDL_Schema.jtm"; - public final static String GET_HASH_OBJECT_PSIS_URL = Window.Location.getProtocol() + "//" + Window.Location.getHost() + "/gdl/tm-sparql"; + public final static String GET_HASH_OBJECT_PSIS_URL = IsidorusConstants.TM_SPARQL_ENDPOINT; //public final static String GET_HASH_OBJECT_PSIS_URL = GWT.getModuleBaseURL() + "HashObjectPsis.json"; - public final static String GET_ENVIRONMENT_PSIS_URL = Window.Location.getProtocol() + "//" + Window.Location.getHost() + "/gdl/tm-sparql"; + public final static String GET_ENVIRONMENT_PSIS_URL = IsidorusConstants.TM_SPARQL_ENDPOINT; //public final static String GET_ENVIRONMENT_PSIS_URL = GWT.getModuleBaseURL() + "EnvironmentPsis.json"; }