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