public void onClick(ClickEvent event) { long diff = System.currentTimeMillis() - lastNameFieldBlurTime; if (Math.abs(diff) < 750) { /* * This event propagation is annoying. If the threshold is set too low, then both * the name field blur event and this star image click event fire...but the blur * event fires first, which turns the star white. Then a click on a white star * triggers edit mode, re-enabling the name field. However, setting the threshold * too high will prevent the click event from being handled when the user naturally * wants to click on the star in rapid succession within the threshold time frame. * It is hoped that 750ms will strike a nice balance, and that most users will never * experienced any oddities from this trade-off. */ return; } if (starImage.getUrl().endsWith(STAR_ACTIVE_URL)) { patternNameField.setText(DEFAULT_PATTERN_NAME); patternNameField.setVisible(true); patternNameField.selectAll(); patternNameField.setFocus(true); patternNameLabel.setVisible(false); } else if (starImage.getUrl().endsWith(STAR_ON_URL)) { starImage.setUrl(STAR_ACTIVE_URL); patternNameField.setVisible(false); patternNameLabel.setVisible(false); GWTServiceLookup.getSearchService().deleteSavedSearch(currentSearchId, blackHoleCallback); } }
private void activeSavedSearchByIdOrName(Integer savedSearchId, String savedSearchName) { Subject subject = UserSessionManager.getSessionSubject(); SavedSearchCriteria criteria = new SavedSearchCriteria(); criteria.addFilterSubjectId(subject.getId()); criteria.addFilterId(savedSearchId); // null OK criteria.addFilterName(savedSearchName); // null OK GWTServiceLookup.getSearchService() .findSavedSearchesByCriteria( criteria, new AsyncCallback<List<SavedSearch>>() { @Override public void onFailure(Throwable caught) { CoreGUI.getErrorHandler().handleError("Failure to select saved search", caught); } @Override public void onSuccess(List<SavedSearch> results) { if (results.size() != 1) { CoreGUI.getMessageCenter() .notify(new Message("Error selecting saved search", Severity.Error)); } else { SavedSearch savedSearch = results.get(0); activateSavedSearch(savedSearch); } } }); }
private void turnNameFieldIntoLabel() { String name = patternNameField.getText(); if (name.equalsIgnoreCase(DEFAULT_PATTERN_NAME)) { name = ""; } arrowImage.setVisible(true); patternNameField.setVisible(false); if (name.equals("")) { GWTServiceLookup.getSearchService().deleteSavedSearch(currentSearchId, blackHoleCallback); currentSearchId = 0; starImage.setUrl(STAR_OFF_URL); } else { // NOTE: currently do not support updated a saved search pattern if (currentSearchId == 0) { String pattern = autoCompletePatternField.getText(); createSavedSearch(name, pattern); } else { updateSavedSearchName(currentSearchId, name); } patternNameLabel.setText(elipse(name)); patternNameLabel.setVisible(true); starImage.setUrl(STAR_ON_URL); } }
class SearchSuggestOracle extends SuggestOracle { private SearchGWTServiceAsync searchService = GWTServiceLookup.getSearchService(); @Override public boolean isDisplayStringHTML() { return true; } @Override public void requestDefaultSuggestions(Request request, Callback callback) { requestSuggestions(request, callback); } @Override public void requestSuggestions(final Request request, final Callback callback) { SearchSuggestionRequest suggestionRequest = (SearchSuggestionRequest) request; String expression = suggestionRequest.getQuery(); int caretPosition = suggestionRequest.getCursorPosition(); searchService.getTabAwareSuggestions( searchBar.getSearchSubsystem(), expression, caretPosition, searchBar.getSelectedTab(), new AsyncCallback<List<SearchSuggestion>>() { public void onSuccess(List<SearchSuggestion> results) { adaptAndHandle(results.toArray(new SearchSuggestion[results.size()])); } public void onFailure(Throwable caught) { SearchSuggestion errorInform = new SearchSuggestion( Kind.InstructionalTextComment, MSG.view_searchBar_instructional_failSuggest()); adaptAndHandle(errorInform); } private void adaptAndHandle(SearchSuggestion... searchSuggestionResults) { List<SearchSuggestionOracleAdapter> adaptedResults = new java.util.ArrayList<SearchSuggestionOracleAdapter>(); for (SearchSuggestion next : searchSuggestionResults) { adaptedResults.add(new SearchSuggestionOracleAdapter(next)); } if (adaptedResults.isEmpty()) { adaptedResults.add( new SearchSuggestionOracleAdapter( new SearchSuggestion( Kind.InstructionalTextComment, MSG.view_searchBar_instructional_noSuggest()))); } SuggestOracle.Response response = new SuggestOracle.Response(adaptedResults); callback.onSuggestionsReady(request, response); } }); } }
private void updateSavedSearchName(final int savedSearchId, final String newName) { GWTServiceLookup.getSearchService() .updateSavedSearchName( savedSearchId, newName, new AsyncCallback<Boolean>() { @Override public void onSuccess(Boolean hadUpdates) { // no message bar to send update message to if hadUpdates } @Override public void onFailure(Throwable caught) {} }); }
private void createSavedSearch(final String name, final String pattern) { Subject subject = UserSessionManager.getSessionSubject(); SavedSearch newSavedSearch = new SavedSearch(searchSubsystem, name, pattern, subject); GWTServiceLookup.getSearchService() .createSavedSearch( newSavedSearch, new AsyncCallback<Integer>() { @Override public void onSuccess(Integer newSavedSearchId) { currentSearchId = newSavedSearchId; } @Override public void onFailure(Throwable caught) {} }); }
public void handleSelection( final int rowIndex, final int columnIndex, final SavedSearch savedSearch) { Log.debug( "SavedSearchesEventHandler.handleSelection(" + rowIndex + "," + columnIndex + "," + savedSearch + ")"); if (columnIndex == 1) { GWTServiceLookup.getSearchService() .deleteSavedSearch( savedSearch.getId(), new AsyncCallback<Void>() { @Override public void onFailure(Throwable caught) {} @Override public void onSuccess(Void result) { if (currentSearchId == savedSearch.getId()) { currentSearchId = 0; patternNameField.setValue("", true); patternNameField.setVisible(false); patternNameLabel.setText(""); patternNameLabel.setVisible(false); autoCompletePatternField.setFocus(true); starImage.setUrl(STAR_OFF_URL); savedSearchesPanel.hide(); } // is user deleting the one and only element in the list? if (savedSearchesGrid.size() == 1) { savedSearchesPanel.hide(); } savedSearchesGrid.removeRow(rowIndex); } }); } else { activateSavedSearch(savedSearch); // activating the saved search also clicks the button } }