private ISiteFeature[] getFeaturesFromSelection(IStructuredSelection sel) {
   if (sel.isEmpty()) return new ISiteFeature[0];
   if (cachedSelection == sel) return cachedFeatures;
   cachedSelection = sel;
   ArrayList<ISiteFeature> features = new ArrayList<ISiteFeature>(sel.size());
   Iterator<?> iterator = sel.iterator();
   while (iterator.hasNext()) {
     Object next = iterator.next();
     if (next instanceof SiteFeatureAdapter) {
       if ((((SiteFeatureAdapter) next).feature) != null) {
         features.add(((SiteFeatureAdapter) next).feature);
       }
     }
   }
   cachedFeatures = features.toArray(new ISiteFeature[features.size()]);
   return cachedFeatures;
 }
  private boolean canOperateOnSelection() {
    ISelection sel = fSite.getSelectionProvider().getSelection();
    if (!(sel instanceof IStructuredSelection)) return false;
    IStructuredSelection selection = (IStructuredSelection) sel;

    if (selection.isEmpty()) {
      return false;
    }

    for (Iterator iter = selection.iterator(); iter.hasNext(); ) {
      Object element = iter.next();

      if (element instanceof IProject) {
        IProject project = (IProject) element;
        if (!project.isAccessible()) {
          return false;
        }
      }

      if (element instanceof IWorkingSet) return false;
    }
    return true;
  }
  private boolean handleRemove() {
    IStructuredSelection ssel = (IStructuredSelection) fCategoryViewer.getSelection();
    Iterator<?> iterator = ssel.iterator();
    boolean success = true;
    Set<?> removedCategories = new HashSet<Object>();
    while (iterator.hasNext()) {
      Object object = iterator.next();
      if (object == null) continue;
      if (object instanceof ISiteCategoryDefinition) {
        if (!handleRemoveCategoryDefinition((ISiteCategoryDefinition) object)) {
          success = false;
        }
      } else {
        // check if some of features was not removed during category removal
        SiteFeatureAdapter fa = (SiteFeatureAdapter) object;
        if (removedCategories.contains(fa.category)) continue;

        if (!handleRemoveSiteFeatureAdapter(fa)) {
          success = false;
        }
      }
    }
    return success;
  }