X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Ffts%2Fservice%2Funiprot%2FUniprotFTSPanel.java;h=09c6ab80e0a7526b2808c2de3befb60de2155c76;hb=81667097b92ba72f5eb4d824646b31e7ff5383a0;hp=6c28ee52862767d4334e9106b5e5d26698d1afe8;hpb=b809c6936e9e108f8bfd00b579318b765c252a5b;p=jalview.git diff --git a/src/jalview/fts/service/uniprot/UniprotFTSPanel.java b/src/jalview/fts/service/uniprot/UniprotFTSPanel.java index 6c28ee5..09c6ab8 100644 --- a/src/jalview/fts/service/uniprot/UniprotFTSPanel.java +++ b/src/jalview/fts/service/uniprot/UniprotFTSPanel.java @@ -29,7 +29,9 @@ 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 @@ -38,73 +40,80 @@ public class UniprotFTSPanel extends GFTSPanel private static String defaultFTSFrameTitle = MessageManager .getString("label.uniprot_sequence_fetcher"); - private String ftsFrameTitle = defaultFTSFrameTitle; + private static Map tempUserPrefs = new HashMap<>(); + private static final String UNIPROT_FTS_CACHE_KEY = "CACHE.UNIPROT_FTS"; + private static final String UNIPROT_AUTOSEARCH = "FTS.UNIPROT.AUTOSEARCH"; - public UniprotFTSPanel(SequenceFetcher seqFetcher) + /** + * Constructor given an (optional) sequence fetcher panel to revert to on + * clicking the 'Back' button + * + * @param fetcher + */ + public UniprotFTSPanel(SequenceFetcher fetcher) { + super(fetcher); pageLimit = UniProtFTSRestClient.getInstance() .getDefaultResponsePageSize(); - this.seqFetcher = seqFetcher; - this.progressIdicator = (seqFetcher == null) ? null : seqFetcher - .getProgressIndicator(); + this.seqFetcher = fetcher; + this.progressIndicator = (fetcher == null) ? null + : fetcher.getProgressIndicator(); } @Override public void searchAction(boolean isFreshSearch) { + mainFrame.requestFocusInWindow(); if (isFreshSearch) { offSet = 0; } new Thread() - { + { @Override public void run() { - ftsFrameTitle = defaultFTSFrameTitle; reset(); - if (getTypedText().length() > 0) + String searchInput = getTypedText(); + if (searchInput.length() > 0) { setSearchInProgress(true); long startTime = System.currentTimeMillis(); - + searchInput = getTypedText(); String searchTarget = ((FTSDataColumnI) cmb_searchTarget .getSelectedItem()).getAltCode(); - wantedFields = UniProtFTSRestClient.getInstance() - .getAllDefaulDisplayedDataColumns(); - String searchTerm = decodeSearchTerm(txt_search.getText(), - searchTarget); + .getAllDefaultDisplayedFTSDataColumns(); + String searchTerm = decodeSearchTerm(searchInput, searchTarget); FTSRestRequest request = new FTSRestRequest(); request.setFieldToSearchBy(searchTarget); request.setSearchTerm(searchTerm); request.setOffSet(offSet); request.setWantedFields(wantedFields); - FTSRestClientI uniProtRestCleint = UniProtFTSRestClient + FTSRestClientI uniProtRestClient = UniProtFTSRestClient .getInstance(); FTSRestResponse resultList; try { - resultList = uniProtRestCleint.executeRequest(request); + resultList = uniProtRestClient.executeRequest(request); } catch (Exception e) { - e.printStackTrace(); setErrorMessage(e.getMessage()); checkForErrors(); + setSearchInProgress(false); return; } if (resultList.getSearchSummary() != null && resultList.getSearchSummary().size() > 0) { - getResultTable().setModel( - FTSRestResponse.getTableModel(request, - resultList.getSearchSummary())); + getResultTable().setModel(FTSRestResponse.getTableModel(request, + resultList.getSearchSummary())); FTSRestResponse.configureTableColumn(getResultTable(), - wantedFields); + wantedFields, tempUserPrefs); getResultTable().setVisible(true); } @@ -112,15 +121,22 @@ public class UniprotFTSPanel extends GFTSPanel totalResultSetCount = resultList.getNumberOfItemsFound(); resultSetCount = resultList.getSearchSummary() == null ? 0 : resultList.getSearchSummary().size(); - String result = (resultSetCount > 0) ? MessageManager - .getString("label.results") : MessageManager - .getString("label.result"); + String result = (resultSetCount > 0) + ? MessageManager.getString("label.results") + : MessageManager.getString("label.result"); if (isPaginationEnabled() && resultSetCount > 0) { updateSearchFrameTitle(defaultFTSFrameTitle + " - " + result - + " " + (offSet + 1) + " to " - + (offSet + resultSetCount) + " of " - + totalResultSetCount + + " " + + totalNumberformatter + .format(Integer.valueOf(offSet + 1)) + + " to " + + totalNumberformatter + .format(Integer + .valueOf(offSet + resultSetCount)) + + " of " + + totalNumberformatter + .format(Integer.valueOf(totalResultSetCount)) + " " + " (" + (endTime - startTime) + " milli secs)"); } else @@ -133,6 +149,7 @@ public class UniprotFTSPanel extends GFTSPanel refreshPaginatorState(); updateSummaryTableSelections(); } + txt_search.updateCache(); } }.start(); @@ -165,7 +182,6 @@ public class UniprotFTSPanel extends GFTSPanel return foundSearchTerms; } - @Override public boolean isPaginationEnabled() { @@ -177,12 +193,12 @@ public class UniprotFTSPanel extends GFTSPanel { disableActionButtons(); StringBuilder selectedIds = new StringBuilder(); - HashSet selectedIdsSet = new HashSet(); + HashSet selectedIdsSet = new HashSet<>(); int primaryKeyColIndex = 0; try { - primaryKeyColIndex = getFTSRestClient().getPrimaryKeyColumIndex( - wantedFields, false); + primaryKeyColIndex = getFTSRestClient() + .getPrimaryKeyColumIndex(wantedFields, false); } catch (Exception e) { e.printStackTrace(); @@ -190,8 +206,8 @@ public class UniprotFTSPanel extends GFTSPanel int[] selectedRows = getResultTable().getSelectedRows(); for (int summaryRow : selectedRows) { - String idStr = getResultTable().getValueAt(summaryRow, - primaryKeyColIndex).toString(); + String idStr = getResultTable() + .getValueAt(summaryRow, primaryKeyColIndex).toString(); selectedIdsSet.add(idStr); } selectedIdsSet.addAll(paginatorCart); @@ -201,8 +217,7 @@ public class UniprotFTSPanel extends GFTSPanel } String ids = selectedIds.toString(); - // System.out.println(">>>>>>>>>>>>>>>> selected Ids: " + ids); - seqFetcher.getTextArea().setText(ids); + seqFetcher.setQuery(ids); Thread worker = new Thread(seqFetcher); worker.start(); delayAndEnableActionButtons(); @@ -217,7 +232,24 @@ public class UniprotFTSPanel extends GFTSPanel @Override public String getFTSFrameTitle() { - return ftsFrameTitle; + return defaultFTSFrameTitle; + } + + @Override + public Map getTempUserPrefs() + { + return tempUserPrefs; + } + + @Override + public String getCacheKey() + { + return UNIPROT_FTS_CACHE_KEY; } + @Override + public String getAutosearchPreference() + { + return UNIPROT_AUTOSEARCH; + } }