From 4db71e4f6ef511949f93b29adb47488955f31edf Mon Sep 17 00:00:00 2001 From: Dan Vasilescu Date: Wed, 3 Jul 2024 16:28:54 -0400 Subject: [PATCH] AnnotationsPanel: Fix multiple null pointer exceptions --- .../desktop/biomodel/AnnotationsPanel.java | 15 +++- .../annotations/AddAnnotationsPanel.java | 90 +++++++++++++++---- 2 files changed, 85 insertions(+), 20 deletions(-) diff --git a/vcell-client/src/main/java/cbit/vcell/client/desktop/biomodel/AnnotationsPanel.java b/vcell-client/src/main/java/cbit/vcell/client/desktop/biomodel/AnnotationsPanel.java index 70032f8be3..c5f5a9cc20 100644 --- a/vcell-client/src/main/java/cbit/vcell/client/desktop/biomodel/AnnotationsPanel.java +++ b/vcell-client/src/main/java/cbit/vcell/client/desktop/biomodel/AnnotationsPanel.java @@ -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()) { @@ -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"); @@ -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) { @@ -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")) @@ -1114,6 +1118,9 @@ private void initializeComboBoxURI() { List tooltips = new ArrayList<> (); List 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); } diff --git a/vcell-client/src/main/java/cbit/vcell/client/desktop/biomodel/annotations/AddAnnotationsPanel.java b/vcell-client/src/main/java/cbit/vcell/client/desktop/biomodel/annotations/AddAnnotationsPanel.java index 416bf93620..455be75b13 100644 --- a/vcell-client/src/main/java/cbit/vcell/client/desktop/biomodel/annotations/AddAnnotationsPanel.java +++ b/vcell-client/src/main/java/cbit/vcell/client/desktop/biomodel/annotations/AddAnnotationsPanel.java @@ -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); @@ -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; @@ -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("" + mdt.getDataTypeName() + ""), sGbc); + JLabel linkLabel = new JLabel(); + String s = "" + "URL : " + " " + mdt.getDataTypeURL() + "  " + ""; + 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; @@ -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 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 @@ -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<>(); @@ -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