JAL-1136 JAL-811 JAL-812 store/recover autocalc alignment annotation based on calcId...
[jalview.git] / src / jalview / gui / Jalview2XML.java
index d9aca36..7fb7f0b 100644 (file)
@@ -1306,7 +1306,7 @@ public class Jalview2XML
       // recreate settings from preset 3) predefined settings provided by
       // service - or settings that can be transferred (or discarded)
       vCalcIdParam.setParameters(settings
-              .getWsParamFile());
+              .getWsParamFile().replace("\n", "|\\n|"));
       vCalcIdParam.setAutoUpdate(settings.isAutoUpdate());
       // todo - decide if updateImmediately is needed for any projects.
 
@@ -1325,7 +1325,7 @@ public class Jalview2XML
       {
         WsParamSetI parmSet=null;
         try {
-          service.getParamStore().parseServiceParameterFile(calcIdParam.getName(), calcIdParam.getDescription(), calcIdParam.getServiceURL(), calcIdParam.getParameters());
+          parmSet = service.getParamStore().parseServiceParameterFile(calcIdParam.getName(), calcIdParam.getDescription(), calcIdParam.getServiceURL(), calcIdParam.getParameters().replace("|\\n|", "\n"));
         } catch (IOException x)
         {
           warn("Couldn't parse parameter data for "+calcIdParam.getCalcId(), x);
@@ -1345,15 +1345,14 @@ public class Jalview2XML
         }
         AAConsSettings settings = new AAConsSettings(calcIdParam.isAutoUpdate(), service, parmSet, argList);
         av.setCalcIdSettingsFor(calcIdParam.getCalcId(), settings, calcIdParam.isNeedsUpdate());
+        return true;
       } else {
         warn("Cannot resolve a service for the parameters used in this project. Try configuring a JABAWS server.");
         return false;
       }
     }
-    else
-      throw new Error("Unsupported Version for calcIdparam "
-              + calcIdParam.toString());
-    return false;
+    throw new Error("Unsupported Version for calcIdparam "
+            + calcIdParam.toString());
   }
   /**
    * External mapping between jalview objects and objects yielding a valid and
@@ -3368,7 +3367,16 @@ public class Jalview2XML
                 );
       }
     }
-
+    if (view.getCalcIdParam()!=null)
+    {
+      for (CalcIdParam calcIdParam:view.getCalcIdParam())
+      {
+        if (recoverCalcIdParam(calcIdParam, af.viewport)) {
+        } else {
+          warn("Couldn't recover parameters for "+calcIdParam.getCalcId());
+        }
+      }
+    }
     af.setMenusFromViewport(af.viewport);
     // TODO: we don't need to do this if the viewport is aready visible.
     Desktop.addInternalFrame(af, view.getTitle(), view.getWidth(),
@@ -3398,10 +3406,13 @@ public class Jalview2XML
       }
       for (JvAnnotRow auan : autoAlan)
       {
-        visan.put(auan.template.label, auan);
+        visan.put(auan.template.label+(auan.template.getCalcId()==null ? "" : "\t"+auan.template.getCalcId()), auan);
       }
       int hSize = al.getAlignmentAnnotation().length;
       ArrayList<JvAnnotRow> reorder = new ArrayList<JvAnnotRow>();
+      // work through any autoCalculated annotation already on the view
+      // removing it if it should be placed in a different location on the
+      // annotation panel.
       for (int h = 0; h < hSize; h++)
       {
         jalview.datamodel.AlignmentAnnotation jalan = al
@@ -3409,10 +3420,15 @@ public class Jalview2XML
         if (jalan.autoCalculated)
         {
           JvAnnotRow valan = visan.get(jalan.label);
+          if (jalan.getCalcId()!=null)
+          {
+            valan = visan.get(jalan.label+ "\t"+jalan.getCalcId());
+          }
+          
           if (valan != null)
           {
             // delete the auto calculated row from the alignment
-            al.deleteAnnotation(al.getAlignmentAnnotation()[h], false);
+            al.deleteAnnotation(jalan, false);
             hSize--;
             h--;
             if (valan != nullAnnot)