JAL-281 option pane with error handling for selecting an URL
authorkjvdheide <kjvanderheide@dundee.ac.uk>
Fri, 17 Nov 2017 17:57:31 +0000 (17:57 +0000)
committerkjvdheide <kjvanderheide@dundee.ac.uk>
Mon, 20 Nov 2017 09:36:07 +0000 (09:36 +0000)
resources/lang/Messages.properties
src/jalview/ext/archaeopteryx/AptxInit.java
src/jalview/ext/archaeopteryx/AptxTreeBuilder.java
src/jalview/ext/archaeopteryx/LoadedTreeAssociation.java
src/jalview/ext/forester/io/TreeParser.java
src/jalview/ext/treeviewer/ExternalTreeBuilderI.java
src/jalview/ext/treeviewer/ExternalTreeParserI.java
src/jalview/gui/AlignFrame.java
src/jalview/gui/Desktop.java
src/jalview/jbgui/GAlignFrame.java
src/jalview/util/MappingUtils.java

index 7a7bfbf..3c69dcd 100644 (file)
@@ -388,6 +388,8 @@ label.selected_region_to_tree_may_only_contain_residues_or_gaps =  The selected
 label.sequences_selection_not_aligned = Sequences in selection are not aligned
 label.problem_reading_tree_file =  Problem reading tree file
 label.possible_problem_with_tree_file = Possible problem with tree file
+label.tree_url_example = Please enter a complete URL, \"for example http://purl.org/phylo/treebase/phylows/study/TB2:S15480?format=nexus\"
+label.load_tree_url = Tree from URL
 label.select_at_least_three_bases_in_at_least_one_sequence_to_cDNA_translation = Please select at least three bases in at least one sequence in order to perform a cDNA translation.
 label.translation_failed = Translation Failed
 label.error_when_translating_sequences_submit_bug_report = Unfortunately, something went wrong when translating your sequences.\nPlease take a look in the Jalview java console\nand submit a bug report including the stacktrace.
@@ -417,7 +419,7 @@ label.input_alignment_from_url = Input Alignment From URL
 label.input_alignment = Input Alignment
 label.couldnt_import_as_vamsas_session = Couldn't import {0} as a new vamsas session.
 label.vamsas_document_import_failed = Vamsas Document Import Failed
-label.couldnt_locate = Couldn't locate {0}
+label.couldnt_locate = Could not locate {0}
 label.url_not_found = URL not found
 label.new_sequence_url_link = New sequence URL link
 label.cannot_edit_annotations_in_wrapped_view = Cannot edit annotations in wrapped view
index 817fef3..107aeca 100644 (file)
@@ -8,6 +8,7 @@ import jalview.gui.Desktop;
 import jalview.viewmodel.AlignmentViewport;
 
 import java.awt.Dimension;
+import java.net.URL;
 import java.util.Map;
 
 import org.forester.archaeopteryx.Archaeopteryx;
@@ -93,7 +94,7 @@ public final class AptxInit
     return bindFrameToJalview(aptxApp);
   }
 
-  public static MainFrame createInstanceFromUrl()
+  public static MainFrame createInstanceFromUrl(URL url)
   {
 
     return null;
index 7b03d5c..74d89d2 100644 (file)
@@ -5,6 +5,7 @@ import jalview.datamodel.SequenceI;
 import jalview.ext.forester.DataConversions;
 import jalview.ext.forester.ForesterMatrix;
 import jalview.ext.treeviewer.ExternalTreeBuilderI;
+import jalview.util.MappingUtils;
 import jalview.util.MessageManager;
 
 import java.util.HashMap;
@@ -91,9 +92,9 @@ public class AptxTreeBuilder
       NodeData nodeData = sequenceNode.getNodeData();
       nodeData.setSequence(seq);
 
-      ExternalTreeBuilderI.putWithDuplicationCheck(nodesWithAlignment,
+      MappingUtils.putWithDuplicationCheck(nodesWithAlignment,
               sequenceNode, sequence);
-      ExternalTreeBuilderI.putWithDuplicationCheck(alignmentWithNodes,
+      MappingUtils.putWithDuplicationCheck(alignmentWithNodes,
               sequence, sequenceNode);
       rootNode.addAsChild(sequenceNode);
     }
index adea693..c869cd5 100644 (file)
@@ -4,7 +4,7 @@ import jalview.analysis.SequenceIdMatcher;
 import jalview.datamodel.SequenceI;
 import jalview.ext.forester.DataConversions;
 import jalview.ext.treeviewer.ExternalLoadedTreeAssociationI;
-import jalview.ext.treeviewer.ExternalTreeBuilderI;
+import jalview.util.MappingUtils;
 
 import java.util.HashMap;
 import java.util.List;
@@ -67,9 +67,9 @@ public class LoadedTreeAssociation
                 .createForesterSequence(nodeSequence, true);
         treeNode.getNodeData().setSequence(foresterNodeSeq);
 
-        ExternalTreeBuilderI.putWithDuplicationCheck(alignmentWithNodes,
+        MappingUtils.putWithDuplicationCheck(alignmentWithNodes,
                 nodeSequence, treeNode);
-        ExternalTreeBuilderI.putWithDuplicationCheck(nodesWithAlignment,
+        MappingUtils.putWithDuplicationCheck(nodesWithAlignment,
                 treeNode, nodeSequence);
 
 
index 96b5770..43fd1fa 100644 (file)
@@ -52,7 +52,7 @@ public class TreeParser // implements ExternalTreeParserI<MainFrame>
   public void loadTree(AlignViewport viewport)
   {
 
-      NewickFile fin = null;
+    NewickFile fin = null; // old tree
       try
       {
         AptxInit.createInstanceFromFile(filePath, viewport);
@@ -60,6 +60,7 @@ public class TreeParser // implements ExternalTreeParserI<MainFrame>
         fin = new NewickFile(filePath, DataSourceType.FILE);
         viewport.setCurrentTree(viewport.getAlignPanel().alignFrame
                 .showNewickTree(fin, filePath).getTree());
+
       } catch (Exception ex)
       {
         JvOptionPane.showMessageDialog(Desktop.desktop, ex.getMessage(),
index 27659d7..8fd1d1d 100644 (file)
@@ -28,30 +28,4 @@ public interface ExternalTreeBuilderI<T, N>
 
   public String generateTreeName();
 
-  /**
-   * probably move
-   * 
-   * @param map
-   * @param key
-   * @param value
-   * @return
-   */
-  static <K, V> Map<K, V> putWithDuplicationCheck(Map<K, V> map, K key,
-          V value)
-  {
-    if (!map.containsKey(key))
-    {
-      map.put(key, value);
-    }
-    else
-    {
-      jalview.bin.Cache.log.warn(
-              "Attempt to add duplicate entry detected for map with key: "
-                      + key.toString() + " and value: " + value.toString());
-    }
-
-    return map;
-    
-  }
-
 }
index fb7227f..47960f9 100644 (file)
@@ -2,20 +2,17 @@
 //
 // import jalview.viewmodel.AlignmentViewport;
 //
-// import javax.swing.JInternalFrame;
-//
 /// **
+// *
 // * Interface for loading in existing trees to an external tree viewer.
 // *
 // * @author kjvanderheide
 // *
-// * @param <F>
-// * Frame of the tree viewer.
 // */
-// public interface ExternalTreeParserI<F extends JInternalFrame>
+// public interface ExternalTreeParserI
 // {
-// public void loadTreeFile(AlignmentViewport viewport);
+// public ExternalTreeI loadTreeFile(AlignmentViewport viewport);
 //
-// public void loadTreeUrl(AlignmentViewport viewport);
+// public ExternalTreeI loadTreeUrl(AlignmentViewport viewport);
 //
 // }
index 4bd20fc..3d9e0bb 100644 (file)
@@ -127,6 +127,7 @@ import java.beans.PropertyChangeEvent;
 import java.io.File;
 import java.io.FileWriter;
 import java.io.PrintWriter;
+import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -3879,7 +3880,7 @@ public void chooseTreeFile() {
   chooser.setDialogTitle(
           MessageManager.getString("label.select_newick_like_tree_file")); // modify
   chooser.setToolTipText(
-          MessageManager.getString("label.load_tree_file"));
+            MessageManager.getString("label.load_tree_for_sequence_set"));
   for (SupportedTreeFileFilter treeFormat : SupportedTreeFileFilter
           .values())
   {
@@ -3899,6 +3900,46 @@ public void chooseTreeFile() {
     }
   }
 
+  public void chooseTreeUrl()
+  {
+    URL treeUrl;
+
+    String urlString = JvOptionPane.showInputDialog(this,
+            MessageManager.getString("label.tree_url_example"),
+            MessageManager.getString("label.load_tree_url"),
+            JvOptionPane.QUESTION_MESSAGE);
+    if ((urlString != null) && (!urlString.isEmpty()))
+    {
+      try
+      {
+        treeUrl = new URL(urlString);
+        AptxInit.createInstanceFromUrl(treeUrl);
+
+      } catch (MalformedURLException e)
+      {
+        JvOptionPane.showMessageDialog(this,
+                MessageManager.formatMessage(
+                        "exception.failed_to_read_data_from_source",
+                        new String[]
+                        { urlString }),
+                MessageManager.getString("label.url_not_found")
+         , JvOptionPane.ERROR_MESSAGE);
+      }
+
+    }
+
+
+    // final String url_string = JOptionPane
+    // .showInputDialog( this,
+    // message,
+    // "Use URL/webservice to obtain a phylogeny",
+    // JOptionPane.QUESTION_MESSAGE );
+    // boolean nhx_or_nexus = false;
+    // if ( ( url_string != null ) && ( url_string.length() > 0 ) ) {
+    // try {
+    // url = new URL( url_string );
+  }
+
   /**
    * DOCUMENT ME!
    * 
@@ -3914,8 +3955,7 @@ public void chooseTreeFile() {
   @Override
   protected void loadTreeUrlItem_actionPerformed(ActionEvent e)
   {
-    AptxInit.createInstanceFromUrl();
-
+    chooseTreeUrl();
   }
 
   @Override
index f90752b..ca82d90 100644 (file)
@@ -1161,8 +1161,9 @@ public class Desktop extends jalview.jbgui.GDesktop
       if (format == null)
       {
         JvOptionPane.showInternalMessageDialog(Desktop.desktop,
-                MessageManager.formatMessage("label.couldnt_locate",
-                        new Object[]
+                MessageManager.formatMessage(
+                        "label.couldnt_locate",
+                        new String[]
                         { url }),
                 MessageManager.getString("label.url_not_found"),
                 JvOptionPane.WARNING_MESSAGE);
index 4073fcc..954721e 100755 (executable)
@@ -1079,8 +1079,7 @@ public class GAlignFrame extends JInternalFrame
 
     JMenuItem loadTreeFile = new JMenuItem(
             MessageManager.getString("label.from_file"));
-    // loadTreeMenuItem.setActionCommand(
-    // MessageManager.getString());
+
     loadTreeFile.addActionListener(new ActionListener()
     {
       @Override
@@ -1707,7 +1706,8 @@ public class GAlignFrame extends JInternalFrame
             MessageManager.getString("label.export_image"));
     JMenu loadTreeMenu = new JMenu(
             MessageManager.getString("label.load_associated_tree"));
-    loadTreeMenu.setActionCommand("label.load_tree_for_sequence_set");
+    // loadTreeMenu.setToolTipText(
+    // MessageManager.getString("label.load_tree_for_sequence_set"));
     
     JMenu fileMenu = new JMenu(MessageManager.getString("action.file"));
 
@@ -1884,6 +1884,8 @@ public class GAlignFrame extends JInternalFrame
     // JAL-574
     // selectMenu.addSeparator();
     // selectMenu.add(listenToViewSelections);
+
+
   }
 
   /**
index 9c5c109..78a833e 100644 (file)
@@ -990,4 +990,23 @@ public final class MappingUtils
       }
     }
   }
+
+
+  public static <K, V> Map<K, V> putWithDuplicationCheck(Map<K, V> map, K key,
+          V value)
+  {
+    if (!map.containsKey(key))
+    {
+      map.put(key, value);
+    }
+    else
+    {
+      jalview.bin.Cache.log.warn(
+              "Attempt to add duplicate entry detected for map with key: "
+                      + key.toString() + " and value: " + value.toString());
+    }
+  
+    return map;
+    
+  }
 }