Skip to content

Commit

Permalink
Merge pull request #1295 from virtualcell/dan-annotations=bugs
Browse files Browse the repository at this point in the history
AnnotationsPanel: Fix multiple null pointer exceptions
  • Loading branch information
danv61 authored Jul 4, 2024
2 parents 4ce5122 + 4db71e4 commit 00fbaba
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ public void actionPerformed(ActionEvent evt) {
addIdentifier();
} else if(evt.getSource() == getJButtonSearchRef()) {
initializeAddAnnotationsPanel();
} else if(evt.getSource() == addAnnotationsPanel.getOkButton()) {
annotationTextArea.setText("A test from the void");
} else if(addAnnotationsPanel != null && evt.getSource() == addAnnotationsPanel.getOkButton()) {
annotationTextArea.setText("");
} else if(evt.getSource() == getJButtonDeleteRef()) {
removeIdentifier();
} else if(evt.getSource() == getJButtonRemoveText()) {
Expand Down Expand Up @@ -728,7 +728,7 @@ private void showBrowseToLink(LinkNode linkNode) {
DialogUtils.showWarningDialog(this, "No Web-site link available");
}
}
private void showBrowseToLink(VCMetaDataDataType md) {
public void showBrowseToLink(VCMetaDataDataType md) {
String link = md.getDataTypeURL();
if (link != null) {
DialogUtils.browserLauncher(getJComboBoxURI(), link, "Failed to launch");
Expand Down Expand Up @@ -761,7 +761,8 @@ private void initialize() {
initializeComboBoxQualifier();
initializeComboBoxURI();

getJTreeMIRIAM().addTreeSelectionListener(new TreeSelectionListener() {
JTree miriamTree = getJTreeMIRIAM();
miriamTree.addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent e) {
TreePath tp = ((JTree)e.getSource()).getSelectionPath();
if(tp == null) {
Expand Down Expand Up @@ -1033,6 +1034,9 @@ else if (uri.toString().contains("GO"))
id = uri.getPath().replace("/obo/GO_","");
else if (uri.toString().contains("ncit"))
id = uri.toString().replace("https://ncit.nci.nih.gov/ncitbrowser/ConceptReport.jsp?dictionary=NCI_Thesaurus&ns=ncit&code=","");

// TODO: links are not working, and links with UBERON are giving error
// TODO: links need to point to the same database as in purl
else if (uri.toString().contains("PATO"))
id = uri.getPath().replace("/obo/PATO_","");
else if (uri.toString().contains("PR"))
Expand Down Expand Up @@ -1114,6 +1118,9 @@ private void initializeComboBoxURI() {
List<String> tooltips = new ArrayList<> ();
List<DataType> dataTypeList = new ArrayList<>();
if(entity == null) {
if(bioModel == null || vcMetaData == null) {
return; // called way too early, will be again called later
}
for (DataType dt : vcMetaData.getMiriamManager().getAllDataTypes().values()) {
dataTypeList.add(dt);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,21 @@
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.StringTokenizer;

import static cbit.vcell.biomodel.meta.VCMetaDataMiriamManager.VCMetaDataDataType.DataType_UNIPROT;

public class AddAnnotationsPanel extends JFrame implements ActionListener {

public static final int MAX_DESCRIPTION_LENGTH = 160;

private JButton searchButton;
private JTextField searchBar;
private JTextField organismSearchField = new JTextField(20);
Expand Down Expand Up @@ -140,9 +146,10 @@ private void addSearchPanelComponents(JPanel topPanel) {
VCMetaDataMiriamManager.VCMetaDataDataType mdt = (VCMetaDataMiriamManager.VCMetaDataDataType)jComboBoxURI.getSelectedItem();
topPanel.setLayout(new GridBagLayout());

int gridy = 0;
GridBagConstraints sGbc = new GridBagConstraints();
//adding select ontology Label
sGbc.gridy = 0;
sGbc.gridy = gridy;
sGbc.gridx = 0;
sGbc.insets = new Insets(0,0,10,0);
sGbc.anchor = GridBagConstraints.WEST;
Expand All @@ -151,12 +158,31 @@ private void addSearchPanelComponents(JPanel topPanel) {

sGbc = new GridBagConstraints();
sGbc.insets = new Insets(3, 5, 3, 4);
sGbc.gridy = 0;
sGbc.gridy = gridy;
sGbc.gridx = 1;
sGbc.insets = new Insets(0,10,10,20);
sGbc.anchor = GridBagConstraints.WEST;
topPanel.add(new JLabel("<html><b>" + mdt.getDataTypeName() + "</b></html>"), sGbc);

JLabel linkLabel = new JLabel();
String s = "<html>" + "URL : " + "&nbsp;<font color=\"" + "blue" + "\"><a href=" + mdt.getDataTypeURL() + ">" + mdt.getDataTypeURL() + "</a></font>&nbsp;&nbsp;" + "</html>";
linkLabel.setToolTipText("Double-click to open link");
linkLabel.setText(s);
linkLabel.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
if(e.getClickCount() == 2) {
annotationsPanel.showBrowseToLink(mdt);
}
}
});
sGbc = new GridBagConstraints();
sGbc.insets = new Insets(3, 5, 3, 4);
sGbc.gridy = gridy;
sGbc.gridx = 2;
sGbc.insets = new Insets(0,10,10,20);
sGbc.anchor = GridBagConstraints.WEST;
topPanel.add(linkLabel, sGbc);

// sGbc = new GridBagConstraints();
// sGbc.gridy = 0;
// sGbc.gridx = 1;
Expand All @@ -171,48 +197,80 @@ private void addSearchPanelComponents(JPanel topPanel) {
// topPanel.add(jComboBoxURI, sGbc); // ontologies combobox

sGbc = new GridBagConstraints();
sGbc.gridy = 0;
sGbc.gridx = 2;
sGbc.gridy = gridy;
sGbc.gridx = 3;
sGbc.weightx = 1;
topPanel.add(new javax.swing.JLabel(""), sGbc); // empty filler

// ---------- second row -----------------------------------------------------------------
// gridy++;
List <String> rows = new ArrayList<>();
String value = mdt.getDescription();
StringTokenizer tokenizer = new StringTokenizer(value, " ");
String row = "";
while(tokenizer.hasMoreTokens()) {
String word = tokenizer.nextToken();
if((row.length() + word.length()) > MAX_DESCRIPTION_LENGTH) {
rows.add(row);
row = word + " ";
} else {
row += word + " ";
}
}
if(!row.isEmpty()) {
rows.add(row);
}
for(String currentRow : rows) {
gridy++;
sGbc = new GridBagConstraints();
sGbc.insets = new Insets(2, 4, 4, 0);
sGbc.gridx = 0;
sGbc.gridy = gridy;
sGbc.gridwidth = 8;
sGbc.fill = GridBagConstraints.HORIZONTAL;
sGbc.weightx = 1.0;
topPanel.add(new JLabel(currentRow), sGbc);
}

// ---------- next row -------------------------------------------------------------------
gridy++;
sGbc = new GridBagConstraints();
sGbc.gridy = 1;
sGbc.gridy = gridy;
sGbc.gridx = 0;
sGbc.anchor = GridBagConstraints.WEST;
sGbc.insets = new Insets(0,0,10,0);
sGbc.insets = new Insets(9,0,10,0);
JLabel searchLabel = new JLabel("Search term:"); // search label
topPanel.add(searchLabel, sGbc);

sGbc = new GridBagConstraints();
sGbc.gridy = 1;
sGbc.gridy = gridy;
sGbc.gridx = 1;
sGbc.anchor = GridBagConstraints.WEST;
sGbc.insets = new Insets(0,10,10,0);
sGbc.insets = new Insets(9,10,10,0);
containsBox = new JComboBox<>(); // contains/exact Jcombobox
containsBox.addItem("contains");
containsBox.addItem("exact");
topPanel.add(containsBox, sGbc);

sGbc = new GridBagConstraints();
sGbc.gridy = 1;
sGbc.gridy = gridy;
sGbc.fill = GridBagConstraints.HORIZONTAL;
sGbc.gridx = 2;
sGbc.weightx = 1;
sGbc.gridwidth = 3;
sGbc.anchor = GridBagConstraints.WEST;
sGbc.insets = new Insets(0,20,10,0);
sGbc.insets = new Insets(9,20,10,0);
// searchBar = new JTextField(25);
// searchBar = new JTextField(15);
// leftPanel.add(searchBar, sGbc);
topPanel.add(getSearchComponentsPanel(), sGbc); // the searchComponentsPanel

// --------- third row -------------------------------------------------------------------
// --------- next row -------------------------------------------------------------------
gridy++;
sGbc.fill = GridBagConstraints.NONE;
sGbc.anchor = GridBagConstraints.WEST;
sGbc.gridwidth = 1;
sGbc.gridy = 2;
sGbc.gridy = gridy;
sGbc.gridx = 0;
sGbc.insets = new Insets(0,0,0,10);
JLabel limitLabel = new JLabel("Limit to"); // limit label
Expand All @@ -221,7 +279,7 @@ private void addSearchPanelComponents(JPanel topPanel) {
//adding limit JComboBox
sGbc.fill = GridBagConstraints.HORIZONTAL;
sGbc.anchor = GridBagConstraints.WEST;
sGbc.gridy = 2;
sGbc.gridy = gridy;
sGbc.gridx = 1;
sGbc.insets = new Insets(0,10,0,10);
limitBox = new JComboBox<>();
Expand All @@ -233,20 +291,20 @@ private void addSearchPanelComponents(JPanel topPanel) {
//adding limit term label
sGbc.fill = GridBagConstraints.NONE;
sGbc.anchor = GridBagConstraints.WEST;
sGbc.gridy = 2;
sGbc.gridy = gridy;
sGbc.gridx = 2;
sGbc.insets = new Insets(0,0,0,20);
JLabel elementLabel = new JLabel("elements");
topPanel.add(elementLabel, sGbc);

sGbc = new GridBagConstraints();
sGbc.gridy = 2;
sGbc.gridy = gridy;
sGbc.gridx = 3;
sGbc.weightx = 1;
topPanel.add(new javax.swing.JLabel(""), sGbc); // empty filler

sGbc.anchor = GridBagConstraints.EAST;
sGbc.gridy = 2;
sGbc.gridy = gridy;
sGbc.gridx = 4;
sGbc.insets = new Insets(0,10,0,0);
searchButton = new JButton("Search"); // the Search button
Expand Down

0 comments on commit 00fbaba

Please sign in to comment.