Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.fts.core

File FTSRestResponse.java

 

Coverage histogram

../../../img/srcFileCovDistChart0.png
56% of files have more coverage

Code metrics

12
33
10
1
175
113
18
0.55
3.3
10
1.8

Classes

Class Line # Actions
FTSRestResponse 40 33 18 55
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
7    * Jalview is free software: you can redistribute it and/or
8    * modify it under the terms of the GNU General Public License
9    * as published by the Free Software Foundation, either version 3
10    * of the License, or (at your option) any later version.
11    *
12    * Jalview is distributed in the hope that it will be useful, but
13    * WITHOUT ANY WARRANTY; without even the implied warranty
14    * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    * PURPOSE. See the GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU General Public License
18    * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19    * The Jalview Authors are detailed in the 'AUTHORS' file.
20    */
21   
22    package jalview.fts.core;
23   
24    import jalview.fts.api.FTSData;
25    import jalview.fts.api.FTSDataColumnI;
26   
27    import java.util.Collection;
28    import java.util.Map;
29   
30    import javax.swing.JTable;
31    import javax.swing.table.DefaultTableModel;
32   
33    /**
34    * Represents the response model generated by the FTSRestClient upon successful
35    * execution of a given FTS request
36    *
37    * @author tcnofoegbu
38    *
39    */
 
40    public class FTSRestResponse
41    {
42    private int numberOfItemsFound;
43   
44    private String responseTime;
45   
46    private Collection<FTSData> searchSummary;
47   
 
48  0 toggle public int getNumberOfItemsFound()
49    {
50  0 return numberOfItemsFound;
51    }
52   
 
53  0 toggle public void setNumberOfItemsFound(int itemFound)
54    {
55  0 this.numberOfItemsFound = itemFound;
56    }
57   
 
58  0 toggle public String getResponseTime()
59    {
60  0 return responseTime;
61    }
62   
 
63  0 toggle public void setResponseTime(String responseTime)
64    {
65  0 this.responseTime = responseTime;
66    }
67   
 
68  0 toggle public Collection<FTSData> getSearchSummary()
69    {
70  0 return searchSummary;
71    }
72   
 
73  0 toggle public void setSearchSummary(Collection<FTSData> searchSummary)
74    {
75  0 this.searchSummary = searchSummary;
76    }
77   
78    /**
79    * Convenience method to obtain a Table model for a given summary List based
80    * on the request parameters
81    *
82    * @param request
83    * the FTSRestRequest object which holds useful information for
84    * creating a table model
85    * @param summariesList
86    * the summary list which contains the data for populating the
87    * table's rows
88    * @return the table model which was dynamically generated
89    */
 
90  0 toggle public static DefaultTableModel getTableModel(FTSRestRequest request,
91    Collection<FTSData> summariesList)
92    {
93  0 final FTSDataColumnI[] cols = request.getWantedFields()
94    .toArray(new FTSDataColumnI[0]);
95  0 final int colOffset = request.getAssociatedSequence() == null ? 0 : 1;
96  0 DefaultTableModel tableModel = new DefaultTableModel()
97    {
 
98  0 toggle @Override
99    public boolean isCellEditable(int row, int column)
100    {
101  0 return false;
102    }
103   
 
104  0 toggle @Override
105    public Class<?> getColumnClass(int columnIndex)
106    {
107  0 if (colOffset == 1 && columnIndex == 0)
108    {
109  0 return String.class;
110    }
111  0 return cols[columnIndex - colOffset].getDataType()
112    .getDataTypeClass();
113    }
114   
115    };
116  0 if (request.getAssociatedSequence() != null)
117    {
118  0 tableModel.addColumn("Ref Sequence"); // Create sequence column header if
119    // exists in the request
120    }
121  0 for (FTSDataColumnI field : request.getWantedFields())
122    {
123  0 tableModel.addColumn(field.getName()); // Create sequence column header if
124    // exists in the request
125    }
126   
127  0 for (FTSData res : summariesList)
128    {
129  0 tableModel.addRow(res.getSummaryData()); // Populate table rows with
130    // summary list
131    }
132   
133  0 return tableModel;
134    }
135   
 
136  0 toggle public static void configureTableColumn(JTable tbl_summary,
137    Collection<FTSDataColumnI> wantedFields,
138    Map<String, Integer> columnPrefs)
139    {
140  0 for (FTSDataColumnI wantedField : wantedFields)
141    {
142  0 try
143    {
144  0 tbl_summary.getColumn(wantedField.getName())
145    .setMinWidth(wantedField.getMinWidth());
146  0 tbl_summary.getColumn(wantedField.getName())
147    .setMaxWidth(wantedField.getMaxWidth());
148  0 int prefedWidth = columnPrefs.get(wantedField.getName()) == null
149    ? wantedField.getPreferredWidth()
150    : columnPrefs.get(wantedField.getName());
151  0 tbl_summary.getColumn(wantedField.getName())
152    .setPreferredWidth(prefedWidth);
153    } catch (Exception e)
154    {
155  0 e.printStackTrace();
156    }
157  0 if (wantedField.getDataType().getDataTypeClass() == Double.class)
158    {
159  0 DecimalFormatTableCellRenderer dfr = new DecimalFormatTableCellRenderer(
160    wantedField.getDataType().isFormtted(),
161    wantedField.getDataType().getSignificantFigures());
162  0 tbl_summary.getColumn(wantedField.getName()).setCellRenderer(dfr);
163    }
164  0 else if (wantedField.getDataType()
165    .getDataTypeClass() == Integer.class)
166    {
167  0 DecimalFormatTableCellRenderer dfr = new DecimalFormatTableCellRenderer(
168    wantedField.getDataType().isFormtted(),
169    wantedField.getDataType().getSignificantFigures());
170  0 tbl_summary.getColumn(wantedField.getName()).setCellRenderer(dfr);
171    }
172    }
173    }
174   
175    }