private boolean categoryExists(String name) {
   ISiteCategoryDefinition[] defs = fModel.getSite().getCategoryDefinitions();
   for (int i = 0; i < defs.length; i++) {
     ISiteCategoryDefinition def = defs[i];
     String dname = def.getName();
     if (dname != null && dname.equals(name)) return true;
   }
   return false;
 }
 private boolean alreadyExists(String name) {
   ISiteCategoryDefinition[] defs =
       fCurrentCategoryDefinition.getModel().getSite().getCategoryDefinitions();
   for (int i = 0; i < defs.length; i++) {
     ISiteCategoryDefinition def = defs[i];
     if (def == fCurrentCategoryDefinition) continue;
     String dname = def.getName();
     if (dname != null && dname.equals(name)) return true;
   }
   return false;
 }
 private void bringFeatures(String oldCategory) {
   ISiteFeature[] siteFeatures = fCurrentCategoryDefinition.getModel().getSite().getFeatures();
   for (int i = 0; i < siteFeatures.length; i++) {
     ISiteCategory[] categories = siteFeatures[i].getCategories();
     for (int c = 0; c < categories.length; c++) {
       if (oldCategory.equals(categories[c].getName())) {
         try {
           categories[c].setName(fCurrentCategoryDefinition.getName());
         } catch (CoreException ce) {
         }
       }
     }
   }
 }
 private void applyValue(String property, String value) throws CoreException {
   if (fCurrentCategoryDefinition == null) return;
   if (property.equals(PROPERTY_NAME)) {
     String oldName = fCurrentCategoryDefinition.getName();
     fCurrentCategoryDefinition.setName(value);
     bringFeatures(oldName);
   } else if (property.equals(PROPERTY_TYPE)) fCurrentCategoryDefinition.setLabel(value);
   else if (property.equals(PROPERTY_DESC)) {
     if (value == null || value.length() == 0) {
       fCurrentCategoryDefinition.setDescription(null);
     } else {
       ISiteDescription siteDesc = fCurrentCategoryDefinition.getDescription();
       if (siteDesc == null) {
         siteDesc =
             fCurrentCategoryDefinition
                 .getModel()
                 .getFactory()
                 .createDescription(fCurrentCategoryDefinition);
         siteDesc.setText(value);
         fCurrentCategoryDefinition.setDescription(siteDesc);
       } else {
         siteDesc.setText(value);
       }
     }
   }
 }
 private void setValue(String property) {
   if (fCurrentCategoryDefinition == null) {
     clearField(property);
   } else {
     if (property.equals(PROPERTY_NAME))
       fNameText.setValue(fCurrentCategoryDefinition.getName(), true);
     else if (property.equals(PROPERTY_TYPE))
       fLabelText.setValue(fCurrentCategoryDefinition.getLabel(), true);
     else if (property.equals(PROPERTY_DESC)) {
       ISiteDescription siteDesc = fCurrentCategoryDefinition.getDescription();
       if (siteDesc == null) {
         clearField(property);
       } else {
         fDescriptionText.setValue(siteDesc.getText(), true);
       }
     }
   }
 }
 /*
  * (non-Javadoc)
  *
  * @see org.eclipse.pde.internal.ui.editor.StructuredViewerSection#canPaste(java.lang.Object,
  *      java.lang.Object[])
  */
 protected boolean canPaste(Object target, Object[] objects) {
   if (target == null || target instanceof ISiteCategoryDefinition) {
     for (int i = 0; i < objects.length; i++) {
       if (objects[i] instanceof SiteFeatureAdapter) return true;
       if (objects[i] instanceof ISiteCategoryDefinition) {
         String name = ((ISiteCategoryDefinition) objects[i]).getName();
         ISiteCategoryDefinition[] defs = fModel.getSite().getCategoryDefinitions();
         for (int j = 0; j < defs.length; j++) {
           ISiteCategoryDefinition def = defs[j];
           String dname = def.getName();
           if (dname != null && dname.equals(name)) return false;
         }
         return true;
       }
     }
   }
   return 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);
 }