X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Ffts%2Fservice%2Funiprot%2FUniprotFTSPanel.java;h=88442de1877d06e88ea91797b8e45e5e674df590;hb=7b10124f09af29607ea0150726ad5d63da09fdaf;hp=51d773566219ddf464ccf0fdf006f59e66771fb4;hpb=007af0c9001900071f6d8e9214143f79e10f4938;p=jalview.git diff --git a/src/jalview/fts/service/uniprot/UniprotFTSPanel.java b/src/jalview/fts/service/uniprot/UniprotFTSPanel.java index 51d7735..88442de 100644 --- a/src/jalview/fts/service/uniprot/UniprotFTSPanel.java +++ b/src/jalview/fts/service/uniprot/UniprotFTSPanel.java @@ -1,47 +1,246 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ + package jalview.fts.service.uniprot; +import jalview.fts.api.FTSDataColumnI; import jalview.fts.api.FTSRestClientI; +import jalview.fts.core.FTSRestRequest; +import jalview.fts.core.FTSRestResponse; import jalview.fts.core.GFTSPanel; import jalview.gui.SequenceFetcher; import jalview.util.MessageManager; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; + @SuppressWarnings("serial") public class UniprotFTSPanel extends GFTSPanel { + private static String defaultFTSFrameTitle = MessageManager + .getString("label.uniprot_sequence_fetcher"); + + + private static Map tempUserPrefs = new HashMap(); + + private static final String UNIPROT_FTS_CACHE_KEY = "CACHE.UNIPROT_FTS"; public UniprotFTSPanel(SequenceFetcher seqFetcher) { + super(); + pageLimit = UniProtFTSRestClient.getInstance() + .getDefaultResponsePageSize(); this.seqFetcher = seqFetcher; - this.progressIdicator = (seqFetcher == null) ? null : seqFetcher + this.progressIndicator = (seqFetcher == null) ? null : seqFetcher .getProgressIndicator(); + initCache(); } @Override - public void txt_search_ActionPerformed() + public void searchAction(boolean isFreshSearch) { - // TODO Auto-generated method stub + if (isFreshSearch) + { + offSet = 0; + } + new Thread() + { + @Override + public void run() + { + reset(); + String searchInput = getTypedText(); + if (searchInput.length() > 0) + { + setSearchInProgress(true); + long startTime = System.currentTimeMillis(); + + String searchTarget = ((FTSDataColumnI) cmb_searchTarget + .getSelectedItem()).getAltCode(); + + wantedFields = UniProtFTSRestClient.getInstance() + .getAllDefaultDisplayedFTSDataColumns(); + String searchTerm = decodeSearchTerm(getTypedText(), + searchTarget); + + FTSRestRequest request = new FTSRestRequest(); + request.setFieldToSearchBy(searchTarget); + request.setSearchTerm(searchTerm); + request.setOffSet(offSet); + request.setWantedFields(wantedFields); + FTSRestClientI uniProtRestCleint = UniProtFTSRestClient + .getInstance(); + FTSRestResponse resultList; + try + { + resultList = uniProtRestCleint.executeRequest(request); + } catch (Exception e) + { + e.printStackTrace(); + setErrorMessage(e.getMessage()); + checkForErrors(); + return; + } + + if (resultList.getSearchSummary() != null + && resultList.getSearchSummary().size() > 0) + { + getResultTable().setModel( + FTSRestResponse.getTableModel(request, + resultList.getSearchSummary())); + FTSRestResponse.configureTableColumn(getResultTable(), + wantedFields, tempUserPrefs); + getResultTable().setVisible(true); + } + + long endTime = System.currentTimeMillis(); + totalResultSetCount = resultList.getNumberOfItemsFound(); + resultSetCount = resultList.getSearchSummary() == null ? 0 + : resultList.getSearchSummary().size(); + String result = (resultSetCount > 0) ? MessageManager + .getString("label.results") : MessageManager + .getString("label.result"); + if (isPaginationEnabled() && resultSetCount > 0) + { + updateSearchFrameTitle(defaultFTSFrameTitle + + " - " + + result + + " " + + totalNumberformatter.format((Number) (offSet + 1)) + + " to " + + totalNumberformatter + .format((Number) (offSet + resultSetCount)) + + " of " + + totalNumberformatter + .format((Number) totalResultSetCount) + " " + + " (" + (endTime - startTime) + " milli secs)"); + } + else + { + updateSearchFrameTitle(defaultFTSFrameTitle + " - " + + resultSetCount + " " + result + " (" + + (endTime - startTime) + " milli secs)"); + } + setSearchInProgress(false); + refreshPaginatorState(); + updateSummaryTableSelections(); + } + updateCache(); + } + }.start(); } - @Override - public void btn_ok_ActionPerformed() + public String decodeSearchTerm(String enteredText, String targetField) { - // TODO Auto-generated method stub + int searchTargetLength = targetField.equalsIgnoreCase("Search All") ? 0 + : targetField.length() + 1; + String searchTarget = targetField.equalsIgnoreCase("Search All") ? "" + : targetField + ":"; + String foundSearchTerms = enteredText; + StringBuilder foundSearchTermsBuilder = new StringBuilder(); + if (enteredText.contains(";")) + { + String[] searchTerms = enteredText.split(";"); + for (String searchTerm : searchTerms) + { + foundSearchTermsBuilder.append(searchTarget).append(searchTerm) + .append(" OR "); + } + int endIndex = foundSearchTermsBuilder.lastIndexOf(" OR "); + foundSearchTerms = foundSearchTermsBuilder.toString(); + if (foundSearchTerms.contains(" OR ")) + { + foundSearchTerms = foundSearchTerms.substring(searchTargetLength, + endIndex); + } + } + return foundSearchTerms; + } + @Override + public boolean isPaginationEnabled() + { + return true; } + @Override + public void okAction() + { + disableActionButtons(); + StringBuilder selectedIds = new StringBuilder(); + HashSet selectedIdsSet = new HashSet(); + int primaryKeyColIndex = 0; + try + { + primaryKeyColIndex = getFTSRestClient().getPrimaryKeyColumIndex( + wantedFields, false); + } catch (Exception e) + { + e.printStackTrace(); + } + int[] selectedRows = getResultTable().getSelectedRows(); + for (int summaryRow : selectedRows) + { + String idStr = getResultTable().getValueAt(summaryRow, + primaryKeyColIndex).toString(); + selectedIdsSet.add(idStr); + } + selectedIdsSet.addAll(paginatorCart); + for (String selectedId : selectedIdsSet) + { + selectedIds.append(selectedId).append(";"); + } + + String ids = selectedIds.toString(); + // System.out.println(">>>>>>>>>>>>>>>> selected Ids: " + ids); + seqFetcher.getTextArea().setText(ids); + Thread worker = new Thread(seqFetcher); + worker.start(); + delayAndEnableActionButtons(); + } @Override public FTSRestClientI getFTSRestClient() { - return UniProtRestClient.getInstance(); + return UniProtFTSRestClient.getInstance(); } @Override public String getFTSFrameTitle() { - return MessageManager.getString("label.uniprot_sequence_fetcher"); + return defaultFTSFrameTitle; + } + + @Override + public Map getTempUserPrefs() + { + return tempUserPrefs; } + @Override + public String getCacheKey() + { + return UNIPROT_FTS_CACHE_KEY; + } }