1 /*******************************************************************************
2 * Copyright (c) 2015, 2016 EfficiOS Inc., Alexandre Montplaisir
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 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.internal
.provisional
.analysis
.lami
.ui
.views
;
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
;
22 * Control for Lami viewers.
24 * Since viewers can be disposed, the "viewer control" will remain and be ready
25 * to re-instantiate the viewer if required to.
27 * @author Alexandre Montplaisir
29 public final class LamiViewerControl
{
31 private final Action fToggleAction
;
33 private @Nullable ILamiViewer fViewer
;
36 * Build a new control for a Lami table viewer.
39 * The parent composite
41 * The results table populating the table viewer
43 public LamiViewerControl(Composite parent
, LamiResultTable table
) {
44 fToggleAction
= new Action() {
47 ILamiViewer viewer
= fViewer
;
49 fViewer
= ILamiViewer
.createLamiTable(parent
, table
);
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$
63 * Build a new control for a graph viewer.
66 * The parent composite
68 * The table containing the source data
72 public LamiViewerControl(Composite parent
, LamiResultTable table
, LamiChartModel graphModel
) {
73 fToggleAction
= new Action() {
76 ILamiViewer viewer
= fViewer
;
78 fViewer
= ILamiViewer
.createLamiChart(parent
, table
, graphModel
);
86 fToggleAction
.setText(Messages
.LamiReportView_ToggleAction_ButtonNamePrefix
+ ' ' + graphModel
.getName());
87 fToggleAction
.setToolTipText(Messages
.LamiReportView_ToggleAction_ButtonTooltip
);
88 fToggleAction
.setImageDescriptor(getIconForGraphType(graphModel
.getChartType()));
92 * Get the viewer of this control. Returns null if the viewer is current
97 public @Nullable ILamiViewer
getViewer() {
102 * Get the toggle action that shows/hide this control's viewer.
104 * @return The toggle action
106 public Action
getToggleAction() {
107 return fToggleAction
;
111 * Explicitly dispose this control's viewer.
113 public void dispose() {
114 if (fViewer
!= null) {
119 private static @Nullable ImageDescriptor
getIconForGraphType(LamiChartModel
.ChartType graphType
) {
122 return Activator
.getDefault().getImageDescripterFromPath("icons/histogram.gif"); //$NON-NLS-1$
126 // FIXME Use other icons
127 return Activator
.getDefault().getImageDescripterFromPath("icons/histogram.gif"); //$NON-NLS-1$