/* (non-Javadoc)
   * @see org.eclipse.pde.internal.ui.editor.PDESection#createClient(org.eclipse.ui.forms.widgets.Section, org.eclipse.ui.forms.widgets.FormToolkit)
   */
  protected void createClient(Section section, FormToolkit toolkit) {

    section.setLayout(FormLayoutFactory.createClearGridLayout(false, 1));
    GridData sectionData = new GridData(GridData.FILL_BOTH);
    sectionData.verticalSpan = 2;
    section.setLayoutData(sectionData);

    Composite container = createClientContainer(section, 2, toolkit);
    createViewerPartControl(container, SWT.MULTI, 2, toolkit);
    container.setLayoutData(new GridData(GridData.FILL_BOTH));

    createOptionalDependenciesButton(container);

    TablePart tablePart = getTablePart();
    fPluginTable = tablePart.getTableViewer();
    fPluginTable.setContentProvider(new ContentProvider());
    fPluginTable.setLabelProvider(PDEPlugin.getDefault().getLabelProvider());
    fPluginTable.setComparator(
        new ViewerComparator() {
          public int compare(Viewer viewer, Object e1, Object e2) {
            IProductPlugin p1 = (IProductPlugin) e1;
            IProductPlugin p2 = (IProductPlugin) e2;
            return super.compare(viewer, p1.getId(), p2.getId());
          }
        });
    GridData data = (GridData) tablePart.getControl().getLayoutData();
    data.minimumWidth = 200;
    fPluginTable.setInput(getProduct());

    tablePart.setButtonEnabled(0, isEditable());
    tablePart.setButtonEnabled(1, isEditable());
    tablePart.setButtonEnabled(2, isEditable());

    // remove buttons will be updated on refresh

    tablePart.setButtonEnabled(5, isEditable());

    toolkit.paintBordersFor(container);
    section.setClient(container);

    section.setText(PDEUIMessages.Product_PluginSection_title);
    section.setDescription(PDEUIMessages.Product_PluginSection_desc);
    getModel().addModelChangedListener(this);
    createSectionToolbar(section, toolkit);
  }
  /* (non-Javadoc)
   * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
   */
  public void createControl(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout());
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    setControl(composite);

    Label label = new Label(composite, SWT.WRAP);
    label.setText(PDEUIMessages.PluginWorkingSet_setName);
    label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

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

    label = new Label(composite, SWT.WRAP);
    label.setText(PDEUIMessages.PluginWorkingSet_setContent);
    label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    fTree = new CheckboxFilteredTree(composite, SWT.BORDER, new PatternFilter());
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.heightHint = 250;
    fTree.getViewer().getControl().setLayoutData(gd);
    final IStructuredContentProvider fTableContentProvider = new ContentProvider();
    fTree.getCheckboxTreeViewer().setContentProvider(fTableContentProvider);
    fTree.getCheckboxTreeViewer().setLabelProvider(new WorkingSetLabelProvider());
    fTree.getCheckboxTreeViewer().setUseHashlookup(true);
    fTree.getCheckboxTreeViewer().setInput(PDECore.getDefault());

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

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

    Button selectAllButton = new Button(buttonComposite, SWT.PUSH);
    selectAllButton.setText(PDEUIMessages.PluginWorkingSet_selectAll_label);
    selectAllButton.setToolTipText(PDEUIMessages.PluginWorkingSet_selectAll_toolTip);
    selectAllButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent selectionEvent) {
            fTree
                .getCheckboxTreeViewer()
                .setCheckedElements(
                    fTableContentProvider.getElements(fTree.getCheckboxTreeViewer().getInput()));
            validatePage();
          }
        });
    selectAllButton.setLayoutData(new GridData());
    SWTUtil.setButtonDimensionHint(selectAllButton);

    Button deselectAllButton = new Button(buttonComposite, SWT.PUSH);
    deselectAllButton.setText(PDEUIMessages.PluginWorkingSet_deselectAll_label);
    deselectAllButton.setToolTipText(PDEUIMessages.PluginWorkingSet_deselectAll_toolTip);
    deselectAllButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent selectionEvent) {
            fTree.getCheckboxTreeViewer().setCheckedElements(new Object[0]);
            validatePage();
          }
        });
    deselectAllButton.setLayoutData(new GridData());
    SWTUtil.setButtonDimensionHint(deselectAllButton);
    setPageComplete(false);
    setMessage(PDEUIMessages.PluginWorkingSet_message);

    initialize();
    Dialog.applyDialogFont(composite);

    PlatformUI.getWorkbench()
        .getHelpSystem()
        .setHelp(composite, IHelpContextIds.PLUGIN_WORKING_SET);
  }