KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > feature > FeatureOutlinePage


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.feature;
12
13 import java.util.Vector JavaDoc;
14
15 import org.eclipse.jface.viewers.ITreeContentProvider;
16 import org.eclipse.pde.core.IModelChangedEvent;
17 import org.eclipse.pde.core.build.IBuildEntry;
18 import org.eclipse.pde.internal.core.ifeature.IFeature;
19 import org.eclipse.pde.internal.core.ifeature.IFeatureChild;
20 import org.eclipse.pde.internal.core.ifeature.IFeatureData;
21 import org.eclipse.pde.internal.core.ifeature.IFeatureImport;
22 import org.eclipse.pde.internal.core.ifeature.IFeatureInfo;
23 import org.eclipse.pde.internal.core.ifeature.IFeatureModel;
24 import org.eclipse.pde.internal.core.ifeature.IFeaturePlugin;
25 import org.eclipse.pde.internal.core.ifeature.IFeatureURL;
26 import org.eclipse.pde.internal.core.ifeature.IFeatureURLElement;
27 import org.eclipse.pde.internal.ui.PDEPlugin;
28 import org.eclipse.pde.internal.ui.PDEPluginImages;
29 import org.eclipse.pde.internal.ui.PDEUIMessages;
30 import org.eclipse.pde.internal.ui.editor.FormOutlinePage;
31 import org.eclipse.pde.internal.ui.editor.PDEFormEditor;
32 import org.eclipse.pde.internal.ui.editor.build.BuildPage;
33 import org.eclipse.pde.internal.ui.elements.NamedElement;
34 import org.eclipse.swt.graphics.Image;
35 import org.eclipse.ui.forms.editor.IFormPage;
36
37 public class FeatureOutlinePage extends FormOutlinePage {
38     class ContentProvider extends BasicContentProvider {
39         public Object JavaDoc[] getChildren(Object JavaDoc parent) {
40             IFeatureModel model = (IFeatureModel) fEditor.getAggregateModel();
41             if (model.isValid()) {
42                 if (parent instanceof FeatureFormPage) {
43                     return new Object JavaDoc[0];
44                 }
45                 if (parent instanceof InfoFormPage) {
46                     return getInfos();
47                 }
48                 if (parent.equals(fDiscoveryUrls)) {
49                     return getURLs();
50                 }
51                 if (parent instanceof FeatureReferencePage) {
52                     return getReferences();
53                 }
54                 if (parent instanceof FeatureIncludesPage) {
55                     return getIncludes();
56                 }
57                 if (parent instanceof FeatureDependenciesPage) {
58                     return getImports();
59                 }
60                 if (parent instanceof FeatureAdvancedPage) {
61                     return getData();
62                 }
63             }
64             return super.getChildren(parent);
65         }
66
67         public Object JavaDoc getParent(Object JavaDoc child) {
68             String JavaDoc pageId = getParentPageId(child);
69             if (pageId != null)
70                 return fEditor.findPage(pageId);
71             return super.getParent(child);
72         }
73     }
74
75     private NamedElement fDiscoveryUrls;
76
77     public FeatureOutlinePage(PDEFormEditor editor) {
78         super(editor);
79         Image folderImage = PDEPlugin.getDefault().getLabelProvider().get(
80                 PDEPluginImages.DESC_DOC_SECTION_OBJ);
81         fDiscoveryUrls = new NamedElement(PDEUIMessages.FeatureOutlinePage_discoverUrls,
82                 folderImage);
83     }
84
85     public ITreeContentProvider createContentProvider() {
86         return new ContentProvider();
87     }
88
89     public String JavaDoc getParentPageId(Object JavaDoc item) {
90         if (item instanceof IFeaturePlugin)
91             return FeatureReferencePage.PAGE_ID;
92         if (item instanceof IFeatureChild)
93             return FeatureIncludesPage.PAGE_ID;
94         if (item instanceof IFeatureImport)
95             return FeatureDependenciesPage.PAGE_ID;
96         if (item instanceof IFeatureInfo || item.equals(fDiscoveryUrls)
97                 || item instanceof IFeatureURLElement)
98             return InfoFormPage.PAGE_ID;
99         if (item instanceof IFeatureData)
100             return FeatureAdvancedPage.PAGE_ID;
101         else if (item instanceof IBuildEntry)
102             return BuildPage.PAGE_ID;
103         return super.getParentPageId(item);
104     }
105
106     private Object JavaDoc[] getInfos() {
107         IFeatureModel model = (IFeatureModel) fEditor.getAggregateModel();
108         IFeature feature = model.getFeature();
109         Vector JavaDoc result = new Vector JavaDoc();
110         for (int i = 0; i < 3; i++) {
111             IFeatureInfo info = feature.getFeatureInfo(i);
112             if (info != null)
113                 result.add(info);
114         }
115         result.add(fDiscoveryUrls);
116         return result.toArray();
117     }
118
119     private Object JavaDoc[] getReferences() {
120         IFeatureModel model = (IFeatureModel) fEditor.getAggregateModel();
121         IFeature feature = model.getFeature();
122         return feature.getPlugins();
123     }
124
125     private Object JavaDoc[] getImports() {
126         IFeatureModel model = (IFeatureModel) fEditor.getAggregateModel();
127         IFeature feature = model.getFeature();
128         return feature.getImports();
129     }
130
131     private Object JavaDoc[] getIncludes() {
132         IFeatureModel model = (IFeatureModel) fEditor.getAggregateModel();
133         IFeature feature = model.getFeature();
134         return feature.getIncludedFeatures();
135     }
136
137     private Object JavaDoc[] getData() {
138         IFeatureModel model = (IFeatureModel) fEditor.getAggregateModel();
139         IFeature feature = model.getFeature();
140         return feature.getData();
141     }
142
143     private Object JavaDoc[] getURLs() {
144         IFeatureModel model = (IFeatureModel) fEditor.getAggregateModel();
145         IFeature feature = model.getFeature();
146         IFeatureURL url = feature.getURL();
147         if (url == null)
148             return new Object JavaDoc[0];
149         return url.getDiscoveries();
150     }
151
152     public Object JavaDoc getParent(Object JavaDoc object) {
153         if (object instanceof IFeatureURLElement) {
154             return fDiscoveryUrls;
155         }
156         return fEditor.findPage(getParentPageId(object));
157     }
158
159     public void modelChanged(IModelChangedEvent event) {
160         if (fTreeViewer.getControl().isDisposed()) {
161             return;
162         }
163         if (event.getChangeType() == IModelChangedEvent.WORLD_CHANGED) {
164             fTreeViewer.refresh();
165             return;
166         }
167         Object JavaDoc object = event.getChangedObjects()[0];
168         if (object instanceof IFeature) {
169             if (event.getChangeType() == IModelChangedEvent.CHANGE) {
170                 String JavaDoc property = event.getChangedProperty();
171                 if (property.equals(IFeature.P_DESCRIPTION)
172                         || property.equals(IFeature.P_COPYRIGHT)
173                         || property.equals(IFeature.P_LICENSE)) {
174                     IFormPage page = fEditor.findPage(InfoFormPage.PAGE_ID);
175                     fTreeViewer.refresh(page);
176                     return;
177                 }
178             }
179         }
180         if (object instanceof IFeatureImport || object instanceof IFeatureInfo
181                 || object instanceof IFeaturePlugin
182                 || object instanceof IFeatureData
183                 || object instanceof IFeatureURLElement
184                 || object instanceof IFeatureChild) {
185             if (event.getChangeType() == IModelChangedEvent.CHANGE) {
186                 fTreeViewer.update(object, null);
187             } else {
188                 // find the parent
189
Object JavaDoc parent = getParent(object);
190                 if (parent != null) {
191                     if (event.getChangeType() == IModelChangedEvent.INSERT)
192                         fTreeViewer.add(parent, event.getChangedObjects());
193                     else
194                         fTreeViewer.remove(event.getChangedObjects());
195                 } else {
196                     fTreeViewer.refresh();
197                     fTreeViewer.expandAll();
198                 }
199             }
200         }
201     }
202
203 }
204
Popular Tags