Commit | Line | Data |
---|---|---|
87c5447c | 1 | /******************************************************************************* |
abf7b9b0 | 2 | * Copyright (c) 2014, 2015 École Polytechnique de Montréal |
87c5447c 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 | ||
2bdf0193 | 13 | package org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.xychart; |
87c5447c GB |
14 | |
15 | import org.eclipse.jdt.annotation.Nullable; | |
16 | import org.eclipse.jface.util.IPropertyChangeListener; | |
17 | import org.eclipse.jface.util.PropertyChangeEvent; | |
87c5447c GB |
18 | import org.eclipse.swt.widgets.Composite; |
19 | import org.eclipse.swt.widgets.Display; | |
e23402bb | 20 | import org.eclipse.tracecompass.common.core.NonNullUtils; |
2bdf0193 AM |
21 | import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.TmfXmlUiStrings; |
22 | import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.XmlViewInfo; | |
23 | import org.eclipse.tracecompass.tmf.ui.viewers.xycharts.TmfXYChartViewer; | |
24 | import org.eclipse.tracecompass.tmf.ui.views.TmfChartView; | |
c389833c | 25 | import org.eclipse.tracecompass.tmf.ui.views.TmfViewFactory; |
87c5447c GB |
26 | import org.w3c.dom.Element; |
27 | ||
28 | /** | |
29 | * This view displays state system data in an xy chart. It uses an XML | |
30 | * {@link TmfXmlUiStrings#XY_VIEW} element from an XML file. This element | |
31 | * defines which entries from the state system will be shown and also gives | |
32 | * additional information on the presentation of the view. | |
33 | * | |
34 | * @author Geneviève Bastien | |
35 | */ | |
36 | public class XmlXYView extends TmfChartView { | |
37 | ||
38 | /** View ID. */ | |
39 | public static final String ID = "org.eclipse.linuxtools.internal.tmf.analysis.xml.ui.views.xyview"; //$NON-NLS-1$ | |
40 | ||
41 | private final XmlViewInfo fViewInfo = new XmlViewInfo(ID); | |
42 | ||
43 | /** | |
44 | * Default constructor | |
45 | */ | |
46 | public XmlXYView() { | |
47 | super(Messages.XmlXYView_DefaultTitle); | |
48 | ||
49 | this.addPartPropertyListener(new IPropertyChangeListener() { | |
50 | @Override | |
51 | public void propertyChange(@Nullable PropertyChangeEvent event) { | |
52 | if (event == null) { | |
53 | return; | |
54 | } | |
55 | if (event.getProperty().equals(TmfXmlUiStrings.XML_OUTPUT_DATA)) { | |
56 | Object newValue = event.getNewValue(); | |
57 | if (newValue instanceof String) { | |
58 | fViewInfo.setViewData((String) newValue); | |
59 | setViewTitle(); | |
60 | TmfXYChartViewer viewer = getChartViewer(); | |
61 | if (viewer instanceof XmlXYViewer) { | |
62 | ((XmlXYViewer) viewer).viewInfoUpdated(); | |
63 | } | |
64 | ||
65 | } | |
66 | } | |
67 | } | |
68 | ||
69 | }); | |
87c5447c GB |
70 | } |
71 | ||
87c5447c GB |
72 | private void setViewTitle() { |
73 | /* | |
74 | * Get the view element from the XML file. If the element can't be | |
75 | * found, return. | |
76 | */ | |
77 | Element viewElement = fViewInfo.getViewElement(TmfXmlUiStrings.XY_VIEW); | |
78 | if (viewElement == null) { | |
79 | return; | |
80 | } | |
81 | ||
82 | String title = fViewInfo.getViewTitle(viewElement); | |
83 | if (title == null) { | |
84 | title = Messages.XmlXYView_DefaultTitle; | |
85 | } | |
86 | final String viewTitle = title; | |
87 | Display.getDefault().asyncExec(new Runnable() { | |
88 | @Override | |
89 | public void run() { | |
90 | setPartName(viewTitle); | |
91 | } | |
92 | }); | |
93 | } | |
94 | ||
e23402bb GB |
95 | @Override |
96 | public void createPartControl(@Nullable Composite parent) { | |
97 | super.createPartControl(parent); | |
c389833c | 98 | fViewInfo.setName(NonNullUtils.checkNotNull(TmfViewFactory.getBaseSecId(getViewSite().getSecondaryId()))); |
e23402bb GB |
99 | setViewTitle(); |
100 | } | |
101 | ||
4c5e027b MAL |
102 | @Override |
103 | protected TmfXYChartViewer createChartViewer(@Nullable Composite parent) { | |
104 | return new XmlXYViewer(parent, fViewInfo); | |
105 | } | |
106 | ||
87c5447c | 107 | } |