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.Help;
30 import jalview.gui.Help.HelpId;
31 import jalview.gui.SequenceFetcher;
32 import jalview.util.MessageManager;
34 import java.util.HashMap;
35 import java.util.HashSet;
38 import javax.help.HelpSetException;
40 @SuppressWarnings("serial")
41 public class UniprotFTSPanel extends GFTSPanel
44 private static String defaultFTSFrameTitle = MessageManager
45 .getString("label.uniprot_sequence_fetcher");
47 private static Map<String, Integer> tempUserPrefs = new HashMap<>();
49 private static final String UNIPROT_FTS_CACHE_KEY = "CACHE.UNIPROT_FTS";
51 private static final String UNIPROT_AUTOSEARCH = "FTS.UNIPROT.AUTOSEARCH";
53 public UniprotFTSPanel(SequenceFetcher fetcher)
56 pageLimit = UniProtFTSRestClient.getInstance()
57 .getDefaultResponsePageSize();
58 this.seqFetcher = fetcher;
59 this.progressIndicator = (fetcher == null) ? null
60 : fetcher.getProgressIndicator();
64 public void searchAction(boolean isFreshSearch)
66 mainFrame.requestFocusInWindow();
77 String searchInput = getTypedText();
78 if (searchInput.length() > 0)
80 setSearchInProgress(true);
81 long startTime = System.currentTimeMillis();
82 searchInput = getTypedText();
83 String searchTarget = ((FTSDataColumnI) cmb_searchTarget
84 .getSelectedItem()).getAltCode();
85 wantedFields = UniProtFTSRestClient.getInstance()
86 .getAllDefaultDisplayedFTSDataColumns();
87 String searchTerm = decodeSearchTerm(searchInput, searchTarget);
89 FTSRestRequest request = new FTSRestRequest();
90 request.setFieldToSearchBy(searchTarget);
91 request.setSearchTerm(searchTerm);
92 request.setOffSet(offSet);
93 request.setWantedFields(wantedFields);
94 FTSRestClientI uniProtRestClient = UniProtFTSRestClient
96 FTSRestResponse resultList;
99 resultList = uniProtRestClient.executeRequest(request);
100 } catch (Exception e)
102 setErrorMessage(e.getMessage());
104 setSearchInProgress(false);
108 if (resultList.getSearchSummary() != null
109 && resultList.getSearchSummary().size() > 0)
111 getResultTable().setModel(FTSRestResponse.getTableModel(request,
112 resultList.getSearchSummary()));
113 FTSRestResponse.configureTableColumn(getResultTable(),
114 wantedFields, tempUserPrefs);
115 getResultTable().setVisible(true);
118 long endTime = System.currentTimeMillis();
119 totalResultSetCount = resultList.getNumberOfItemsFound();
120 resultSetCount = resultList.getSearchSummary() == null ? 0
121 : resultList.getSearchSummary().size();
122 String result = (resultSetCount > 0)
123 ? MessageManager.getString("label.results")
124 : MessageManager.getString("label.result");
125 if (isPaginationEnabled() && resultSetCount > 0)
127 updateSearchFrameTitle(defaultFTSFrameTitle + " - " + result
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();
148 txt_search.updateCache();
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<>();
193 int primaryKeyColIndex = 0;
196 primaryKeyColIndex = getFTSRestClient()
197 .getPrimaryKeyColumIndex(wantedFields, false);
198 } catch (Exception e)
202 int[] selectedRows = getResultTable().getSelectedRows();
203 for (int summaryRow : selectedRows)
205 String idStr = getResultTable()
206 .getValueAt(summaryRow, 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;
248 public String getAutosearchPreference()
250 return UNIPROT_AUTOSEARCH;
254 protected void showHelp()
258 Help.showHelpWindow(HelpId.UniprotFts);
259 } catch (HelpSetException e1)
261 e1.printStackTrace();