X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fws%2Fuimodel%2FPDBRestResponse.java;fp=src%2Fjalview%2Fws%2Fuimodel%2FPDBSearchResponse.java;h=5a1f53deba07af73a828b404b339366e3d6704e7;hb=d9cedb863c0d5b665b8cdde3f8791d8a96030c6b;hp=7b172dedd1126806cb0c6a0d47af69bb25d8f07b;hpb=0ae0771700df811f421f8548e40dae2cd11cfae0;p=jalview.git diff --git a/src/jalview/ws/uimodel/PDBSearchResponse.java b/src/jalview/ws/uimodel/PDBRestResponse.java similarity index 58% rename from src/jalview/ws/uimodel/PDBSearchResponse.java rename to src/jalview/ws/uimodel/PDBRestResponse.java index 7b172de..5a1f53d 100644 --- a/src/jalview/ws/uimodel/PDBSearchResponse.java +++ b/src/jalview/ws/uimodel/PDBRestResponse.java @@ -1,3 +1,24 @@ +/* + * 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.ws.dbsources.PDBRestClient.PDBDocField; @@ -11,22 +32,29 @@ import javax.swing.table.DefaultTableModel; 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 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() @@ -49,6 +77,14 @@ public class PDBSearchResponse 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 getListModel( Collection summariesList) { @@ -60,7 +96,19 @@ public class PDBSearchResponse 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 summariesList) { DefaultTableModel model = new DefaultTableModel(); @@ -76,38 +124,42 @@ public class PDBSearchResponse 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 diplayFields, String associatedSeq) + public PDBResponseSummary(JSONObject doc, PDBRestRequest request) { StringBuilder summaryBuilder = new StringBuilder(); - + List 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; } @@ -142,25 +194,25 @@ public class PDBSearchResponse + 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; } @@ -174,24 +226,24 @@ public class PDBSearchResponse 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() @@ -199,7 +251,7 @@ public class PDBSearchResponse StringBuilder html = new StringBuilder(); html.append("
"); - html.append(summaryRow); + html.append(concatenatedSummaryData); html.append("
"); return html.toString(); } @@ -207,7 +259,7 @@ public class PDBSearchResponse @Override public int hashCode() { - return Objects.hash(this.pdbId, this.summaryRow); + return Objects.hash(this.pdbId, this.concatenatedSummaryData); } @Override @@ -222,7 +274,8 @@ public class PDBSearchResponse // Custom equality check here. return this.pdbId.equals(that.pdbId) - && this.summaryRow.equals(that.summaryRow); + && this.concatenatedSummaryData + .equals(that.concatenatedSummaryData); } }