+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+
package jalview.ws.uimodel;
import jalview.ws.dbsources.PDBRestClient.PDBDocField;
import org.json.simple.JSONObject;
-public class PDBSearchResponse
+/**
+ * Represents the response model produced by the PDBRestClient upon successful
+ * execution of a given request
+ *
+ * @author tcnofoegbu
+ *
+ */
+public class PDBRestResponse
{
- private int itemsFound;
+ private int numberOfItemsFound;
private String responseTime;
private Collection<PDBResponseSummary> searchSummary;
- public int getItemsFound()
+ public int getNumberOfItemsFound()
{
- return itemsFound;
+ return numberOfItemsFound;
}
- public void setItemsFound(int itemFound)
+ public void setNumberOfItemsFound(int itemFound)
{
- this.itemsFound = itemFound;
+ this.numberOfItemsFound = itemFound;
}
public String getResponseTime()
this.searchSummary = searchSummary;
}
+ /**
+ * Convenience method to obtain a List model for a given summary list
+ *
+ * @param summariesList
+ * the summary list which contains the data for generating the lists
+ * data
+ * @return the list model generated for the search summary
+ */
public static DefaultListModel<PDBResponseSummary> getListModel(
Collection<PDBResponseSummary> summariesList)
{
return defaultListModel;
}
- public static DefaultTableModel getTableModel(PDBSearchRequest request,
+ /**
+ * Convenience method to obtain a Table model for a given summary List and
+ * request
+ *
+ * @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<PDBResponseSummary> summariesList)
{
DefaultTableModel model = new DefaultTableModel();
for (PDBResponseSummary res : summariesList)
{
- model.addRow(res.getSummaryColums());
+ model.addRow(res.getSummaryData());
}
return model;
}
-
-
+ /**
+ * Model for a unique response summary
+ *
+ * @author tcnofoegbu
+ *
+ */
public class PDBResponseSummary
{
private String pdbId;
- private String summaryRow;
+ private String concatenatedSummaryData;
- private String[] summaryColums;
+ private String[] summaryData;
private String associatedSequence;
private int width = 480;
- public PDBResponseSummary(JSONObject doc,
- List<PDBDocField> diplayFields, String associatedSeq)
+ public PDBResponseSummary(JSONObject doc, PDBRestRequest request)
{
StringBuilder summaryBuilder = new StringBuilder();
-
+ List<PDBDocField> diplayFields = request.getWantedFields();
+ String associatedSeq = request.getAssociatedSequence();
int colCounter = 0;
- summaryColums = new String[(associatedSeq != null) ? diplayFields
+ summaryData = new String[(associatedSeq != null) ? diplayFields
.size() + 1 : diplayFields.size()];
if (associatedSeq != null)
{
this.associatedSequence = (associatedSeq.length() > 18) ? associatedSeq
.substring(0, 18) : associatedSeq;
- summaryColums[0] = associatedSequence;
+ summaryData[0] = associatedSequence;
colCounter = 1;
}
+ getClass().getResource("/images/sugar.png")
.toString() + "\">");
}
- summaryColums[colCounter++] = moleculeType;
+ summaryData[colCounter++] = moleculeType;
}
else if (field.equals(PDBDocField.PDB_ID)
&& doc.get(PDBDocField.PDB_ID.getCode()) != null)
{
this.pdbId = doc.get(PDBDocField.PDB_ID.getCode()).toString();
summaryBuilder.append(this.pdbId).append(" | ");
- summaryColums[colCounter++] = this.pdbId;
+ summaryData[colCounter++] = this.pdbId;
}
else if (doc.get(field.getCode()) != null)
{
summaryBuilder.append(field.getName()).append(": ")
.append(doc.get(field.getCode())).append(" | ");
- summaryColums[colCounter++] = doc.get(field.getCode()).toString();
+ summaryData[colCounter++] = doc.get(field.getCode()).toString();
}
}
int endIndex = summaryBuilder.lastIndexOf(" | ");
String fSummary = summaryBuilder.toString().substring(0, endIndex);
- this.summaryRow = fSummary.trim();
+ this.concatenatedSummaryData = fSummary.trim();
summaryBuilder = null;
}
this.pdbId = pdbId;
}
- public String getSummaryRow()
+ public String getConcatenatedSummaryData()
{
- return summaryRow;
+ return concatenatedSummaryData;
}
- public void setSummaryRow(String summary)
+ public void setConcatenatedSummaryData(String concatenatedSummaryData)
{
- this.summaryRow = summary;
+ this.concatenatedSummaryData = concatenatedSummaryData;
}
- public String[] getSummaryColums()
+ public String[] getSummaryData()
{
- return summaryColums;
+ return summaryData;
}
- public void setSummaryColums(String[] summaryColums)
+ public void setSummaryData(String[] summaryData)
{
- this.summaryColums = summaryColums;
+ this.summaryData = summaryData;
}
public String toString()
StringBuilder html = new StringBuilder();
html.append("<html><div style=\"width:" + width
+ "; word-wrap: break-word; border-bottom-style: dotted;\"> ");
- html.append(summaryRow);
+ html.append(concatenatedSummaryData);
html.append("</div></html>");
return html.toString();
}
@Override
public int hashCode()
{
- return Objects.hash(this.pdbId, this.summaryRow);
+ return Objects.hash(this.pdbId, this.concatenatedSummaryData);
}
@Override
// Custom equality check here.
return this.pdbId.equals(that.pdbId)
- && this.summaryRow.equals(that.summaryRow);
+ && this.concatenatedSummaryData
+ .equals(that.concatenatedSummaryData);
}
}