From 614b72c437f14dd2ddd72ae918dada3fd5d64468 Mon Sep 17 00:00:00 2001 From: kiramt Date: Thu, 3 Nov 2016 20:58:08 +0000 Subject: [PATCH] JAL-2282 Link menu disabled if there are no valid links --- src/jalview/appletgui/APopupMenu.java | 24 ++++++++++++++++-------- src/jalview/gui/PopupMenu.java | 11 +++++++++++ test/jalview/gui/PopupMenuTest.java | 10 ++++++++++ 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/jalview/appletgui/APopupMenu.java b/src/jalview/appletgui/APopupMenu.java index d625f78..1ff0ac1 100644 --- a/src/jalview/appletgui/APopupMenu.java +++ b/src/jalview/appletgui/APopupMenu.java @@ -335,17 +335,25 @@ public class APopupMenu extends java.awt.PopupMenu implements addshowLinks(linkMenu, linkset.values()); + // disable link menu if there are no valid entries if (linkMenu.getItemCount() > 0) { - if (seq != null) - { - seqMenu.add(linkMenu); - } - else - { - add(linkMenu); - } + linkMenu.setEnabled(true); + } + else + { + linkMenu.setEnabled(false); } + + if (seq != null) + { + seqMenu.add(linkMenu); + } + else + { + add(linkMenu); + } + } private void addshowLinks(Menu linkMenu, Collection> linkset) diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java index b342f86..bb816cd 100644 --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@ -641,6 +641,16 @@ public class PopupMenu extends JPopupMenu addshowLinks(linkMenu, linkset.values()); + // disable link menu if there are no valid entries + if (linkMenu.getItemCount() > 0) + { + linkMenu.setEnabled(true); + } + else + { + linkMenu.setEnabled(false); + } + if (sequence != null) { sequenceMenu.add(linkMenu); @@ -649,6 +659,7 @@ public class PopupMenu extends JPopupMenu { add(linkMenu); } + } diff --git a/test/jalview/gui/PopupMenuTest.java b/test/jalview/gui/PopupMenuTest.java index 7b1eac1..14354ff 100644 --- a/test/jalview/gui/PopupMenuTest.java +++ b/test/jalview/gui/PopupMenuTest.java @@ -534,6 +534,16 @@ public class PopupMenuTest ((JMenuItem) linkItems[i]).getText().split("\\|")[1]); } + // if there are no valid links the Links submenu is disabled + List nomatchlinks = new ArrayList(); + nomatchlinks.add("NOMATCH | http://www.uniprot.org/uniprot/$" + + DB_ACCESSION + "$"); + + testee = new PopupMenu(parentPanel, (Sequence) seqs.get(0), + nomatchlinks); + seqItems = testee.sequenceMenu.getMenuComponents(); + linkMenu = (JMenu) seqItems[6]; + assertFalse(linkMenu.isEnabled()); } } -- 1.7.10.2