KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > target > TargetOutlinePage


1 /*******************************************************************************
2  * Copyright (c) 2005, 2007 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.target;
12
13 import org.eclipse.jface.viewers.ILabelProvider;
14 import org.eclipse.pde.core.IModelChangedEvent;
15 import org.eclipse.pde.internal.core.itarget.ITarget;
16 import org.eclipse.pde.internal.core.itarget.ITargetModel;
17 import org.eclipse.pde.internal.core.itarget.ITargetObject;
18 import org.eclipse.pde.internal.core.itarget.ITargetPlugin;
19 import org.eclipse.pde.internal.ui.PDELabelProvider;
20 import org.eclipse.pde.internal.ui.PDEPlugin;
21 import org.eclipse.pde.internal.ui.PDEPluginImages;
22 import org.eclipse.pde.internal.ui.PDEUIMessages;
23 import org.eclipse.pde.internal.ui.editor.FormOutlinePage;
24 import org.eclipse.pde.internal.ui.editor.PDEFormEditor;
25 import org.eclipse.swt.graphics.Image;
26 import org.eclipse.ui.forms.editor.FormPage;
27
28 public class TargetOutlinePage extends FormOutlinePage {
29     
30     public class TargetContentNode {
31         
32         private ITarget fTarget;
33         private boolean fFeatureBased = false;
34         
35         public String JavaDoc toString() {
36             return fFeatureBased
37                     ? PDEUIMessages.TargetOutlinePage_features
38                     : PDEUIMessages.TargetOutlinePage_plugins;
39         }
40         
41         public TargetContentNode(ITarget target, boolean featureBased) {
42             fTarget = target;
43             fFeatureBased = featureBased;
44         }
45         
46         public ITargetObject[] getModels() {
47             if (fTarget.useAllPlugins())
48                 return new ITargetObject[0];
49             if (fFeatureBased)
50                 return fTarget.getFeatures();
51             return fTarget.getPlugins();
52         }
53         
54         public boolean isFeatureBased() {
55             return fFeatureBased;
56         }
57         
58     }
59     
60     private TargetContentNode pNode;
61     private TargetContentNode fNode;
62     
63     public TargetOutlinePage(PDEFormEditor editor) {
64         super(editor);
65     }
66     
67     public void modelChanged(IModelChangedEvent event) {
68         if (ITarget.P_ALL_PLUGINS.equals(event.getChangedProperty())
69                 || event.getChangeType() == IModelChangedEvent.WORLD_CHANGED) {
70             super.modelChanged(event);
71             return;
72         }
73         
74         if (event.getChangeType() == IModelChangedEvent.INSERT
75                 || event.getChangeType() == IModelChangedEvent.REMOVE) {
76             Object JavaDoc object = event.getChangedObjects()[0];
77             if (object instanceof ITargetPlugin)
78                 getTreeViewer().refresh(pNode);
79             else
80                 getTreeViewer().refresh(fNode);
81             return;
82         }
83     }
84     
85     protected Object JavaDoc[] getChildren(Object JavaDoc parent) {
86         if (parent instanceof ContentPage) {
87             ContentPage page = (ContentPage)parent;
88             ITarget target = ((ITargetModel)page.getModel()).getTarget();
89             if (target.useAllPlugins())
90                 return new Object JavaDoc[0];
91             
92             if (pNode == null)
93                 pNode = new TargetContentNode(target, false);
94             if (fNode == null)
95                 fNode = new TargetContentNode(target, true);
96             return new Object JavaDoc[] {pNode, fNode};
97         }
98         if (parent instanceof TargetContentNode)
99             return ((TargetContentNode)parent).getModels();
100         return new Object JavaDoc[0];
101     }
102     
103     public ILabelProvider createLabelProvider() {
104         return new BasicLabelProvider() {
105             public Image getImage(Object JavaDoc element) {
106                 PDELabelProvider provider = PDEPlugin.getDefault().getLabelProvider();
107                 if (element instanceof TargetContentNode) {
108                     if (((TargetContentNode)element).isFeatureBased())
109                         return provider.get(PDEPluginImages.DESC_FEATURE_OBJ);
110                     return provider.get(PDEPluginImages.DESC_PLUGIN_OBJ);
111                 }
112                 if (element instanceof FormPage)
113                     return super.getImage(element);
114                 return provider.getImage(element);
115         }};
116     }
117
118 }
119
Popular Tags