JAL-2505 delete and readd amended sequence feature
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 4 May 2017 11:33:00 +0000 (12:33 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 4 May 2017 11:33:00 +0000 (12:33 +0100)
src/jalview/datamodel/features/FeatureStore.java
src/jalview/gui/FeatureRenderer.java

index cd7d055..75e99c7 100644 (file)
@@ -696,7 +696,8 @@ public class FeatureStore
 
   /**
    * Rescan all features to recompute any cached values after an entry has been
-   * deleted
+   * deleted. This is expected to be an infrequent event, so performance here is
+   * not critical.
    */
   protected synchronized void rescanAfterDelete()
   {
index f519f99..56da67c 100644 (file)
@@ -42,6 +42,7 @@ import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
 import java.util.Arrays;
 import java.util.Comparator;
+import java.util.HashMap;
 
 import javax.swing.JColorChooser;
 import javax.swing.JComboBox;
@@ -357,22 +358,47 @@ public class FeatureRenderer extends
       }
       else if (reply == JvOptionPane.YES_OPTION)
       {
-        sf.type = lastFeatureAdded;
-        sf.featureGroup = lastFeatureGroupAdded;
-        sf.description = lastDescriptionAdded;
-
-        setColour(sf.type, fcol);
-        getFeaturesDisplayed().setVisible(sf.type);
-
+        String newType = lastFeatureAdded;
+        String newFeatureGroup = lastFeatureGroupAdded;
+        String newDescription = lastDescriptionAdded;
+
+        setColour(newType, fcol);
+        getFeaturesDisplayed().setVisible(newType);
+        int newBegin = sf.begin;
+        int newEnd = sf.end;
         try
         {
-          sf.begin = ((Integer) start.getValue()).intValue();
-          sf.end = ((Integer) end.getValue()).intValue();
+          newBegin = ((Integer) start.getValue()).intValue();
+          newEnd = ((Integer) end.getValue()).intValue();
         } catch (NumberFormatException ex)
         {
+          // JSpinner doesn't accept invalid format data :-)
         }
 
-        ffile.parseDescriptionHTML(sf, false);
+        /*
+         * replace the feature by deleting it and adding a new one
+         * (to ensure integrity of SequenceFeatures data store)
+         */
+        sequences[0].deleteFeature(sf);
+        SequenceFeature newSf = new SequenceFeature(newType,
+                newDescription, newBegin, newEnd, sf.getScore(),
+                newFeatureGroup);
+        // ensure any additional properties are copied
+        if (sf.otherDetails != null)
+        {
+          newSf.otherDetails = new HashMap<String, Object>(sf.otherDetails);
+        }
+        ffile.parseDescriptionHTML(newSf, false);
+        // add any additional links not parsed from description
+        if (sf.links != null)
+        {
+          for (String link : sf.links)
+          {
+            newSf.addLink(link);
+          }
+        }
+        // amend features only gets one sequence to act on
+        sequences[0].addSequenceFeature(newSf);
       }
     }
     else