2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ 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.fts.service.pdb;
24 import jalview.fts.api.FTSDataColumnI;
25 import jalview.fts.api.FTSRestClientI;
26 import jalview.fts.core.FTSRestRequest;
27 import jalview.fts.core.FTSRestResponse;
28 import jalview.fts.core.GFTSPanel;
29 import jalview.gui.SequenceFetcher;
30 import jalview.util.MessageManager;
32 import java.util.HashSet;
34 @SuppressWarnings("serial")
35 public class PDBFTSPanel extends GFTSPanel
37 private static String defaultFTSFrameTitle = MessageManager
38 .getString("label.pdb_sequence_fetcher");
40 private String ftsFrameTitle = defaultFTSFrameTitle;
42 public PDBFTSPanel(SequenceFetcher seqFetcher)
44 pageLimit = PDBFTSRestClient.getInstance().getDefaultResponsePageSize();
45 this.seqFetcher = seqFetcher;
46 this.progressIdicator = (seqFetcher == null) ? null : seqFetcher
47 .getProgressIndicator();
52 public void searchAction(boolean isFreshSearch)
63 ftsFrameTitle = defaultFTSFrameTitle;
65 boolean allowEmptySequence = false;
66 if (getTypedText().length() > 0)
68 setSearchInProgress(true);
69 long startTime = System.currentTimeMillis();
71 String searchTarget = ((FTSDataColumnI) cmb_searchTarget
72 .getSelectedItem()).getCode();
73 wantedFields = PDBFTSRestClient.getInstance()
74 .getAllDefaulDisplayedDataColumns();
75 String searchTerm = decodeSearchTerm(txt_search.getText(),
78 FTSRestRequest request = new FTSRestRequest();
79 request.setAllowEmptySeq(allowEmptySequence);
80 request.setResponseSize(100);
81 request.setFieldToSearchBy("(" + searchTarget + ":");
82 request.setSearchTerm(searchTerm + ")");
83 request.setOffSet(offSet);
84 request.setWantedFields(wantedFields);
85 FTSRestClientI pdbRestCleint = PDBFTSRestClient.getInstance();
86 FTSRestResponse resultList;
89 resultList = pdbRestCleint.executeRequest(request);
92 setErrorMessage(e.getMessage());
97 if (resultList.getSearchSummary() != null
98 && resultList.getSearchSummary().size() > 0)
100 getResultTable().setModel(
101 FTSRestResponse.getTableModel(request,
102 resultList.getSearchSummary()));
103 FTSRestResponse.configureTableColumn(getResultTable(),
105 getResultTable().setVisible(true);
108 long endTime = System.currentTimeMillis();
109 totalResultSetCount = resultList.getNumberOfItemsFound();
110 resultSetCount = resultList.getSearchSummary() == null ? 0
111 : resultList.getSearchSummary().size();
112 String result = (resultSetCount > 0) ? MessageManager
113 .getString("label.results") : MessageManager
114 .getString("label.result");
116 if (isPaginationEnabled() && resultSetCount > 0)
118 updateSearchFrameTitle(defaultFTSFrameTitle + " - " + result
119 + " " + (offSet + 1) + " to "
120 + (offSet + resultSetCount) + " of "
121 + totalResultSetCount
122 + " " + " (" + (endTime - startTime) + " milli secs)");
126 updateSearchFrameTitle(defaultFTSFrameTitle + " - "
127 + resultSetCount + " " + result + " ("
128 + (endTime - startTime) + " milli secs)");
131 setSearchInProgress(false);
132 refreshPaginatorState();
133 updateSummaryTableSelections();
139 public static String decodeSearchTerm(String enteredText,
142 String foundSearchTerms = enteredText;
143 StringBuilder foundSearchTermsBuilder = new StringBuilder();
144 if (enteredText.contains(";"))
146 String[] searchTerms = enteredText.split(";");
147 for (String searchTerm : searchTerms)
149 if (searchTerm.contains(":"))
151 foundSearchTermsBuilder.append(targetField).append(":")
152 .append(searchTerm.split(":")[0]).append(" OR ");
156 foundSearchTermsBuilder.append(targetField).append(":")
157 .append(searchTerm).append(" OR ");
160 int endIndex = foundSearchTermsBuilder.lastIndexOf(" OR ");
161 foundSearchTerms = foundSearchTermsBuilder.toString();
162 if (foundSearchTerms.contains(" OR "))
164 foundSearchTerms = foundSearchTerms.substring(
165 targetField.length() + 1, endIndex);
168 else if (enteredText.contains(":"))
170 foundSearchTerms = foundSearchTerms.split(":")[0];
172 return foundSearchTerms;
176 public void okAction()
178 // mainFrame.dispose();
179 disableActionButtons();
180 StringBuilder selectedIds = new StringBuilder();
181 HashSet<String> selectedIdsSet = new HashSet<String>();
182 int primaryKeyColIndex = 0;
185 primaryKeyColIndex = getFTSRestClient().getPrimaryKeyColumIndex(
188 } catch (Exception e)
192 int[] selectedRows = getResultTable().getSelectedRows();
193 String searchTerm = txt_search.getText();
194 for (int summaryRow : selectedRows)
196 String idStr = getResultTable().getValueAt(summaryRow,
199 selectedIdsSet.add(getPDBIdwithSpecifiedChain(idStr, searchTerm));
202 for (String idStr : paginatorCart)
204 selectedIdsSet.add(getPDBIdwithSpecifiedChain(idStr, searchTerm));
207 for (String selectedId : selectedIdsSet)
209 selectedIds.append(selectedId).append(";");
212 String ids = selectedIds.toString();
213 // System.out.println(">>>>>>>>>>>>>>>> selected Ids: " + ids);
214 seqFetcher.getTextArea().setText(ids);
215 Thread worker = new Thread(seqFetcher);
217 delayAndEnableActionButtons();
221 public static String getPDBIdwithSpecifiedChain(String pdbId,
224 String pdbIdWithChainCode = "";
225 if (searchTerm.contains(";"))
227 String[] foundTerms = searchTerm.split(";");
228 for (String foundTerm : foundTerms)
230 if (foundTerm.contains(pdbId))
232 pdbIdWithChainCode = foundTerm;
236 else if (searchTerm.contains(pdbId))
238 pdbIdWithChainCode = searchTerm;
242 pdbIdWithChainCode = pdbId;
244 return pdbIdWithChainCode;
248 public FTSRestClientI getFTSRestClient()
250 return PDBFTSRestClient.getInstance();
254 public String getFTSFrameTitle()
256 return ftsFrameTitle;
260 public boolean isPaginationEnabled()