001: /*******************************************************************************
002: * Copyright (c) 2005, 2007 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.target;
011:
012: import org.eclipse.jface.viewers.ILabelProvider;
013: import org.eclipse.pde.core.IModelChangedEvent;
014: import org.eclipse.pde.internal.core.itarget.ITarget;
015: import org.eclipse.pde.internal.core.itarget.ITargetModel;
016: import org.eclipse.pde.internal.core.itarget.ITargetObject;
017: import org.eclipse.pde.internal.core.itarget.ITargetPlugin;
018: import org.eclipse.pde.internal.ui.PDELabelProvider;
019: import org.eclipse.pde.internal.ui.PDEPlugin;
020: import org.eclipse.pde.internal.ui.PDEPluginImages;
021: import org.eclipse.pde.internal.ui.PDEUIMessages;
022: import org.eclipse.pde.internal.ui.editor.FormOutlinePage;
023: import org.eclipse.pde.internal.ui.editor.PDEFormEditor;
024: import org.eclipse.swt.graphics.Image;
025: import org.eclipse.ui.forms.editor.FormPage;
026:
027: public class TargetOutlinePage extends FormOutlinePage {
028:
029: public class TargetContentNode {
030:
031: private ITarget fTarget;
032: private boolean fFeatureBased = false;
033:
034: public String toString() {
035: return fFeatureBased ? PDEUIMessages.TargetOutlinePage_features
036: : PDEUIMessages.TargetOutlinePage_plugins;
037: }
038:
039: public TargetContentNode(ITarget target, boolean featureBased) {
040: fTarget = target;
041: fFeatureBased = featureBased;
042: }
043:
044: public ITargetObject[] getModels() {
045: if (fTarget.useAllPlugins())
046: return new ITargetObject[0];
047: if (fFeatureBased)
048: return fTarget.getFeatures();
049: return fTarget.getPlugins();
050: }
051:
052: public boolean isFeatureBased() {
053: return fFeatureBased;
054: }
055:
056: }
057:
058: private TargetContentNode pNode;
059: private TargetContentNode fNode;
060:
061: public TargetOutlinePage(PDEFormEditor editor) {
062: super (editor);
063: }
064:
065: public void modelChanged(IModelChangedEvent event) {
066: if (ITarget.P_ALL_PLUGINS.equals(event.getChangedProperty())
067: || event.getChangeType() == IModelChangedEvent.WORLD_CHANGED) {
068: super .modelChanged(event);
069: return;
070: }
071:
072: if (event.getChangeType() == IModelChangedEvent.INSERT
073: || event.getChangeType() == IModelChangedEvent.REMOVE) {
074: Object object = event.getChangedObjects()[0];
075: if (object instanceof ITargetPlugin)
076: getTreeViewer().refresh(pNode);
077: else
078: getTreeViewer().refresh(fNode);
079: return;
080: }
081: }
082:
083: protected Object[] getChildren(Object parent) {
084: if (parent instanceof ContentPage) {
085: ContentPage page = (ContentPage) parent;
086: ITarget target = ((ITargetModel) page.getModel())
087: .getTarget();
088: if (target.useAllPlugins())
089: return new Object[0];
090:
091: if (pNode == null)
092: pNode = new TargetContentNode(target, false);
093: if (fNode == null)
094: fNode = new TargetContentNode(target, true);
095: return new Object[] { pNode, fNode };
096: }
097: if (parent instanceof TargetContentNode)
098: return ((TargetContentNode) parent).getModels();
099: return new Object[0];
100: }
101:
102: public ILabelProvider createLabelProvider() {
103: return new BasicLabelProvider() {
104: public Image getImage(Object element) {
105: PDELabelProvider provider = PDEPlugin.getDefault()
106: .getLabelProvider();
107: if (element instanceof TargetContentNode) {
108: if (((TargetContentNode) element).isFeatureBased())
109: return provider
110: .get(PDEPluginImages.DESC_FEATURE_OBJ);
111: return provider
112: .get(PDEPluginImages.DESC_PLUGIN_OBJ);
113: }
114: if (element instanceof FormPage)
115: return super.getImage(element);
116: return provider.getImage(element);
117: }
118: };
119: }
120:
121: }
|