Exemple #1
0
  private void createFilterControl(Composite panel) {
    // Filter control
    searchControl = new SearchControl(panel);
    if (isHorizontal) {
      GridDataFactory.fillDefaults().grab(true, false).span(3, 1).applyTo(searchControl);
    } else {
      GridDataFactory.fillDefaults().grab(true, false).applyTo(searchControl);
    }

    searchControl.setInitialText("Tag name");
    searchControl.getFilterControl().setToolTipText(TOOLTIP_FILTER);

    proposalAdapter =
        new AutocompleteContentProposalAdapter(
            searchControl.getFilterControl(),
            new TextContentAdapter(),
            new AutocompleteContentProposalProvider(),
            null,
            null);
    proposalAdapter.setPropagateKeys(true);
    proposalAdapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
    proposalAdapter.addContentProposalListener(
        new IContentProposalListener() {

          @Override
          public void proposalAccepted(IContentProposal proposal) {
            selectAutocompleteOffer();
          }
        });

    searchControl
        .getFilterControl()
        .addListener(
            SWT.KeyDown,
            new Listener() {
              @Override
              public void handleEvent(Event event) {
                switch (event.keyCode) {
                    // ContentProposalAdapter can't be activated by any character and CTRL+SPACE at
                    // the same time,
                    // so by default it's activated by any alphanumeric character and here it's
                    // activated by CTRL+SPACE
                  case SWT.SPACE:
                    if ((event.stateMask & SWT.CTRL) == SWT.CTRL) {
                      proposalAdapter.showProposals();
                      event.doit = false;
                    }
                    break;
                    // Uses Enter to refresh listViewer if User typed filter query instead of using
                    // autocompletion
                  case SWT.CR:
                    selectAutocompleteOffer();
                    break;
                }
              }
            });
  }
Exemple #2
0
  private void updateFilterControl(IStructuredSelection selection) {
    if (selection.size() >= 1) {
      ArrayList<String> tags = new ArrayList<String>();
      for (Object o : selection.toArray()) {
        if (o instanceof Tag) {
          String tagName = ((Tag) o).getPath();
          if (tagName.matches(REGEX_SPEC_CHARS)) {
            tags.add("\"" + tagName + "\"");
          } else {
            tags.add(tagName);
          }
        }
      }

      proposalAdapter.setEnabled(false);
      searchControl.getFilterControl().setText(StringUtils.join(" " + OPERATOR_OR + " ", tags));
      proposalAdapter.setEnabled(true);
      if (selection.size() == 1) {
        listViewer.setInput(
            selection.getFirstElement()); // Don't run searching if only one tag is selected
      } else {
        updateList();
      }
    }
  }
Exemple #3
0
  /** Updates RCPTT item list depending on current filter value. */
  public void updateList() {
    String string = searchControl.getFilterString();
    if (string == null) string = "";
    string = string.trim();

    if (string.isEmpty()) {
      listViewer.setInput(null);
    } else {
      listViewer.setInput(TagsSearch.findAllByExpression(string));
    }
  }