/* (non-Javadoc)
  * @see org.eclipse.swt.widgets.Control#setEnabled(boolean)
  */
 public void setEnabled(boolean enabled) {
   fTree.getControl().setEnabled(enabled);
   if (enabled) {
     updateButtons();
   } else {
     fSelectButton.setEnabled(false);
     fSelectAllButton.setEnabled(false);
     fDeselectButton.setEnabled(false);
     fDeselectAllButton.setEnabled(false);
     fSelectRequiredButton.setEnabled(false);
     fCountLabel.setText(""); // $NON-NLS-1$
   }
   fModeLabel.setEnabled(enabled);
   fPluginModeButton.setEnabled(enabled);
   fFeaureModeButton.setEnabled(enabled);
   fShowLabel.setEnabled(enabled);
   fShowPluginsButton.setEnabled(enabled);
   fShowSourceButton.setEnabled(enabled);
   boolean isPluginMode = !fFeaureModeButton.getSelection();
   fGroupLabel.setEnabled(enabled && isPluginMode);
   if (fGroupCombo != null) {
     fGroupCombo.setEnabled(enabled && isPluginMode);
   } else {
     fGroupComboPart.setEnabled(enabled && isPluginMode);
   }
 }
  private void updateButtonEnablement(boolean doAddEnablement, boolean doRemoveEnablement) {
    updateCount();
    int availableCount = fAvailableListViewer.getTable().getItemCount();
    int importCount = fImportListViewer.getTable().getItemCount();

    if (doAddEnablement) updateSelectionBasedEnablement(fAvailableListViewer.getSelection(), true);
    if (doRemoveEnablement) updateSelectionBasedEnablement(fImportListViewer.getSelection(), false);

    fAddAllButton.setEnabled(availableCount > 0);
    fRemoveAllButton.setEnabled(importCount > 0);
    fAddRequiredButton.setEnabled(importCount > 0);
  }
  public void createClient(Section section, FormToolkit toolkit) {

    section.setLayout(FormLayoutFactory.createClearGridLayout(false, 1));
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    section.setLayoutData(data);

    section.setText(PDEUIMessages.IntroSection_sectionText);
    section.setDescription(PDEUIMessages.IntroSection_sectionDescription);

    boolean canCreateNew = TargetPlatformHelper.getTargetVersion() >= NEW_INTRO_SUPPORT_VERSION;

    Composite client = toolkit.createComposite(section);
    client.setLayout(FormLayoutFactory.createSectionClientGridLayout(false, canCreateNew ? 3 : 2));
    client.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    Label label = toolkit.createLabel(client, PDEUIMessages.IntroSection_introLabel, SWT.WRAP);
    GridData td = new GridData();
    td.horizontalSpan = canCreateNew ? 3 : 2;
    label.setLayoutData(td);

    Label introLabel = toolkit.createLabel(client, PDEUIMessages.IntroSection_introInput);
    introLabel.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));

    fIntroCombo = new ComboPart();
    fIntroCombo.createControl(client, toolkit, SWT.READ_ONLY);
    td = new GridData(GridData.FILL_HORIZONTAL);
    fIntroCombo.getControl().setLayoutData(td);
    loadManifestAndIntroIds(false);
    if (fAvailableIntroIds != null) fIntroCombo.setItems(fAvailableIntroIds);
    fIntroCombo.add(""); // $NON-NLS-1$
    fIntroCombo.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            handleSelection();
          }
        });

    if (canCreateNew) {
      Button button = toolkit.createButton(client, PDEUIMessages.IntroSection_new, SWT.PUSH);
      button.setEnabled(isEditable());
      button.setLayoutData(new GridData(GridData.FILL));
      button.addSelectionListener(
          new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
              handleNewIntro();
            }
          });
    }

    fIntroCombo.getControl().setEnabled(isEditable());

    toolkit.paintBordersFor(client);
    section.setClient(client);
    // Register to be notified when the model changes
    getModel().addModelChangedListener(this);
  }
 private void updateSelectionBasedEnablement(ISelection theSelection, boolean available) {
   if (available) fAddButton.setEnabled(!theSelection.isEmpty());
   else fRemoveButton.setEnabled(!theSelection.isEmpty());
 }
 private void updateImpButtons() {
   boolean empty = fElementViewer.getSelection().isEmpty();
   fRemoveButton.setEnabled(!empty);
   boolean hasElements = fElementViewer.getTable().getItemCount() > 0;
   fRemoveAllButton.setEnabled(hasElements);
 }
  private void updateButtons() {
    if (fTargetDefinition != null && !fTree.getSelection().isEmpty()) {
      Object[] selection = ((IStructuredSelection) fTree.getSelection()).toArray();
      boolean hasResolveBundle = false;
      boolean hasParent = false;
      boolean allSelected = true;
      boolean noneSelected = true;
      for (int i = 0; i < selection.length; i++) {
        if (!hasResolveBundle || !hasParent) {
          if (selection[i] instanceof IResolvedBundle) {
            hasResolveBundle = true;
          } else {
            hasParent = true;
          }
        }
        boolean checked = fTree.getChecked(selection[i]);
        if (checked) {
          noneSelected = false;
        } else {
          allSelected = false;
        }
      }
      // Selection is available if not everything is already selected and not both a parent and
      // child item are selected
      fSelectButton.setEnabled(!allSelected && !(hasResolveBundle && hasParent));
      fDeselectButton.setEnabled(!noneSelected && !(hasResolveBundle && hasParent));
    } else {
      fSelectButton.setEnabled(false);
      fDeselectButton.setEnabled(false);
    }

    int total = fAllBundles.size();
    if (fFeaureModeButton.getSelection()) {
      if (fTargetDefinition == null) {
        total = 0;
      } else {
        total = fTargetDefinition.getAllFeatures().length;
        total += ((TargetDefinition) fTargetDefinition).getOtherBundles().length;
      }
    }
    if (fMissing != null) {
      total += fMissing.size();
    }

    fSelectAllButton.setEnabled(fTargetDefinition != null && fTree.getCheckedLeafCount() != total);
    fDeselectAllButton.setEnabled(fTargetDefinition != null && fTree.getCheckedLeafCount() != 0);
    fSelectRequiredButton.setEnabled(
        fTargetDefinition != null
            && fTree.getCheckedLeafCount() > 0
            && fTree.getCheckedLeafCount() != total);

    if (fTargetDefinition != null) {
      fCountLabel.setText(
          MessageFormat.format(
              Messages.TargetContentsGroup_9,
              new String[] {
                Integer.toString(fTree.getCheckedLeafCount()), Integer.toString(total)
              }));
    } else {
      fCountLabel.setText(""); // $NON-NLS-1$
    }
  }