2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
22 package jalview.fts.core;
24 import jalview.fts.api.FTSData;
25 import jalview.fts.api.FTSDataColumnI;
27 import java.util.Collection;
30 import javax.swing.JTable;
31 import javax.swing.table.DefaultTableModel;
34 * Represents the response model generated by the FTSRestClient upon successful
35 * execution of a given FTS request
40 public class FTSRestResponse
42 private int numberOfItemsFound;
44 private String responseTime;
46 private Collection<FTSData> searchSummary;
48 public int getNumberOfItemsFound()
50 return numberOfItemsFound;
53 public void setNumberOfItemsFound(int itemFound)
55 this.numberOfItemsFound = itemFound;
58 public String getResponseTime()
63 public void setResponseTime(String responseTime)
65 this.responseTime = responseTime;
68 public Collection<FTSData> getSearchSummary()
73 public void setSearchSummary(Collection<FTSData> searchSummary)
75 this.searchSummary = searchSummary;
79 * Convenience method to obtain a Table model for a given summary List based
80 * on the request parameters
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
88 * @return the table model which was dynamically generated
90 public static DefaultTableModel getTableModel(FTSRestRequest request,
91 Collection<FTSData> summariesList)
93 final FTSDataColumnI[] cols = request.getWantedFields()
94 .toArray(new FTSDataColumnI[0]);
95 final int colOffset = request.getAssociatedSequence() == null ? 0 : 1;
96 DefaultTableModel tableModel = new DefaultTableModel()
99 public boolean isCellEditable(int row, int column)
105 public Class<?> getColumnClass(int columnIndex)
107 if (colOffset == 1 && columnIndex == 0)
111 return cols[columnIndex - colOffset].getDataType()
116 if (request.getAssociatedSequence() != null)
118 tableModel.addColumn("Ref Sequence"); // Create sequence column header if
119 // exists in the request
121 for (FTSDataColumnI field : request.getWantedFields())
123 tableModel.addColumn(field.getName()); // Create sequence column header if
124 // exists in the request
127 for (FTSData res : summariesList)
129 tableModel.addRow(res.getSummaryData()); // Populate table rows with
136 public static void configureTableColumn(JTable tbl_summary,
137 Collection<FTSDataColumnI> wantedFields,
138 Map<String, Integer> columnPrefs)
140 for (FTSDataColumnI wantedField : wantedFields)
144 tbl_summary.getColumn(wantedField.getName())
145 .setMinWidth(wantedField.getMinWidth());
146 tbl_summary.getColumn(wantedField.getName())
147 .setMaxWidth(wantedField.getMaxWidth());
148 int prefedWidth = columnPrefs.get(wantedField.getName()) == null
149 ? wantedField.getPreferredWidth()
150 : columnPrefs.get(wantedField.getName());
151 tbl_summary.getColumn(wantedField.getName())
152 .setPreferredWidth(prefedWidth);
153 } catch (Exception e)
157 if (wantedField.getDataType().getDataTypeClass() == Double.class)
159 DecimalFormatTableCellRenderer dfr = new DecimalFormatTableCellRenderer(
160 wantedField.getDataType().isFormtted(),
161 wantedField.getDataType().getSignificantFigures());
162 tbl_summary.getColumn(wantedField.getName()).setCellRenderer(dfr);
164 else if (wantedField.getDataType()
165 .getDataTypeClass() == Integer.class)
167 DecimalFormatTableCellRenderer dfr = new DecimalFormatTableCellRenderer(
168 wantedField.getDataType().isFormtted(),
169 wantedField.getDataType().getSignificantFigures());
170 tbl_summary.getColumn(wantedField.getName()).setCellRenderer(dfr);