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.uniprot;
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.HashMap;
33 import java.util.HashSet;
36 @SuppressWarnings("serial")
37 public class UniprotFTSPanel extends GFTSPanel
40 private static String defaultFTSFrameTitle = MessageManager
41 .getString("label.uniprot_sequence_fetcher");
44 private static Map<String, Integer> tempUserPrefs = new HashMap<String, Integer>();
46 private static final String UNIPROT_FTS_CACHE_KEY = "CACHE.UNIPROT_FTS";
48 public UniprotFTSPanel(SequenceFetcher seqFetcher)
51 pageLimit = UniProtFTSRestClient.getInstance()
52 .getDefaultResponsePageSize();
53 this.seqFetcher = seqFetcher;
54 this.progressIndicator = (seqFetcher == null) ? null : seqFetcher
55 .getProgressIndicator();
59 public void searchAction(boolean isFreshSearch)
71 String searchInput = getTypedText();
72 if (searchInput.length() > 0)
74 setSearchInProgress(true);
75 long startTime = System.currentTimeMillis();
76 searchInput = getTypedText();
77 String searchTarget = ((FTSDataColumnI) cmb_searchTarget
78 .getSelectedItem()).getAltCode();
79 wantedFields = UniProtFTSRestClient.getInstance()
80 .getAllDefaultDisplayedFTSDataColumns();
81 String searchTerm = decodeSearchTerm(searchInput, searchTarget);
83 FTSRestRequest request = new FTSRestRequest();
84 request.setFieldToSearchBy(searchTarget);
85 request.setSearchTerm(searchTerm);
86 request.setOffSet(offSet);
87 request.setWantedFields(wantedFields);
88 FTSRestClientI uniProtRestCleint = UniProtFTSRestClient
90 FTSRestResponse resultList;
93 resultList = uniProtRestCleint.executeRequest(request);
97 setErrorMessage(e.getMessage());
102 if (resultList.getSearchSummary() != null
103 && resultList.getSearchSummary().size() > 0)
105 getResultTable().setModel(
106 FTSRestResponse.getTableModel(request,
107 resultList.getSearchSummary()));
108 FTSRestResponse.configureTableColumn(getResultTable(),
109 wantedFields, tempUserPrefs);
110 getResultTable().setVisible(true);
113 long endTime = System.currentTimeMillis();
114 totalResultSetCount = resultList.getNumberOfItemsFound();
115 resultSetCount = resultList.getSearchSummary() == null ? 0
116 : resultList.getSearchSummary().size();
117 String result = (resultSetCount > 0) ? MessageManager
118 .getString("label.results") : MessageManager
119 .getString("label.result");
120 if (isPaginationEnabled() && resultSetCount > 0)
122 updateSearchFrameTitle(defaultFTSFrameTitle
126 + totalNumberformatter.format((Number) (offSet + 1))
128 + totalNumberformatter
129 .format((Number) (offSet + resultSetCount))
131 + totalNumberformatter
132 .format((Number) totalResultSetCount) + " "
133 + " (" + (endTime - startTime) + " milli secs)");
137 updateSearchFrameTitle(defaultFTSFrameTitle + " - "
138 + resultSetCount + " " + result + " ("
139 + (endTime - startTime) + " milli secs)");
141 setSearchInProgress(false);
142 refreshPaginatorState();
143 updateSummaryTableSelections();
145 txt_search.updateCache();
151 public String decodeSearchTerm(String enteredText, String targetField)
153 int searchTargetLength = targetField.equalsIgnoreCase("Search All") ? 0
154 : targetField.length() + 1;
155 String searchTarget = targetField.equalsIgnoreCase("Search All") ? ""
157 String foundSearchTerms = enteredText;
158 StringBuilder foundSearchTermsBuilder = new StringBuilder();
159 if (enteredText.contains(";"))
161 String[] searchTerms = enteredText.split(";");
162 for (String searchTerm : searchTerms)
164 foundSearchTermsBuilder.append(searchTarget).append(searchTerm)
167 int endIndex = foundSearchTermsBuilder.lastIndexOf(" OR ");
168 foundSearchTerms = foundSearchTermsBuilder.toString();
169 if (foundSearchTerms.contains(" OR "))
171 foundSearchTerms = foundSearchTerms.substring(searchTargetLength,
175 return foundSearchTerms;
179 public boolean isPaginationEnabled()
185 public void okAction()
187 disableActionButtons();
188 StringBuilder selectedIds = new StringBuilder();
189 HashSet<String> selectedIdsSet = new HashSet<String>();
190 int primaryKeyColIndex = 0;
193 primaryKeyColIndex = getFTSRestClient().getPrimaryKeyColumIndex(
194 wantedFields, false);
195 } catch (Exception e)
199 int[] selectedRows = getResultTable().getSelectedRows();
200 for (int summaryRow : selectedRows)
202 String idStr = getResultTable().getValueAt(summaryRow,
203 primaryKeyColIndex).toString();
204 selectedIdsSet.add(idStr);
206 selectedIdsSet.addAll(paginatorCart);
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 FTSRestClientI getFTSRestClient()
223 return UniProtFTSRestClient.getInstance();
227 public String getFTSFrameTitle()
229 return defaultFTSFrameTitle;
233 public Map<String, Integer> getTempUserPrefs()
235 return tempUserPrefs;
239 public String getCacheKey()
241 return UNIPROT_FTS_CACHE_KEY;