JAL-2045 JAL-2047 improvement for sorting PDB quality measure numerically, and improv...
authortcofoegbu <tcnofoegbu@dundee.ac.uk>
Fri, 1 Apr 2016 10:07:14 +0000 (11:07 +0100)
committertcofoegbu <tcnofoegbu@dundee.ac.uk>
Fri, 1 Apr 2016 10:07:14 +0000 (11:07 +0100)
src/jalview/gui/PDBSearchPanel.java
src/jalview/gui/StructureChooser.java
src/jalview/jbgui/GPDBSearchPanel.java
src/jalview/jbgui/GStructureChooser.java
src/jalview/jbgui/PDBDocFieldPreferences.java
src/jalview/ws/uimodel/PDBRestResponse.java

index a228c67..9b94c27 100644 (file)
@@ -110,11 +110,10 @@ public class PDBSearchPanel extends GPDBSearchPanel
           {
             tbl_summary.setModel(PDBRestResponse.getTableModel(request,
                     resultList.getSearchSummary()));
-            // request.ge
-            // TableRowSorter<TableModel> sorter = new TableRowSorter<>(
-            // tbl_pdbDocFieldConfig.getModel());
           }
 
+          PDBRestResponse.configureTableColumn(tbl_summary, wantedFields);
+
           long endTime = System.currentTimeMillis();
           int resultSetCount = resultList.getNumberOfItemsFound();
           String result = (resultSetCount > 1) ? MessageManager
index 89ba84b..f38f267 100644 (file)
@@ -458,6 +458,10 @@ public class StructureChooser extends GStructureChooser implements
           tbl_summary.setModel(PDBRestResponse.getTableModel(
                   lastPdbRequest, reorderedStructuresSet));
 
+          PDBRestResponse.configureTableColumn(tbl_summary, wantedFields);
+          tbl_summary.getColumn("Ref Sequence").setPreferredWidth(120);
+          tbl_summary.getColumn("Ref Sequence").setMinWidth(100);
+          tbl_summary.getColumn("Ref Sequence").setMaxWidth(200);
           // Update table selection model here
           tbl_summary.addRowSelectionInterval(0, filterResponseCount - 1);
           mainFrame.setTitle(MessageManager.formatMessage(
index 1ee4158..d640df8 100644 (file)
@@ -90,7 +90,12 @@ public abstract class GPDBSearchPanel extends JPanel
 
       try
       {
+        if (getValueAt(rowIndex, colIndex) == null)
+        {
+          return null;
+        }
         toolTipText = getValueAt(rowIndex, colIndex).toString();
+
       } catch (Exception e)
       {
         e.printStackTrace();
@@ -158,6 +163,7 @@ public abstract class GPDBSearchPanel extends JPanel
     lbl_loading.setVisible(false);
     lbl_loading.setFont(new java.awt.Font("Verdana", 0, 12));
 
+    tbl_summary.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
     tbl_summary.setAutoCreateRowSorter(true);
     tbl_summary.getTableHeader().setReorderingAllowed(false);
     tbl_summary.addMouseListener(new MouseAdapter()
index efc3062..8430557 100644 (file)
@@ -169,6 +169,10 @@ public abstract class GStructureChooser extends JPanel implements
 
       try
       {
+        if (getValueAt(rowIndex, colIndex) == null)
+        {
+          return null;
+        }
         toolTipText = getValueAt(rowIndex, colIndex).toString();
       } catch (Exception e)
       {
index da67196..e33cf01 100644 (file)
@@ -64,9 +64,11 @@ public class PDBDocFieldPreferences extends JScrollPane
   {
     searchSummaryFields.add(PDBDocField.PDB_ID);
     searchSummaryFields.add(PDBDocField.TITLE);
+    searchSummaryFields.add(PDBDocField.RESOLUTION);
 
     structureSummaryFields.add(PDBDocField.PDB_ID);
     structureSummaryFields.add(PDBDocField.TITLE);
+    structureSummaryFields.add(PDBDocField.RESOLUTION);
   }
 
   public PDBDocFieldPreferences(PreferenceSource source)
@@ -128,20 +130,21 @@ public class PDBDocFieldPreferences extends JScrollPane
     PDBFieldTableModel model = new PDBFieldTableModel(columnNames, data);
     tbl_pdbDocFieldConfig.setModel(model);
 
-    // DefaultTableCellRenderer rightRenderer = new DefaultTableCellRenderer();
-    // rightRenderer.setHorizontalAlignment(SwingConstants.LEFT);
-    // tbl_pdbDocFieldConfig.getColumn("Show in structure summary")
-    // .setCellRenderer(rightRenderer);
     switch (source)
     {
     case SEARCH_SUMMARY:
     case STRUCTURE_CHOOSER:
       tbl_pdbDocFieldConfig.getColumnModel().getColumn(0)
-              .setPreferredWidth(5);
+              .setPreferredWidth(30);
+      tbl_pdbDocFieldConfig.getColumnModel().getColumn(0).setMinWidth(20);
+      tbl_pdbDocFieldConfig.getColumnModel().getColumn(0).setMaxWidth(40);
       tbl_pdbDocFieldConfig.getColumnModel().getColumn(1)
-              .setPreferredWidth(195);
+              .setPreferredWidth(150);
+      tbl_pdbDocFieldConfig.getColumnModel().getColumn(1).setMinWidth(150);
       tbl_pdbDocFieldConfig.getColumnModel().getColumn(2)
-              .setPreferredWidth(200);
+              .setPreferredWidth(150);
+      tbl_pdbDocFieldConfig.getColumnModel().getColumn(2)
+.setMinWidth(150);
 
       TableRowSorter<TableModel> sorter = new TableRowSorter<>(
               tbl_pdbDocFieldConfig.getModel());
@@ -162,13 +165,15 @@ public class PDBDocFieldPreferences extends JScrollPane
                 }
               });
       sorter.sort();
+
+      tbl_pdbDocFieldConfig
+              .setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
       break;
     case PREFERENCES:
     default:
       break;
     }
 
-
   }
 
   public static Collection<PDBDocField> getSearchSummaryFields()
index bbd5e84..2a38b39 100644 (file)
@@ -23,10 +23,12 @@ package jalview.ws.uimodel;
 
 import jalview.datamodel.SequenceI;
 import jalview.ws.dbsources.PDBRestClient.PDBDocField;
+import jalview.ws.dbsources.PDBRestClient.PDBDocField.Group;
 
 import java.util.Collection;
 import java.util.Objects;
 
+import javax.swing.JTable;
 import javax.swing.table.DefaultTableModel;
 
 import org.json.simple.JSONObject;
@@ -91,6 +93,9 @@ public class PDBRestResponse
   public static DefaultTableModel getTableModel(PDBRestRequest request,
           Collection<PDBResponseSummary> summariesList)
   {
+    final PDBDocField[] cols = request.getWantedFields().toArray(
+            new PDBDocField[0]);
+    final int colOffset = request.getAssociatedSequence() == null ? 0 : 1;
     DefaultTableModel tableModel = new DefaultTableModel()
     {
       @Override
@@ -98,6 +103,22 @@ public class PDBRestResponse
       {
         return false;
       }
+
+      @Override
+      public Class<?> getColumnClass(int columnIndex)
+      {
+        if (colOffset == 1 && columnIndex == 0)
+        {
+          return String.class;
+        }
+        if (cols[columnIndex - colOffset].getGroup().getName()
+                .equalsIgnoreCase(Group.QUALITY_MEASURES.getName()))
+        {
+          return Double.class;
+        }
+        return String.class;
+      }
+
     };
     if (request.getAssociatedSequence() != null)
     {
@@ -156,12 +177,34 @@ public class PDBRestResponse
         }
         else
         {
-          summaryRowData[colCounter++] = fieldData;
+          if (field.getGroup().getName()
+                  .equals(Group.QUALITY_MEASURES.getName()))
+          {
+            try
+            {
+              if (fieldData == null || fieldData.isEmpty())
+              {
+                summaryRowData[colCounter++] = null;
+              }
+              else
+              {
+              Double value = Double.valueOf(fieldData);
+              summaryRowData[colCounter++] = value;
+              }
+            } catch (Exception e)
+            {
+              e.printStackTrace();
+              System.out.println("offending value:" + fieldData);
+              summaryRowData[colCounter++] = 0.0;
+            }
+          }else{
+            summaryRowData[colCounter++] = fieldData;
+          }
         }
       }
     }
 
-    public String getPdbId()
+    public Object getPdbId()
     {
       return pdbId;
     }
@@ -176,7 +219,7 @@ public class PDBRestResponse
       return summaryRowData;
     }
 
-    public void setSummaryData(String[] summaryData)
+    public void setSummaryData(Object[] summaryData)
     {
       this.summaryRowData = summaryData;
     }
@@ -190,7 +233,9 @@ public class PDBRestResponse
       StringBuilder summaryFieldValues = new StringBuilder();
       for (Object summaryField : summaryRowData)
       {
-        summaryFieldValues.append(summaryField.toString()).append("\t");
+        summaryFieldValues.append(
+                summaryField == null ? " " : summaryField.toString())
+                .append("\t");
       }
       return summaryFieldValues.toString();
     }
@@ -220,4 +265,35 @@ public class PDBRestResponse
 
   }
 
+  public static void configureTableColumn(JTable tbl_summary,
+          Collection<PDBDocField> wantedFields)
+  {
+    for (PDBDocField wantedField : wantedFields)
+    {
+      if (wantedField.equals(PDBDocField.PDB_ID))
+      {
+        tbl_summary.getColumn(wantedField.getName()).setMinWidth(40);
+        tbl_summary.getColumn(wantedField.getName()).setMaxWidth(60);
+        tbl_summary.getColumn(wantedField.getName()).setPreferredWidth(45);
+      }
+      else if (wantedField.equals(PDBDocField.TITLE))
+      {
+        tbl_summary.getColumn(wantedField.getName()).setMinWidth(300);
+        tbl_summary.getColumn(wantedField.getName()).setMaxWidth(1000);
+        tbl_summary.getColumn(wantedField.getName()).setPreferredWidth(400);
+      }
+      else if (wantedField.getGroup() == Group.QUALITY_MEASURES)
+      {
+        tbl_summary.getColumn(wantedField.getName()).setMinWidth(50);
+        tbl_summary.getColumn(wantedField.getName()).setMaxWidth(150);
+        tbl_summary.getColumn(wantedField.getName()).setPreferredWidth(85);
+      }
+      else
+      {
+        tbl_summary.getColumn(wantedField.getName()).setMinWidth(50);
+        tbl_summary.getColumn(wantedField.getName()).setMaxWidth(400);
+        tbl_summary.getColumn(wantedField.getName()).setPreferredWidth(95);
+      }
+    }
+  }
 }