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;
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
// term detail table
private static Table termDetailTable;
-
+
// Control to change brush size
private final BrushControl brushControl;
};
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;
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());
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());
+ }
}
/**
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]);
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();
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;