From: gmungoc Date: Wed, 22 Nov 2017 16:56:35 +0000 (+0000) Subject: JAL-2808 update conditions list on change of attribute (safely) X-Git-Tag: Release_2_11_0~110 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=8690631b5afe2db0a06ef1b074d2633598c403ae;p=jalview.git JAL-2808 update conditions list on change of attribute (safely) --- diff --git a/src/jalview/gui/FeatureTypeSettings.java b/src/jalview/gui/FeatureTypeSettings.java index e280091..372234a 100644 --- a/src/jalview/gui/FeatureTypeSettings.java +++ b/src/jalview/gui/FeatureTypeSettings.java @@ -1330,7 +1330,20 @@ public class FeatureTypeSettings extends JalviewDialog { attCombo.setSelectedItem(toAttributeDisplayName(attName)); } - attCombo.addItemListener(itemListener); + attCombo.addItemListener(new ItemListener() + { + @Override + public void itemStateChanged(ItemEvent e) + { + /* + * on change of attribute, refresh the conditions list to + * ensure it is appropriate for the attribute datatype + */ + populateConditions((String) attCombo.getSelectedItem(), + (Condition) condCombo.getSelectedItem(), condCombo); + actionListener.actionPerformed(null); + } + }); filterRow.add(attCombo); @@ -1395,7 +1408,7 @@ public class FeatureTypeSettings extends JalviewDialog JComboBox condCombo) { Datatype type = FeatureAttributes.getInstance().getDatatype(featureType, - attName); + fromAttributeDisplayName(attName)); if (MessageManager.getString("label.label").equals(attName)) { type = Datatype.Character; @@ -1405,22 +1418,39 @@ public class FeatureTypeSettings extends JalviewDialog type = Datatype.Number; } + /* + * remove itemListener before starting + */ + ItemListener listener = condCombo.getItemListeners()[0]; + condCombo.removeItemListener(listener); + boolean condIsValid = false; + condCombo.removeAllItems(); for (Condition c : Condition.values()) { if ((c.isNumeric() && type != Datatype.Character) || (!c.isNumeric() && type != Datatype.Number)) { condCombo.addItem(c); + if (c == cond) + { + condIsValid = true; + } } } /* * set the selected condition (does nothing if not in the list) */ - if (cond != null) + if (condIsValid) { condCombo.setSelectedItem(cond); } + else + { + condCombo.setSelectedIndex(0); + } + + condCombo.addItemListener(listener); } /**