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 public UniprotFTSPanel(SequenceFetcher seqFetcher)
45 this.seqFetcher = seqFetcher;
46 this.progressIdicator = (seqFetcher == null) ? null : seqFetcher
47 .getProgressIndicator();
51 public void searchAction()
58 ftsFrameTitle = defaultFTSFrameTitle;
60 if (getTypedText().length() > 0)
62 setSearchInProgress(true);
63 long startTime = System.currentTimeMillis();
65 String searchTarget = ((FTSDataColumnI) cmb_searchTarget
66 .getSelectedItem()).getAltCode();
68 wantedFields = UniProtFTSRestClient.getInstance()
69 .getAllDefaulDisplayedDataColumns();
70 String searchTerm = txt_search.getText();
72 FTSRestRequest request = new FTSRestRequest();
73 request.setFieldToSearchBy(searchTarget);
74 request.setSearchTerm(searchTerm);
75 request.setWantedFields(wantedFields);
76 FTSRestClientI uniProtRestCleint = UniProtFTSRestClient
78 FTSRestResponse resultList;
81 resultList = uniProtRestCleint.executeRequest(request);
85 setErrorMessage(e.getMessage());
90 if (resultList.getSearchSummary() != null
91 && resultList.getSearchSummary().size() > 0)
93 getResultTable().setModel(
94 FTSRestResponse.getTableModel(request,
95 resultList.getSearchSummary()));
96 FTSRestResponse.configureTableColumn(getResultTable(),
98 getResultTable().setVisible(true);
101 long endTime = System.currentTimeMillis();
102 int resultSetCount = resultList.getNumberOfItemsFound();
103 String result = (resultSetCount > 1) ? MessageManager
104 .getString("label.results") : MessageManager
105 .getString("label.result");
106 updateSearchFrameTitle(defaultFTSFrameTitle + " - "
107 + resultSetCount + " " + result + " ("
108 + (endTime - startTime) + " milli secs)");
109 setSearchInProgress(false);
117 public void okAction()
119 disableActionButtons();
120 StringBuilder selectedIds = new StringBuilder();
121 HashSet<String> selectedIdsSet = new HashSet<String>();
122 int primaryKeyColIndex = 0;
125 primaryKeyColIndex = getFTSRestClient().getPrimaryKeyColumIndex(
126 wantedFields, false);
127 } catch (Exception e)
131 int[] selectedRows = getResultTable().getSelectedRows();
132 for (int summaryRow : selectedRows)
134 String idStr = getResultTable().getValueAt(summaryRow,
135 primaryKeyColIndex).toString();
136 selectedIdsSet.add(idStr);
139 for (String selectedId : selectedIdsSet)
141 selectedIds.append(selectedId).append(";");
144 String ids = selectedIds.toString();
145 // System.out.println(">>>>>>>>>>>>>>>> selected Ids: " + ids);
146 seqFetcher.getTextArea().setText(ids);
147 Thread worker = new Thread(seqFetcher);
149 delayAndEnableActionButtons();
153 public FTSRestClientI getFTSRestClient()
155 return UniProtFTSRestClient.getInstance();
159 public String getFTSFrameTitle()
161 return ftsFrameTitle;