JAL-3388 correct class for column 0 Ref Sequence
[jalview.git] / src / jalview / fts / core / FTSRestResponse.java
index 17204d7..597bb89 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
- * Copyright (C) 2014 The Jalview Authors
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
  * 
  * This file is part of Jalview.
  * 
 
 package jalview.fts.core;
 
+import jalview.datamodel.SequenceI;
 import jalview.fts.api.FTSData;
 import jalview.fts.api.FTSDataColumnI;
 
 import java.util.Collection;
+import java.util.Map;
 
 import javax.swing.JTable;
 import javax.swing.table.DefaultTableModel;
 
 /**
- * Represents the response model produced by the PDBRestClient upon successful
- * execution of a given request
+ * Represents the response model generated by the FTSRestClient upon successful
+ * execution of a given FTS request
  * 
  * @author tcnofoegbu
  *
@@ -79,7 +81,7 @@ public class FTSRestResponse
    * on the request parameters
    * 
    * @param request
-   *          the PDBRestRequest object which holds useful information for
+   *          the FTSRestRequest object which holds useful information for
    *          creating a table model
    * @param summariesList
    *          the summary list which contains the data for populating the
@@ -105,14 +107,10 @@ public class FTSRestResponse
       {
         if (colOffset == 1 && columnIndex == 0)
         {
-          return String.class;
+          return SequenceI.class;
         }
-        if (cols[columnIndex - colOffset].getGroup().getName()
-                .equalsIgnoreCase("Quality Measures"))
-        {
-          return Double.class;
-        }
-        return String.class;
+        return cols[columnIndex - colOffset].getDataType()
+                .getDataTypeClass();
       }
 
     };
@@ -121,8 +119,7 @@ public class FTSRestResponse
       tableModel.addColumn("Ref Sequence"); // Create sequence column header if
       // exists in the request
     }
-    for (FTSDataColumnI field : request
-            .getWantedFields())
+    for (FTSDataColumnI field : request.getWantedFields())
     {
       tableModel.addColumn(field.getName()); // Create sequence column header if
                                              // exists in the request
@@ -138,32 +135,42 @@ public class FTSRestResponse
   }
 
   public static void configureTableColumn(JTable tbl_summary,
-          Collection<FTSDataColumnI> wantedFields)
+          Collection<FTSDataColumnI> wantedFields,
+          Map<String, Integer> columnPrefs)
   {
-    try
-    {
-      // wait for table model initialisation to complete
-      Thread.sleep(1200);
-    } catch (InterruptedException e1)
-    {
-      e1.printStackTrace();
-    }
     for (FTSDataColumnI wantedField : wantedFields)
     {
       try
       {
-        tbl_summary.getColumn(wantedField.getName()).setMinWidth(
-                wantedField.getMinWidth());
-        tbl_summary.getColumn(wantedField.getName()).setMaxWidth(
-                wantedField.getMaxWidth());
-        tbl_summary.getColumn(wantedField.getName()).setPreferredWidth(
-                wantedField.getPreferredWidth());
+        tbl_summary.getColumn(wantedField.getName())
+                .setMinWidth(wantedField.getMinWidth());
+        tbl_summary.getColumn(wantedField.getName())
+                .setMaxWidth(wantedField.getMaxWidth());
+        int prefedWidth = columnPrefs.get(wantedField.getName()) == null
+                ? wantedField.getPreferredWidth()
+                : columnPrefs.get(wantedField.getName());
+        tbl_summary.getColumn(wantedField.getName())
+                .setPreferredWidth(prefedWidth);
       } catch (Exception e)
       {
         e.printStackTrace();
       }
+      if (wantedField.getDataType().getDataTypeClass() == Double.class)
+      {
+        DecimalFormatTableCellRenderer dfr = new DecimalFormatTableCellRenderer(
+                wantedField.getDataType().isFormtted(),
+                wantedField.getDataType().getSignificantFigures());
+        tbl_summary.getColumn(wantedField.getName()).setCellRenderer(dfr);
+      }
+      else if (wantedField.getDataType()
+              .getDataTypeClass() == Integer.class)
+      {
+        DecimalFormatTableCellRenderer dfr = new DecimalFormatTableCellRenderer(
+                wantedField.getDataType().isFormtted(),
+                wantedField.getDataType().getSignificantFigures());
+        tbl_summary.getColumn(wantedField.getName()).setCellRenderer(dfr);
+      }
     }
   }
 
-
 }