Commit | Line | Data |
---|---|---|
12c155f5 | 1 | /******************************************************************************* |
60ae41e1 | 2 | * Copyright (c) 2010, 2014 Ericsson |
013a5f1c | 3 | * |
12c155f5 FC |
4 | * All rights reserved. This program and the accompanying materials are |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
013a5f1c | 8 | * |
12c155f5 FC |
9 | * Contributors: |
10 | * Francois Chouinard - Initial API and implementation | |
1169a815 | 11 | * Bernd Hufmann - Implement getParent() |
339d539c | 12 | * Patrick Tasse - Add support for folder elements |
12c155f5 FC |
13 | *******************************************************************************/ |
14 | ||
15 | package org.eclipse.linuxtools.tmf.ui.project.model; | |
16 | ||
12c155f5 FC |
17 | import java.util.Set; |
18 | ||
12c155f5 FC |
19 | import org.eclipse.core.resources.IProject; |
20 | import org.eclipse.core.resources.IResource; | |
12c155f5 FC |
21 | import org.eclipse.jface.viewers.Viewer; |
22 | import org.eclipse.ui.IMemento; | |
23 | import org.eclipse.ui.navigator.ICommonContentExtensionSite; | |
12c155f5 FC |
24 | import org.eclipse.ui.navigator.IPipelinedTreeContentProvider; |
25 | import org.eclipse.ui.navigator.PipelinedShapeModification; | |
26 | import org.eclipse.ui.navigator.PipelinedViewerUpdate; | |
27 | ||
28 | /** | |
013a5f1c | 29 | * The TMF project content provider for the tree viewer in the project explorer view. |
12c155f5 | 30 | * <p> |
b544077e BH |
31 | * @version 1.0 |
32 | * @author Francois Chouinard | |
12c155f5 | 33 | */ |
013a5f1c | 34 | public class TmfNavigatorContentProvider implements IPipelinedTreeContentProvider { |
12c155f5 FC |
35 | |
36 | // ------------------------------------------------------------------------ | |
37 | // ICommonContentProvider | |
38 | // ------------------------------------------------------------------------ | |
11252342 | 39 | |
12c155f5 FC |
40 | @Override |
41 | public Object[] getElements(Object inputElement) { | |
42 | return null; | |
43 | } | |
44 | ||
45 | @Override | |
46 | public Object getParent(Object element) { | |
1169a815 BH |
47 | if (element instanceof IProject) { |
48 | IProject project = (IProject) element; | |
49 | return project.getParent(); | |
50 | } | |
51 | ||
339d539c PT |
52 | if (element instanceof TmfTracesFolder) { |
53 | TmfTracesFolder folder = (TmfTracesFolder) element; | |
1169a815 BH |
54 | // Return the corresponding IProject as parent because from CNF point of view the IProject is the parent. |
55 | // The IProject is needed e.g. for link with Editor to work correctly. | |
56 | return folder.getParent().getResource(); | |
57 | } | |
58 | ||
1169a815 BH |
59 | if (element instanceof TmfExperimentFolder) { |
60 | TmfExperimentFolder folder = (TmfExperimentFolder) element; | |
61 | // Return the corresponding IProject as parent because from CNF point of view the IProject is the parent. | |
62 | // The IProject is needed e.g. for link with Editor to work correctly. | |
63 | return folder.getParent().getResource(); | |
64 | } | |
65 | ||
339d539c PT |
66 | if (element instanceof ITmfProjectModelElement) { |
67 | ITmfProjectModelElement modelElement = (ITmfProjectModelElement) element; | |
68 | return modelElement.getParent(); | |
1169a815 | 69 | } |
339d539c | 70 | |
12c155f5 FC |
71 | return null; |
72 | } | |
73 | ||
74 | @Override | |
75 | public boolean hasChildren(Object element) { | |
76 | if (element instanceof IProject) { | |
77 | IProject project = (IProject) element; | |
78 | return project.isAccessible(); | |
79 | } | |
339d539c PT |
80 | if (element instanceof ITmfProjectModelElement) { |
81 | ITmfProjectModelElement modelElement = (ITmfProjectModelElement) element; | |
c068a752 | 82 | return modelElement.hasChildren(); |
12c155f5 FC |
83 | } |
84 | return false; | |
85 | } | |
86 | ||
87 | @Override | |
88 | public void dispose() { | |
89 | } | |
90 | ||
91 | @Override | |
92 | public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { | |
93 | } | |
013a5f1c | 94 | |
12c155f5 FC |
95 | @Override |
96 | public void restoreState(IMemento aMemento) { | |
97 | } | |
013a5f1c | 98 | |
12c155f5 FC |
99 | @Override |
100 | public void saveState(IMemento aMemento) { | |
101 | } | |
102 | ||
103 | @Override | |
104 | public void init(ICommonContentExtensionSite aConfig) { | |
105 | } | |
106 | ||
107 | // ------------------------------------------------------------------------ | |
108 | // ICommonContentProvider - getChildren() | |
109 | // ------------------------------------------------------------------------ | |
11252342 | 110 | |
12c155f5 FC |
111 | @Override |
112 | public synchronized Object[] getChildren(Object parentElement) { | |
113 | ||
114 | // Tracing project level | |
115 | if (parentElement instanceof IProject) { | |
f537c959 PT |
116 | TmfProjectElement element = TmfProjectRegistry.getProject((IProject) parentElement, true); |
117 | return element.getChildren().toArray(); | |
12c155f5 FC |
118 | } |
119 | ||
f537c959 PT |
120 | // Other project model elements |
121 | if (parentElement instanceof ITmfProjectModelElement) { | |
122 | return ((ITmfProjectModelElement) parentElement).getChildren().toArray(); | |
c068a752 GB |
123 | } |
124 | ||
12c155f5 FC |
125 | return new Object[0]; |
126 | } | |
127 | ||
12c155f5 FC |
128 | // ------------------------------------------------------------------------ |
129 | // IPipelinedTreeContentProvider | |
130 | // ------------------------------------------------------------------------ | |
131 | ||
132 | @Override | |
12c155f5 FC |
133 | public void getPipelinedChildren(Object parent, Set currentChildren) { |
134 | customizeTmfElements(getChildren(parent), currentChildren); | |
135 | } | |
136 | ||
137 | @Override | |
12c155f5 FC |
138 | public void getPipelinedElements(Object input, Set currentElements) { |
139 | customizeTmfElements(getElements(input), currentElements); | |
140 | } | |
141 | ||
142 | /** | |
143 | * Add/replace the ITmfProjectElement to the list of children | |
013a5f1c | 144 | * |
12c155f5 FC |
145 | * @param elements |
146 | * the list returned by getChildren() | |
147 | * @param children | |
148 | * the current children | |
149 | */ | |
abbdd66a AM |
150 | private static void customizeTmfElements(Object[] elements, |
151 | Set<Object> children) { | |
12c155f5 FC |
152 | if (elements != null && children != null) { |
153 | for (Object element : elements) { | |
154 | if (element instanceof ITmfProjectModelElement) { | |
155 | ITmfProjectModelElement tmfElement = (ITmfProjectModelElement) element; | |
156 | IResource resource = tmfElement.getResource(); | |
157 | if (resource != null) { | |
158 | children.remove(resource); | |
159 | } | |
160 | children.add(element); | |
161 | } | |
162 | else if (element != null) { | |
163 | children.add(element); | |
164 | } | |
165 | } | |
166 | } | |
167 | } | |
168 | ||
169 | @Override | |
170 | public Object getPipelinedParent(Object anObject, Object aSuggestedParent) { | |
bfa12ff0 | 171 | return aSuggestedParent; |
12c155f5 FC |
172 | } |
173 | ||
174 | @Override | |
175 | public PipelinedShapeModification interceptAdd(PipelinedShapeModification anAddModification) { | |
bfa12ff0 | 176 | return anAddModification; |
12c155f5 FC |
177 | } |
178 | ||
179 | @Override | |
180 | public PipelinedShapeModification interceptRemove(PipelinedShapeModification aRemoveModification) { | |
181 | return null; | |
182 | } | |
183 | ||
184 | @Override | |
185 | public boolean interceptRefresh(PipelinedViewerUpdate aRefreshSynchronization) { | |
186 | return false; | |
187 | } | |
188 | ||
189 | @Override | |
190 | public boolean interceptUpdate(PipelinedViewerUpdate anUpdateSynchronization) { | |
191 | return false; | |
192 | } | |
12c155f5 | 193 | } |