Created 3Dbeacons data_columns.txt Test passed for data columns
[jalview.git] / src / jalview / fts / core / FTSRestResponse.java
index c56b8c8..a5c8705 100644 (file)
 
 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;
@@ -39,6 +41,8 @@ import javax.swing.table.DefaultTableModel;
 public class FTSRestResponse
 {
   private int numberOfItemsFound;
+  
+  private int sequenceLength;
 
   private String responseTime;
 
@@ -73,6 +77,14 @@ public class FTSRestResponse
   {
     this.searchSummary = searchSummary;
   }
+  
+  public int getSequenceLength() {
+    return sequenceLength;
+  }
+  
+  public void setSequenceLength(int sequenceLength) {
+    this.sequenceLength = sequenceLength;
+  }
 
   /**
    * Convenience method to obtain a Table model for a given summary List based
@@ -105,9 +117,10 @@ public class FTSRestResponse
       {
         if (colOffset == 1 && columnIndex == 0)
         {
-          return String.class;
+          return SequenceI.class;
         }
-        return cols[columnIndex - colOffset].getDataColumnClass();
+        return cols[columnIndex - colOffset].getDataType()
+                .getDataTypeClass();
       }
 
     };
@@ -116,8 +129,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
@@ -133,32 +145,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);
+      }
     }
   }
 
-
 }