Commit | Line | Data |
---|---|---|
c068a752 | 1 | /******************************************************************************* |
60ae41e1 | 2 | * Copyright (c) 2013, 2014 École Polytechnique de Montréal |
c068a752 GB |
3 | * |
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 | |
8 | * | |
9 | * Contributors: | |
10 | * Geneviève Bastien - Initial API and implementation | |
339d539c | 11 | * Patrick Tasse - Add support for folder elements |
c068a752 GB |
12 | *******************************************************************************/ |
13 | ||
2bdf0193 | 14 | package org.eclipse.tracecompass.tmf.ui.project.model; |
c068a752 GB |
15 | |
16 | import org.eclipse.core.resources.IResource; | |
c068a752 | 17 | import org.eclipse.swt.graphics.Image; |
2bdf0193 AM |
18 | import org.eclipse.tracecompass.internal.tmf.ui.Activator; |
19 | import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisOutput; | |
20 | import org.eclipse.tracecompass.tmf.ui.analysis.TmfAnalysisViewOutput; | |
c068a752 GB |
21 | import org.eclipse.ui.PlatformUI; |
22 | import org.eclipse.ui.views.IViewDescriptor; | |
23 | ||
24 | /** | |
25 | * Class for project elements of type analysis output | |
26 | * | |
27 | * @author Geneviève Bastien | |
c068a752 GB |
28 | */ |
29 | public class TmfAnalysisOutputElement extends TmfProjectModelElement { | |
30 | ||
31 | private final IAnalysisOutput fOutput; | |
32 | ||
33 | /** | |
34 | * Constructor | |
35 | * | |
36 | * @param name | |
37 | * Name of the view | |
38 | * @param resource | |
39 | * Resource for the view | |
40 | * @param parent | |
41 | * Parent analysis of the view | |
42 | * @param output | |
43 | * The output object | |
44 | */ | |
45 | protected TmfAnalysisOutputElement(String name, IResource resource, ITmfProjectModelElement parent, IAnalysisOutput output) { | |
46 | super(name, resource, parent); | |
47 | fOutput = output; | |
94227c30 | 48 | parent.addChild(this); |
c068a752 GB |
49 | } |
50 | ||
c068a752 GB |
51 | /** |
52 | * Gets the icon of the view, if applicable | |
53 | * | |
54 | * @return The view icon or null if output is not a view | |
55 | */ | |
56 | public Image getIcon() { | |
57 | if (fOutput instanceof TmfAnalysisViewOutput) { | |
58 | IViewDescriptor descr = PlatformUI.getWorkbench().getViewRegistry().find( | |
59 | ((TmfAnalysisViewOutput) fOutput).getViewId()); | |
60 | if (descr != null) { | |
e1288d8a MAL |
61 | Activator bundle = Activator.getDefault(); |
62 | String key = descr.getId(); | |
63 | Image icon = bundle.getImageRegistry().get(key); | |
64 | if (icon == null) { | |
65 | icon = descr.getImageDescriptor().createImage(); | |
66 | bundle.getImageRegistry().put(key, icon); | |
67 | } | |
68 | return icon; | |
c068a752 GB |
69 | } |
70 | } | |
71 | return null; | |
72 | } | |
73 | ||
74 | /** | |
75 | * Outputs the analysis | |
76 | */ | |
77 | public void outputAnalysis() { | |
78 | ITmfProjectModelElement parent = getParent(); | |
79 | if (parent instanceof TmfAnalysisElement) { | |
80 | ((TmfAnalysisElement) parent).activateParent(); | |
81 | fOutput.requestOutput(); | |
82 | } | |
83 | } | |
84 | ||
85 | } |