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");
43 private String ftsFrameTitle = defaultFTSFrameTitle;
45 private static Map<String, Integer> tempUserPrefs = new HashMap<String, Integer>();
47 public UniprotFTSPanel(SequenceFetcher seqFetcher)
50 pageLimit = UniProtFTSRestClient.getInstance()
51 .getDefaultResponsePageSize();
52 this.seqFetcher = seqFetcher;
53 this.progressIdicator = (seqFetcher == null) ? null : seqFetcher
54 .getProgressIndicator();
58 public void searchAction(boolean isFreshSearch)
69 ftsFrameTitle = defaultFTSFrameTitle;
71 if (getTypedText().length() > 0)
73 setSearchInProgress(true);
74 long startTime = System.currentTimeMillis();
76 String searchTarget = ((FTSDataColumnI) cmb_searchTarget
77 .getSelectedItem()).getAltCode();
79 wantedFields = UniProtFTSRestClient.getInstance()
80 .getAllDefaultDisplayedFTSDataColumns();
81 String searchTerm = decodeSearchTerm(txt_search.getText(),
84 FTSRestRequest request = new FTSRestRequest();
85 request.setFieldToSearchBy(searchTarget);
86 request.setSearchTerm(searchTerm);
87 request.setOffSet(offSet);
88 request.setWantedFields(wantedFields);
89 FTSRestClientI uniProtRestCleint = UniProtFTSRestClient
91 FTSRestResponse resultList;
94 resultList = uniProtRestCleint.executeRequest(request);
98 setErrorMessage(e.getMessage());
103 if (resultList.getSearchSummary() != null
104 && resultList.getSearchSummary().size() > 0)
106 getResultTable().setModel(
107 FTSRestResponse.getTableModel(request,
108 resultList.getSearchSummary()));
109 FTSRestResponse.configureTableColumn(getResultTable(),
110 wantedFields, tempUserPrefs);
111 getResultTable().setVisible(true);
114 long endTime = System.currentTimeMillis();
115 totalResultSetCount = resultList.getNumberOfItemsFound();
116 resultSetCount = resultList.getSearchSummary() == null ? 0
117 : resultList.getSearchSummary().size();
118 String result = (resultSetCount > 0) ? MessageManager
119 .getString("label.results") : MessageManager
120 .getString("label.result");
121 if (isPaginationEnabled() && resultSetCount > 0)
123 updateSearchFrameTitle(defaultFTSFrameTitle + " - " + result
125 + totalNumberformatter.format((Number) (offSet + 1))
127 + totalNumberformatter
128 .format((Number) (offSet + resultSetCount))
130 + totalNumberformatter
131 .format((Number) totalResultSetCount)
132 + " " + " (" + (endTime - startTime) + " milli secs)");
136 updateSearchFrameTitle(defaultFTSFrameTitle + " - "
137 + resultSetCount + " " + result + " ("
138 + (endTime - startTime) + " milli secs)");
140 setSearchInProgress(false);
141 refreshPaginatorState();
142 updateSummaryTableSelections();
149 public String decodeSearchTerm(String enteredText, String targetField)
151 int searchTargetLength = targetField.equalsIgnoreCase("Search All") ? 0
152 : targetField.length() + 1;
153 String searchTarget = targetField.equalsIgnoreCase("Search All") ? ""
155 String foundSearchTerms = enteredText;
156 StringBuilder foundSearchTermsBuilder = new StringBuilder();
157 if (enteredText.contains(";"))
159 String[] searchTerms = enteredText.split(";");
160 for (String searchTerm : searchTerms)
162 foundSearchTermsBuilder.append(searchTarget).append(searchTerm)
165 int endIndex = foundSearchTermsBuilder.lastIndexOf(" OR ");
166 foundSearchTerms = foundSearchTermsBuilder.toString();
167 if (foundSearchTerms.contains(" OR "))
169 foundSearchTerms = foundSearchTerms.substring(searchTargetLength,
173 return foundSearchTerms;
178 public boolean isPaginationEnabled()
184 public void okAction()
186 disableActionButtons();
187 StringBuilder selectedIds = new StringBuilder();
188 HashSet<String> selectedIdsSet = new HashSet<String>();
189 int primaryKeyColIndex = 0;
192 primaryKeyColIndex = getFTSRestClient().getPrimaryKeyColumIndex(
193 wantedFields, false);
194 } catch (Exception e)
198 int[] selectedRows = getResultTable().getSelectedRows();
199 for (int summaryRow : selectedRows)
201 String idStr = getResultTable().getValueAt(summaryRow,
202 primaryKeyColIndex).toString();
203 selectedIdsSet.add(idStr);
205 selectedIdsSet.addAll(paginatorCart);
206 for (String selectedId : selectedIdsSet)
208 selectedIds.append(selectedId).append(";");
211 String ids = selectedIds.toString();
212 // System.out.println(">>>>>>>>>>>>>>>> selected Ids: " + ids);
213 seqFetcher.getTextArea().setText(ids);
214 Thread worker = new Thread(seqFetcher);
216 delayAndEnableActionButtons();
220 public FTSRestClientI getFTSRestClient()
222 return UniProtFTSRestClient.getInstance();
226 public String getFTSFrameTitle()
228 return ftsFrameTitle;
232 public Map<String, Integer> getTempUserPrefs()
234 return tempUserPrefs;