/**
   * Creates this group's tree viewer.
   *
   * @param parent parent composite
   * @param width the width
   * @param height the height
   */
  protected void createTreeViewer(Composite parent, int width, int height) {
    Tree tree = new Tree(parent, SWT.CHECK | SWT.BORDER);
    GridData data = new GridData(GridData.FILL_BOTH);
    data.widthHint = width;
    data.heightHint = height;
    tree.setLayoutData(data);

    fTreeViewer = new CheckboxTreeViewer(tree);
    fTreeViewer.setUseHashlookup(true);
    fTreeViewer.setContentProvider(fTreeContentProvider);
    fTreeViewer.setLabelProvider(fTreeLabelProvider);
    fTreeViewer.addTreeListener(this);
    fTreeViewer.addCheckStateListener(this);
    fTreeViewer.addSelectionChangedListener(this);
  }
Exemplo n.º 2
0
  /*
   * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
   */
  public void createControl(Composite parent) {
    initializeDialogUnits(parent);

    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout());
    composite.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
    setControl(composite);

    Label label = new Label(composite, SWT.WRAP);
    label.setText(WorkingSetMessages.ScriptWorkingSetPage_workingSet_name);
    GridData gd =
        new GridData(
            GridData.GRAB_HORIZONTAL
                | GridData.HORIZONTAL_ALIGN_FILL
                | GridData.VERTICAL_ALIGN_CENTER);
    label.setLayoutData(gd);

    fWorkingSetName = new Text(composite, SWT.SINGLE | SWT.BORDER);
    fWorkingSetName.setLayoutData(
        new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
    fWorkingSetName.addModifyListener(
        new ModifyListener() {
          public void modifyText(ModifyEvent e) {
            validateInput();
          }
        });
    fWorkingSetName.setFocus();

    label = new Label(composite, SWT.WRAP);
    label.setText(WorkingSetMessages.ScriptWorkingSetPage_workingSet_content);
    gd =
        new GridData(
            GridData.GRAB_HORIZONTAL
                | GridData.HORIZONTAL_ALIGN_FILL
                | GridData.VERTICAL_ALIGN_CENTER);
    label.setLayoutData(gd);

    fTree = new CheckboxTreeViewer(composite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    gd = new GridData(GridData.FILL_BOTH | GridData.GRAB_VERTICAL);
    gd.heightHint = convertHeightInCharsToPixels(15);
    fTree.getControl().setLayoutData(gd);

    fTreeContentProvider = new ScriptWorkingSetPageContentProvider();
    fTree.setContentProvider(fTreeContentProvider);

    AppearanceAwareLabelProvider fScriptElementLabelProvider =
        new AppearanceAwareLabelProvider(
            AppearanceAwareLabelProvider.DEFAULT_TEXTFLAGS | ScriptElementLabels.P_COMPRESSED,
            AppearanceAwareLabelProvider.DEFAULT_IMAGEFLAGS
                | ScriptElementImageProvider.SMALL_ICONS,
            DLTKUIPlugin.getDefault().getPreferenceStore());

    fTree.setLabelProvider(new DecoratingModelLabelProvider(fScriptElementLabelProvider));
    fTree.setSorter(new ModelElementSorter());
    if (DLTKCore.DEBUG) {
      System.err.println("Add empty inner package filter support here..."); // $NON-NLS-1$
    }
    // fTree.addFilter(new EmptyInnerPackageFilter());
    fTree.setUseHashlookup(true);

    fTree.setInput(DLTKCore.create(ResourcesPlugin.getWorkspace().getRoot()));

    fTree.addCheckStateListener(
        new ICheckStateListener() {
          public void checkStateChanged(CheckStateChangedEvent event) {
            handleCheckStateChange(event);
          }
        });

    fTree.addTreeListener(
        new ITreeViewerListener() {
          public void treeCollapsed(TreeExpansionEvent event) {}

          public void treeExpanded(TreeExpansionEvent event) {
            final Object element = event.getElement();
            if (fTree.getGrayed(element) == false)
              BusyIndicator.showWhile(
                  getShell().getDisplay(),
                  new Runnable() {
                    public void run() {
                      setSubtreeChecked(element, fTree.getChecked(element), false);
                    }
                  });
          }
        });

    // Add select / deselect all buttons for bug 46669
    Composite buttonComposite = new Composite(composite, SWT.NONE);
    GridLayout layout = new GridLayout(2, false);
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    buttonComposite.setLayout(layout);
    buttonComposite.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    Button selectAllButton = new Button(buttonComposite, SWT.PUSH);
    selectAllButton.setText(WorkingSetMessages.ScriptWorkingSetPage_selectAll_label);
    selectAllButton.setToolTipText(WorkingSetMessages.ScriptWorkingSetPage_selectAll_toolTip);
    selectAllButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent selectionEvent) {
            fTree.setCheckedElements(fTreeContentProvider.getElements(fTree.getInput()));
            validateInput();
          }
        });
    selectAllButton.setLayoutData(new GridData());
    SWTUtil.setButtonDimensionHint(selectAllButton);

    Button deselectAllButton = new Button(buttonComposite, SWT.PUSH);
    deselectAllButton.setText(WorkingSetMessages.ScriptWorkingSetPage_deselectAll_label);
    deselectAllButton.setToolTipText(WorkingSetMessages.ScriptWorkingSetPage_deselectAll_toolTip);
    deselectAllButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent selectionEvent) {
            fTree.setCheckedElements(new Object[0]);
            validateInput();
          }
        });
    deselectAllButton.setLayoutData(new GridData());
    SWTUtil.setButtonDimensionHint(deselectAllButton);

    if (fWorkingSet != null) fWorkingSetName.setText(fWorkingSet.getName());
    initializeCheckedState();
    validateInput();

    Dialog.applyDialogFont(composite);
    // Set help for the page
    if (DLTKCore.DEBUG) {
      System.err.println("Add help support here..."); // $NON-NLS-1$
    }
    // ScriptUIHelp.setHelp(fTree, IScriptHelpContextIds.Script_WORKING_SET_PAGE);
  }