From c0aa726fbb87cc78858025f1bd51ccde40672a5d Mon Sep 17 00:00:00 2001 From: preecej Date: Wed, 16 May 2012 22:45:21 +0000 Subject: [PATCH] PO web service term detail call complete; still needs UI refinement (i.e. nested list for synonyms with annotated synonym highlighted, proper horiz and vert expansion of composite) but the basics are there svn path=/; revision=330 --- .../dcu/apps/ist/views/SegmentationView.java | 92 +++++++++++++++---- 1 file changed, 75 insertions(+), 17 deletions(-) diff --git a/Annotation/src/ie/dcu/apps/ist/views/SegmentationView.java b/Annotation/src/ie/dcu/apps/ist/views/SegmentationView.java index 2af7ee9..fd827a0 100644 --- a/Annotation/src/ie/dcu/apps/ist/views/SegmentationView.java +++ b/Annotation/src/ie/dcu/apps/ist/views/SegmentationView.java @@ -13,6 +13,8 @@ import ie.dcu.segment.painters.SegmentationPainter; import ie.dcu.swt.*; import ie.dcu.swt.event.*; +import java.io.BufferedReader; +import java.io.InputStreamReader; import java.lang.reflect.InvocationTargetException; import java.net.*; import java.util.ArrayList; @@ -30,6 +32,8 @@ import org.eclipse.swt.events.*; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.layout.*; import org.eclipse.swt.widgets.*; +import org.json.JSONArray; +import org.json.JSONObject; public class SegmentationView extends Composite { // Logger @@ -54,7 +58,7 @@ public class SegmentationView extends Composite { // term detail table private static Table termDetailTable; - + // Control to change brush size private final BrushControl brushControl; @@ -123,12 +127,12 @@ public class SegmentationView extends Composite { }; public enum termDetailLabels { - n("Name"), - a("Accession ID"), - b("Branch") /* a.k.a. "Aspect" */, - d("Definition"), - c("Comment"), - s("Synonyms"); + name("Name"), + accession_id("Accession ID"), + aspect("Branch") /* a.k.a. "Aspect" */, + definition("Definition"), + comment("Comment"), + synonyms("Synonyms"); final String extendedLabel; termDetailLabels(String extendedLabel) { this.extendedLabel = extendedLabel; @@ -264,7 +268,7 @@ public class SegmentationView extends Composite { term.setName((String)comboLabel.getData(comboLabel.getText())); term.setAccessionId(parseAccessionIdFromComboLabel(comboLabel)); view.getContext().getEnabledMask().ontologyTerm = term; - /* TODO: remove this and reference SegementationMake.ontologyTerm.getName() instead + /* TODO: remove this and reference SegmentationMask.ontologyTerm.getName() instead * (find tooltip and any other reference as well) */ view.getContext().getEnabledMask().segmentName = (String) comboLabel.getData(comboLabel.getText()); @@ -329,6 +333,59 @@ public class SegmentationView extends Composite { public static void termDetailLookup(String accessionId) { System.out.println("curr accession id (from segment or label): " + accessionId); termDetailTable.setEnabled(true); + + String webServiceURL = new String(); + try { + String encodedContent = URLEncoder.encode(accessionId.toString(),"UTF-8"); + webServiceURL = AppWindow.props.getProperty("POWebService.TermDetail.URL"); + webServiceURL = webServiceURL.replace("", encodedContent); + URL url = new URL(webServiceURL); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); + // if the response from Web service is 'OK' + if (connection.getResponseCode() == 200) + { + String inputLine; + JSONObject responseObject = null; + while ((inputLine = in.readLine()) != null) + { + responseObject = new JSONObject(inputLine); + } + JSONArray responseArray = new JSONArray(responseObject.getString("PO_term_detail_response")); + + // set the table values + termDetailLabels[] values = termDetailLabels.values(); + TableItem[] items = termDetailTable.getItems(); + for(int i=0; i