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;
43 private int resultSetCount;
47 private static int pageLimit = UniProtFTSRestClient.getInstance()
48 .getDefaultResponsePageSize();
50 public UniprotFTSPanel(SequenceFetcher seqFetcher)
52 this.seqFetcher = seqFetcher;
53 this.progressIdicator = (seqFetcher == null) ? null : seqFetcher
54 .getProgressIndicator();
58 public void searchAction()
64 public void executeSearch()
71 ftsFrameTitle = defaultFTSFrameTitle;
73 if (getTypedText().length() > 0)
75 setSearchInProgress(true);
76 long startTime = System.currentTimeMillis();
78 String searchTarget = ((FTSDataColumnI) cmb_searchTarget
79 .getSelectedItem()).getAltCode();
81 wantedFields = UniProtFTSRestClient.getInstance()
82 .getAllDefaulDisplayedDataColumns();
83 String searchTerm = txt_search.getText();
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 FTSRestResponse.getTableModel(request,
109 resultList.getSearchSummary()));
110 FTSRestResponse.configureTableColumn(getResultTable(),
112 getResultTable().setVisible(true);
115 long endTime = System.currentTimeMillis();
116 resultSetCount = resultList.getNumberOfItemsFound();
117 String result = (resultSetCount > 1) ? MessageManager
118 .getString("label.results") : MessageManager
119 .getString("label.result");
120 if (isPaginationEnabled() && resultSetCount > 1)
122 updateSearchFrameTitle(defaultFTSFrameTitle + " - " + result
123 + " " + offSet + " to " + (offSet + resultSetCount)
124 + " " + " (" + (endTime - startTime) + " milli secs)");
128 updateSearchFrameTitle(defaultFTSFrameTitle + " - "
129 + resultSetCount + " " + result + " ("
130 + (endTime - startTime) + " milli secs)");
132 setSearchInProgress(false);
133 refreshPaginatorState();
142 public void refreshPaginatorState()
144 // System.out.println("resultSet count : " + resultSetCount);
145 // System.out.println("offSet : " + offSet);
146 // System.out.println("page limit : " + pageLimit);
147 setPrevPageButtonEnabled(false);
148 setNextPageButtonEnabled(false);
149 if (resultSetCount >= pageLimit)
151 setNextPageButtonEnabled(true);
153 if (offSet >= pageLimit)
155 setPrevPageButtonEnabled(true);
160 public void prevPageAction()
162 if (offSet >= pageLimit)
164 offSet = offSet - pageLimit;
167 refreshPaginatorState();
172 public void nextPageAction()
174 offSet = offSet + pageLimit;
180 public boolean isPaginationEnabled()
186 public void okAction()
188 disableActionButtons();
189 StringBuilder selectedIds = new StringBuilder();
190 HashSet<String> selectedIdsSet = new HashSet<String>();
191 int primaryKeyColIndex = 0;
194 primaryKeyColIndex = getFTSRestClient().getPrimaryKeyColumIndex(
195 wantedFields, false);
196 } catch (Exception e)
200 int[] selectedRows = getResultTable().getSelectedRows();
201 for (int summaryRow : selectedRows)
203 String idStr = getResultTable().getValueAt(summaryRow,
204 primaryKeyColIndex).toString();
205 selectedIdsSet.add(idStr);
208 for (String selectedId : selectedIdsSet)
210 selectedIds.append(selectedId).append(";");
213 String ids = selectedIds.toString();
214 // System.out.println(">>>>>>>>>>>>>>>> selected Ids: " + ids);
215 seqFetcher.getTextArea().setText(ids);
216 Thread worker = new Thread(seqFetcher);
218 delayAndEnableActionButtons();
222 public FTSRestClientI getFTSRestClient()
224 return UniProtFTSRestClient.getInstance();
228 public String getFTSFrameTitle()
230 return ftsFrameTitle;