package jalview.fts.core;
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;
/**
* Represents the response model generated by the FTSRestClient upon successful
this.searchSummary = searchSummary;
}
- /**
- * Convenience method to obtain a Table model for a given summary List based
- * on the request parameters
- *
- * @param request
- * the FTSRestRequest object which holds useful information for
- * creating a table model
- * @param summariesList
- * the summary list which contains the data for populating the
- * table's rows
- * @return the table model which was dynamically generated
- */
- public static DefaultTableModel getTableModel(FTSRestRequest request,
- Collection<FTSData> summariesList)
- {
- final FTSDataColumnI[] cols = request.getWantedFields().toArray(
- new FTSDataColumnI[0]);
- final int colOffset = request.getAssociatedSequence() == null ? 0 : 1;
- DefaultTableModel tableModel = new DefaultTableModel()
- {
- @Override
- public boolean isCellEditable(int row, int column)
- {
- return false;
- }
-
- @Override
- public Class<?> getColumnClass(int columnIndex)
- {
- if (colOffset == 1 && columnIndex == 0)
- {
- return String.class;
- }
- return cols[columnIndex - colOffset].getDataType()
- .getDataTypeClass();
- }
-
- };
- if (request.getAssociatedSequence() != null)
- {
- tableModel.addColumn("Ref Sequence"); // Create sequence column header if
- // exists in the request
- }
- for (FTSDataColumnI field : request.getWantedFields())
- {
- tableModel.addColumn(field.getName()); // Create sequence column header if
- // exists in the request
- }
-
- for (FTSData res : summariesList)
- {
- tableModel.addRow(res.getSummaryData()); // Populate table rows with
- // summary list
- }
-
- return tableModel;
- }
-
- public static void configureTableColumn(JTable tbl_summary,
- Collection<FTSDataColumnI> wantedFields,
- Map<String, Integer> columnPrefs)
- {
- for (FTSDataColumnI wantedField : wantedFields)
- {
- try
- {
- 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);
- }
- }
- }
-
}