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 = "UNIPROT_FTS_CACHE_KEY";
48 public UniprotFTSPanel(SequenceFetcher seqFetcher)
51 pageLimit = UniProtFTSRestClient.getInstance()
52 .getDefaultResponsePageSize();
53 this.seqFetcher = seqFetcher;
54 this.progressIndicator = (seqFetcher == null) ? null : seqFetcher
55 .getProgressIndicator();
60 public void searchAction(boolean isFreshSearch)
72 String searchInput = getTypedText();
73 if (searchInput.length() > 0)
75 setSearchInProgress(true);
76 long startTime = System.currentTimeMillis();
78 String searchTarget = ((FTSDataColumnI) cmb_searchTarget
79 .getSelectedItem()).getAltCode();
81 wantedFields = UniProtFTSRestClient.getInstance()
82 .getAllDefaultDisplayedFTSDataColumns();
83 String searchTerm = decodeSearchTerm(getTypedText(),
86 FTSRestRequest request = new FTSRestRequest();
87 request.setFieldToSearchBy(searchTarget);
88 request.setSearchTerm(searchTerm);
89 request.setOffSet(offSet);
90 request.setWantedFields(wantedFields);
91 FTSRestClientI uniProtRestCleint = UniProtFTSRestClient
93 FTSRestResponse resultList;
96 resultList = uniProtRestCleint.executeRequest(request);
100 setErrorMessage(e.getMessage());
105 if (resultList.getSearchSummary() != null
106 && resultList.getSearchSummary().size() > 0)
108 getResultTable().setModel(
109 FTSRestResponse.getTableModel(request,
110 resultList.getSearchSummary()));
111 FTSRestResponse.configureTableColumn(getResultTable(),
112 wantedFields, tempUserPrefs);
113 getResultTable().setVisible(true);
116 long endTime = System.currentTimeMillis();
117 totalResultSetCount = resultList.getNumberOfItemsFound();
118 resultSetCount = resultList.getSearchSummary() == null ? 0
119 : resultList.getSearchSummary().size();
120 String result = (resultSetCount > 0) ? MessageManager
121 .getString("label.results") : MessageManager
122 .getString("label.result");
123 if (isPaginationEnabled() && resultSetCount > 0)
125 updateSearchFrameTitle(defaultFTSFrameTitle
129 + totalNumberformatter.format((Number) (offSet + 1))
131 + totalNumberformatter
132 .format((Number) (offSet + resultSetCount))
134 + totalNumberformatter
135 .format((Number) totalResultSetCount) + " "
136 + " (" + (endTime - startTime) + " milli secs)");
140 updateSearchFrameTitle(defaultFTSFrameTitle + " - "
141 + resultSetCount + " " + result + " ("
142 + (endTime - startTime) + " milli secs)");
144 setSearchInProgress(false);
145 refreshPaginatorState();
146 updateSummaryTableSelections();
154 public String decodeSearchTerm(String enteredText, String targetField)
156 int searchTargetLength = targetField.equalsIgnoreCase("Search All") ? 0
157 : targetField.length() + 1;
158 String searchTarget = targetField.equalsIgnoreCase("Search All") ? ""
160 String foundSearchTerms = enteredText;
161 StringBuilder foundSearchTermsBuilder = new StringBuilder();
162 if (enteredText.contains(";"))
164 String[] searchTerms = enteredText.split(";");
165 for (String searchTerm : searchTerms)
167 foundSearchTermsBuilder.append(searchTarget).append(searchTerm)
170 int endIndex = foundSearchTermsBuilder.lastIndexOf(" OR ");
171 foundSearchTerms = foundSearchTermsBuilder.toString();
172 if (foundSearchTerms.contains(" OR "))
174 foundSearchTerms = foundSearchTerms.substring(searchTargetLength,
178 return foundSearchTerms;
182 public boolean isPaginationEnabled()
188 public void okAction()
190 disableActionButtons();
191 StringBuilder selectedIds = new StringBuilder();
192 HashSet<String> selectedIdsSet = new HashSet<String>();
193 int primaryKeyColIndex = 0;
196 primaryKeyColIndex = getFTSRestClient().getPrimaryKeyColumIndex(
197 wantedFields, false);
198 } catch (Exception e)
202 int[] selectedRows = getResultTable().getSelectedRows();
203 for (int summaryRow : selectedRows)
205 String idStr = getResultTable().getValueAt(summaryRow,
206 primaryKeyColIndex).toString();
207 selectedIdsSet.add(idStr);
209 selectedIdsSet.addAll(paginatorCart);
210 for (String selectedId : selectedIdsSet)
212 selectedIds.append(selectedId).append(";");
215 String ids = selectedIds.toString();
216 // System.out.println(">>>>>>>>>>>>>>>> selected Ids: " + ids);
217 seqFetcher.getTextArea().setText(ids);
218 Thread worker = new Thread(seqFetcher);
220 delayAndEnableActionButtons();
224 public FTSRestClientI getFTSRestClient()
226 return UniProtFTSRestClient.getInstance();
230 public String getFTSFrameTitle()
232 return defaultFTSFrameTitle;
236 public Map<String, Integer> getTempUserPrefs()
238 return tempUserPrefs;
242 public String getCacheKey()
244 return UNIPROT_FTS_CACHE_KEY;