KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > site > SiteOutlinePage


1 /*******************************************************************************
2  * Copyright (c) 2003, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.ui.editor.site;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.HashSet JavaDoc;
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     /**
32      * @param editor
33      */

34     public SiteOutlinePage(PDEFormEditor editor) {
35         super(editor);
36     }
37
38     protected Object JavaDoc[] getChildren(Object JavaDoc 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 JavaDoc result = new ArrayList JavaDoc();
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 JavaDoc result = new HashSet JavaDoc();
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 JavaDoc[0];
85     }
86
87     protected String JavaDoc getParentPageId(Object JavaDoc item) {
88         String JavaDoc 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     /*
100      * (non-Javadoc)
101      *
102      * @see org.eclipse.pde.internal.ui.editor.FormOutlinePage#createLabelProvider()
103      */

104     public ILabelProvider createLabelProvider() {
105         fLabelProvider = new SiteLabelProvider();
106         return fLabelProvider;
107     }
108
109     /*
110      * (non-Javadoc)
111      *
112      * @see org.eclipse.pde.internal.ui.editor.FormOutlinePage#dispose()
113      */

114     public void dispose() {
115         super.dispose();
116         if (fLabelProvider != null)
117             fLabelProvider.dispose();
118     }
119 }
120
Popular Tags