Beispiel #1
0
 public void activateSavedSearch(SavedSearch savedSearch) {
   currentSearchId = savedSearch.getId();
   autoCompletePatternField.setValue(savedSearch.getPattern(), true);
   patternNameField.setValue(savedSearch.getName(), true);
   Log.debug(
       "search results change: [" + savedSearch.getName() + "," + savedSearch.getPattern() + "]");
   turnNameFieldIntoLabel();
   savedSearchesPanel.hide();
   click(searchButton);
 }
Beispiel #2
0
  protected void complete(Suggestion suggestion, int cursorPosition) {
    SearchSuggestion searchSuggestion = extraSearchSuggestion(suggestion);
    String currentText = getText().toLowerCase();

    if (searchSuggestion.getKind() == SearchSuggestion.Kind.GlobalSavedSearch
        || searchSuggestion.getKind() == SearchSuggestion.Kind.UserSavedSearch) {
      // execute saved searches immediately, since they presumably constitute complete expressions
      Log.debug("selected '" + searchSuggestion.getLabel() + "' saved search suggestion");
      searchBar.activateSavedSearch(searchSuggestion.getValue());
    } else {
      // selecting a simple suggestion or advanced suggestion

      int previousWhitespaceIndex = cursorPosition;
      if (cursorPosition != 0) {
        while (--previousWhitespaceIndex > 0) {
          if (currentText.charAt(previousWhitespaceIndex) == ' ') {
            previousWhitespaceIndex++; // put index right after found whitespace
            break;
          }
        }
      }

      int futureWhitespaceIndex = cursorPosition;
      while (futureWhitespaceIndex < currentText.length()) {
        if (currentText.charAt(futureWhitespaceIndex) == ' ') {
          break;
        }
        futureWhitespaceIndex++;
      }

      String before = getText().substring(0, previousWhitespaceIndex);
      String completion = suggestion.getReplacementString();
      String after = getText().substring(futureWhitespaceIndex);

      setValue(before + completion + after, true);
      currentCursorPosition = before.length() + completion.length();
      getTextBox().setCursorPos(currentCursorPosition);

      showSuggestions();
    }
  }