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.JvSummaryTable;
30 import jalview.gui.SequenceFetcher;
31 import jalview.util.MessageManager;
33 import java.util.HashMap;
34 import java.util.HashSet;
37 @SuppressWarnings("serial")
38 public class UniprotFTSPanel extends GFTSPanel
41 private static String defaultFTSFrameTitle = MessageManager
42 .getString("label.uniprot_sequence_fetcher");
45 private static Map<String, Integer> tempUserPrefs = new HashMap<String, Integer>();
47 private static final String UNIPROT_FTS_CACHE_KEY = "CACHE.UNIPROT_FTS";
49 public UniprotFTSPanel(SequenceFetcher seqFetcher)
52 pageLimit = UniProtFTSRestClient.getInstance()
53 .getDefaultResponsePageSize();
54 this.seqFetcher = seqFetcher;
55 this.progressIndicator = (seqFetcher == null) ? null : seqFetcher
56 .getProgressIndicator();
60 public void searchAction(boolean isFreshSearch)
62 mainFrame.requestFocusInWindow();
73 String searchInput = getTypedText();
74 if (searchInput.length() > 0)
76 setSearchInProgress(true);
77 long startTime = System.currentTimeMillis();
78 searchInput = getTypedText();
79 String searchTarget = ((FTSDataColumnI) cmb_searchTarget
80 .getSelectedItem()).getAltCode();
81 wantedFields = UniProtFTSRestClient.getInstance()
82 .getAllDefaultDisplayedFTSDataColumns();
83 String searchTerm = decodeSearchTerm(searchInput, searchTarget);
85 FTSRestRequest request = new FTSRestRequest();
86 request.setFieldToSearchBy(searchTarget);
87 request.setSearchTerm(searchTerm);
88 request.setOffSet(offSet);
89 request.setWantedFields(wantedFields);
90 FTSRestClientI uniProtRestCleint = UniProtFTSRestClient
92 FTSRestResponse resultList;
95 resultList = uniProtRestCleint.executeRequest(request);
99 setErrorMessage(e.getMessage());
104 if (resultList.getSearchSummary() != null
105 && resultList.getSearchSummary().size() > 0)
107 getResultTable().setModel(
108 JvSummaryTable.getTableModel(request,
109 resultList.getSearchSummary()));
110 JvSummaryTable.configureTableColumn(getResultTable(),
111 wantedFields, tempUserPrefs);
112 getResultTable().setVisible(true);
115 long endTime = System.currentTimeMillis();
116 totalResultSetCount = resultList.getNumberOfItemsFound();
117 resultSetCount = resultList.getSearchSummary() == null ? 0
118 : resultList.getSearchSummary().size();
119 String result = (resultSetCount > 0) ? MessageManager
120 .getString("label.results") : MessageManager
121 .getString("label.result");
122 if (isPaginationEnabled() && resultSetCount > 0)
124 updateSearchFrameTitle(defaultFTSFrameTitle
128 + totalNumberformatter.format((Number) (offSet + 1))
130 + totalNumberformatter
131 .format((Number) (offSet + resultSetCount))
133 + totalNumberformatter
134 .format((Number) totalResultSetCount) + " "
135 + " (" + (endTime - startTime) + " milli secs)");
139 updateSearchFrameTitle(defaultFTSFrameTitle + " - "
140 + resultSetCount + " " + result + " ("
141 + (endTime - startTime) + " milli secs)");
143 setSearchInProgress(false);
144 refreshPaginatorState();
145 updateSummaryTableSelections();
147 txt_search.updateCache();
153 public String decodeSearchTerm(String enteredText, String targetField)
155 int searchTargetLength = targetField.equalsIgnoreCase("Search All") ? 0
156 : targetField.length() + 1;
157 String searchTarget = targetField.equalsIgnoreCase("Search All") ? ""
159 String foundSearchTerms = enteredText;
160 StringBuilder foundSearchTermsBuilder = new StringBuilder();
161 if (enteredText.contains(";"))
163 String[] searchTerms = enteredText.split(";");
164 for (String searchTerm : searchTerms)
166 foundSearchTermsBuilder.append(searchTarget).append(searchTerm)
169 int endIndex = foundSearchTermsBuilder.lastIndexOf(" OR ");
170 foundSearchTerms = foundSearchTermsBuilder.toString();
171 if (foundSearchTerms.contains(" OR "))
173 foundSearchTerms = foundSearchTerms.substring(searchTargetLength,
177 return foundSearchTerms;
181 public boolean isPaginationEnabled()
187 public void okAction()
189 disableActionButtons();
190 StringBuilder selectedIds = new StringBuilder();
191 HashSet<String> selectedIdsSet = new HashSet<String>();
192 int primaryKeyColIndex = 0;
195 primaryKeyColIndex = getFTSRestClient().getPrimaryKeyColumIndex(
196 wantedFields, false);
197 } catch (Exception e)
201 int[] selectedRows = getResultTable().getSelectedRows();
202 for (int summaryRow : selectedRows)
204 String idStr = getResultTable().getValueAt(summaryRow,
205 primaryKeyColIndex).toString();
206 selectedIdsSet.add(idStr);
208 selectedIdsSet.addAll(paginatorCart);
209 for (String selectedId : selectedIdsSet)
211 selectedIds.append(selectedId).append(";");
214 String ids = selectedIds.toString();
215 // System.out.println(">>>>>>>>>>>>>>>> selected Ids: " + ids);
216 seqFetcher.getTextArea().setText(ids);
217 Thread worker = new Thread(seqFetcher);
219 delayAndEnableActionButtons();
223 public FTSRestClientI getFTSRestClient()
225 return UniProtFTSRestClient.getInstance();
229 public String getFTSFrameTitle()
231 return defaultFTSFrameTitle;
235 public Map<String, Integer> getTempUserPrefs()
237 return tempUserPrefs;
241 public String getCacheKey()
243 return UNIPROT_FTS_CACHE_KEY;