From: kiramt Date: Mon, 12 Dec 2016 16:20:05 +0000 (+0000) Subject: JAL-2316 Added GUI checks for duplicate link ids X-Git-Tag: Release_2_10_3b1~346^2~16 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=4d22590f9c429fe89f4e44b2045e6741acb27fa5;p=jalview.git JAL-2316 Added GUI checks for duplicate link ids --- diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index 9ffa292..477b3d6 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -1284,4 +1284,6 @@ label.default = On Click label.inmenu = In Menu label.id = ID label.urltooltip = Only one url, which must use a sequence id, can be selected for the 'On Click' option -label.edit_sequence_url_link = Edit sequence URL link \ No newline at end of file +label.edit_sequence_url_link = Edit sequence URL link +warn.name_cannot_be_duplicate = URL names must be unique +label.invalid_name = Invalid Name ! \ No newline at end of file diff --git a/resources/lang/Messages_es.properties b/resources/lang/Messages_es.properties index a4b6c71..d2d04a9 100644 --- a/resources/lang/Messages_es.properties +++ b/resources/lang/Messages_es.properties @@ -1285,4 +1285,6 @@ label.default = On Click label.inmenu = In Menu label.id = ID label.urltooltip = Only one url, which must use a sequence id, can be selected for the 'On Click' option -label.edit_sequence_url_link = Edit sequence URL link \ No newline at end of file +label.edit_sequence_url_link = Edit sequence URL link +warn.name_cannot_be_duplicate = URL names must be unique +label.invalid_name = Invalid Name ! \ No newline at end of file diff --git a/src/jalview/gui/Preferences.java b/src/jalview/gui/Preferences.java index 9ee3077..b46ae10 100755 --- a/src/jalview/gui/Preferences.java +++ b/src/jalview/gui/Preferences.java @@ -867,9 +867,18 @@ public class Preferences extends GPreferences { if (link.checkValid()) { - ((UrlLinkTableModel) linkUrlTable.getModel()).insertRow( - link.getName(), link.getURL()); - valid = true; + if (((UrlLinkTableModel) linkUrlTable.getModel()) + .isUniqueName(link.getName())) + { + ((UrlLinkTableModel) linkUrlTable.getModel()).insertRow( + link.getName(), link.getURL()); + valid = true; + } + else + { + link.notifyDuplicate(); + continue; + } } } else @@ -904,9 +913,18 @@ public class Preferences extends GPreferences { if (link.checkValid()) { - linkUrlTable.setValueAt(link.getName(), index, 0); - linkUrlTable.setValueAt(link.getURL(), index, 1); - valid = true; + if (((UrlLinkTableModel) linkUrlTable.getModel()) + .isUniqueName(link.getName())) + { + linkUrlTable.setValueAt(link.getName(), index, 0); + linkUrlTable.setValueAt(link.getURL(), index, 1); + valid = true; + } + else + { + link.notifyDuplicate(); + continue; + } } } else diff --git a/src/jalview/jbgui/GSequenceLink.java b/src/jalview/jbgui/GSequenceLink.java index 9e44096..93b7935 100755 --- a/src/jalview/jbgui/GSequenceLink.java +++ b/src/jalview/jbgui/GSequenceLink.java @@ -225,6 +225,14 @@ public class GSequenceLink extends JPanel return false; } + public void notifyDuplicate() + { + JOptionPane.showInternalMessageDialog(jalview.gui.Desktop.desktop, + MessageManager.getString("warn.name_cannot_be_duplicate"), + MessageManager.getString("label.invalid_name"), + JOptionPane.WARNING_MESSAGE); + } + public void nameTB_keyTyped(KeyEvent e) { if (e.getKeyChar() == '|') diff --git a/src/jalview/urls/UrlLinkTableModel.java b/src/jalview/urls/UrlLinkTableModel.java index 6b03667..bda92cc 100644 --- a/src/jalview/urls/UrlLinkTableModel.java +++ b/src/jalview/urls/UrlLinkTableModel.java @@ -264,4 +264,9 @@ public class UrlLinkTableModel extends AbstractTableModel return dataProvider .isUserEntry(entry.getStringValue(UrlLinkDisplay.ID)); } + + public boolean isUniqueName(String name) + { + return !dataProvider.contains(name); + } }