import ie.dcu.apps.ist.labelling.*;
import ie.dcu.swt.layout.LayoutFactory;
+import org.apache.commons.lang3.StringEscapeUtils;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
labelCombo.addKeyListener(new KeyListener() {
@Override
public void keyReleased(KeyEvent e) {
- ArrayList<String> listElements = new ArrayList<String>();
+ ArrayList<OntologyTerm> terms = new ArrayList<OntologyTerm>();
//For the down arrow functionality
if(e.keyCode == 16777218)
{
labelCombo.setListVisible(true);
}
- // If key pressed is only a number of charecter or space.
+ // If key pressed is only a number of character or space.
else if ((e.keyCode >= 48 && e.keyCode <= 57) || (e.keyCode >= 97 && e.keyCode <= 122) || e.keyCode == 32)
{
//For removing all previously assigned labels
labelCombo.remove(0,labelCombo.getItemCount()-1);
- listElements = labels.getLabels(labelCombo.getText());
+ terms = labels.getLabels(labelCombo.getText());
}
- for (int i=0; i<listElements.size();i++)
+ int i = 0;
+ for (OntologyTerm term : terms)
{
- labelCombo.add(listElements.get(i),i);
+ // set text for term label
+ labelCombo.add(term.getFormattedTerm(),i);
+ i++;
}
}
import ie.dcu.apps.ist.AppWindow;
+import java.awt.List;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
* ArrayList<String> containing each Label item
*
*/
- public ArrayList<String> getLabels(String content) {
- ArrayList<String> labels = new ArrayList<String>();
+ public ArrayList<OntologyTerm> getLabels(String content) {
+ ArrayList<OntologyTerm> terms = new ArrayList<OntologyTerm>();
// temporary variable for storing each list element in the loop
- String listElement;
try
{
String encodedContent = URLEncoder.encode(content.toString(),"UTF-8");
{
object = new JSONObject(inputLine);
}
+
JSONArray array = new JSONArray(object.getString("PO_term_search_response"));
for(int i=0; i<array.length();i++)
{
- listElement = (array.getJSONObject(i).getString("match")+" {"+array.getJSONObject(i).getString("accession_id")+"}");
- labels.add(i,StringEscapeUtils.unescapeHtml4(listElement));
+ OntologyTerm term = new OntologyTerm();
+ term.setAccessionId(array.getJSONObject(i).getString("accession_id"));
+ term.setName(array.getJSONObject(i).getString("match"));
+ terms.add(term);
}
in.close();
}
catch(Exception ex)
{
}
- return labels;
+ return terms;
}
}
\ No newline at end of file
--- /dev/null
+/**
+ *
+ */
+package ie.dcu.apps.ist.labelling;
+
+import java.util.ArrayList;
+
+import org.apache.commons.lang3.StringEscapeUtils;
+
+/**
+ * @author preecej
+ * Contains attributes associated with terms received from ontologies.
+ */
+public class OntologyTerm {
+
+ private String accessionId;
+ private String name;
+ private String aspect;
+ private String definition;
+ private String comment;
+ private ArrayList<String> synonyms;
+
+ public String getAccessionId() {
+ return this.accessionId;
+ }
+ public String getName() {
+ return this.name;
+ }
+ public String getAspect() {
+ return this.aspect;
+ }
+ public String getDefinition() {
+ return this.definition;
+ }
+ public String getComment() {
+ return this.comment;
+ }
+ public ArrayList<String> getSynonyms() {
+ return this.synonyms;
+ }
+ // returns an HTML-safe label formatted to include both name and accession id
+ public String getFormattedTerm() {
+ return StringEscapeUtils.unescapeHtml4(this.name) + " {" + this.accessionId + "}";
+ }
+
+ public void setAccessionId(String accessionId) {
+ this.accessionId = accessionId;
+ }
+ public void setName(String name) {
+ this.name = name;
+ }
+ public void setAspect(String aspect) {
+ this.aspect = aspect;
+ }
+ public void setDefinition(String definition) {
+ this.definition = definition;
+ }
+ public void setComment(String comment) {
+ this.comment = comment;
+ }
+ public void setSynonyms(ArrayList<String> synonyms) {
+ this.synonyms = synonyms;
+ }
+
+ // constructor
+ public OntologyTerm() {
+ this.synonyms = new ArrayList<String>();
+ }
+
+}
import java.util.Properties;
import java.util.logging.*;
+import org.apache.commons.lang3.StringEscapeUtils;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.action.*;
import org.eclipse.jface.operation.*;
dropdownLabels(e);
}
});
+ /*
comboLabel.addFocusListener(new FocusAdapter() {
public void focusGained(FocusEvent e) {
termDetailLookup(e);
}
});
+ */
assign = SwtUtils.addButton(termLookupBar, 52, "Assign");
assign.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
*/
public void dropdownLabels(KeyEvent e)
{
- ArrayList<String> listElements = new ArrayList<String>();
+ ArrayList<OntologyTerm> terms = new ArrayList<OntologyTerm>();
//For the down arrow functionality
if(e.keyCode == 16777218)
{
{
//For removing all previously assigned labels
comboLabel.remove(0,comboLabel.getItemCount()-1);
- listElements = labels.getLabels(comboLabel.getText());
+ terms = labels.getLabels(comboLabel.getText());
assign.setEnabled(!(comboLabel.getText().isEmpty()));
-
+ if (e.keyCode == 32) {
+ termDetailLookup();
+ }
}
- for (int i=0; i<listElements.size();i++)
+ int i = 0;
+ for (OntologyTerm term : terms)
{
- comboLabel.add(listElements.get(i),i);
+ // set text for term label
+ comboLabel.add(term.getFormattedTerm(),i);
+ i++;
}
}
- private void termDetailLookup(FocusEvent e) {
+ private void termDetailLookup() {
// call term detail web service method using accession id (from 1) segment obj or 2) label selection (before assign button is clicked))
termDetailTable.setEnabled(true);
}