analysis.lami: Implementation of LAMI plugins
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.lami.ui / src / org / eclipse / tracecompass / internal / provisional / analysis / lami / ui / views / LamiViewerControl.java
1 /*******************************************************************************
2 * Copyright (c) 2015, 2016 EfficiOS Inc., Alexandre Montplaisir
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
10 package org.eclipse.tracecompass.internal.provisional.analysis.lami.ui.views;
11
12 import org.eclipse.jdt.annotation.Nullable;
13 import org.eclipse.jface.action.Action;
14 import org.eclipse.jface.resource.ImageDescriptor;
15 import org.eclipse.swt.widgets.Composite;
16 import org.eclipse.tracecompass.internal.analysis.lami.ui.Activator;
17 import org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module.LamiChartModel;
18 import org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module.LamiResultTable;
19 import org.eclipse.tracecompass.internal.provisional.analysis.lami.ui.viewers.ILamiViewer;
20
21 /**
22 * Control for Lami viewers.
23 *
24 * Since viewers can be disposed, the "viewer control" will remain and be ready
25 * to re-instantiate the viewer if required to.
26 *
27 * @author Alexandre Montplaisir
28 */
29 public final class LamiViewerControl {
30
31 private final Action fToggleAction;
32
33 private @Nullable ILamiViewer fViewer;
34
35 /**
36 * Build a new control for a Lami table viewer.
37 *
38 * @param parent
39 * The parent composite
40 * @param table
41 * The results table populating the table viewer
42 */
43 public LamiViewerControl(Composite parent, LamiResultTable table) {
44 fToggleAction = new Action() {
45 @Override
46 public void run() {
47 ILamiViewer viewer = fViewer;
48 if (viewer == null) {
49 fViewer = ILamiViewer.createLamiTable(parent, table);
50 } else {
51 viewer.dispose();
52 fViewer = null;
53 }
54 parent.layout();
55 }
56 };
57 fToggleAction.setText(Messages.LamiReportView_ActivateTableAction_ButtonName);
58 fToggleAction.setToolTipText(Messages.LamiReportView_ActivateTableAction_ButtonTooltip);
59 fToggleAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath("icons/table.gif")); //$NON-NLS-1$
60 }
61
62 /**
63 * Build a new control for a graph viewer.
64 *
65 * @param parent
66 * The parent composite
67 * @param table
68 * The table containing the source data
69 * @param graphModel
70 * The graph model
71 */
72 public LamiViewerControl(Composite parent, LamiResultTable table, LamiChartModel graphModel) {
73 fToggleAction = new Action() {
74 @Override
75 public void run() {
76 ILamiViewer viewer = fViewer;
77 if (viewer == null) {
78 fViewer = ILamiViewer.createLamiChart(parent, table, graphModel);
79 } else {
80 viewer.dispose();
81 fViewer = null;
82 }
83 parent.layout();
84 }
85 };
86 fToggleAction.setText(Messages.LamiReportView_ToggleAction_ButtonNamePrefix + ' ' + graphModel.getName());
87 fToggleAction.setToolTipText(Messages.LamiReportView_ToggleAction_ButtonTooltip);
88 fToggleAction.setImageDescriptor(getIconForGraphType(graphModel.getChartType()));
89 }
90
91 /**
92 * Get the viewer of this control. Returns null if the viewer is current
93 * disposed.
94 *
95 * @return The viewer
96 */
97 public @Nullable ILamiViewer getViewer() {
98 return fViewer;
99 }
100
101 /**
102 * Get the toggle action that shows/hide this control's viewer.
103 *
104 * @return The toggle action
105 */
106 public Action getToggleAction() {
107 return fToggleAction;
108 }
109
110 /**
111 * Explicitly dispose this control's viewer.
112 */
113 public void dispose() {
114 if (fViewer != null) {
115 fViewer.dispose();
116 }
117 }
118
119 private static @Nullable ImageDescriptor getIconForGraphType(LamiChartModel.ChartType graphType) {
120 switch (graphType) {
121 case BAR_CHART:
122 return Activator.getDefault().getImageDescripterFromPath("icons/histogram.gif"); //$NON-NLS-1$
123 case PIE_CHART:
124 case XY_SCATTER:
125 default:
126 // FIXME Use other icons
127 return Activator.getDefault().getImageDescripterFromPath("icons/histogram.gif"); //$NON-NLS-1$
128 }
129 }
130
131 }
This page took 0.041066 seconds and 5 git commands to generate.