JAL-1715 implemented selection validation for the new PDB Query interface
authortcofoegbu <tcnofoegbu@dundee.ac.uk>
Mon, 27 Apr 2015 16:00:33 +0000 (17:00 +0100)
committertcofoegbu <tcnofoegbu@dundee.ac.uk>
Mon, 27 Apr 2015 16:00:33 +0000 (17:00 +0100)
src/jalview/gui/PDBSearchPanel.java
src/jalview/jbgui/GPDBSearchPanel.java

index 514406a..7762605 100644 (file)
@@ -33,6 +33,7 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
+import java.util.HashSet;
 import java.util.List;
 
 import javax.swing.table.DefaultTableModel;
@@ -60,6 +61,7 @@ public class PDBSearchPanel extends GPDBSearchPanel
   @Override
   public void txt_search_ActionPerformed()
   {
+    btn_ok.setEnabled(false);
     boolean allowEmptySequence = false;
     mainFrame.setTitle(MessageManager
             .getString("label.pdb_sequence_getcher"));
@@ -165,20 +167,24 @@ public class PDBSearchPanel extends GPDBSearchPanel
   {
     mainFrame.dispose();
     StringBuilder selectedIds = new StringBuilder();
+    HashSet<String> selectedIdsSet = new HashSet<String>();
     int pdbIdCol = PDBRestClient.getPDBIdColumIndex(wantedFields, false);
     int[] selectedRows = tbl_summary.getSelectedRows();
     for (int summaryRow : selectedRows)
     {
       String pdbIdStr = tbl_summary.getValueAt(summaryRow, pdbIdCol)
               .toString();
-
       String searchTerm = txt_search.getText();
-      selectedIds.append(getPDBIdwithSpecifiedChain(pdbIdStr, searchTerm))
-              .append(";");
+      selectedIdsSet.add(getPDBIdwithSpecifiedChain(pdbIdStr, searchTerm));
+    }
+
+    for (String selectedId : selectedIdsSet)
+    {
+      selectedIds.append(selectedId).append(";");
     }
 
     String ids = selectedIds.toString();
-    // System.out.println(">>>>>>>>>>>>>>>> selected Ids: " + ids);
+    System.out.println(">>>>>>>>>>>>>>>> selected Ids: " + ids);
     seqFetcher.textArea.setText(ids);
     Thread worker = new Thread(seqFetcher);
     worker.start();
index 29a0014..e74f0ef 100644 (file)
@@ -30,6 +30,8 @@ import java.awt.BorderLayout;
 import java.awt.Dimension;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
 
 import javax.swing.JButton;
 import javax.swing.JComboBox;
@@ -108,6 +110,21 @@ tbl_summary);
   private void jbInit() throws Exception
   {
     tbl_summary.setAutoCreateRowSorter(true);
+    tbl_summary.addMouseListener(new MouseAdapter()
+    {
+      public void mouseClicked(MouseEvent e)
+      {
+        if (tbl_summary.getSelectedRows().length > 0)
+        {
+          btn_ok.setEnabled(true);
+        }
+        else
+        {
+          btn_ok.setEnabled(false);
+        }
+      }
+    });
+
     btn_back.setFont(new java.awt.Font("Verdana", 0, 12));
     btn_back.setText(MessageManager.getString("action.back"));
     btn_back.addActionListener(new java.awt.event.ActionListener()
@@ -117,6 +134,8 @@ tbl_summary);
         btn_back_ActionPerformed();
       }
     });
+
+    btn_ok.setEnabled(false);
     btn_ok.setFont(new java.awt.Font("Verdana", 0, 12));
     btn_ok.setText(MessageManager.getString("action.ok"));
     btn_ok.addActionListener(new java.awt.event.ActionListener()
@@ -136,6 +155,7 @@ tbl_summary);
       }
     });
 
+
     scrl_searchResult.setPreferredSize(new Dimension(500, 300));
     scrl_searchResult
             .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);