JAL-1697 added ablity to select/view cached structures in the new structure chooser... bug/JAL-1697_browse-local-structures
authortcofoegbu <tcnofoegbu@dundee.ac.uk>
Fri, 17 Apr 2015 15:33:52 +0000 (16:33 +0100)
committertcofoegbu <tcnofoegbu@dundee.ac.uk>
Fri, 17 Apr 2015 15:33:52 +0000 (16:33 +0100)
src/jalview/gui/StructureChooser.java
src/jalview/jbgui/GStructureChooser.java

index 1197921..5c86ce2 100644 (file)
@@ -27,6 +27,7 @@ import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
 import jalview.jbgui.GStructureChooser;
 import jalview.jbgui.PDBDocFieldPreferences;
+import jalview.structure.StructureSelectionManager;
 import jalview.util.MessageManager;
 import jalview.ws.dbsources.PDBRestClient;
 import jalview.ws.dbsources.PDBRestClient.PDBDocField;
@@ -38,12 +39,15 @@ import java.awt.event.ItemEvent;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashSet;
+import java.util.Hashtable;
 import java.util.LinkedHashSet;
 import java.util.List;
 
 import javax.swing.JCheckBox;
 import javax.swing.JComboBox;
 import javax.swing.JLabel;
+import javax.swing.table.DefaultTableModel;
+
 
 /**
  * Provides the behaviors for the Structure chooser Panel
@@ -72,6 +76,8 @@ public class StructureChooser extends GStructureChooser
 
   private boolean isValidPBDEntry;
 
+  private static Hashtable<String, PDBEntry> cachedEntryMap;
+
   public StructureChooser(SequenceI[] selectedSeqs, SequenceI selectedSeq,
           AlignmentPanel ap)
   {
@@ -95,6 +101,7 @@ public class StructureChooser extends GStructureChooser
         long startTime = System.currentTimeMillis();
         String msg = MessageManager.getString("status.fetching_db_refs");
         updateProgressIndicator(msg, startTime);
+        loadLocalCachedPDBEntries();
         fetchStructuresMetaData();
         populateFilterComboBox();
         updateProgressIndicator(null, startTime);
@@ -167,6 +174,33 @@ public class StructureChooser extends GStructureChooser
             + " Found (" + totalTime + ")");
   }
 
+  public void loadLocalCachedPDBEntries()
+  {
+    DefaultTableModel tableModel = new DefaultTableModel();
+    tableModel.addColumn("Sequence");
+    tableModel.addColumn("PDB Id");
+    tableModel.addColumn("Type");
+    tableModel.addColumn("File");
+    cachedEntryMap = new Hashtable<String, PDBEntry>();
+    for (SequenceI seq : selectedSequences)
+    {
+      if (seq.getDatasetSequence() != null
+              && seq.getDatasetSequence().getPDBId() != null)
+      {
+        for (PDBEntry pdbEntry : seq.getDatasetSequence().getPDBId())
+        {
+          String[] pdbEntryRowData = new String[]
+          { seq.getDisplayId(false), pdbEntry.getId(), pdbEntry.getType(),
+              pdbEntry.getFile() };
+          tableModel.addRow(pdbEntryRowData);
+          cachedEntryMap.put(seq.getDisplayId(false) + pdbEntry.getId(),
+                  pdbEntry);
+        }
+      }
+    }
+    tbl_local_pdb.setModel(tableModel);
+  }
+
   /**
    * Update the DBRef entry for a given sequence with values retrieved from
    * PDBResponseSummary
@@ -195,7 +229,7 @@ public class StructureChooser extends GStructureChooser
    *          the sequences to build a query for
    * @return the built query string
    */
-  @SuppressWarnings("unchecked")
+
   public static String buildQuery(SequenceI seq)
   {
     String query = seq.getName();
@@ -352,6 +386,8 @@ public class StructureChooser extends GStructureChooser
             VIEWS_ENTER_ID));
     cmb_filterOption.addItem(new FilterOption("From File", "-",
             VIEWS_FROM_FILE));
+    cmb_filterOption.addItem(new FilterOption("Cached PDB Entries", "-",
+            VIEWS_LOCAL_PDB));
   }
 
   /**
@@ -372,7 +408,8 @@ public class StructureChooser extends GStructureChooser
       chk_invertFilter.setVisible(true);
       filterResultSet(selectedFilterOpt.getValue());
     }
-    else
+    else if (selectedFilterOpt.getView() == VIEWS_ENTER_ID
+            || selectedFilterOpt.getView() == VIEWS_FROM_FILE)
     {
       idInputAssSeqPanel.loadCmbAssSeq();
       fileChooserAssSeqPanel.loadCmbAssSeq();
@@ -397,6 +434,13 @@ public class StructureChooser extends GStructureChooser
         btn_view.setEnabled(true);
       }
     }
+    else if (currentView == VIEWS_LOCAL_PDB)
+    {
+      if (tbl_local_pdb.getSelectedRows().length > 0)
+      {
+        btn_view.setEnabled(true);
+      }
+    }
     else if (currentView == VIEWS_ENTER_ID)
     {
       validateAssociationEnterPdb();
@@ -513,19 +557,20 @@ public class StructureChooser extends GStructureChooser
         pdbEntriesToView[count++] = pdbEntry;
       }
 
-      StructureViewer sViewer = new StructureViewer(
-              ap.getStructureSelectionManager());
-      if (pdbEntriesToView.length > 1)
-      {
-        sViewer.viewStructures(ap, pdbEntriesToView,
-                ap.av.collateForPDB(pdbEntriesToView));
-      }
-      else
+      launchStructureViewer(ap.getStructureSelectionManager(),
+              pdbEntriesToView, ap, selectedSequences);
+    }
+    else if(currentView == VIEWS_LOCAL_PDB){
+      int[] selectedRows = tbl_local_pdb.getSelectedRows();
+      PDBEntry[] pdbEntriesToView = new PDBEntry[selectedRows.length];
+      int count = 0;
+      for (int row : selectedRows)
       {
-        sViewer.viewStructures(pdbEntriesToView[0], selectedSequences,
-                null, ap);
+         String entryKey = tbl_local_pdb.getValueAt(row, 0).toString() + tbl_local_pdb.getValueAt(row, 1).toString();
+        pdbEntriesToView[count++] = cachedEntryMap.get(entryKey);
       }
-
+      launchStructureViewer(ap.getStructureSelectionManager(),
+              pdbEntriesToView, ap, selectedSequences);
     }
     else if (currentView == VIEWS_ENTER_ID)
     {
@@ -541,9 +586,9 @@ public class StructureChooser extends GStructureChooser
       selectedSequence.getDatasetSequence().addPDBId(pdbEntry);
       PDBEntry[] pdbEntriesToView = new PDBEntry[]
       { pdbEntry };
-      new StructureViewer(ap.getStructureSelectionManager())
-              .viewStructures(ap, pdbEntriesToView,
-                      ap.av.collateForPDB(pdbEntriesToView));
+      launchStructureViewer(ap.getStructureSelectionManager(),
+              pdbEntriesToView, ap, new SequenceI[]
+              { selectedSequence });
     }
     else if (currentView == VIEWS_FROM_FILE)
     {
@@ -553,15 +598,36 @@ public class StructureChooser extends GStructureChooser
       {
         selectedSequence = userSelectedSeq;
       }
-      System.out.println(">>>>>>>>>>>>> Selected file >>>>>>>>>>>>>>> "
-              + selectedPdbFileName);
-      new AssociatePdbFileWithSeq().associatePdbWithSeq(
+      PDBEntry fileEntry = new AssociatePdbFileWithSeq()
+              .associatePdbWithSeq(
               selectedPdbFileName, jalview.io.AppletFormatAdapter.FILE,
               selectedSequence, true, Desktop.instance);
+
+      launchStructureViewer(ap.getStructureSelectionManager(),
+              new PDBEntry[]
+              { fileEntry }, ap, new SequenceI[]
+              { selectedSequence });
     }
     mainFrame.dispose();
   }
 
+  private void launchStructureViewer(StructureSelectionManager ssm,
+          PDBEntry[] pdbEntriesToView, AlignmentPanel alignPanel,
+          SequenceI[] selectedSequences)
+  {
+    StructureViewer sViewer = new StructureViewer(ssm);
+    if (pdbEntriesToView.length > 1)
+    {
+      sViewer.viewStructures(alignPanel, pdbEntriesToView,
+              alignPanel.av.collateForPDB(pdbEntriesToView));
+    }
+    else
+    {
+      sViewer.viewStructures(pdbEntriesToView[0], selectedSequences, null,
+              alignPanel);
+    }
+  }
+
   /**
    * Populates the combo-box used in associating manually fetched structures to
    * a unique sequence when more than one sequence selection is made.
index b79a7f7..fc035b6 100644 (file)
@@ -34,6 +34,8 @@ import java.awt.FlowLayout;
 import java.awt.event.ActionEvent;
 import java.awt.event.ItemEvent;
 import java.awt.event.ItemListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
 
 import javax.swing.ImageIcon;
 import javax.swing.JButton;
@@ -83,7 +85,7 @@ public abstract class GStructureChooser extends JPanel implements
 
   private JPanel pnl_actions = new JPanel();
 
-  private JPanel pnl_filter = new JPanel();
+  private JPanel pnl_main = new JPanel();
 
   private JPanel pnl_idInput = new JPanel(new FlowLayout());
 
@@ -93,6 +95,8 @@ public abstract class GStructureChooser extends JPanel implements
 
   private JPanel pnl_fileChooserBL = new JPanel(new BorderLayout());
 
+  private JPanel pnl_locPDB = new JPanel(new BorderLayout());
+
   protected JPanel pnl_switchableViews = new JPanel(new CardLayout());
 
   protected CardLayout layout_switchableViews = (CardLayout) (pnl_switchableViews
@@ -132,12 +136,18 @@ public abstract class GStructureChooser extends JPanel implements
 
   protected static final String VIEWS_ENTER_ID = "VIEWS_ENTER_ID";
 
+  protected static final String VIEWS_LOCAL_PDB = "VIEWS_LOCAL_PDB";
+
   protected JTable tbl_summary = new JTable();
 
   protected JScrollPane scrl_foundStructures = new JScrollPane(
           tbl_summary);
 
-  private JTabbedPane tabbedPane = new JTabbedPane();
+  protected JTable tbl_local_pdb = new JTable();
+
+  protected JScrollPane scrl_localPDB = new JScrollPane(tbl_local_pdb);
+
+  private JTabbedPane pnl_filter = new JTabbedPane();
 
   private PDBDocFieldPreferences pdbDocFieldPrefs = new PDBDocFieldPreferences(
           PreferenceSource.STRUCTURE_CHOOSER);
@@ -164,6 +174,15 @@ public abstract class GStructureChooser extends JPanel implements
   private void jbInit() throws Exception
   {
     tbl_summary.setAutoCreateRowSorter(true);
+    tbl_local_pdb.setAutoCreateRowSorter(true);
+    tbl_local_pdb.addMouseListener(new MouseAdapter()
+    {
+      public void mouseClicked(MouseEvent e)
+      {
+        updateCurrentView();
+      }
+    });
+
     btn_view.setFont(new java.awt.Font("Verdana", 0, 12));
     btn_view.setText(MessageManager.getString("action.view"));
     btn_view.addActionListener(new java.awt.event.ActionListener()
@@ -198,6 +217,10 @@ public abstract class GStructureChooser extends JPanel implements
     scrl_foundStructures
             .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
 
+    scrl_localPDB.setPreferredSize(new Dimension(500, 300));
+    scrl_localPDB
+            .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
+
     cmb_filterOption.setFont(new java.awt.Font("Verdana", 0, 12));
     chk_invertFilter.setFont(new java.awt.Font("Verdana", 0, 12));
     chk_rememberSettings.setFont(new java.awt.Font("Verdana", 0, 12));
@@ -236,20 +259,19 @@ public abstract class GStructureChooser extends JPanel implements
     pnl_actions.add(btn_cancel);
 
     // pnl_filter.add(lbl_result);
-    pnl_filter.add(cmb_filterOption);
-    pnl_filter.add(lbl_loading);
-    pnl_filter.add(chk_invertFilter);
+    pnl_main.add(cmb_filterOption);
+    pnl_main.add(lbl_loading);
+    pnl_main.add(chk_invertFilter);
     lbl_loading.setVisible(false);
 
-    pnl_idInput.add(txt_search);
-    pnl_idInput.add(lbl_pdbManualFetchStatus);
 
     pnl_fileChooser.add(btn_pdbFromFile);
     pnl_fileChooser.add(lbl_fromFileStatus);
-
     pnl_fileChooserBL.add(fileChooserAssSeqPanel, BorderLayout.NORTH);
     pnl_fileChooserBL.add(pnl_fileChooser, BorderLayout.CENTER);
 
+    pnl_idInput.add(txt_search);
+    pnl_idInput.add(lbl_pdbManualFetchStatus);
     pnl_idInputBL.add(idInputAssSeqPanel, BorderLayout.NORTH);
     pnl_idInputBL.add(pnl_idInput, BorderLayout.CENTER);
     
@@ -270,20 +292,22 @@ public abstract class GStructureChooser extends JPanel implements
         }
       }
     };
-    tabbedPane.addChangeListener(changeListener);
-    tabbedPane.setPreferredSize(new Dimension(500, 300));
-    tabbedPane.add(foundStructureSummary, scrl_foundStructures);
-    tabbedPane.add(
+    pnl_filter.addChangeListener(changeListener);
+    pnl_filter.setPreferredSize(new Dimension(500, 300));
+    pnl_filter.add(foundStructureSummary, scrl_foundStructures);
+    pnl_filter.add(
             MessageManager.getString("label.configure_displayed_columns"),
             pdbDocFieldPrefs);
     
+    pnl_locPDB.add(scrl_localPDB);
 
     pnl_switchableViews.add(pnl_fileChooserBL, VIEWS_FROM_FILE);
     pnl_switchableViews.add(pnl_idInputBL, VIEWS_ENTER_ID);
-    pnl_switchableViews.add(tabbedPane, VIEWS_FILTER);
+    pnl_switchableViews.add(pnl_filter, VIEWS_FILTER);
+    pnl_switchableViews.add(pnl_locPDB, VIEWS_LOCAL_PDB);
     
     this.setLayout(mainLayout);
-    this.add(pnl_filter, java.awt.BorderLayout.NORTH);
+    this.add(pnl_main, java.awt.BorderLayout.NORTH);
     this.add(pnl_switchableViews, java.awt.BorderLayout.CENTER);
     this.add(pnl_actions, java.awt.BorderLayout.SOUTH);