/* (non-Javadoc)
  * @see org.eclipse.ui.forms.AbstractFormPart#setFormInput(java.lang.Object)
  */
 public boolean setFormInput(Object input) {
   if (input instanceof ISiteCategoryDefinition) {
     fCategoryViewer.setSelection(new StructuredSelection(input), true);
     return true;
   }
   if (input instanceof SiteFeatureAdapter) {
     // first, expand the category, otherwise tree will not find the feature
     String category = ((SiteFeatureAdapter) input).category;
     if (category != null) {
       expandCategory(category);
     }
     fCategoryViewer.setSelection(new StructuredSelection(input), true);
     return true;
   }
   return super.setFormInput(input);
 }
  /**
   * @param candidates Array of IFeatureModel
   * @param monitor
   * @throws CoreException
   */
  public void doAdd(Object[] candidates) throws CoreException {
    // Category to add features to
    String categoryName = null;
    ISelection selection = fCategoryViewer.getSelection();
    if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
      Object element = ((IStructuredSelection) selection).getFirstElement();
      if (element instanceof ISiteCategoryDefinition) {
        categoryName = ((ISiteCategoryDefinition) element).getName();
      } else if (element instanceof SiteFeatureAdapter) {
        categoryName = ((SiteFeatureAdapter) element).category;
      }
    }
    //
    ISiteFeature[] added = new ISiteFeature[candidates.length];
    for (int i = 0; i < candidates.length; i++) {
      IFeatureModel candidate = (IFeatureModel) candidates[i];
      ISiteFeature child = createSiteFeature(fModel, candidate);
      if (categoryName != null) {
        addCategory(child, categoryName);
      }
      added[i] = child;
    }

    // Update model
    fModel.getSite().addFeatures(added);
    // Select last added feature
    if (added.length > 0) {
      if (categoryName != null) {
        expandCategory(categoryName);
      }
      fCategoryViewer.setSelection(
          new StructuredSelection(new SiteFeatureAdapter(categoryName, added[added.length - 1])),
          true);
    }
  }
 private void handleAddCategoryDefinition() {
   String name =
       NLS.bind(
           PDEUIMessages.CategorySection_newCategoryName, Integer.toString(++newCategoryCounter));
   while (categoryExists(name)) {
     name =
         NLS.bind(
             PDEUIMessages.CategorySection_newCategoryName,
             Integer.toString(++newCategoryCounter));
   }
   String label =
       NLS.bind(
           PDEUIMessages.CategorySection_newCategoryLabel, Integer.toString(newCategoryCounter));
   ISiteCategoryDefinition categoryDef = fModel.getFactory().createCategoryDefinition();
   try {
     categoryDef.setName(name);
     categoryDef.setLabel(label);
     fModel.getSite().addCategoryDefinitions(new ISiteCategoryDefinition[] {categoryDef});
   } catch (CoreException e) {
     PDEPlugin.logException(e);
   }
   fCategoryViewer.setSelection(new StructuredSelection(categoryDef), true);
 }
 void fireSelection() {
   fCategoryViewer.setSelection(fCategoryViewer.getSelection());
 }