2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 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.ws.uimodel;
24 import jalview.datamodel.SequenceI;
25 import jalview.ws.dbsources.PDBRestClient.PDBDocField;
27 import java.util.Collection;
28 import java.util.Objects;
30 import javax.swing.table.DefaultTableModel;
32 import org.json.simple.JSONObject;
35 * Represents the response model produced by the PDBRestClient upon successful
36 * execution of a given request
41 public class PDBRestResponse
43 private int numberOfItemsFound;
45 private String responseTime;
47 private Collection<PDBResponseSummary> 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<PDBResponseSummary> getSearchSummary()
74 public void setSearchSummary(Collection<PDBResponseSummary> 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 PDBRestRequest 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(PDBRestRequest request,
92 Collection<PDBResponseSummary> summariesList)
94 DefaultTableModel tableModel = new DefaultTableModel()
97 public boolean isCellEditable(int row, int column)
102 if (request.getAssociatedSequence() != null)
104 tableModel.addColumn("Ref Sequence"); // Create sequence column header if
105 // exists in the request
107 for (PDBDocField field : request.getWantedFields())
109 tableModel.addColumn(field.getName()); // Create sequence column header if
110 // exists in the request
113 for (PDBResponseSummary res : summariesList)
115 tableModel.addRow(res.getSummaryData()); // Populate table rows with
123 * Model for a unique response summary
126 public class PDBResponseSummary
128 private String pdbId;
130 private Object[] summaryRowData;
132 private SequenceI associatedSequence;
134 public PDBResponseSummary(JSONObject pdbJsonDoc, PDBRestRequest request)
136 Collection<PDBDocField> diplayFields = request.getWantedFields();
137 SequenceI associatedSeq = request.getAssociatedSequence();
139 summaryRowData = new Object[(associatedSeq != null) ? diplayFields
140 .size() + 1 : diplayFields.size()];
141 if (associatedSeq != null)
143 this.associatedSequence = associatedSeq;
144 summaryRowData[0] = associatedSequence;
148 for (PDBDocField field : diplayFields)
150 String fieldData = (pdbJsonDoc.get(field.getCode()) == null) ? ""
151 : pdbJsonDoc.get(field.getCode()).toString();
152 if (field.equals(PDBDocField.PDB_ID))
154 this.pdbId = fieldData;
155 summaryRowData[colCounter++] = this.pdbId;
159 summaryRowData[colCounter++] = fieldData;
164 public String getPdbId()
169 public void setPdbId(String pdbId)
174 public Object[] getSummaryData()
176 return summaryRowData;
179 public void setSummaryData(String[] summaryData)
181 this.summaryRowData = summaryData;
185 * Returns a string representation of this object;
188 public String toString()
190 StringBuilder summaryFieldValues = new StringBuilder();
191 for (Object summaryField : summaryRowData)
193 summaryFieldValues.append(summaryField.toString()).append("\t");
195 return summaryFieldValues.toString();
199 * Returns hash code value for this object
202 public int hashCode()
204 return Objects.hash(this.pdbId, this.toString());
208 * Indicates whether some object is equal to this one
211 public boolean equals(Object that)
213 if (!(that instanceof PDBResponseSummary))
217 PDBResponseSummary another = (PDBResponseSummary) that;
218 return this.toString().equals(another.toString());