1 11 package org.eclipse.pde.internal.ui.editor.feature; 12 13 import java.util.Vector ; 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 [] getChildren(Object parent) { 40 IFeatureModel model = (IFeatureModel) fEditor.getAggregateModel(); 41 if (model.isValid()) { 42 if (parent instanceof FeatureFormPage) { 43 return new Object [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 getParent(Object child) { 68 String 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 getParentPageId(Object 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 [] getInfos() { 107 IFeatureModel model = (IFeatureModel) fEditor.getAggregateModel(); 108 IFeature feature = model.getFeature(); 109 Vector result = new Vector (); 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 [] getReferences() { 120 IFeatureModel model = (IFeatureModel) fEditor.getAggregateModel(); 121 IFeature feature = model.getFeature(); 122 return feature.getPlugins(); 123 } 124 125 private Object [] getImports() { 126 IFeatureModel model = (IFeatureModel) fEditor.getAggregateModel(); 127 IFeature feature = model.getFeature(); 128 return feature.getImports(); 129 } 130 131 private Object [] getIncludes() { 132 IFeatureModel model = (IFeatureModel) fEditor.getAggregateModel(); 133 IFeature feature = model.getFeature(); 134 return feature.getIncludedFeatures(); 135 } 136 137 private Object [] getData() { 138 IFeatureModel model = (IFeatureModel) fEditor.getAggregateModel(); 139 IFeature feature = model.getFeature(); 140 return feature.getData(); 141 } 142 143 private Object [] 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 [0]; 149 return url.getDiscoveries(); 150 } 151 152 public Object getParent(Object 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 object = event.getChangedObjects()[0]; 168 if (object instanceof IFeature) { 169 if (event.getChangeType() == IModelChangedEvent.CHANGE) { 170 String 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 Object 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 |