001: /*******************************************************************************
002: * Copyright (c) 2000, 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.feature;
011:
012: import java.util.Vector;
013:
014: import org.eclipse.jface.viewers.ITreeContentProvider;
015: import org.eclipse.pde.core.IModelChangedEvent;
016: import org.eclipse.pde.core.build.IBuildEntry;
017: import org.eclipse.pde.internal.core.ifeature.IFeature;
018: import org.eclipse.pde.internal.core.ifeature.IFeatureChild;
019: import org.eclipse.pde.internal.core.ifeature.IFeatureData;
020: import org.eclipse.pde.internal.core.ifeature.IFeatureImport;
021: import org.eclipse.pde.internal.core.ifeature.IFeatureInfo;
022: import org.eclipse.pde.internal.core.ifeature.IFeatureModel;
023: import org.eclipse.pde.internal.core.ifeature.IFeaturePlugin;
024: import org.eclipse.pde.internal.core.ifeature.IFeatureURL;
025: import org.eclipse.pde.internal.core.ifeature.IFeatureURLElement;
026: import org.eclipse.pde.internal.ui.PDEPlugin;
027: import org.eclipse.pde.internal.ui.PDEPluginImages;
028: import org.eclipse.pde.internal.ui.PDEUIMessages;
029: import org.eclipse.pde.internal.ui.editor.FormOutlinePage;
030: import org.eclipse.pde.internal.ui.editor.PDEFormEditor;
031: import org.eclipse.pde.internal.ui.editor.build.BuildPage;
032: import org.eclipse.pde.internal.ui.elements.NamedElement;
033: import org.eclipse.swt.graphics.Image;
034: import org.eclipse.ui.forms.editor.IFormPage;
035:
036: public class FeatureOutlinePage extends FormOutlinePage {
037: class ContentProvider extends BasicContentProvider {
038: public Object[] getChildren(Object parent) {
039: IFeatureModel model = (IFeatureModel) fEditor
040: .getAggregateModel();
041: if (model.isValid()) {
042: if (parent instanceof FeatureFormPage) {
043: return new Object[0];
044: }
045: if (parent instanceof InfoFormPage) {
046: return getInfos();
047: }
048: if (parent.equals(fDiscoveryUrls)) {
049: return getURLs();
050: }
051: if (parent instanceof FeatureReferencePage) {
052: return getReferences();
053: }
054: if (parent instanceof FeatureIncludesPage) {
055: return getIncludes();
056: }
057: if (parent instanceof FeatureDependenciesPage) {
058: return getImports();
059: }
060: if (parent instanceof FeatureAdvancedPage) {
061: return getData();
062: }
063: }
064: return super .getChildren(parent);
065: }
066:
067: public Object getParent(Object child) {
068: String pageId = getParentPageId(child);
069: if (pageId != null)
070: return fEditor.findPage(pageId);
071: return super .getParent(child);
072: }
073: }
074:
075: private NamedElement fDiscoveryUrls;
076:
077: public FeatureOutlinePage(PDEFormEditor editor) {
078: super (editor);
079: Image folderImage = PDEPlugin.getDefault().getLabelProvider()
080: .get(PDEPluginImages.DESC_DOC_SECTION_OBJ);
081: fDiscoveryUrls = new NamedElement(
082: PDEUIMessages.FeatureOutlinePage_discoverUrls,
083: folderImage);
084: }
085:
086: public ITreeContentProvider createContentProvider() {
087: return new ContentProvider();
088: }
089:
090: public String getParentPageId(Object item) {
091: if (item instanceof IFeaturePlugin)
092: return FeatureReferencePage.PAGE_ID;
093: if (item instanceof IFeatureChild)
094: return FeatureIncludesPage.PAGE_ID;
095: if (item instanceof IFeatureImport)
096: return FeatureDependenciesPage.PAGE_ID;
097: if (item instanceof IFeatureInfo || item.equals(fDiscoveryUrls)
098: || item instanceof IFeatureURLElement)
099: return InfoFormPage.PAGE_ID;
100: if (item instanceof IFeatureData)
101: return FeatureAdvancedPage.PAGE_ID;
102: else if (item instanceof IBuildEntry)
103: return BuildPage.PAGE_ID;
104: return super .getParentPageId(item);
105: }
106:
107: private Object[] getInfos() {
108: IFeatureModel model = (IFeatureModel) fEditor
109: .getAggregateModel();
110: IFeature feature = model.getFeature();
111: Vector result = new Vector();
112: for (int i = 0; i < 3; i++) {
113: IFeatureInfo info = feature.getFeatureInfo(i);
114: if (info != null)
115: result.add(info);
116: }
117: result.add(fDiscoveryUrls);
118: return result.toArray();
119: }
120:
121: private Object[] getReferences() {
122: IFeatureModel model = (IFeatureModel) fEditor
123: .getAggregateModel();
124: IFeature feature = model.getFeature();
125: return feature.getPlugins();
126: }
127:
128: private Object[] getImports() {
129: IFeatureModel model = (IFeatureModel) fEditor
130: .getAggregateModel();
131: IFeature feature = model.getFeature();
132: return feature.getImports();
133: }
134:
135: private Object[] getIncludes() {
136: IFeatureModel model = (IFeatureModel) fEditor
137: .getAggregateModel();
138: IFeature feature = model.getFeature();
139: return feature.getIncludedFeatures();
140: }
141:
142: private Object[] getData() {
143: IFeatureModel model = (IFeatureModel) fEditor
144: .getAggregateModel();
145: IFeature feature = model.getFeature();
146: return feature.getData();
147: }
148:
149: private Object[] getURLs() {
150: IFeatureModel model = (IFeatureModel) fEditor
151: .getAggregateModel();
152: IFeature feature = model.getFeature();
153: IFeatureURL url = feature.getURL();
154: if (url == null)
155: return new Object[0];
156: return url.getDiscoveries();
157: }
158:
159: public Object getParent(Object object) {
160: if (object instanceof IFeatureURLElement) {
161: return fDiscoveryUrls;
162: }
163: return fEditor.findPage(getParentPageId(object));
164: }
165:
166: public void modelChanged(IModelChangedEvent event) {
167: if (fTreeViewer.getControl().isDisposed()) {
168: return;
169: }
170: if (event.getChangeType() == IModelChangedEvent.WORLD_CHANGED) {
171: fTreeViewer.refresh();
172: return;
173: }
174: Object object = event.getChangedObjects()[0];
175: if (object instanceof IFeature) {
176: if (event.getChangeType() == IModelChangedEvent.CHANGE) {
177: String property = event.getChangedProperty();
178: if (property.equals(IFeature.P_DESCRIPTION)
179: || property.equals(IFeature.P_COPYRIGHT)
180: || property.equals(IFeature.P_LICENSE)) {
181: IFormPage page = fEditor
182: .findPage(InfoFormPage.PAGE_ID);
183: fTreeViewer.refresh(page);
184: return;
185: }
186: }
187: }
188: if (object instanceof IFeatureImport
189: || object instanceof IFeatureInfo
190: || object instanceof IFeaturePlugin
191: || object instanceof IFeatureData
192: || object instanceof IFeatureURLElement
193: || object instanceof IFeatureChild) {
194: if (event.getChangeType() == IModelChangedEvent.CHANGE) {
195: fTreeViewer.update(object, null);
196: } else {
197: // find the parent
198: Object parent = getParent(object);
199: if (parent != null) {
200: if (event.getChangeType() == IModelChangedEvent.INSERT)
201: fTreeViewer.add(parent, event
202: .getChangedObjects());
203: else
204: fTreeViewer.remove(event.getChangedObjects());
205: } else {
206: fTreeViewer.refresh();
207: fTreeViewer.expandAll();
208: }
209: }
210: }
211: }
212:
213: }
|