Commit | Line | Data |
---|---|---|
12c155f5 | 1 | /******************************************************************************* |
11252342 | 2 | * Copyright (c) 2011, 2013 Ericsson |
f28d404e | 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 | |
f28d404e | 8 | * |
12c155f5 FC |
9 | * Contributors: |
10 | * Francois Chouinard - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.tmf.ui.project.model; | |
14 | ||
12c155f5 FC |
15 | import org.eclipse.core.resources.IProject; |
16 | import org.eclipse.core.resources.IResourceChangeEvent; | |
f523352d PT |
17 | import org.eclipse.swt.widgets.Display; |
18 | import org.eclipse.ui.IViewPart; | |
19 | import org.eclipse.ui.IViewReference; | |
20 | import org.eclipse.ui.IWorkbench; | |
21 | import org.eclipse.ui.IWorkbenchPage; | |
eb319a80 | 22 | import org.eclipse.ui.IWorkbenchWindow; |
f523352d PT |
23 | import org.eclipse.ui.PlatformUI; |
24 | import org.eclipse.ui.navigator.CommonNavigator; | |
25 | import org.eclipse.ui.navigator.CommonViewer; | |
12c155f5 FC |
26 | |
27 | /** | |
f28d404e AM |
28 | * The implementation of TMF project model element. |
29 | * | |
b544077e BH |
30 | * @version 1.0 |
31 | * @author Francois Chouinard | |
12c155f5 FC |
32 | */ |
33 | public class TmfProjectElement extends TmfProjectModelElement { | |
34 | ||
35 | // ------------------------------------------------------------------------ | |
36 | // Attributes | |
37 | // ------------------------------------------------------------------------ | |
38 | ||
b544077e BH |
39 | private TmfTraceFolder fTraceFolder = null; |
40 | private TmfExperimentFolder fExperimentFolder = null; | |
12c155f5 FC |
41 | |
42 | // ------------------------------------------------------------------------ | |
43 | // Constructor | |
44 | // ------------------------------------------------------------------------ | |
b544077e BH |
45 | /** |
46 | * Constructor. | |
f28d404e AM |
47 | * |
48 | * Creates the TMF project model element. | |
b544077e BH |
49 | * @param name The name of the project. |
50 | * @param project The project reference. | |
51 | * @param parent The parent element | |
52 | */ | |
12c155f5 FC |
53 | public TmfProjectElement(String name, IProject project, ITmfProjectModelElement parent) { |
54 | super(name, project, parent); | |
55 | } | |
56 | ||
57 | // ------------------------------------------------------------------------ | |
58 | // TmfProjectModelElement | |
59 | // ------------------------------------------------------------------------ | |
60 | ||
61 | @Override | |
62 | public IProject getResource() { | |
63 | return (IProject) fResource; | |
64 | } | |
65 | ||
66 | @Override | |
67 | public void addChild(ITmfProjectModelElement child) { | |
68 | super.addChild(child); | |
69 | if (child instanceof TmfTraceFolder) { | |
70 | fTraceFolder = (TmfTraceFolder) child; | |
71 | return; | |
72 | } | |
73 | if (child instanceof TmfExperimentFolder) { | |
74 | fExperimentFolder = (TmfExperimentFolder) child; | |
75 | return; | |
76 | } | |
77 | } | |
78 | ||
79 | // ------------------------------------------------------------------------ | |
80 | // Accessors | |
81 | // ------------------------------------------------------------------------ | |
11252342 | 82 | |
b544077e | 83 | /** |
f28d404e | 84 | * Returns the containing trace folder element. |
b544077e BH |
85 | * @return the TMF trace folder element. |
86 | */ | |
12c155f5 FC |
87 | public TmfTraceFolder getTracesFolder() { |
88 | return fTraceFolder; | |
89 | } | |
90 | ||
b544077e BH |
91 | /** |
92 | * Returns the containing experiment folder element. | |
93 | * @return the TMF experiment folder element. | |
94 | */ | |
12c155f5 FC |
95 | public TmfExperimentFolder getExperimentsFolder() { |
96 | return fExperimentFolder; | |
97 | } | |
98 | ||
99 | // ------------------------------------------------------------------------ | |
100 | // TmfProjectElement | |
101 | // ------------------------------------------------------------------------ | |
102 | ||
103 | @Override | |
104 | public void refresh() { | |
f523352d PT |
105 | Display.getDefault().asyncExec(new Runnable(){ |
106 | @Override | |
107 | public void run() { | |
108 | IWorkbench wb = PlatformUI.getWorkbench(); | |
eb319a80 PT |
109 | IWorkbenchWindow wbWindow = wb.getActiveWorkbenchWindow(); |
110 | if (wbWindow == null) { | |
111 | return; | |
112 | } | |
113 | IWorkbenchPage activePage = wbWindow.getActivePage(); | |
f28d404e AM |
114 | if (activePage == null) { |
115 | return; | |
116 | } | |
117 | ||
f523352d PT |
118 | for (IViewReference viewReference : activePage.getViewReferences()) { |
119 | IViewPart viewPart = viewReference.getView(false); | |
120 | if (viewPart instanceof CommonNavigator) { | |
121 | CommonViewer commonViewer = ((CommonNavigator) viewPart).getCommonViewer(); | |
122 | commonViewer.refresh(); | |
123 | } | |
12c155f5 | 124 | } |
f523352d | 125 | }}); |
12c155f5 FC |
126 | } |
127 | ||
128 | @Override | |
129 | public void resourceChanged(IResourceChangeEvent event) { | |
130 | if (event.getType() == IResourceChangeEvent.POST_CHANGE) { | |
131 | refresh(); | |
132 | } | |
133 | } | |
134 | ||
135 | @Override | |
136 | public TmfProjectElement getProject() { | |
137 | return this; | |
138 | } | |
12c155f5 | 139 | } |