Exemplo n.º 1
0
  /*
   * Implementation of method defined on <code>IAction</code>.
   */
  public void run() {
    FiltersContentProvider contentProvider = new FiltersContentProvider();

    ListSelectionDialog dialog =
        new ListSelectionDialog(
            explorer.getSite().getShell(),
            explorer.getTreeViewer(),
            contentProvider,
            new LabelProvider(),
            FILTER_SELECTION_MESSAGE);
    dialog.setTitle(FILTER_TITLE_MESSAGE);
    dialog.setInitialSelections(contentProvider.getInitialSelections());
    dialog.open();
    if (dialog.getReturnCode() == Dialog.OK) {
      Object[] results = dialog.getResult();
      String[] selectedPatterns = new String[results.length];
      System.arraycopy(results, 0, selectedPatterns, 0, results.length);
      contentProvider.setSelections(selectedPatterns);
      Viewer viewer = explorer.getTreeViewer();
      viewer.getControl().setRedraw(false);
      explorer.updateFilters(selectedPatterns);
      viewer.refresh();
      viewer.getControl().setRedraw(true);
    }
  }
  /*
   * Implementation of method defined on <code>IAction</code>.
   */
  @Override
  public void run() {
    IResourceNavigator navigator = getNavigator();
    ResourcePatternFilter filter = navigator.getPatternFilter();
    FiltersContentProvider contentProvider = new FiltersContentProvider(filter);

    ListSelectionDialog dialog =
        new ListSelectionDialog(
            getShell(),
            getViewer(),
            contentProvider,
            new LabelProvider(),
            FILTER_SELECTION_MESSAGE);

    dialog.setTitle(FILTER_TITLE_MESSAGE);
    dialog.setInitialSelections(contentProvider.getInitialSelections());
    dialog.open();
    if (dialog.getReturnCode() == Window.OK) {
      Object[] results = dialog.getResult();
      String[] selectedPatterns = new String[results.length];
      System.arraycopy(results, 0, selectedPatterns, 0, results.length);
      filter.setPatterns(selectedPatterns);
      navigator.setFiltersPreference(selectedPatterns);
      Viewer viewer = getViewer();
      viewer.getControl().setRedraw(false);
      viewer.refresh();
      viewer.getControl().setRedraw(true);
    }
  }
  private void handleCustomizePressed() {
    List input = SearchPlugin.getDefault().getSearchPageDescriptors();
    input = filterByActivities(input);

    final ArrayList createdImages = new ArrayList(input.size());
    ILabelProvider labelProvider =
        new LabelProvider() {
          public String getText(Object element) {
            if (element instanceof SearchPageDescriptor)
              return LegacyActionTools.removeMnemonics(((SearchPageDescriptor) element).getLabel());
            return null;
          }

          public Image getImage(Object element) {
            if (element instanceof SearchPageDescriptor) {
              ImageDescriptor imageDesc = ((SearchPageDescriptor) element).getImage();
              if (imageDesc == null) return null;
              Image image = imageDesc.createImage();
              if (image != null) createdImages.add(image);
              return image;
            }
            return null;
          }
        };

    String message = SearchMessages.SearchPageSelectionDialog_message;

    ListSelectionDialog dialog =
        new ListSelectionDialog(
            getShell(), input, new ArrayContentProvider(), labelProvider, message) {
          Button fLastUsedPageButton;

          public void create() {
            super.create();
            final CheckboxTableViewer viewer = getViewer();
            final Button okButton = this.getOkButton();
            viewer.addCheckStateListener(
                new ICheckStateListener() {
                  public void checkStateChanged(CheckStateChangedEvent event) {
                    okButton.setEnabled(viewer.getCheckedElements().length > 0);
                  }
                });
            SelectionListener listener =
                new SelectionAdapter() {
                  public void widgetSelected(SelectionEvent e) {
                    okButton.setEnabled(viewer.getCheckedElements().length > 0);
                  }
                };
            this.getButton(IDialogConstants.SELECT_ALL_ID).addSelectionListener(listener);
            this.getButton(IDialogConstants.DESELECT_ALL_ID).addSelectionListener(listener);
          }

          protected Control createDialogArea(Composite parent) {
            Composite control = (Composite) super.createDialogArea(parent);
            fLastUsedPageButton = new Button(control, SWT.CHECK);
            fLastUsedPageButton.setText(
                SearchMessages.SearchPageSelectionDialog_rememberLastUsedPage_message);
            fLastUsedPageButton.setSelection(
                fDialogSettings.getBoolean(STORE_IS_OPEN_PREVIOUS_PAGE));
            return control;
          }

          protected void okPressed() {
            fDialogSettings.put(STORE_IS_OPEN_PREVIOUS_PAGE, fLastUsedPageButton.getSelection());
            super.okPressed();
          }
        };
    dialog.setTitle(SearchMessages.SearchPageSelectionDialog_title);
    dialog.setInitialSelections(
        SearchPlugin.getDefault().getEnabledSearchPageDescriptors(fInitialPageId).toArray());
    if (dialog.open() == Window.OK) {
      SearchPageDescriptor.setEnabled(dialog.getResult());
      Display display = getShell().getDisplay();
      close();
      if (display != null && !display.isDisposed()) {
        display.asyncExec(
            new Runnable() {
              public void run() {
                new OpenSearchDialogAction().run();
              }
            });
      }
    }
    destroyImages(createdImages);
  }