/* (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 Object[] getBundleChildren(Object parent) {
   Object[] result = null;
   if (parent == null) {
     result = fAllBundles.toArray();
   } else if (fFeaureModeButton.getSelection() && parent == OTHER_CATEGORY) {
     result = ((TargetDefinition) fTargetDefinition).getOtherBundles();
   } else if (fGrouping == GROUP_BY_CONTAINER && parent instanceof IBundleContainer) {
     IBundleContainer container = (IBundleContainer) parent;
     result = container.getBundles();
   } else if (fGrouping == GROUP_BY_FILE_LOC && parent instanceof IPath) {
     List bundles = (List) getFileBundleMapping().get(parent);
     if (bundles != null && bundles.size() > 0) {
       result = bundles.toArray();
     }
   }
   if (result == null) {
     return new Object[0];
   }
   return result;
 }
 private void updateCheckState() {
   List result = new ArrayList();
   // Checked error statuses
   if (fMissing != null) {
     result.addAll(fMissing);
   }
   if (fFeaureModeButton.getSelection()) {
     // Checked features and plugins
     result.addAll(((TargetDefinition) fTargetDefinition).getFeaturesAndBundles());
   } else {
     // Bundles with errors are already included from fMissing, do not add twice
     IResolvedBundle[] bundles = fTargetDefinition.getBundles();
     for (int i = 0; i < bundles.length; i++) {
       if (bundles[i].getStatus().isOK()) {
         result.add(bundles[i]);
       }
     }
   }
   fTree.setCheckedElements(result.toArray());
 }
 /* (non-Javadoc)
  * @see org.eclipse.pde.internal.ui.editor.StructuredViewerSection#buttonSelected(int)
  */
 protected void buttonSelected(int index) {
   switch (index) {
     case 0:
       handleAdd();
       break;
     case 1:
       handleAddWorkingSet();
       break;
     case 2:
       handleAddRequired(getProduct().getPlugins(), fIncludeOptionalButton.getSelection());
       break;
     case 3:
       handleDelete();
       break;
     case 4:
       handleRemoveAll();
       break;
     case 5:
       handleProperties();
       break;
   }
 }
  private void addFilters() {
    fVersionFilter = new VersionFilter();
    fVersionFilter.setModel(fModels);
    fSourceFilter = new SourcePluginFilter(fPage1.getState());
    fAvailableFilter = new AvailableFilter();
    fAvailableListViewer.addFilter(fAvailableFilter);
    if (fFilterOldVersionButton.getSelection()) {
      fAvailableListViewer.addFilter(fVersionFilter);
    }
    fAvailableListViewer.addFilter(fSourceFilter);
    fRepositoryFilter = new RepositoryFilter();
    fAvailableListViewer.addFilter(fRepositoryFilter);

    fFilterJob =
        new WorkbenchJob("FilterJob") { // $NON-NLS-1$
          @Override
          public IStatus runInUIThread(IProgressMonitor monitor) {
            handleFilter();
            return Status.OK_STATUS;
          }
        };
    fFilterJob.setSystem(true);
  }
 @Override
 public void storeSettings() {
   IDialogSettings settings = getDialogSettings();
   settings.put(SETTINGS_SHOW_LATEST, fFilterOldVersionButton.getSelection());
   super.storeSettings();
 }
 public boolean getSelection() {
   return fEnableJavaScriptSupport.getSelection();
 }
 protected void updateJREWidgets() {
   fNamedJREsCombo.setEnabled(fNamedJREButton.getSelection());
   fExecEnvsCombo.setEnabled(fExecEnvButton.getSelection());
 }
 public boolean includeOptionalDependencies() {
   return fIncludeOptionalButton.getSelection();
 }
  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$
    }
  }
  public void saveIncludedBundleState() {
    if (fFeaureModeButton.getSelection()) {
      // Create a list of checked bundle infos
      List included = new ArrayList();
      int missingCount = 0;
      Object[] checked = fTree.getCheckedLeafElements();
      for (int i = 0; i < checked.length; i++) {
        if (checked[i] instanceof IFeatureModel) {
          included.add(
              new NameVersionDescriptor(
                  ((IFeatureModel) checked[i]).getFeature().getId(),
                  null,
                  NameVersionDescriptor.TYPE_FEATURE));
        }
        if (checked[i] instanceof IResolvedBundle) {
          // Missing features are included as IResolvedBundles, save them as features instead
          if (((IResolvedBundle) checked[i]).getStatus().getCode()
              == IResolvedBundle.STATUS_PLUGIN_DOES_NOT_EXIST) {
            included.add(
                new NameVersionDescriptor(
                    ((IResolvedBundle) checked[i]).getBundleInfo().getSymbolicName(),
                    null,
                    NameVersionDescriptor.TYPE_PLUGIN));
            missingCount++;
          } else if (((IResolvedBundle) checked[i]).getStatus().getCode()
              == IResolvedBundle.STATUS_FEATURE_DOES_NOT_EXIST) {
            included.add(
                new NameVersionDescriptor(
                    ((IResolvedBundle) checked[i]).getBundleInfo().getSymbolicName(),
                    null,
                    NameVersionDescriptor.TYPE_FEATURE));
            missingCount++;
          } else {
            included.add(
                new NameVersionDescriptor(
                    ((IResolvedBundle) checked[i]).getBundleInfo().getSymbolicName(), null));
          }
        }
      }

      if (included.size() == 0) {
        fTargetDefinition.setIncluded(new NameVersionDescriptor[0]);
      } else if (included.size() == 0
          || included.size() - missingCount
              == fTargetDefinition.getAllFeatures().length
                  + ((TargetDefinition) fTargetDefinition).getOtherBundles().length) {
        fTargetDefinition.setIncluded(null);
      } else {
        fTargetDefinition.setIncluded(
            (NameVersionDescriptor[]) included.toArray(new NameVersionDescriptor[included.size()]));
      }
    } else {
      // Figure out if there are multiple bundles sharing the same id
      Set multi = new HashSet(); // BSNs of bundles with multiple versions available
      Set all = new HashSet();
      for (Iterator iterator = fAllBundles.iterator(); iterator.hasNext(); ) {
        IResolvedBundle rb = (IResolvedBundle) iterator.next();
        if (!all.add(rb.getBundleInfo().getSymbolicName())) {
          multi.add(rb.getBundleInfo().getSymbolicName());
        }
      }

      // Create a list of checked bundle infos
      List included = new ArrayList();
      Object[] checked = fTree.getCheckedLeafElements();
      for (int i = 0; i < checked.length; i++) {
        if (checked[i] instanceof IResolvedBundle) {
          // Create the bundle info object
          String bsn = ((IResolvedBundle) checked[i]).getBundleInfo().getSymbolicName();
          NameVersionDescriptor info = null;
          if (multi.contains(bsn)) {
            // include version info
            info =
                new NameVersionDescriptor(
                    bsn, ((IResolvedBundle) checked[i]).getBundleInfo().getVersion());
          } else {
            // don't store version info
            info = new NameVersionDescriptor(bsn, null);
          }
          included.add(info);
        }
      }

      if (included.size() == 0) {
        fTargetDefinition.setIncluded(new NameVersionDescriptor[0]);
      } else if (included.size() == fAllBundles.size() + fMissing.size()) {
        fTargetDefinition.setIncluded(null);
      } else {
        fTargetDefinition.setIncluded(
            (NameVersionDescriptor[]) included.toArray(new NameVersionDescriptor[included.size()]));
      }
    }
  }
  private void showMessageBoxDialog() {
    int style = getStyle();
    if (okButton.getEnabled() && okButton.getSelection()) {
      style |= SWT.OK;
    }
    if (cancelButton.getEnabled() && cancelButton.getSelection()) {
      style |= SWT.CANCEL;
    }
    if (yesButton.getEnabled() && yesButton.getSelection()) {
      style |= SWT.YES;
    }
    if (noButton.getEnabled() && noButton.getSelection()) {
      style |= SWT.NO;
    }
    if (retryButton.getEnabled() && retryButton.getSelection()) {
      style |= SWT.RETRY;
    }
    if (abortButton.getEnabled() && abortButton.getSelection()) {
      style |= SWT.ABORT;
    }
    if (ignoreButton.getEnabled() && ignoreButton.getSelection()) {
      style |= SWT.IGNORE;
    }
    if (iconErrorButton.getEnabled() && iconErrorButton.getSelection()) {
      style |= SWT.ICON_ERROR;
    }
    if (iconInformationButton.getEnabled() && iconInformationButton.getSelection()) {
      style |= SWT.ICON_INFORMATION;
    }
    if (iconQuestionButton.getEnabled() && iconQuestionButton.getSelection()) {
      style |= SWT.ICON_QUESTION;
    }
    if (iconWarningButton.getEnabled() && iconWarningButton.getSelection()) {
      style |= SWT.ICON_WARNING;
    }
    if (iconWorkingButton.getEnabled() && iconWorkingButton.getSelection()) {
      style |= SWT.ICON_WORKING;
    }

    String title = "MessageBox Title";
    String mesg = "Lorem ipsum dolor sit amet consectetuer adipiscing elit.";
    MessageBox mb = new MessageBox(getShell(), style);
    mb.setText(title);
    mb.setMessage(mesg);
    int result = mb.open();
    String strResult = "";
    switch (result) {
      case SWT.OK:
        strResult = "SWT.OK";
        break;
      case SWT.YES:
        strResult = "SWT.YES";
        break;
      case SWT.NO:
        strResult = "SWT.NO";
        break;
      case SWT.CANCEL:
        strResult = "SWT.CANCEL";
        break;
      case SWT.ABORT:
        strResult = "SWT.ABORT";
        break;
      case SWT.RETRY:
        strResult = "SWT.RETRY";
        break;
      case SWT.IGNORE:
        strResult = "SWT.IGNORE";
        break;
      default:
        strResult = "" + result;
        break;
    }
    messageBoxDlgResLabel.setText("Result: " + strResult);
    messageBoxDlgResLabel.pack();
  }