X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fws%2Fuimodel%2FPDBRestResponse.java;fp=src%2Fjalview%2Fws%2Fuimodel%2FPDBRestResponse.java;h=0000000000000000000000000000000000000000;hb=64dd25185d2caf389946bb7e70053183d5aa31a6;hp=3471fab0ae4e8e233df672a38c21630b82b6ac4d;hpb=39a3725d4d499eb0f1bd14e3c049cd954faddfdc;p=jalview.git diff --git a/src/jalview/ws/uimodel/PDBRestResponse.java b/src/jalview/ws/uimodel/PDBRestResponse.java deleted file mode 100644 index 3471fab..0000000 --- a/src/jalview/ws/uimodel/PDBRestResponse.java +++ /dev/null @@ -1,314 +0,0 @@ -/* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2) - * Copyright (C) 2014 The Jalview Authors - * - * This file is part of Jalview. - * - * Jalview is free software: you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation, either version 3 - * of the License, or (at your option) any later version. - * - * Jalview is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Jalview. If not, see . - * The Jalview Authors are detailed in the 'AUTHORS' file. - */ - -package jalview.ws.uimodel; - -import jalview.datamodel.SequenceI; -import jalview.ws.dbsources.PDBRestClient.PDBDocField; -import jalview.ws.dbsources.PDBRestClient.PDBDocField.Group; - -import java.util.Collection; -import java.util.Objects; - -import javax.swing.JTable; -import javax.swing.table.DefaultTableModel; - -import org.json.simple.JSONObject; - -/** - * Represents the response model produced by the PDBRestClient upon successful - * execution of a given request - * - * @author tcnofoegbu - * - */ -public class PDBRestResponse -{ - private int numberOfItemsFound; - - private String responseTime; - - private Collection searchSummary; - - public int getNumberOfItemsFound() - { - return numberOfItemsFound; - } - - public void setNumberOfItemsFound(int itemFound) - { - this.numberOfItemsFound = itemFound; - } - - public String getResponseTime() - { - return responseTime; - } - - public void setResponseTime(String responseTime) - { - this.responseTime = responseTime; - } - - public Collection getSearchSummary() - { - return searchSummary; - } - - public void setSearchSummary(Collection searchSummary) - { - this.searchSummary = searchSummary; - } - - /** - * Convenience method to obtain a Table model for a given summary List based - * on the request parameters - * - * @param request - * the PDBRestRequest 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(PDBRestRequest request, - Collection summariesList) - { - final PDBDocField[] cols = request.getWantedFields().toArray( - new PDBDocField[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; - } - if (cols[columnIndex - colOffset].getGroup().getName() - .equalsIgnoreCase(Group.QUALITY_MEASURES.getName())) - { - return Double.class; - } - return String.class; - } - - }; - if (request.getAssociatedSequence() != null) - { - tableModel.addColumn("Ref Sequence"); // Create sequence column header if - // exists in the request - } - for (PDBDocField field : request.getWantedFields()) - { - tableModel.addColumn(field.getName()); // Create sequence column header if - // exists in the request - } - - for (PDBResponseSummary res : summariesList) - { - tableModel.addRow(res.getSummaryData()); // Populate table rows with - // summary list - } - - return tableModel; - } - - /** - * Model for a unique response summary - * - */ - public class PDBResponseSummary - { - private String pdbId; - - private Object[] summaryRowData; - - private SequenceI associatedSequence; - - public PDBResponseSummary(JSONObject pdbJsonDoc, PDBRestRequest request) - { - Collection diplayFields = request.getWantedFields(); - SequenceI associatedSeq = request.getAssociatedSequence(); - int colCounter = 0; - summaryRowData = new Object[(associatedSeq != null) ? diplayFields - .size() + 1 : diplayFields.size()]; - if (associatedSeq != null) - { - this.associatedSequence = associatedSeq; - summaryRowData[0] = associatedSequence; - colCounter = 1; - } - - for (PDBDocField field : diplayFields) - { - String fieldData = (pdbJsonDoc.get(field.getCode()) == null) ? "" - : pdbJsonDoc.get(field.getCode()).toString(); - if (field.equals(PDBDocField.PDB_ID)) - { - this.pdbId = fieldData; - summaryRowData[colCounter++] = this.pdbId; - } - else - { - if (field.getGroup().getName() - .equals(Group.QUALITY_MEASURES.getName())) - { - try - { - if (fieldData == null || fieldData.isEmpty()) - { - summaryRowData[colCounter++] = null; - } - else - { - Double value = Double.valueOf(fieldData); - summaryRowData[colCounter++] = value; - } - } catch (Exception e) - { - e.printStackTrace(); - System.out.println("offending value:" + fieldData); - summaryRowData[colCounter++] = 0.0; - } - }else{ - summaryRowData[colCounter++] = (fieldData == null || fieldData - .isEmpty()) ? null : fieldData; - } - } - } - } - - public Object getPdbId() - { - return pdbId; - } - - public void setPdbId(String pdbId) - { - this.pdbId = pdbId; - } - - public Object[] getSummaryData() - { - return summaryRowData; - } - - public void setSummaryData(Object[] summaryData) - { - this.summaryRowData = summaryData; - } - - /** - * Returns a string representation of this object; - */ - @Override - public String toString() - { - StringBuilder summaryFieldValues = new StringBuilder(); - for (Object summaryField : summaryRowData) - { - summaryFieldValues.append( - summaryField == null ? " " : summaryField.toString()) - .append("\t"); - } - return summaryFieldValues.toString(); - } - - /** - * Returns hash code value for this object - */ - @Override - public int hashCode() - { - return Objects.hash(this.pdbId, this.toString()); - } - - /** - * Indicates whether some object is equal to this one - */ - @Override - public boolean equals(Object that) - { - if (!(that instanceof PDBResponseSummary)) - { - return false; - } - PDBResponseSummary another = (PDBResponseSummary) that; - return this.toString().equals(another.toString()); - } - - } - - public static void configureTableColumn(JTable tbl_summary, - Collection wantedFields) - { - try - { - // wait for table model initialisation to complete - Thread.sleep(1200); - } catch (InterruptedException e1) - { - e1.printStackTrace(); - } - for (PDBDocField wantedField : wantedFields) - { - try - { - if (wantedField.equals(PDBDocField.PDB_ID)) - { - tbl_summary.getColumn(wantedField.getName()).setMinWidth(40); - tbl_summary.getColumn(wantedField.getName()).setMaxWidth(60); - tbl_summary.getColumn(wantedField.getName()).setPreferredWidth(45); - } - else if (wantedField.equals(PDBDocField.TITLE)) - { - tbl_summary.getColumn(wantedField.getName()).setMinWidth(300); - tbl_summary.getColumn(wantedField.getName()).setMaxWidth(1000); - tbl_summary.getColumn(wantedField.getName()).setPreferredWidth(400); - } - else if (wantedField.getGroup() == Group.QUALITY_MEASURES) - { - tbl_summary.getColumn(wantedField.getName()).setMinWidth(50); - tbl_summary.getColumn(wantedField.getName()).setMaxWidth(150); - tbl_summary.getColumn(wantedField.getName()).setPreferredWidth(85); - } - else - { - tbl_summary.getColumn(wantedField.getName()).setMinWidth(50); - tbl_summary.getColumn(wantedField.getName()).setMaxWidth(400); - tbl_summary.getColumn(wantedField.getName()).setPreferredWidth(95); - } - } catch (Exception e) - { - e.printStackTrace(); - } - } - } -}