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.HashSet;
34 @SuppressWarnings("serial")
35 public class UniprotFTSPanel extends GFTSPanel
38 private static String defaultFTSFrameTitle = MessageManager
39 .getString("label.uniprot_sequence_fetcher");
41 private String ftsFrameTitle = defaultFTSFrameTitle;
45 public UniprotFTSPanel(SequenceFetcher seqFetcher)
47 pageLimit = UniProtFTSRestClient.getInstance()
48 .getDefaultResponsePageSize();
49 this.seqFetcher = seqFetcher;
50 this.progressIdicator = (seqFetcher == null) ? null : seqFetcher
51 .getProgressIndicator();
55 public void searchAction(boolean isFreshSearch)
66 ftsFrameTitle = defaultFTSFrameTitle;
68 if (getTypedText().length() > 0)
70 setSearchInProgress(true);
71 long startTime = System.currentTimeMillis();
73 String searchTarget = ((FTSDataColumnI) cmb_searchTarget
74 .getSelectedItem()).getAltCode();
76 wantedFields = UniProtFTSRestClient.getInstance()
77 .getAllDefaulDisplayedDataColumns();
78 String searchTerm = decodeSearchTerm(txt_search.getText(),
81 FTSRestRequest request = new FTSRestRequest();
82 request.setFieldToSearchBy(searchTarget);
83 request.setSearchTerm(searchTerm);
84 request.setOffSet(offSet);
85 request.setWantedFields(wantedFields);
86 FTSRestClientI uniProtRestCleint = UniProtFTSRestClient
88 FTSRestResponse resultList;
91 resultList = uniProtRestCleint.executeRequest(request);
95 setErrorMessage(e.getMessage());
100 if (resultList.getSearchSummary() != null
101 && resultList.getSearchSummary().size() > 0)
103 getResultTable().setModel(
104 FTSRestResponse.getTableModel(request,
105 resultList.getSearchSummary()));
106 FTSRestResponse.configureTableColumn(getResultTable(),
108 getResultTable().setVisible(true);
111 long endTime = System.currentTimeMillis();
112 totalResultSetCount = resultList.getNumberOfItemsFound();
113 resultSetCount = resultList.getSearchSummary() == null ? 0
114 : resultList.getSearchSummary().size();
115 String result = (resultSetCount > 0) ? MessageManager
116 .getString("label.results") : MessageManager
117 .getString("label.result");
118 if (isPaginationEnabled() && resultSetCount > 0)
120 updateSearchFrameTitle(defaultFTSFrameTitle + " - " + result
121 + " " + (offSet + 1) + " to "
122 + (offSet + resultSetCount) + " of "
123 + totalResultSetCount
124 + " " + " (" + (endTime - startTime) + " milli secs)");
128 updateSearchFrameTitle(defaultFTSFrameTitle + " - "
129 + resultSetCount + " " + result + " ("
130 + (endTime - startTime) + " milli secs)");
132 setSearchInProgress(false);
133 refreshPaginatorState();
134 updateSummaryTableSelections();
141 public String decodeSearchTerm(String enteredText, String targetField)
143 int searchTargetLength = targetField.equalsIgnoreCase("Search All") ? 0
144 : targetField.length() + 1;
145 String searchTarget = targetField.equalsIgnoreCase("Search All") ? ""
147 String foundSearchTerms = enteredText;
148 StringBuilder foundSearchTermsBuilder = new StringBuilder();
149 if (enteredText.contains(";"))
151 String[] searchTerms = enteredText.split(";");
152 for (String searchTerm : searchTerms)
154 foundSearchTermsBuilder.append(searchTarget).append(searchTerm)
157 int endIndex = foundSearchTermsBuilder.lastIndexOf(" OR ");
158 foundSearchTerms = foundSearchTermsBuilder.toString();
159 if (foundSearchTerms.contains(" OR "))
161 foundSearchTerms = foundSearchTerms.substring(searchTargetLength,
165 return foundSearchTerms;
170 public boolean isPaginationEnabled()
176 public void okAction()
178 disableActionButtons();
179 StringBuilder selectedIds = new StringBuilder();
180 HashSet<String> selectedIdsSet = new HashSet<String>();
181 int primaryKeyColIndex = 0;
184 primaryKeyColIndex = getFTSRestClient().getPrimaryKeyColumIndex(
185 wantedFields, false);
186 } catch (Exception e)
190 int[] selectedRows = getResultTable().getSelectedRows();
191 for (int summaryRow : selectedRows)
193 String idStr = getResultTable().getValueAt(summaryRow,
194 primaryKeyColIndex).toString();
195 selectedIdsSet.add(idStr);
197 selectedIdsSet.addAll(paginatorCart);
198 for (String selectedId : selectedIdsSet)
200 selectedIds.append(selectedId).append(";");
203 String ids = selectedIds.toString();
204 // System.out.println(">>>>>>>>>>>>>>>> selected Ids: " + ids);
205 seqFetcher.getTextArea().setText(ids);
206 Thread worker = new Thread(seqFetcher);
208 delayAndEnableActionButtons();
212 public FTSRestClientI getFTSRestClient()
214 return UniProtFTSRestClient.getInstance();
218 public String getFTSFrameTitle()
220 return ftsFrameTitle;