Commit | Line | Data |
---|---|---|
c068a752 GB |
1 | /******************************************************************************* |
2 | * Copyright (c) 2013 École Polytechnique de Montréal | |
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; | |
16 | import org.eclipse.linuxtools.tmf.core.analysis.IAnalysisOutput; | |
17 | import org.eclipse.linuxtools.tmf.ui.analysis.TmfAnalysisViewOutput; | |
18 | import org.eclipse.swt.graphics.Image; | |
19 | import org.eclipse.ui.PlatformUI; | |
20 | import org.eclipse.ui.views.IViewDescriptor; | |
21 | ||
22 | /** | |
23 | * Class for project elements of type analysis output | |
24 | * | |
25 | * @author Geneviève Bastien | |
26 | * @since 3.0 | |
27 | */ | |
28 | public class TmfAnalysisOutputElement extends TmfProjectModelElement { | |
29 | ||
30 | private final IAnalysisOutput fOutput; | |
31 | ||
32 | /** | |
33 | * Constructor | |
34 | * | |
35 | * @param name | |
36 | * Name of the view | |
37 | * @param resource | |
38 | * Resource for the view | |
39 | * @param parent | |
40 | * Parent analysis of the view | |
41 | * @param output | |
42 | * The output object | |
43 | */ | |
44 | protected TmfAnalysisOutputElement(String name, IResource resource, ITmfProjectModelElement parent, IAnalysisOutput output) { | |
45 | super(name, resource, parent); | |
46 | fOutput = output; | |
47 | } | |
48 | ||
49 | @Override | |
50 | public TmfProjectElement getProject() { | |
51 | return getParent().getProject(); | |
52 | } | |
53 | ||
54 | /** | |
55 | * Gets the icon of the view, if applicable | |
56 | * | |
57 | * @return The view icon or null if output is not a view | |
58 | */ | |
59 | public Image getIcon() { | |
60 | if (fOutput instanceof TmfAnalysisViewOutput) { | |
61 | IViewDescriptor descr = PlatformUI.getWorkbench().getViewRegistry().find( | |
62 | ((TmfAnalysisViewOutput) fOutput).getViewId()); | |
63 | if (descr != null) { | |
64 | return descr.getImageDescriptor().createImage(); | |
65 | } | |
66 | } | |
67 | return null; | |
68 | } | |
69 | ||
70 | /** | |
71 | * Outputs the analysis | |
72 | */ | |
73 | public void outputAnalysis() { | |
74 | ITmfProjectModelElement parent = getParent(); | |
75 | if (parent instanceof TmfAnalysisElement) { | |
76 | ((TmfAnalysisElement) parent).activateParent(); | |
77 | fOutput.requestOutput(); | |
78 | } | |
79 | } | |
80 | ||
81 | } |