Exemple #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);
 }
Exemple #2
0
    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
      }
    }
Exemple #3
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();
    }
  }
Exemple #4
0
  public SearchBar() {
    Log.info("Loading SearchBar...");

    // in the future, will be instantiated directly from a higher-level widget
    if (existsOnPage()) {
      loadAdditionalDataFromDivAttributes();
    }

    RootPanel.get("patternFieldContainer").add(autoCompletePatternField);
    RootPanel.get("patternNameFieldContainer").add(patternNameField);
    RootPanel.get("patternNameLabelContainer").add(patternNameLabel);
    RootPanel.get("starImageContainer").add(starImage);
    RootPanel.get("arrowImageContainer").add(arrowImage);
    RootPanel.get("savedSearchesContainer").add(savedSearchesPanel);

    setupAutoCompletingPatternField();
    setupPatternNameField();
    setupPatternNameLabel();
    setupStarImage();
    setupArrowImage();
    setupSavedSearches();

    //
    if (defaultSearchText != null) {
      this.autoCompletePatternField.setText(defaultSearchText);
      click(searchButton); // execute the search with this default search expression
    } else if (defaultSavedSearchPatternId != null) {
      try {
        Integer savedSearchId = Integer.valueOf(defaultSavedSearchPatternId);
        activateSavedSearch(savedSearchId);
      } catch (Exception e) {
        this.autoCompletePatternField.setText(
            MSG.view_searchBar_savedSearch_failFind(defaultSavedSearchPatternId));
        click(searchButton); // execute the search, which will help to further highlight the error
      }
    }

    // presume the enclosing page logic loads results without a button click
  }
  public void executeFetch(final DSRequest request, final DSResponse response) {

    long ctime = -1;
    int maxItems = -1;
    // retrieve current portlet display settings
    if ((this.portlet != null) && (this.portlet instanceof RecentlyAddedResourcesPortlet)) {
      RecentlyAddedResourcesPortlet recentAdditionsPortlet =
          (RecentlyAddedResourcesPortlet) this.portlet;
      if (recentAdditionsPortlet != null) {
        if (getMaximumRecentlyAddedToDisplay() > 0) {
          maxItems = getMaximumRecentlyAddedToDisplay();
        }

        // define the time window
        if (getMaximumRecentlyAddedWithinHours() > 0) {
          ctime =
              System.currentTimeMillis()
                  - (getMaximumRecentlyAddedWithinHours() * MeasurementUtility.HOURS);
          setOldestDate(ctime);
        }
      }
    }

    // TODO: spinder: revisit this later. ResourceCriteria mechanism does not work. Not sure if it's
    // better?
    //        ResourceCriteria c = new ResourceCriteria();
    //
    //        String p = request.getCriteria().getAttribute("parentId");
    //
    //        if (p == null) {
    //            c.addFilterResourceCategory(ResourceCategory.PLATFORM);
    //            c.fetchChildResources(true);
    //        } else {
    //            c.addFilterParentResourceId(Integer.parseInt(p));
    //        }

    // TODO GH: Enhance resourceCriteria query to support itime based filtering for
    // "Recently imported" resources

    // if logged in then proceed making server side calls
    if (UserSessionManager.isLoggedIn()) {
      GWTServiceLookup.getResourceService()
          .findRecentlyAddedResources(
              ctime,
              maxItems,
              new AsyncCallback<List<RecentlyAddedResourceComposite>>() {
                public void onFailure(Throwable throwable) {
                  CoreGUI.getErrorHandler()
                      .handleError(MSG.view_portlet_recentlyAdded_error1(), throwable);
                }

                public void onSuccess(List<RecentlyAddedResourceComposite> recentlyAddedList) {
                  List<RecentlyAddedResourceComposite> list =
                      new ArrayList<RecentlyAddedResourceComposite>();

                  for (RecentlyAddedResourceComposite recentlyAdded : recentlyAddedList) {
                    list.add(recentlyAdded);
                    list.addAll(recentlyAdded.getChildren());
                  }

                  response.setData(buildNodes(list));
                  response.setTotalRows(list.size());
                  processResponse(request.getRequestId(), response);
                }
              });
    } else { //
      Log.debug("user is not logged in. Not fetching recently added resource now.");
      // answer the datasource
      response.setTotalRows(0);
      processResponse(request.getRequestId(), response);
    }
  }
Exemple #6
0
 public void onKeyPress(KeyPressEvent event) {
   if (event.getCharCode() == KeyCodes.KEY_ENTER) {
     Log.debug("key press pattern name field");
     turnNameFieldIntoLabel();
   }
 }