Пример #1
0
  public void testCheckProviderWithFilter() {
    CheckboxTreeViewer ctv = (CheckboxTreeViewer) fViewer;

    final CheckStateProviderTestsUtil.Filter filter = new CheckStateProviderTestsUtil.Filter();
    ctv.addFilter(filter);

    // First provider
    // Should cause visible items' check state adhere to provider
    final TestCheckStateProvider checkStateProvider = new TestCheckStateProvider(0);
    ctv.setCheckStateProvider(checkStateProvider);
    ctv.expandAll();

    // Check that all states are properly set
    checkAllStates("Testing checkbox state with a sorter", ctv, 0);

    // Check that the provider is only invoked on elements which pass the filter
    for (Iterator i = checkStateProvider.isCheckedInvokedOn.iterator(); i.hasNext(); ) {
      TestElement element = (TestElement) i.next();
      assertTrue(
          "The check provider should not be invoked on elements which did not get through the filter",
          filter.select(ctv, null, element));
    }

    for (Iterator i = checkStateProvider.isGrayedInvokedOn.iterator(); i.hasNext(); ) {
      TestElement element = (TestElement) i.next();
      assertTrue(
          "The check provider should not be invoked on elements which did not get through the filter",
          filter.select(ctv, null, element));
    }
  }
  /**
   * Creates the tree viewer.
   *
   * @param parent the parent composite
   * @return the tree viewer
   */
  protected CheckboxTreeViewer createTreeViewer(Composite parent) {
    fViewer = new CheckboxTreeViewer(parent, SWT.BORDER);

    fViewer.setContentProvider(fContentProvider);
    fViewer.setLabelProvider(fLabelProvider);
    fViewer.addCheckStateListener(
        new ICheckStateListener() {
          public void checkStateChanged(CheckStateChangedEvent event) {
            updateOKStatus();
          }
        });

    fViewer.setComparator(new ResourceComparator(ResourceComparator.NAME));
    if (fFilters != null) {
      for (int i = 0; i != fFilters.size(); i++) fViewer.addFilter(fFilters.get(i));
    }

    fViewer.setInput(fInput);

    return fViewer;
  }
  /**
   * Creates the tree viewer.
   *
   * @param parent the parent composite
   * @return the tree viewer
   */
  protected CheckboxTreeViewer createTreeViewer(Composite parent) {
    if (fContainerMode) {
      fViewer = new ContainerCheckedTreeViewer(parent, this.fStyle);
    } else {
      fViewer = new CheckboxTreeViewer(parent, this.fStyle);
    }
    fViewer.setContentProvider(fContentProvider);
    fViewer.setLabelProvider(fLabelProvider);
    fViewer.addCheckStateListener(
        new ICheckStateListener() {

          public void checkStateChanged(CheckStateChangedEvent event) {
            updateOKStatus();
          }
        });
    fViewer.setComparator(fComparator);
    if (fFilters != null) {
      for (int i = 0; i != fFilters.size(); i++) {
        fViewer.addFilter((ViewerFilter) fFilters.get(i));
      }
    }
    fViewer.setInput(fInput);
    return fViewer;
  }
 /**
  * Adds the given filter to the tree viewer and triggers refiltering and resorting of the
  * elements.
  *
  * @param filter a viewer filter
  */
 public void addTreeFilter(ViewerFilter filter) {
   fTreeViewer.addFilter(filter);
 }