001: /*******************************************************************************
002: * Copyright (c) 2003, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.ui.editor.site;
011:
012: import java.util.ArrayList;
013: import java.util.HashSet;
014:
015: import org.eclipse.jface.viewers.ILabelProvider;
016: import org.eclipse.jface.viewers.LabelProvider;
017: import org.eclipse.pde.internal.core.isite.ISite;
018: import org.eclipse.pde.internal.core.isite.ISiteArchive;
019: import org.eclipse.pde.internal.core.isite.ISiteCategory;
020: import org.eclipse.pde.internal.core.isite.ISiteCategoryDefinition;
021: import org.eclipse.pde.internal.core.isite.ISiteFeature;
022: import org.eclipse.pde.internal.core.isite.ISiteModel;
023: import org.eclipse.pde.internal.ui.editor.FormOutlinePage;
024: import org.eclipse.pde.internal.ui.editor.PDEFormEditor;
025: import org.eclipse.pde.internal.ui.editor.PDEFormPage;
026:
027: public class SiteOutlinePage extends FormOutlinePage {
028: private LabelProvider fLabelProvider;
029:
030: /**
031: * @param editor
032: */
033: public SiteOutlinePage(PDEFormEditor editor) {
034: super (editor);
035: }
036:
037: protected Object[] getChildren(Object parent) {
038: if (parent instanceof PDEFormPage) {
039: PDEFormPage page = (PDEFormPage) parent;
040: ISiteModel model = (ISiteModel) page.getModel();
041: if (model.isValid()) {
042: ISite site = model.getSite();
043: if (page.getId().equals(FeaturesPage.PAGE_ID)) {
044: ArrayList result = new ArrayList();
045: ISiteCategoryDefinition[] catDefs = site
046: .getCategoryDefinitions();
047: for (int i = 0; i < catDefs.length; i++) {
048: result.add(catDefs[i]);
049: }
050: ISiteFeature[] features = site.getFeatures();
051: for (int i = 0; i < features.length; i++) {
052: if (features[i].getCategories().length == 0)
053: result.add(new SiteFeatureAdapter(null,
054: features[i]));
055: }
056: return result.toArray();
057: }
058: if (page.getId().equals(ArchivePage.PAGE_ID))
059: return site.getArchives();
060: }
061: }
062: if (parent instanceof ISiteCategoryDefinition) {
063: ISiteCategoryDefinition catDef = (ISiteCategoryDefinition) parent;
064: ISiteModel model = catDef.getModel();
065: if (model.isValid()) {
066: ISite site = model.getSite();
067: ISiteFeature[] features = site.getFeatures();
068: HashSet result = new HashSet();
069: for (int i = 0; i < features.length; i++) {
070: ISiteCategory[] cats = features[i].getCategories();
071: for (int j = 0; j < cats.length; j++) {
072: if (cats[j].getDefinition() != null
073: && cats[j].getDefinition().equals(
074: catDef)) {
075: result.add(new SiteFeatureAdapter(cats[j]
076: .getName(), features[i]));
077: }
078: }
079: }
080: return result.toArray();
081: }
082: }
083: return new Object[0];
084: }
085:
086: protected String getParentPageId(Object item) {
087: String pageId = null;
088: if (item instanceof ISiteCategoryDefinition
089: || item instanceof SiteFeatureAdapter)
090: pageId = FeaturesPage.PAGE_ID;
091: else if (item instanceof ISiteArchive)
092: pageId = ArchivePage.PAGE_ID;
093: if (pageId != null)
094: return pageId;
095: return super .getParentPageId(item);
096: }
097:
098: /*
099: * (non-Javadoc)
100: *
101: * @see org.eclipse.pde.internal.ui.editor.FormOutlinePage#createLabelProvider()
102: */
103: public ILabelProvider createLabelProvider() {
104: fLabelProvider = new SiteLabelProvider();
105: return fLabelProvider;
106: }
107:
108: /*
109: * (non-Javadoc)
110: *
111: * @see org.eclipse.pde.internal.ui.editor.FormOutlinePage#dispose()
112: */
113: public void dispose() {
114: super.dispose();
115: if (fLabelProvider != null)
116: fLabelProvider.dispose();
117: }
118: }
|