Hello!

To see the file structure, click on "tree".

Note that updates take place every 10 minutes, commits may not be seen immediately.
PO web service term detail call complete; still needs UI refinement (i.e. nested...
authorpreecej <preecej@localhost>
Wed, 16 May 2012 22:45:21 +0000 (22:45 +0000)
committerpreecej <preecej@localhost>
Wed, 16 May 2012 22:45:21 +0000 (22:45 +0000)
svn path=/; revision=330

Annotation/src/ie/dcu/apps/ist/views/SegmentationView.java

index 2af7ee9c307b313f94d75d9b88f79da4de055997..fd827a0ce5ace6838ec4130b9fa23a62da41ed8d 100644 (file)
@@ -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("<acc_id>", 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<items.length; i++)
+                       {
+                               for (termDetailLabels code : values) {
+                                       String currResponseValue = responseArray.getJSONObject(0).getString(code.toString()); // assumes an array of one response
+                                       if (items[i].getText(0).equals(code.extendedLabel)) {
+                                               if (code.extendedLabel.equals("Synonyms")) {
+                                                       String formattedSyns = new String();
+                                                       JSONArray synArray = responseArray.getJSONObject(0).getJSONArray("synonyms");
+                                                       for (int j=0; j<synArray.length(); j++) {
+                                                               formattedSyns += synArray.getString(j) + System.getProperty("line.separator");
+                                                       }
+                                                       items[i].setText(1, formattedSyns);
+                                               } else {
+                                                       items[i].setText(1, currResponseValue);
+                                               }
+                                       }
+                               }
+                               termDetailTable.getColumn(1).pack();
+                               termDetailTable.pack();
+                       }
+                       in.close();
+               } else {
+                       throw new Exception("Bad HTTP response code: " + connection.getResponseCode());
+               }
+           }
+           catch(Exception e)
+           {
+                       log.info("Unable to retrieve complete term details from remote web service at " + webServiceURL + 
+                                               System.getProperty("line.separator") + "    " + e.getMessage());
+           }
        }
        
        /**
@@ -340,7 +397,7 @@ public class SegmentationView extends Composite {
                termDetailTable.setLinesVisible (true);
                termDetailTable.setHeaderVisible (true);
                
-               String[] titles = {"Label","Data"};
+               String[] titles = {"Term Property","Value"};
                for (int i=0; i<titles.length; i++) {
                        TableColumn column = new TableColumn (termDetailTable, SWT.BORDER_SOLID);
                        column.setText (titles [i]);
@@ -350,11 +407,11 @@ public class SegmentationView extends Composite {
                for (termDetailLabels code : values) {
                        TableItem item = new TableItem (termDetailTable, SWT.NONE);
                        item.setText (0, code.extendedLabel);
-                       item.setText (1, "");
+                       item.setText (1,"");
                }
-               
+                               
                for (int i=0; i<titles.length; i++) {
-                       termDetailTable.getColumn (i).pack ();
+                       termDetailTable.getColumn(i).pack ();
                }
                termDetailTable.setEnabled(false);
                termDetailTable.pack();
@@ -460,30 +517,31 @@ public class SegmentationView extends Composite {
                gd.verticalAlignment = GridData.BEGINNING;
                gd.horizontalAlignment = SWT.FILL;
                gd.grabExcessHorizontalSpace = true;
+               gd.grabExcessVerticalSpace = true;
                termDetailComposite.setLayoutData(gd);
                
                // Layout term detail table                             
                gd = new GridData(SWT.FILL,SWT.FILL,true,true);
                gd.horizontalSpan = 2;
                termDetailTable.setLayoutData(gd);
-               
-               // Layout term detail table                             
+
+               // Layout species dropdown                              
                gd = new GridData();
                gd.widthHint = width/2;
                speciesCombo.setLayoutData(gd);
                
-               // Layout term detail table                             
+               // Layout curator dropdown                              
                gd = new GridData();
                curatorCombo.setLayoutData(gd);
                
-               // Layout term detail table                             
+               // Layout collection id box                             
                gd = new GridData();
                gd.widthHint = width;
                gd.grabExcessHorizontalSpace = true;
                gd.grabExcessVerticalSpace = true;
                collectionId.setLayoutData(gd);
                
-               // Layout term detail table                             
+               // Layout comments box                          
                gd = new GridData();
                gd.widthHint = width;
                gd.grabExcessHorizontalSpace = true;