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 | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.tmf.ui.project.model; | |
14 | ||
15 | import org.eclipse.core.resources.IResource; | |
e1288d8a | 16 | import org.eclipse.linuxtools.internal.tmf.ui.Activator; |
c068a752 GB |
17 | import org.eclipse.linuxtools.tmf.core.analysis.IAnalysisOutput; |
18 | import org.eclipse.linuxtools.tmf.ui.analysis.TmfAnalysisViewOutput; | |
19 | import org.eclipse.swt.graphics.Image; | |
20 | import org.eclipse.ui.PlatformUI; | |
21 | import org.eclipse.ui.views.IViewDescriptor; | |
22 | ||
23 | /** | |
24 | * Class for project elements of type analysis output | |
25 | * | |
26 | * @author Geneviève Bastien | |
27 | * @since 3.0 | |
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 | ||
51 | @Override | |
52 | public TmfProjectElement getProject() { | |
53 | return getParent().getProject(); | |
54 | } | |
55 | ||
56 | /** | |
57 | * Gets the icon of the view, if applicable | |
58 | * | |
59 | * @return The view icon or null if output is not a view | |
60 | */ | |
61 | public Image getIcon() { | |
62 | if (fOutput instanceof TmfAnalysisViewOutput) { | |
63 | IViewDescriptor descr = PlatformUI.getWorkbench().getViewRegistry().find( | |
64 | ((TmfAnalysisViewOutput) fOutput).getViewId()); | |
65 | if (descr != null) { | |
e1288d8a MAL |
66 | Activator bundle = Activator.getDefault(); |
67 | String key = descr.getId(); | |
68 | Image icon = bundle.getImageRegistry().get(key); | |
69 | if (icon == null) { | |
70 | icon = descr.getImageDescriptor().createImage(); | |
71 | bundle.getImageRegistry().put(key, icon); | |
72 | } | |
73 | return icon; | |
c068a752 GB |
74 | } |
75 | } | |
76 | return null; | |
77 | } | |
78 | ||
79 | /** | |
80 | * Outputs the analysis | |
81 | */ | |
82 | public void outputAnalysis() { | |
83 | ITmfProjectModelElement parent = getParent(); | |
84 | if (parent instanceof TmfAnalysisElement) { | |
85 | ((TmfAnalysisElement) parent).activateParent(); | |
86 | fOutput.requestOutput(); | |
87 | } | |
88 | } | |
89 | ||
90 | } |