1 /*******************************************************************************
2 * Copyright (c) 2010, 2014 Ericsson
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
10 * Francois Chouinard - Initial API and implementation
11 * Bernd Hufmann - Implement getParent()
12 * Patrick Tasse - Add support for folder elements
13 *******************************************************************************/
15 package org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
;
19 import org
.eclipse
.core
.resources
.IProject
;
20 import org
.eclipse
.core
.resources
.IResource
;
21 import org
.eclipse
.jface
.viewers
.Viewer
;
22 import org
.eclipse
.ui
.IMemento
;
23 import org
.eclipse
.ui
.navigator
.ICommonContentExtensionSite
;
24 import org
.eclipse
.ui
.navigator
.IPipelinedTreeContentProvider
;
25 import org
.eclipse
.ui
.navigator
.PipelinedShapeModification
;
26 import org
.eclipse
.ui
.navigator
.PipelinedViewerUpdate
;
29 * The TMF project content provider for the tree viewer in the project explorer view.
32 * @author Francois Chouinard
34 public class TmfNavigatorContentProvider
implements IPipelinedTreeContentProvider
{
36 // ------------------------------------------------------------------------
37 // ICommonContentProvider
38 // ------------------------------------------------------------------------
41 public Object
[] getElements(Object inputElement
) {
46 public Object
getParent(Object element
) {
47 if (element
instanceof IProject
) {
48 IProject project
= (IProject
) element
;
49 return project
.getParent();
52 if (element
instanceof TmfTracesFolder
) {
53 TmfTracesFolder folder
= (TmfTracesFolder
) element
;
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();
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();
66 if (element
instanceof ITmfProjectModelElement
) {
67 ITmfProjectModelElement modelElement
= (ITmfProjectModelElement
) element
;
68 return modelElement
.getParent();
75 public boolean hasChildren(Object element
) {
76 if (element
instanceof IProject
) {
77 IProject project
= (IProject
) element
;
78 return project
.isAccessible();
80 if (element
instanceof ITmfProjectModelElement
) {
81 ITmfProjectModelElement modelElement
= (ITmfProjectModelElement
) element
;
82 return modelElement
.hasChildren();
88 public void dispose() {
92 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {
96 public void restoreState(IMemento aMemento
) {
100 public void saveState(IMemento aMemento
) {
104 public void init(ICommonContentExtensionSite aConfig
) {
107 // ------------------------------------------------------------------------
108 // ICommonContentProvider - getChildren()
109 // ------------------------------------------------------------------------
112 public synchronized Object
[] getChildren(Object parentElement
) {
114 // Tracing project level
115 if (parentElement
instanceof IProject
) {
116 TmfProjectElement element
= TmfProjectRegistry
.getProject((IProject
) parentElement
, true);
117 return element
.getChildren().toArray();
120 // Other project model elements
121 if (parentElement
instanceof ITmfProjectModelElement
) {
122 return ((ITmfProjectModelElement
) parentElement
).getChildren().toArray();
125 return new Object
[0];
128 // ------------------------------------------------------------------------
129 // IPipelinedTreeContentProvider
130 // ------------------------------------------------------------------------
133 public void getPipelinedChildren(Object parent
, Set currentChildren
) {
134 customizeTmfElements(getChildren(parent
), currentChildren
);
138 public void getPipelinedElements(Object input
, Set currentElements
) {
139 customizeTmfElements(getElements(input
), currentElements
);
143 * Add/replace the ITmfProjectElement to the list of children
146 * the list returned by getChildren()
148 * the current children
150 private static void customizeTmfElements(Object
[] elements
,
151 Set
<Object
> children
) {
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
);
160 children
.add(element
);
162 else if (element
!= null) {
163 children
.add(element
);
170 public Object
getPipelinedParent(Object anObject
, Object aSuggestedParent
) {
171 return aSuggestedParent
;
175 public PipelinedShapeModification
interceptAdd(PipelinedShapeModification anAddModification
) {
176 return anAddModification
;
180 public PipelinedShapeModification
interceptRemove(PipelinedShapeModification aRemoveModification
) {
185 public boolean interceptRefresh(PipelinedViewerUpdate aRefreshSynchronization
) {
190 public boolean interceptUpdate(PipelinedViewerUpdate anUpdateSynchronization
) {