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; }
/* * (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; }
protected Object[] getChildren(Object parent) { if (parent instanceof PDEFormPage) { PDEFormPage page = (PDEFormPage) parent; ISiteModel model = (ISiteModel) page.getModel(); if (model.isValid()) { ISite site = model.getSite(); if (page.getId().equals(FeaturesPage.PAGE_ID)) { ArrayList<IWritable> result = new ArrayList<IWritable>(); ISiteCategoryDefinition[] catDefs = site.getCategoryDefinitions(); for (int i = 0; i < catDefs.length; i++) { result.add(catDefs[i]); } ISiteFeature[] features = site.getFeatures(); for (int i = 0; i < features.length; i++) { if (features[i].getCategories().length == 0) result.add(new SiteFeatureAdapter(null, features[i])); } return result.toArray(); } if (page.getId().equals(ArchivePage.PAGE_ID)) return site.getArchives(); } } if (parent instanceof ISiteCategoryDefinition) { ISiteCategoryDefinition catDef = (ISiteCategoryDefinition) parent; ISiteModel model = catDef.getModel(); if (model.isValid()) { ISite site = model.getSite(); ISiteFeature[] features = site.getFeatures(); HashSet<SiteFeatureAdapter> result = new HashSet<SiteFeatureAdapter>(); for (int i = 0; i < features.length; i++) { ISiteCategory[] cats = features[i].getCategories(); for (int j = 0; j < cats.length; j++) { if (cats[j].getDefinition() != null && cats[j].getDefinition().equals(catDef)) { result.add(new SiteFeatureAdapter(cats[j].getName(), features[i])); } } } return result.toArray(); } } return new Object[0]; }
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); }