JAL-1668 added validation for manual entry of pdb structures
authorCharles Ofoegbu <tcnofoegbu@dundee.ac.uk>
Mon, 16 Mar 2015 17:31:16 +0000 (17:31 +0000)
committerCharles Ofoegbu <tcnofoegbu@dundee.ac.uk>
Mon, 16 Mar 2015 17:31:16 +0000 (17:31 +0000)
resources/images/error.png [new file with mode: 0644]
resources/images/good.png [new file with mode: 0644]
resources/lang/Messages.properties
src/jalview/gui/PDBSearchPanel.java
src/jalview/gui/StructureChooser.java
src/jalview/jbgui/GPDBSearchPanel.java
src/jalview/jbgui/GStructureChooser.java
test/jalview/gui/PDBSearchPanelTest.java

diff --git a/resources/images/error.png b/resources/images/error.png
new file mode 100644 (file)
index 0000000..6d68a8c
Binary files /dev/null and b/resources/images/error.png differ
diff --git a/resources/images/good.png b/resources/images/good.png
new file mode 100644 (file)
index 0000000..ebbacc9
Binary files /dev/null and b/resources/images/good.png differ
index decf87b..3815cdf 100644 (file)
@@ -1202,4 +1202,6 @@ label.results = results
 label.structure_chooser = Structure Chooser
 label.select = Select : 
 label.invert = Invert 
-label.select_pdb_file = Select PDB File
\ No newline at end of file
+label.select_pdb_file = Select PDB File
+info.select_filter_option = Select Filter Option/Manual Entry
+info.associate_wit_sequence = Associate with Sequence
\ No newline at end of file
index 1441e08..7aa0bb3 100644 (file)
@@ -35,7 +35,6 @@ import java.util.Comparator;
 import java.util.List;
 
 import javax.swing.DefaultListModel;
-import javax.swing.SwingUtilities;
 
 @SuppressWarnings("serial")
 public class PDBSearchPanel extends GPDBSearchPanel
@@ -51,16 +50,6 @@ public class PDBSearchPanel extends GPDBSearchPanel
             .getProgressIndicator();
   }
 
-  public static void main(String[] args)
-  {
-    SwingUtilities.invokeLater(new Runnable()
-    {
-      public void run()
-      {
-        new PDBSearchPanel(null);
-      }
-    });
-  }
 
   @Override
   public void txt_search_ActionPerformed()
@@ -72,15 +61,10 @@ public class PDBSearchPanel extends GPDBSearchPanel
     if (txt_search.getText().trim().length() > 0)
     {
       long startTime = System.currentTimeMillis();
-      PDBRestClient pdbRestCleint = new PDBRestClient();
+
       String searchTarget = ((PDBDocField) cmb_searchTarget
               .getSelectedItem()).getCode();
 
-      PDBRestRequest request = new PDBRestRequest();
-      request.setAllowEmptySeq(allowEmptySequence);
-      request.setResponseSize(100);
-      request.setFieldToSearchBy(searchTarget + ":");
-      request.setSearchTerm(txt_search.getText());
       List<PDBDocField> wantedFields = new ArrayList<PDBDocField>();
       wantedFields.add(PDBDocField.MOLECULE_TYPE);
       wantedFields.add(PDBDocField.PDB_ID);
@@ -89,7 +73,15 @@ public class PDBSearchPanel extends GPDBSearchPanel
       wantedFields.add(PDBDocField.TITLE);
       // wantedFields.add(PDBDocField.RESOLUTION);
       // wantedFields.add(PDBDocField.EXPERIMENTAL_METHOD);
+
+      PDBRestRequest request = new PDBRestRequest();
+      request.setAllowEmptySeq(allowEmptySequence);
+      request.setResponseSize(100);
+      request.setFieldToSearchBy(searchTarget + ":");
+      request.setSearchTerm(txt_search.getText());
       request.setWantedFields(wantedFields);
+
+      PDBRestClient pdbRestCleint = new PDBRestClient();
       PDBRestResponse resultList = pdbRestCleint.executeRequest(request);
       if (resultList.getSearchSummary() != null)
       {
@@ -126,6 +118,9 @@ public class PDBSearchPanel extends GPDBSearchPanel
     mainFrame.dispose();
   }
 
+  /**
+   * Add the discovered/selected sequences to a target alignment window
+   */
   public void loadSelectedPDBSequencesToAlignment()
   {
     mainFrame.dispose();
@@ -141,6 +136,9 @@ public class PDBSearchPanel extends GPDBSearchPanel
     worker.start();
   }
 
+  /**
+   * Populates search target combo-box options
+   */
   public void populateCmbSearchTargetOptions()
   {
     List<PDBDocField> searchableTargets = new ArrayList<PDBDocField>();
index 4b3f5de..a01c1b8 100644 (file)
@@ -40,7 +40,7 @@ import java.util.List;
 import java.util.Vector;
 
 import javax.swing.JCheckBox;
-import javax.swing.JOptionPane;
+import javax.swing.JComboBox;
 import javax.swing.ListSelectionModel;
 
 /**
@@ -66,6 +66,9 @@ public class StructureChooser extends GStructureChooser
 
   private PDBRestClient pdbRestCleint;
 
+  private String selectedPdbFileName;
+
+  private boolean isValidPBDEntry;
 
   public StructureChooser(SequenceI[] selectedSeqs, SequenceI selectedSeq,
           AlignmentPanel ap)
@@ -152,11 +155,8 @@ public class StructureChooser extends GStructureChooser
     if (discoveredStructuresSet != null
             && !discoveredStructuresSet.isEmpty())
     {
-      jList_FoundStructures.setModel(PDBRestResponse
-              .getListModel(discoveredStructuresSet));
       tbl_summary.setModel(PDBRestResponse.getTableModel(pdbRequest,
               discoveredStructuresSet));
-      // resizeColumnWidth(summaryTable);
       structuresDiscovered = true;
       noOfStructuresFound = discoveredStructuresSet.size();
     }
@@ -225,7 +225,6 @@ public class StructureChooser extends GStructureChooser
       int endIndex = queryBuilder.lastIndexOf(" OR ");
       query = queryBuilder.toString().substring(5, endIndex);
     }
-    // System.out.println("Query -----> " + query);
     return query;
   }
 
@@ -242,6 +241,7 @@ public class StructureChooser extends GStructureChooser
       @Override
       public void run()
       {
+        long startTime = System.currentTimeMillis();
         try
         {
           lbl_loading.setVisible(true);
@@ -271,22 +271,17 @@ public class StructureChooser extends GStructureChooser
             List<PDBResponseSummary> originalDiscoveredStructuresList = new ArrayList<PDBResponseSummary>(
                     discoveredStructuresSet);
             originalDiscoveredStructuresList.removeAll(filteredResponse);
-
             Collection<PDBResponseSummary> reorderedStructuresSet = new ArrayList<PDBResponseSummary>();
             reorderedStructuresSet.addAll(filteredResponse);
             reorderedStructuresSet.addAll(originalDiscoveredStructuresList);
 
-            jList_FoundStructures.setModel(PDBRestResponse
-                    .getListModel(reorderedStructuresSet));
             tbl_summary.setModel(PDBRestResponse.getTableModel(pdbRequest,
                     reorderedStructuresSet));
 
-            // int[] filterIndice = new int[filterResponseCount];
             ListSelectionModel model = tbl_summary.getSelectionModel();
             model.clearSelection();
             for (int x = 0; x < filterResponseCount; x++)
             {
-              // filterIndice[x] = x;
               model.addSelectionInterval(x, x);
             }
 
@@ -294,8 +289,6 @@ public class StructureChooser extends GStructureChooser
             // collection
             originalDiscoveredStructuresList = null;
             reorderedStructuresSet = null;
-
-            // jListFoundStructures.setSelectedIndices(filterIndice);
           }
 
           lbl_loading.setVisible(false);
@@ -303,6 +296,12 @@ public class StructureChooser extends GStructureChooser
         {
           e.printStackTrace();
         }
+        String totalTime = (System.currentTimeMillis() - startTime)
+                + " milli secs";
+        mainFrame.setTitle("Structure Chooser - Filter time (" + totalTime
+                + ")");
+
+        validateSelections();
       }
     });
     filterThread.start();
@@ -348,51 +347,9 @@ public class StructureChooser extends GStructureChooser
     int value = chooser.showOpenDialog(null);
     if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION)
     {
-      String choice = chooser.getSelectedFile().getPath();
-      jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
-      new AssociatePdbFileWithSeq().associatePdbWithSeq(choice,
-              jalview.io.AppletFormatAdapter.FILE, selectedSequence, true,
-              Desktop.instance);
-    }
-  }
-
-  /**
-   * Handles action event for btn_ok
-   */
-  @Override
-  public void ok_ActionPerformed()
-  {
-    int pdbIdCol = getPDBIdColumIndex(pdbRequest.getWantedFields());
-    int[] selectedRows = tbl_summary.getSelectedRows();
-    PDBEntry[] pdbEntriesToView = new PDBEntry[selectedRows.length];
-    int count = 0;
-    for (int summaryRow : selectedRows)
-    {
-      String pdbIdStr = tbl_summary.getValueAt(summaryRow, pdbIdCol)
-              .toString();
-      PDBEntry pdbEntry = new PDBEntry();
-      pdbEntry.setId(pdbIdStr);
-      pdbEntry.setType("PDB");
-      pdbEntriesToView[count++] = pdbEntry;
-    }
-    new StructureViewer(ap.getStructureSelectionManager()).viewStructures(
-            ap, pdbEntriesToView, ap.av.collateForPDB(pdbEntriesToView));
-  }
-
-  /**
-   * Handles action event for manual entry of pdb ids
-   */
-  public void enterPDB_actionPerformed()
-  {
-    String id = JOptionPane.showInternalInputDialog(Desktop.desktop,
-            MessageManager.getString("label.enter_pdb_id"),
-            MessageManager.getString("label.enter_pdb_id"),
-            JOptionPane.QUESTION_MESSAGE);
-    if (id != null && id.length() > 0)
-    {
-      PDBEntry entry = new PDBEntry();
-      entry.setId(id.toUpperCase());
-      selectedSequence.getDatasetSequence().addPDBId(entry);
+      selectedPdbFileName = chooser.getSelectedFile().getPath();
+      jalview.bin.Cache.setProperty("LAST_DIRECTORY", selectedPdbFileName);
+      validateSelections();
     }
   }
 
@@ -428,16 +385,112 @@ public class StructureChooser extends GStructureChooser
    */
   protected void updateCurrentView()
   {
-    FilterOption selectedOption = ((FilterOption) cmb_filterOption
+    FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
             .getSelectedItem());
     layout_switchableViews.show(pnl_switchableViews,
-            selectedOption.getView());
-    chk_invertFilter.setEnabled(false);
-    if (selectedOption.getView() == VIEWS_FILTER)
+            selectedFilterOpt.getView());
+    String filterTitle = mainFrame.getTitle();
+    mainFrame.setTitle(frameTitle);
+    chk_invertFilter.setVisible(false);
+    if (selectedFilterOpt.getView() == VIEWS_FILTER)
     {
-      chk_invertFilter.setEnabled(true);
-      filterResultSet(selectedOption.getValue());
+      mainFrame.setTitle(filterTitle);
+      chk_invertFilter.setVisible(true);
+      filterResultSet(selectedFilterOpt.getValue());
     }
+    else
+    {
+      idInputAssSeqPanel.loadCmbAssSeq();
+      fileChooserAssSeqPanel.loadCmbAssSeq();
+    }
+    validateSelections();
+  }
+
+  /**
+   * Validates user selection and activates the view button if all parameters
+   * are correct
+   */
+  public void validateSelections()
+  {
+    FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
+            .getSelectedItem());
+    btn_view.setEnabled(false);
+    String currentView = selectedFilterOpt.getView();
+    if (currentView == VIEWS_FILTER)
+    {
+      if (tbl_summary.getSelectedRows().length > 0)
+      {
+        btn_view.setEnabled(true);
+      }
+    }
+    else if (currentView == VIEWS_ENTER_ID)
+    {
+      validateAssociationEnterPdb();
+    }
+    else if (currentView == VIEWS_FROM_FILE)
+    {
+      validateAssociationFromFile();
+    }
+
+  }
+
+  /**
+   * Validates inputs from the Manual PDB entry panel
+   */
+  public void validateAssociationEnterPdb()
+  {
+    AssociateSeqOptions assSeqOpt = (AssociateSeqOptions) idInputAssSeqPanel
+            .getCmb_assSeq().getSelectedItem();
+    lbl_pdbManualFetchStatus.setIcon(errorImage);
+    if (selectedSequences.length == 1
+            || !assSeqOpt.getName().equalsIgnoreCase(
+                    "-Select Associated Seq-"))
+    {
+      txt_search.setEnabled(true);
+      if (isValidPBDEntry)
+      {
+        btn_view.setEnabled(true);
+        lbl_pdbManualFetchStatus.setIcon(goodImage);
+      }
+    }
+    else
+    {
+      txt_search.setEnabled(false);
+      lbl_pdbManualFetchStatus.setIcon(errorImage);
+    }
+  }
+
+  /**
+   * Validates inputs for the manual PDB file selection options
+   */
+  public void validateAssociationFromFile()
+  {
+    AssociateSeqOptions assSeqOpt = (AssociateSeqOptions) fileChooserAssSeqPanel
+            .getCmb_assSeq().getSelectedItem();
+    lbl_fromFileStatus.setIcon(errorImage);
+    if (selectedSequences.length == 1
+            || (assSeqOpt != null
+            && !assSeqOpt.getName().equalsIgnoreCase(
+                    "-Select Associated Seq-")))
+    {
+      btn_pdbFromFile.setEnabled(true);
+      if (selectedPdbFileName != null && selectedPdbFileName.length() > 0)
+      {
+        btn_view.setEnabled(true);
+        lbl_fromFileStatus.setIcon(goodImage);
+      }
+    }
+    else
+    {
+      btn_pdbFromFile.setEnabled(false);
+      lbl_fromFileStatus.setIcon(errorImage);
+    }
+  }
+
+  @Override
+  public void cmbAssSeqStateChanged()
+  {
+    validateSelections();
   }
 
   /**
@@ -461,6 +514,82 @@ public class StructureChooser extends GStructureChooser
 
   }
 
+  /**
+   * Handles action event for btn_ok
+   */
+  @Override
+  public void ok_ActionPerformed()
+  {
+    FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
+            .getSelectedItem());
+    String currentView = selectedFilterOpt.getView();
+    if (currentView == VIEWS_FILTER)
+    {
+      int pdbIdCol = getPDBIdColumIndex(pdbRequest.getWantedFields());
+      int[] selectedRows = tbl_summary.getSelectedRows();
+      PDBEntry[] pdbEntriesToView = new PDBEntry[selectedRows.length];
+      int count = 0;
+      for (int summaryRow : selectedRows)
+      {
+        String pdbIdStr = tbl_summary.getValueAt(summaryRow, pdbIdCol)
+                .toString();
+        PDBEntry pdbEntry = new PDBEntry();
+        pdbEntry.setId(pdbIdStr);
+        pdbEntry.setType("PDB");
+        pdbEntriesToView[count++] = pdbEntry;
+      }
+      new StructureViewer(ap.getStructureSelectionManager())
+              .viewStructures(ap, pdbEntriesToView,
+                      ap.av.collateForPDB(pdbEntriesToView));
+    }
+    else if (currentView == VIEWS_ENTER_ID)
+    {
+      selectedSequence = ((AssociateSeqOptions) idInputAssSeqPanel
+              .getCmb_assSeq().getSelectedItem()).getSequence();
+      PDBEntry pdbEntry = new PDBEntry();
+      pdbEntry.setId(txt_search.getText());
+      pdbEntry.setType("PDB");
+      selectedSequence.getDatasetSequence().addPDBId(pdbEntry);
+      PDBEntry[] pdbEntriesToView = new PDBEntry[]
+      { pdbEntry };
+      new StructureViewer(ap.getStructureSelectionManager())
+              .viewStructures(ap, pdbEntriesToView,
+                      ap.av.collateForPDB(pdbEntriesToView));
+    }
+    else if (currentView == VIEWS_FROM_FILE)
+    {
+      selectedSequence = ((AssociateSeqOptions) fileChooserAssSeqPanel
+              .getCmb_assSeq().getSelectedItem()).getSequence();
+      new AssociatePdbFileWithSeq().associatePdbWithSeq(
+              selectedPdbFileName, jalview.io.AppletFormatAdapter.FILE,
+              selectedSequence, true, Desktop.instance);
+    }
+    mainFrame.dispose();
+  }
+
+  /**
+   * Populates the combo-box used in associating manually fetched structures to
+   * a unique sequence when more than one sequence selection is made.
+   */
+  public void populateCmbAssociateSeqOptions(
+          JComboBox<AssociateSeqOptions> cmb_assSeq)
+  {
+    cmb_assSeq.removeAllItems();
+    cmb_assSeq.addItem(new AssociateSeqOptions("-Select Associated Seq-",
+            null));
+    // cmb_assSeq.addItem(new AssociateSeqOptions("Auto Detect", null));
+    if (selectedSequences.length > 1)
+    {
+      for (SequenceI seq : selectedSequences)
+      {
+        cmb_assSeq.addItem(new AssociateSeqOptions(seq));
+      }
+    }
+    else
+    {
+      cmb_assSeq.setVisible(false);
+    }
+  }
 
   public boolean isStructuresDiscovered()
   {
@@ -476,4 +605,31 @@ public class StructureChooser extends GStructureChooser
   {
     return discoveredStructuresSet;
   }
+
+  @Override
+  protected void txt_search_ActionPerformed()
+  {
+    isValidPBDEntry = false;
+    if (txt_search.getText().length() > 0)
+    {
+      List<PDBDocField> wantedFields = new ArrayList<PDBDocField>();
+      wantedFields.add(PDBDocField.PDB_ID);
+      pdbRequest = new PDBRestRequest();
+      pdbRequest.setAllowEmptySeq(false);
+      pdbRequest.setResponseSize(1);
+      pdbRequest.setFieldToSearchBy("(pdb_id:");
+      pdbRequest.setWantedFields(wantedFields);
+      pdbRequest.setSearchTerm(txt_search.getText() + ")");
+      pdbRequest.setAssociatedSequence(selectedSequence.getName());
+      pdbRestCleint = new PDBRestClient();
+      PDBRestResponse resultList = pdbRestCleint.executeRequest(pdbRequest);
+      if (resultList.getSearchSummary() != null
+              && resultList.getSearchSummary().size() > 0)
+      {
+        isValidPBDEntry = true;
+      }
+    }
+    validateSelections();
+  }
+
 }
index 5593d5c..a236a5a 100644 (file)
@@ -187,6 +187,21 @@ public abstract class GPDBSearchPanel extends JPanel
     Desktop.addInternalFrame(mainFrame, frameTitle, 800, 400);
   }
 
+  public JComboBox<PDBDocField> getCmbSearchTarget()
+  {
+    return cmb_searchTarget;
+  }
+
+  public JTextField getTxtSearch()
+  {
+    return txt_search;
+  }
+
+  public JInternalFrame getMainFrame()
+  {
+    return mainFrame;
+  }
+
   public abstract void txt_search_ActionPerformed();
 
   public abstract void btn_ok_ActionPerformed();
@@ -195,6 +210,6 @@ public abstract class GPDBSearchPanel extends JPanel
 
   public abstract void btn_cancel_ActionPerformed();
 
-  protected abstract void populateCmbSearchTargetOptions();
+  public abstract void populateCmbSearchTargetOptions();
 
 }
index cbd6f1a..080fce9 100644 (file)
 
 package jalview.jbgui;
 
+import jalview.datamodel.SequenceI;
 import jalview.gui.AlignmentPanel;
 import jalview.gui.Desktop;
 import jalview.util.MessageManager;
-import jalview.ws.uimodel.PDBRestResponse.PDBResponseSummary;
 
 import java.awt.BorderLayout;
 import java.awt.CardLayout;
@@ -41,12 +41,12 @@ import javax.swing.JComboBox;
 import javax.swing.JFrame;
 import javax.swing.JInternalFrame;
 import javax.swing.JLabel;
-import javax.swing.JList;
 import javax.swing.JPanel;
 import javax.swing.JScrollPane;
 import javax.swing.JTable;
 import javax.swing.JTextField;
-import javax.swing.ListSelectionModel;
+import javax.swing.event.DocumentEvent;
+import javax.swing.event.DocumentListener;
 
 @SuppressWarnings("serial")
 /**
@@ -64,26 +64,31 @@ public abstract class GStructureChooser extends JPanel implements
 
   protected JComboBox<FilterOption> cmb_filterOption = new JComboBox<FilterOption>();
 
+
   protected AlignmentPanel ap;
 
   protected JLabel lbl_result = new JLabel(
-          MessageManager.getString("label.select") /* "Select : " */);
+          MessageManager.getString("label.select"));
 
-  protected JButton btn_ok = new JButton();
+  protected JButton btn_view = new JButton();
 
   protected JButton btn_cancel = new JButton();
 
   protected JButton btn_pdbFromFile = new JButton();
 
-  protected JTextField txt_search = new JTextField(18);
+  protected JTextField txt_search = new JTextField(14);
 
   private JPanel pnl_actions = new JPanel();
 
   private JPanel pnl_filter = new JPanel();
 
-  private JPanel pnl_idInput = new JPanel();
+  private JPanel pnl_idInput = new JPanel(new FlowLayout());
+
+  private JPanel pnl_fileChooser = new JPanel(new FlowLayout());
+
+  private JPanel pnl_idInputBL = new JPanel(new BorderLayout());
 
-  private JPanel pnl_fileChooser = new JPanel();
+  private JPanel pnl_fileChooserBL = new JPanel(new BorderLayout());
 
   protected JPanel pnl_switchableViews = new JPanel(new CardLayout());
 
@@ -101,15 +106,30 @@ public abstract class GStructureChooser extends JPanel implements
   protected ImageIcon loadingImage = new ImageIcon(getClass().getResource(
           "/images/loading.gif"));
 
+  protected ImageIcon goodImage = new ImageIcon(getClass().getResource(
+          "/images/good.png"));
+
+  protected ImageIcon errorImage = new ImageIcon(getClass().getResource(
+          "/images/error.png"));
+
   protected JLabel lbl_loading = new JLabel(loadingImage);
 
+  protected JLabel lbl_pdbManualFetchStatus = new JLabel(errorImage);
+
+  protected JLabel lbl_fromFileStatus = new JLabel(errorImage);
+
+  protected AssciateSeqPanel idInputAssSeqPanel = new AssciateSeqPanel();
+
+  protected AssciateSeqPanel fileChooserAssSeqPanel = new AssciateSeqPanel();
+
   protected static final String VIEWS_FILTER = "VIEWS_FILTER";
 
   protected static final String VIEWS_FROM_FILE = "VIEWS_FROM_FILE";
 
   protected static final String VIEWS_ENTER_ID = "VIEWS_ENTER_ID";
 
-  protected JList<PDBResponseSummary> jList_FoundStructures = new JList<PDBResponseSummary>();
+  // protected JList<PDBResponseSummary> jList_FoundStructures = new
+  // JList<PDBResponseSummary>();
 
   protected JTable tbl_summary = new JTable();
 
@@ -137,9 +157,9 @@ public abstract class GStructureChooser extends JPanel implements
    */
   private void jbInit() throws Exception
   {
-    btn_ok.setFont(new java.awt.Font("Verdana", 0, 12));
-    btn_ok.setText(MessageManager.getString("action.view"));
-    btn_ok.addActionListener(new java.awt.event.ActionListener()
+    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()
     {
       public void actionPerformed(ActionEvent e)
       {
@@ -158,7 +178,7 @@ public abstract class GStructureChooser extends JPanel implements
 
     btn_pdbFromFile.setFont(new java.awt.Font("Verdana", 0, 12));
     String btn_title = MessageManager.getString("label.select_pdb_file");
-    btn_pdbFromFile.setText("             " + btn_title + "            ");
+    btn_pdbFromFile.setText(btn_title + "              ");
     btn_pdbFromFile.addActionListener(new java.awt.event.ActionListener()
     {
       public void actionPerformed(ActionEvent e)
@@ -167,10 +187,6 @@ public abstract class GStructureChooser extends JPanel implements
       }
     });
 
-    jList_FoundStructures
-            .setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
-    jList_FoundStructures.setLayoutOrientation(JList.VERTICAL);
-    jList_FoundStructures.setVisibleRowCount(-1);
     scrl_foundStructures.setPreferredSize(new Dimension(500, 300));
     scrl_foundStructures
             .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
@@ -183,25 +199,53 @@ public abstract class GStructureChooser extends JPanel implements
     chk_invertFilter.addItemListener(this);
 
     pnl_actions.add(chk_rememberSettings);
-    pnl_actions.add(btn_ok);
+    pnl_actions.add(btn_view);
     pnl_actions.add(btn_cancel);
 
-    pnl_filter.add(lbl_result);
+    // pnl_filter.add(lbl_result);
     pnl_filter.add(cmb_filterOption);
+    pnl_filter.add(lbl_loading);
+    pnl_filter.add(chk_invertFilter);
     lbl_loading.setVisible(false);
 
-    pnl_filter.add(lbl_loading);
+    txt_search.setToolTipText(MessageManager
+            .getString("label.enter_pdb_id"));
+    cmb_filterOption.setToolTipText(MessageManager
+            .getString("info.select_filter_option"));
+    txt_search.getDocument().addDocumentListener(new DocumentListener()
+    {
+      @Override
+      public void insertUpdate(DocumentEvent e)
+      {
+        txt_search_ActionPerformed();
+      }
 
-    pnl_filter.add(chk_invertFilter);
+      @Override
+      public void removeUpdate(DocumentEvent e)
+      {
+        txt_search_ActionPerformed();
+      }
 
-    pnl_idInput.setLayout(new FlowLayout());
+      @Override
+      public void changedUpdate(DocumentEvent e)
+      {
+        txt_search_ActionPerformed();
+      }
+    });
     pnl_idInput.add(txt_search);
+    pnl_idInput.add(lbl_pdbManualFetchStatus);
 
-    pnl_fileChooser.setLayout(new FlowLayout());
     pnl_fileChooser.add(btn_pdbFromFile);
+    pnl_fileChooser.add(lbl_fromFileStatus);
+
+    pnl_fileChooserBL.add(fileChooserAssSeqPanel, BorderLayout.NORTH);
+    pnl_fileChooserBL.add(pnl_fileChooser, BorderLayout.CENTER);
+
+    pnl_idInputBL.add(idInputAssSeqPanel, BorderLayout.NORTH);
+    pnl_idInputBL.add(pnl_idInput, BorderLayout.CENTER);
 
-    pnl_switchableViews.add(pnl_fileChooser, VIEWS_FROM_FILE);
-    pnl_switchableViews.add(pnl_idInput, VIEWS_ENTER_ID);
+    pnl_switchableViews.add(pnl_fileChooserBL, VIEWS_FROM_FILE);
+    pnl_switchableViews.add(pnl_idInputBL, VIEWS_ENTER_ID);
     pnl_switchableViews.add(scrl_foundStructures, VIEWS_FILTER);
     
     this.setLayout(mainLayout);
@@ -282,6 +326,103 @@ public abstract class GStructureChooser extends JPanel implements
     }
   }
 
+  /**
+   * This inner class provides the provides the data model for associate
+   * sequence combo-box - cmb_assSeq
+   * 
+   * @author tcnofoegbu
+   *
+   */
+  public class AssociateSeqOptions
+  {
+    private SequenceI sequence;
+    private String name;
+
+    public AssociateSeqOptions(SequenceI seq)
+    {
+      this.sequence = seq;
+      this.name = (seq.getName().length() >= 23) ? seq.getName().substring(
+              0, 23) : seq.getName();
+    }
+
+    public AssociateSeqOptions(String name, SequenceI seq)
+    {
+      this.name = name;
+      this.sequence = seq;
+    }
+
+    public String toString()
+    {
+      return name;
+    }
+
+    public String getName()
+    {
+      return name;
+    }
+
+    public void setName(String name)
+    {
+      this.name = name;
+    }
+
+    public SequenceI getSequence()
+    {
+      return sequence;
+    }
+
+    public void setSequence(SequenceI sequence)
+    {
+      this.sequence = sequence;
+    }
+
+  }
+
+  /**
+   * This inner class holds the Layout and configuration of the panel which
+   * handles association of manually fetched structures to a unique sequence
+   * when more than one sequence selection is made
+   * 
+   * @author tcnofoegbu
+   *
+   */
+  public class AssciateSeqPanel extends JPanel implements ItemListener
+  {
+    private JComboBox<AssociateSeqOptions> cmb_assSeq = new JComboBox<AssociateSeqOptions>();
+    public AssciateSeqPanel()
+    {
+      this.setLayout(new FlowLayout());
+      this.add(cmb_assSeq);
+      cmb_assSeq.setToolTipText(MessageManager
+              .getString("info.associate_wit_sequence"));
+      cmb_assSeq.addItemListener(this);
+    }
+
+    public void loadCmbAssSeq()
+    {
+      populateCmbAssociateSeqOptions(cmb_assSeq);
+    }
+
+    public JComboBox<AssociateSeqOptions> getCmb_assSeq()
+    {
+      return cmb_assSeq;
+    }
+
+    public void setCmb_assSeq(JComboBox<AssociateSeqOptions> cmb_assSeq)
+    {
+      this.cmb_assSeq = cmb_assSeq;
+    }
+
+    @Override
+    public void itemStateChanged(ItemEvent e)
+    {
+      if (e.getStateChange() == ItemEvent.SELECTED)
+      {
+        cmbAssSeqStateChanged();
+      }
+    }
+  }
+
   public JComboBox<FilterOption> getCmbFilterOption()
   {
     return cmb_filterOption;
@@ -291,9 +432,16 @@ public abstract class GStructureChooser extends JPanel implements
 
   protected abstract void updateCurrentView();
 
-  protected abstract void ok_ActionPerformed();
-
   protected abstract void populateFilterComboBox();
 
+  protected abstract void ok_ActionPerformed();
+
   protected abstract void pdbFromFile_actionPerformed();
+
+  protected abstract void txt_search_ActionPerformed();
+
+  public abstract void populateCmbAssociateSeqOptions(
+          JComboBox<AssociateSeqOptions> cmb_assSeq);
+
+  public abstract void cmbAssSeqStateChanged();
 }
index 356e664..17ba85a 100644 (file)
@@ -1,6 +1,9 @@
 package jalview.gui;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertTrue;
+
+import javax.swing.JInternalFrame;
+import javax.swing.JTextField;
 
 import org.junit.After;
 import org.junit.Before;
@@ -20,9 +23,28 @@ public class PDBSearchPanelTest
   }
 
   @Test
-  public void test()
+  public void populateCmbSearchTargetOptionsTest()
   {
-    fail("Not yet implemented");
+    PDBSearchPanel searchPanel = new PDBSearchPanel(null);
+    assertTrue(searchPanel.getCmbSearchTarget().getItemCount() > 0);
+    searchPanel.populateCmbSearchTargetOptions();
   }
 
+  @Test
+  public void txt_search_ActionPerformedTest()
+  {
+    PDBSearchPanel searchPanel = new PDBSearchPanel(null);
+    JInternalFrame mainFrame = searchPanel.getMainFrame();
+    JTextField txt_search = searchPanel.getTxtSearch();
+
+    assertTrue(mainFrame.getTitle().length() == 20);
+    assertTrue(mainFrame.getTitle()
+            .equalsIgnoreCase("PDB Sequence Fetcher"));
+
+    txt_search.setText("ABC");
+
+    assertTrue(mainFrame.getTitle().length() > 20);
+    assertTrue(!mainFrame.getTitle().equalsIgnoreCase(
+            "PDB Sequence Fetcher"));
+  }
 }