/* (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);
    }
  }
 public void toggleExpandState(int state, StructuredSelection selection) {
   TreeItem[] items = fExtensionTree.getTree().getSelection();
   if (state == NEEDS_EXPAND) { // expand sub tree
     traverseChildrenAndSetExpanded(items); // load non-expanded children
     fExtensionTree.refresh();
     expandChildrenElements(selection.toArray(), true);
     fExtensionTree.setSelection(selection, false);
   } else { // collapse sub tree
     for (Iterator<?> iterator = selection.iterator(); iterator.hasNext(); ) {
       fExtensionTree.setExpandedState(iterator.next(), false);
     }
   }
 }
 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());
 }