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;
29 import javax.swing.JTable;
30 import javax.swing.table.DefaultTableModel;
33 * Represents the response model generated by the FTSRestClient upon successful
34 * execution of a given FTS request
39 public class FTSRestResponse
41 private int numberOfItemsFound;
43 private String responseTime;
45 private Collection<FTSData> searchSummary;
47 public int getNumberOfItemsFound()
49 return numberOfItemsFound;
52 public void setNumberOfItemsFound(int itemFound)
54 this.numberOfItemsFound = itemFound;
57 public String getResponseTime()
62 public void setResponseTime(String responseTime)
64 this.responseTime = responseTime;
67 public Collection<FTSData> getSearchSummary()
72 public void setSearchSummary(Collection<FTSData> searchSummary)
74 this.searchSummary = searchSummary;
78 * Convenience method to obtain a Table model for a given summary List based
79 * on the request parameters
82 * the FTSRestRequest object which holds useful information for
83 * creating a table model
84 * @param summariesList
85 * the summary list which contains the data for populating the
87 * @return the table model which was dynamically generated
89 public static DefaultTableModel getTableModel(FTSRestRequest request,
90 Collection<FTSData> summariesList)
92 final FTSDataColumnI[] cols = request.getWantedFields()
93 .toArray(new FTSDataColumnI[0]);
94 final int colOffset = request.getAssociatedSequence() == null ? 0 : 1;
95 DefaultTableModel tableModel = new DefaultTableModel()
98 public boolean isCellEditable(int row, int column)
104 public Class<?> getColumnClass(int columnIndex)
106 if (colOffset == 1 && columnIndex == 0)
110 return cols[columnIndex - colOffset].getDataType()
115 if (request.getAssociatedSequence() != null)
117 tableModel.addColumn("Ref Sequence"); // Create sequence column header if
118 // exists in the request
120 for (FTSDataColumnI field : request
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)
139 for (FTSDataColumnI wantedField : wantedFields)
143 tbl_summary.getColumn(wantedField.getName()).setMinWidth(
144 wantedField.getMinWidth());
145 tbl_summary.getColumn(wantedField.getName()).setMaxWidth(
146 wantedField.getMaxWidth());
147 tbl_summary.getColumn(wantedField.getName()).setPreferredWidth(
148 wantedField.getPreferredWidth());
149 } catch (Exception e)
153 if (wantedField.getDataType().getDataTypeClass() == Double.class)
155 DecimalFormatTableCellRenderer dfr = new DecimalFormatTableCellRenderer(
156 wantedField.getDataType().isFormtted(),
157 wantedField.getDataType().getSignificantFigures());
158 tbl_summary.getColumn(wantedField.getName()).setCellRenderer(dfr);
160 else if (wantedField.getDataType().getDataTypeClass() == Integer.class)
162 DecimalFormatTableCellRenderer dfr = new DecimalFormatTableCellRenderer(
163 wantedField.getDataType().isFormtted(),
164 wantedField.getDataType().getSignificantFigures());
165 tbl_summary.getColumn(wantedField.getName()).setCellRenderer(dfr);