1 11 package org.eclipse.pde.internal.ui.editor.site; 12 13 import java.util.ArrayList ; 14 import java.util.HashSet ; 15 16 import org.eclipse.jface.viewers.ILabelProvider; 17 import org.eclipse.jface.viewers.LabelProvider; 18 import org.eclipse.pde.internal.core.isite.ISite; 19 import org.eclipse.pde.internal.core.isite.ISiteArchive; 20 import org.eclipse.pde.internal.core.isite.ISiteCategory; 21 import org.eclipse.pde.internal.core.isite.ISiteCategoryDefinition; 22 import org.eclipse.pde.internal.core.isite.ISiteFeature; 23 import org.eclipse.pde.internal.core.isite.ISiteModel; 24 import org.eclipse.pde.internal.ui.editor.FormOutlinePage; 25 import org.eclipse.pde.internal.ui.editor.PDEFormEditor; 26 import org.eclipse.pde.internal.ui.editor.PDEFormPage; 27 28 public class SiteOutlinePage extends FormOutlinePage { 29 private LabelProvider fLabelProvider; 30 31 34 public SiteOutlinePage(PDEFormEditor editor) { 35 super(editor); 36 } 37 38 protected Object [] getChildren(Object parent) { 39 if (parent instanceof PDEFormPage) { 40 PDEFormPage page = (PDEFormPage) parent; 41 ISiteModel model = (ISiteModel) page.getModel(); 42 if (model.isValid()) { 43 ISite site = model.getSite(); 44 if (page.getId().equals(FeaturesPage.PAGE_ID)) { 45 ArrayList result = new ArrayList (); 46 ISiteCategoryDefinition[] catDefs = site 47 .getCategoryDefinitions(); 48 for (int i = 0; i < catDefs.length; i++) { 49 result.add(catDefs[i]); 50 } 51 ISiteFeature[] features = site.getFeatures(); 52 for (int i = 0; i < features.length; i++) { 53 if (features[i].getCategories().length == 0) 54 result 55 .add(new SiteFeatureAdapter(null, 56 features[i])); 57 } 58 return result.toArray(); 59 } 60 if (page.getId().equals(ArchivePage.PAGE_ID)) 61 return site.getArchives(); 62 } 63 } 64 if (parent instanceof ISiteCategoryDefinition) { 65 ISiteCategoryDefinition catDef = (ISiteCategoryDefinition) parent; 66 ISiteModel model = catDef.getModel(); 67 if (model.isValid()) { 68 ISite site = model.getSite(); 69 ISiteFeature[] features = site.getFeatures(); 70 HashSet result = new HashSet (); 71 for (int i = 0; i < features.length; i++) { 72 ISiteCategory[] cats = features[i].getCategories(); 73 for (int j = 0; j < cats.length; j++) { 74 if (cats[j].getDefinition() != null 75 && cats[j].getDefinition().equals(catDef)) { 76 result.add(new SiteFeatureAdapter( 77 cats[j].getName(), features[i])); 78 } 79 } 80 } 81 return result.toArray(); 82 } 83 } 84 return new Object [0]; 85 } 86 87 protected String getParentPageId(Object item) { 88 String pageId = null; 89 if (item instanceof ISiteCategoryDefinition 90 || item instanceof SiteFeatureAdapter) 91 pageId = FeaturesPage.PAGE_ID; 92 else if (item instanceof ISiteArchive) 93 pageId = ArchivePage.PAGE_ID; 94 if (pageId != null) 95 return pageId; 96 return super.getParentPageId(item); 97 } 98 99 104 public ILabelProvider createLabelProvider() { 105 fLabelProvider = new SiteLabelProvider(); 106 return fLabelProvider; 107 } 108 109 114 public void dispose() { 115 super.dispose(); 116 if (fLabelProvider != null) 117 fLabelProvider.dispose(); 118 } 119 } 120 | Popular Tags |