javadoc on webservice discovery method
[jalview.git] / src / jalview / gui / AlignFrame.java
index f678915..99227e1 100755 (executable)
@@ -696,10 +696,8 @@ public class AlignFrame
   {
     JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
         getProperty( "LAST_DIRECTORY"),
-        new String[]
-        { "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc","amsa","jar" },
-        new String[]
-        { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "AMSA", "Jalview" },
+        jalview.io.AppletFormatAdapter.WRITABLE_EXTENSIONS,
+        jalview.io.AppletFormatAdapter.WRITABLE_FNAMES,
         currentFileFormat,
         false);
 
@@ -781,7 +779,7 @@ public class AlignFrame
       String output = f.formatSequences(
           format,
           (Alignment) viewport.alignment, // class cast exceptions will occur in the distant future
-          omitHidden, f.getCacheSuffixDefault(format));
+          omitHidden, f.getCacheSuffixDefault(format), viewport.colSel);
 
       if (output == null)
       {
@@ -853,7 +851,7 @@ public class AlignFrame
     cap.setText(new FormatAdapter().formatSequences(
         e.getActionCommand(),
         viewport.alignment,
-        omitHidden));
+        omitHidden, viewport.colSel));
   }
 
   /**
@@ -3327,21 +3325,28 @@ public class AlignFrame
     {
       String choice = chooser.getSelectedFile().getPath();
       jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
-
+      jalview.io.NewickFile fin = null;
       try
       {
-        jalview.io.NewickFile fin = new jalview.io.NewickFile(choice,
+        fin = new jalview.io.NewickFile(choice,
             "File");
         viewport.setCurrentTree(ShowNewickTree(fin, choice).getTree());
       }
       catch (Exception ex)
       {
         JOptionPane.showMessageDialog(Desktop.desktop,
-                                      "Problem reading tree file",
                                       ex.getMessage(),
+                                      "Problem reading tree file",
                                       JOptionPane.WARNING_MESSAGE);
         ex.printStackTrace();
       }
+      if (fin!=null && fin.hasWarningMessage())
+      {
+        JOptionPane.showMessageDialog(Desktop.desktop,
+                fin.getWarningMessage(),
+                "Possible problem with tree file",
+                JOptionPane.WARNING_MESSAGE);
+      }
     }
   }
 
@@ -3406,7 +3411,7 @@ public class AlignFrame
     {
       ex.printStackTrace();
     }
-
+    
     return tp;
   }
 
@@ -3417,6 +3422,11 @@ public class AlignFrame
    */
   public void BuildWebServiceMenu()
   {
+    // TODO: add support for context dependent disabling of services based on alignment and current selection
+    // TODO: refactor to allow list of AbstractName/Handler bindings to be stored or retrieved from elsewhere
+    // TODO: add additional serviceHandle parameter to specify abstract handler class independently of AbstractName
+    // TODO: add in rediscovery GUI function to restart discoverer
+    // TODO: group services by location as well as function and/or introduce object broker mechanism.
     if ( (Discoverer.services != null)
         && (Discoverer.services.size() > 0))
     {
@@ -3516,9 +3526,6 @@ public class AlignFrame
       resetWebServiceMenu();
       this.webService.add(this.webServiceNoServices);
     }
-    // TODO: add in rediscovery function
-    // TODO: reduce code redundancy.
-    // TODO: group services by location as well as function.
   }
 
 
@@ -3607,6 +3614,7 @@ public class AlignFrame
 
           public void actionPerformed(ActionEvent e)
           {
+            // TODO: new thread for this call with vis-delay
             af.showProductsFor(sel, ds, isRegSel, dna, source);
           }
           
@@ -3624,33 +3632,61 @@ public class AlignFrame
   }
 protected void showProductsFor(SequenceI[] sel, Alignment ds, boolean isRegSel, boolean dna, String source)
   {
-  ds = this.getViewport().alignment.getDataset(); // update our local dataset reference
-  Alignment prods = CrossRef.findXrefSequences(sel, dna, source, ds);
-  if (prods!=null)
-  {
-    SequenceI[] sprods = new SequenceI[prods.getHeight()];
-    for (int s=0; s<sprods.length;s++)
-    {
-      sprods[s] = (prods.getSequenceAt(s)).deriveSequence();
-      if (ds.getSequences()==null || !ds.getSequences().contains(sprods[s].getDatasetSequence()))
-        ds.addSequence(sprods[s].getDatasetSequence());
-    }
-    Alignment al = new Alignment(sprods);
-    AlignedCodonFrame[] cf = prods.getCodonFrames();
-    for (int s=0; cf!=null && s<cf.length; s++)
+  final boolean fisRegSel = isRegSel;
+  final boolean fdna = dna;
+  final String fsrc = source;
+  final AlignFrame ths = this;
+  final SequenceI[] fsel = sel;
+  Runnable foo = new Runnable() {
+
+    public void run()
     {
-      al.addCodonFrame(cf[s]);
-      cf[s] = null;
+      final long sttime = System.currentTimeMillis();
+      ths.setProgressBar("Searching for sequences from "+fsrc, sttime);
+      try {
+        Alignment ds = ths.getViewport().alignment.getDataset(); // update our local dataset reference
+      Alignment prods = CrossRef.findXrefSequences(fsel, fdna, fsrc, ds);
+      if (prods!=null)
+      {
+        SequenceI[] sprods = new SequenceI[prods.getHeight()];
+        for (int s=0; s<sprods.length;s++)
+        {
+          sprods[s] = (prods.getSequenceAt(s)).deriveSequence();
+          if (ds.getSequences()==null || !ds.getSequences().contains(sprods[s].getDatasetSequence()))
+            ds.addSequence(sprods[s].getDatasetSequence());
+          sprods[s].updatePDBIds();
+        }
+        Alignment al = new Alignment(sprods);
+        AlignedCodonFrame[] cf = prods.getCodonFrames();
+        for (int s=0; cf!=null && s<cf.length; s++)
+        {
+          al.addCodonFrame(cf[s]);
+          cf[s] = null;
+        }
+        al.setDataset(ds);
+        AlignFrame naf = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
+        String newtitle =""+((fdna) ? "Proteins " : "Nucleotides ") + " for "+((fisRegSel) ? "selected region of " : "")
+                + getTitle();
+        Desktop.addInternalFrame(naf, newtitle, DEFAULT_WIDTH,
+                DEFAULT_HEIGHT);
+      } else {
+        System.err.println("No Sequences generated for xRef type "+fsrc);
+      }
+      }
+      catch (Exception e)
+      {
+        jalview.bin.Cache.log.error("Exception when finding crossreferences",e);
+      }
+      catch (Error e)
+      {
+        jalview.bin.Cache.log.error("Error when finding crossreferences",e);
+      }
+      ths.setProgressBar("Finished searching for sequences from "+fsrc, sttime);
     }
-    al.setDataset(ds);
-    AlignFrame naf = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT);
-    String newtitle =""+((dna) ? "Proteins " : "Nucleotides ") + " for "+((isRegSel) ? "selected region of " : "")
-            + getTitle();
-    Desktop.addInternalFrame(naf, newtitle, DEFAULT_WIDTH,
-            DEFAULT_HEIGHT);
-  } else {
-    System.err.println("No Sequences generated for xRef type "+source);
-  }
+    
+  };
+  Thread frunner = new Thread(foo);
+  frunner.start();
   }