JAL-1990 added a progress indicator for Structure Chooser interface
authortcofoegbu <tcnofoegbu@dundee.ac.uk>
Mon, 11 Jan 2016 12:37:07 +0000 (12:37 +0000)
committertcofoegbu <tcnofoegbu@dundee.ac.uk>
Mon, 11 Jan 2016 12:37:07 +0000 (12:37 +0000)
src/jalview/gui/StructureChooser.java
src/jalview/jbgui/GStructureChooser.java
src/jalview/structure/StructureSelectionManager.java

index 720dc9e..cf58322 100644 (file)
@@ -21,6 +21,7 @@
 
 package jalview.gui;
 
+import jalview.bin.Jalview;
 import jalview.datamodel.DBRefEntry;
 import jalview.datamodel.DBRefSource;
 import jalview.datamodel.PDBEntry;
@@ -31,6 +32,7 @@ import jalview.structure.StructureSelectionManager;
 import jalview.util.MessageManager;
 import jalview.ws.dbsources.PDBRestClient;
 import jalview.ws.dbsources.PDBRestClient.PDBDocField;
+import jalview.ws.sifts.SiftsSettings;
 import jalview.ws.uimodel.PDBRestRequest;
 import jalview.ws.uimodel.PDBRestResponse;
 import jalview.ws.uimodel.PDBRestResponse.PDBResponseSummary;
@@ -55,7 +57,8 @@ import javax.swing.table.AbstractTableModel;
  *
  */
 @SuppressWarnings("serial")
-public class StructureChooser extends GStructureChooser
+public class StructureChooser extends GStructureChooser implements
+        IProgressIndicator
 {
   private boolean structuresDiscovered = false;
 
@@ -90,6 +93,11 @@ public class StructureChooser extends GStructureChooser
    */
   public void init()
   {
+    if (!Jalview.isHeadlessMode())
+    {
+      progressBar = new ProgressBar(this.statusPanel, this.statusBar);
+    }
+
     Thread discoverPDBStructuresThread = new Thread(new Runnable()
     {
       @Override
@@ -669,6 +677,15 @@ public class StructureChooser extends GStructureChooser
   @Override
   public void ok_ActionPerformed()
   {
+    final long progressSessionId = System.currentTimeMillis();
+    final StructureSelectionManager ssm = ap.getStructureSelectionManager();
+    ssm.setProgressIndicator(this);
+    ssm.setProgressSessionId(progressSessionId);
+    new Thread(new Runnable()
+    {
+      @Override
+      public void run()
+      {
     FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
             .getSelectedItem());
     String currentView = selectedFilterOpt.getView();
@@ -701,8 +718,7 @@ public class StructureChooser extends GStructureChooser
       }
       SequenceI[] selectedSeqs = selectedSeqsToView
               .toArray(new SequenceI[selectedSeqsToView.size()]);
-      launchStructureViewer(ap.getStructureSelectionManager(),
-              pdbEntriesToView, ap, selectedSeqs);
+          launchStructureViewer(ssm, pdbEntriesToView, ap, selectedSeqs);
     }
     else if (currentView == VIEWS_LOCAL_PDB)
     {
@@ -725,8 +741,7 @@ public class StructureChooser extends GStructureChooser
       }
       SequenceI[] selectedSeqs = selectedSeqsToView
               .toArray(new SequenceI[selectedSeqsToView.size()]);
-      launchStructureViewer(ap.getStructureSelectionManager(),
-              pdbEntriesToView, ap, selectedSeqs);
+          launchStructureViewer(ssm, pdbEntriesToView, ap, selectedSeqs);
     }
     else if (currentView == VIEWS_ENTER_ID)
     {
@@ -748,8 +763,8 @@ public class StructureChooser extends GStructureChooser
       }
 
       PDBEntry[] pdbEntriesToView = new PDBEntry[] { pdbEntry };
-      launchStructureViewer(ap.getStructureSelectionManager(),
-              pdbEntriesToView, ap, new SequenceI[] { selectedSequence });
+          launchStructureViewer(ssm, pdbEntriesToView, ap,
+                  new SequenceI[] { selectedSequence });
     }
     else if (currentView == VIEWS_FROM_FILE)
     {
@@ -764,26 +779,35 @@ public class StructureChooser extends GStructureChooser
                       jalview.io.AppletFormatAdapter.FILE,
                       selectedSequence, true, Desktop.instance);
 
-      launchStructureViewer(ap.getStructureSelectionManager(),
-              new PDBEntry[] { fileEntry }, ap,
-              new SequenceI[] { selectedSequence });
+          launchStructureViewer(ssm, new PDBEntry[] { fileEntry }, ap,
+                  new SequenceI[] { selectedSequence });
     }
     mainFrame.dispose();
+      }
+    }).start();
   }
 
-  private void launchStructureViewer(final StructureSelectionManager ssm,
+  private void launchStructureViewer(StructureSelectionManager ssm,
           final PDBEntry[] pdbEntriesToView,
-          final AlignmentPanel alignPanel, final SequenceI[] sequences)
+          final AlignmentPanel alignPanel, SequenceI[] sequences)
   {
+    ssm.setProgressBar("Launching PDB structure viewer..");
     final StructureViewer sViewer = new StructureViewer(ssm);
 
-    new jalview.ws.DBRefFetcher(sequences, null, null, null, false)
-            .fetchDBRefs(true);
-    new Thread(new Runnable()
+    if (SiftsSettings.isMapWithSifts())
     {
-      @Override
-      public void run()
+      for (SequenceI seq : sequences)
       {
+        if (seq.getSourceDBRef() == null)
+        {
+          ssm.setProgressBar(null);
+          ssm.setProgressBar("Fetching Database refs..");
+          new jalview.ws.DBRefFetcher(sequences, null, null, null, false)
+                  .fetchDBRefs(true);
+          break;
+        }
+      }
+    }
         if (pdbEntriesToView.length > 1)
         {
           ArrayList<SequenceI[]> seqsMap = new ArrayList<SequenceI[]>();
@@ -792,14 +816,17 @@ public class StructureChooser extends GStructureChooser
             seqsMap.add(new SequenceI[] { seq });
           }
           SequenceI[][] collatedSeqs = seqsMap.toArray(new SequenceI[0][0]);
+      ssm.setProgressBar(null);
+      ssm.setProgressBar("Fetching PDB Structures for selected entries..");
           sViewer.viewStructures(pdbEntriesToView, collatedSeqs, alignPanel);
         }
         else
         {
+      ssm.setProgressBar(null);
+      ssm.setProgressBar("Fetching PDB Structure for "
+              + pdbEntriesToView[0].getId());
           sViewer.viewStructures(pdbEntriesToView[0], sequences, alignPanel);
         }
-      }
-    }).start();
   }
 
   /**
@@ -1008,4 +1035,24 @@ public class StructureChooser extends GStructureChooser
     }
 
   }
+
+  private IProgressIndicator progressBar;
+
+  @Override
+  public void setProgressBar(String message, long id)
+  {
+    progressBar.setProgressBar(message, id);
+  }
+
+  @Override
+  public void registerHandler(long id, IProgressIndicatorHandler handler)
+  {
+    progressBar.registerHandler(id, handler);
+  }
+
+  @Override
+  public boolean operationInProgress()
+  {
+    return progressBar.operationInProgress();
+  }
 }
index 67b3a20..d8cff06 100644 (file)
@@ -34,6 +34,7 @@ import java.awt.BorderLayout;
 import java.awt.CardLayout;
 import java.awt.Dimension;
 import java.awt.FlowLayout;
+import java.awt.GridLayout;
 import java.awt.event.ActionEvent;
 import java.awt.event.ItemEvent;
 import java.awt.event.ItemListener;
@@ -69,6 +70,12 @@ import javax.swing.event.DocumentListener;
 public abstract class GStructureChooser extends JPanel implements
         ItemListener
 {
+  protected JPanel statusPanel = new JPanel();
+
+  public JLabel statusBar = new JLabel();
+
+  private JPanel pnl_actionsAndStatus = new JPanel(new BorderLayout());
+
   protected String frameTitle = MessageManager
           .getString("label.structure_chooser");
 
@@ -152,6 +159,7 @@ public abstract class GStructureChooser extends JPanel implements
 
   protected JTable tbl_summary = new JTable()
   {
+    @Override
     public String getToolTipText(MouseEvent evt)
     {
       String toolTipText = null;
@@ -213,11 +221,13 @@ public abstract class GStructureChooser extends JPanel implements
     tbl_summary.getTableHeader().setReorderingAllowed(false);
     tbl_summary.addMouseListener(new MouseAdapter()
     {
+      @Override
       public void mouseClicked(MouseEvent e)
       {
         validateSelections();
       }
 
+      @Override
       public void mouseReleased(MouseEvent e)
       {
         validateSelections();
@@ -260,11 +270,13 @@ public abstract class GStructureChooser extends JPanel implements
     tbl_local_pdb.getTableHeader().setReorderingAllowed(false);
     tbl_local_pdb.addMouseListener(new MouseAdapter()
     {
+      @Override
       public void mouseClicked(MouseEvent e)
       {
         validateSelections();
       }
 
+      @Override
       public void mouseReleased(MouseEvent e)
       {
         validateSelections();
@@ -313,6 +325,7 @@ public abstract class GStructureChooser extends JPanel implements
     btn_view.setText(MessageManager.getString("action.view"));
     btn_view.addActionListener(new java.awt.event.ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
         ok_ActionPerformed();
@@ -334,6 +347,7 @@ public abstract class GStructureChooser extends JPanel implements
     btn_cancel.setText(MessageManager.getString("action.cancel"));
     btn_cancel.addActionListener(new java.awt.event.ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
         mainFrame.dispose();
@@ -356,6 +370,7 @@ public abstract class GStructureChooser extends JPanel implements
     btn_pdbFromFile.setText(btn_title + "              ");
     btn_pdbFromFile.addActionListener(new java.awt.event.ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
         pdbFromFile_actionPerformed();
@@ -440,6 +455,7 @@ public abstract class GStructureChooser extends JPanel implements
             .getString("label.configure_displayed_columns");
     ChangeListener changeListener = new ChangeListener()
     {
+      @Override
       public void stateChanged(ChangeEvent changeEvent)
       {
         JTabbedPane sourceTabbedPane = (JTabbedPane) changeEvent
@@ -483,7 +499,12 @@ public abstract class GStructureChooser extends JPanel implements
     this.setLayout(mainLayout);
     this.add(pnl_main, java.awt.BorderLayout.NORTH);
     this.add(pnl_switchableViews, java.awt.BorderLayout.CENTER);
-    this.add(pnl_actions, java.awt.BorderLayout.SOUTH);
+    // this.add(pnl_actions, java.awt.BorderLayout.SOUTH);
+    statusPanel.setLayout(new GridLayout());
+    pnl_actionsAndStatus.add(pnl_actions, BorderLayout.CENTER);
+    pnl_actionsAndStatus.add(statusPanel, BorderLayout.SOUTH);
+    statusPanel.add(statusBar, null);
+    this.add(pnl_actionsAndStatus, java.awt.BorderLayout.SOUTH);
 
     mainFrame.setVisible(true);
     mainFrame.setContentPane(this);
@@ -564,6 +585,7 @@ public abstract class GStructureChooser extends JPanel implements
       this.view = view;
     }
 
+    @Override
     public String toString()
     {
       return this.name;
@@ -596,6 +618,7 @@ public abstract class GStructureChooser extends JPanel implements
       this.sequence = seq;
     }
 
+    @Override
     public String toString()
     {
       return name;
index 678bf3b..2f962b5 100644 (file)
@@ -32,6 +32,7 @@ import jalview.datamodel.Annotation;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SearchResults;
 import jalview.datamodel.SequenceI;
+import jalview.gui.IProgressIndicator;
 import jalview.io.AppletFormatAdapter;
 import jalview.util.MappingUtils;
 import jalview.util.MessageManager;
@@ -70,6 +71,10 @@ public class StructureSelectionManager
 
   private boolean addTempFacAnnot = false;
 
+  private IProgressIndicator progressIndicator;
+
+  private long progressSessionId;
+
   /*
    * Set of any registered mappings between (dataset) sequences.
    */
@@ -485,6 +490,8 @@ public class StructureSelectionManager
       ArrayList<StructureMapping> seqToStrucMapping = null;
       if (isMapUsingSIFTs)
       {
+        setProgressBar(null);
+        setProgressBar("Obtaining mapping with SIFTS");
         try
         {
           jalview.datamodel.Mapping sqmpping = maxAlignseq
@@ -518,12 +525,16 @@ public class StructureSelectionManager
           e.printStackTrace();
           System.err
                   .println(">>>>>>> SIFTs mapping could not be obtained... Now mapping with NW alignment");
+          setProgressBar(null);
+          setProgressBar("SIFTs mapping could not be obtained... Now mapping with NW alignment");
           seqToStrucMapping = getNWMappings(seq, pdbFile, maxChainId,
                   maxChain, pdb, maxAlignseq);
         }
       }
       else
       {
+        setProgressBar(null);
+        setProgressBar("Obtaining mapping with NW alignment");
         seqToStrucMapping = getNWMappings(seq, pdbFile,
                 maxChainId, maxChain, pdb,
                 maxAlignseq);
@@ -1224,4 +1235,30 @@ public class StructureSelectionManager
     }
     return null;
   }
+
+  public IProgressIndicator getProgressIndicator()
+  {
+    return progressIndicator;
+  }
+
+  public void setProgressIndicator(IProgressIndicator progressIndicator)
+  {
+    this.progressIndicator = progressIndicator;
+  }
+
+  public long getProgressSessionId()
+  {
+    return progressSessionId;
+  }
+
+  public void setProgressSessionId(long progressSessionId)
+  {
+    this.progressSessionId = progressSessionId;
+  }
+
+  public void setProgressBar(String message)
+  {
+    progressIndicator.setProgressBar(message, progressSessionId);
+  }
+
 }