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.datamodel.SequenceI;
25 import jalview.fts.api.FTSData;
26 import jalview.fts.api.FTSDataColumnI;
28 import java.util.Collection;
31 import javax.swing.JTable;
32 import javax.swing.table.DefaultTableModel;
35 * Represents the response model generated by the FTSRestClient upon successful
36 * execution of a given FTS request
41 public class FTSRestResponse
43 private int numberOfItemsFound;
45 private String responseTime;
47 private Collection<FTSData> searchSummary;
49 public int getNumberOfItemsFound()
51 return numberOfItemsFound;
54 public void setNumberOfItemsFound(int itemFound)
56 this.numberOfItemsFound = itemFound;
59 public String getResponseTime()
64 public void setResponseTime(String responseTime)
66 this.responseTime = responseTime;
69 public Collection<FTSData> getSearchSummary()
74 public void setSearchSummary(Collection<FTSData> searchSummary)
76 this.searchSummary = searchSummary;
80 * Convenience method to obtain a Table model for a given summary List based
81 * on the request parameters
84 * the FTSRestRequest object which holds useful information for
85 * creating a table model
86 * @param summariesList
87 * the summary list which contains the data for populating the
89 * @return the table model which was dynamically generated
91 public static DefaultTableModel getTableModel(FTSRestRequest request,
92 Collection<FTSData> summariesList)
94 final FTSDataColumnI[] cols = request.getWantedFields()
95 .toArray(new FTSDataColumnI[0]);
96 final int colOffset = request.getAssociatedSequence() == null ? 0 : 1;
97 DefaultTableModel tableModel = new DefaultTableModel()
100 public boolean isCellEditable(int row, int column)
106 public Class<?> getColumnClass(int columnIndex)
108 if (colOffset == 1 && columnIndex == 0)
110 return SequenceI.class;
112 return cols[columnIndex - colOffset].getDataType()
117 if (request.getAssociatedSequence() != null)
119 tableModel.addColumn("Ref Sequence"); // Create sequence column header if
120 // exists in the request
122 for (FTSDataColumnI field : request.getWantedFields())
124 tableModel.addColumn(field.getName()); // Create sequence column header if
125 // exists in the request
128 for (FTSData res : summariesList)
130 tableModel.addRow(res.getSummaryData()); // Populate table rows with
137 public static void configureTableColumn(JTable tbl_summary,
138 Collection<FTSDataColumnI> wantedFields,
139 Map<String, Integer> columnPrefs)
141 for (FTSDataColumnI wantedField : wantedFields)
145 tbl_summary.getColumn(wantedField.getName())
146 .setMinWidth(wantedField.getMinWidth());
147 tbl_summary.getColumn(wantedField.getName())
148 .setMaxWidth(wantedField.getMaxWidth());
149 int prefedWidth = columnPrefs.get(wantedField.getName()) == null
150 ? wantedField.getPreferredWidth()
151 : columnPrefs.get(wantedField.getName());
152 tbl_summary.getColumn(wantedField.getName())
153 .setPreferredWidth(prefedWidth);
154 } catch (Exception e)
158 if (wantedField.getDataType().getDataTypeClass() == Double.class)
160 DecimalFormatTableCellRenderer dfr = new DecimalFormatTableCellRenderer(
161 wantedField.getDataType().isFormtted(),
162 wantedField.getDataType().getSignificantFigures());
163 tbl_summary.getColumn(wantedField.getName()).setCellRenderer(dfr);
165 else if (wantedField.getDataType()
166 .getDataTypeClass() == Integer.class)
168 DecimalFormatTableCellRenderer dfr = new DecimalFormatTableCellRenderer(
169 wantedField.getDataType().isFormtted(),
170 wantedField.getDataType().getSignificantFigures());
171 tbl_summary.getColumn(wantedField.getName()).setCellRenderer(dfr);