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 static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
14 import java
.util
.ArrayList
;
15 import java
.util
.List
;
17 import org
.eclipse
.jdt
.annotation
.Nullable
;
18 import org
.eclipse
.jface
.action
.Action
;
19 import org
.eclipse
.jface
.action
.IAction
;
20 import org
.eclipse
.jface
.action
.IMenuManager
;
21 import org
.eclipse
.jface
.action
.IToolBarManager
;
22 import org
.eclipse
.jface
.action
.Separator
;
23 import org
.eclipse
.swt
.SWT
;
24 import org
.eclipse
.swt
.custom
.CTabFolder
;
25 import org
.eclipse
.swt
.custom
.CTabItem
;
26 import org
.eclipse
.swt
.custom
.SashForm
;
27 import org
.eclipse
.swt
.widgets
.Composite
;
28 import org
.eclipse
.tracecompass
.internal
.analysis
.lami
.ui
.Activator
;
29 import org
.eclipse
.tracecompass
.internal
.provisional
.analysis
.lami
.core
.module
.LamiAnalysisReport
;
30 import org
.eclipse
.tracecompass
.internal
.provisional
.analysis
.lami
.core
.module
.LamiChartModel
.ChartType
;
31 import org
.eclipse
.tracecompass
.internal
.provisional
.analysis
.lami
.core
.module
.LamiResultTable
;
32 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.TmfView
;
35 * Base view showing output of Babeltrace scripts.
37 * Implementations can specify which analysis modules to use, which will define
38 * the scripts and parameters to use accordingly.
40 * @author Alexandre Montplaisir
42 public final class LamiReportView
extends TmfView
{
44 // ------------------------------------------------------------------------
46 // ------------------------------------------------------------------------
49 public static final String VIEW_ID
= "org.eclipse.tracecompass.analysis.lami.views.reportview"; //$NON-NLS-1$
51 private final @Nullable LamiAnalysisReport fReport
;
52 private final List
<LamiReportViewTabPage
> fTabPages
;
54 private @Nullable CTabFolder fTabFolder
;
56 // ------------------------------------------------------------------------
58 // ------------------------------------------------------------------------
60 private class ToggleTableAction
extends Action
{
63 LamiReportViewTabPage page
= getCurrentSelectedPage();
67 page
.toggleTableViewer();
71 private class NewChartAction
extends Action
{
73 private final ChartType fChartType
;
75 public NewChartAction(ChartType chartType
) {
76 fChartType
= chartType
;
81 LamiReportViewTabPage page
= getCurrentSelectedPage();
85 page
.createNewCustomChart(fChartType
);
89 // ------------------------------------------------------------------------
91 // ------------------------------------------------------------------------
96 public LamiReportView() {
98 fReport
= LamiReportViewFactory
.getCurrentReport();
99 fTabPages
= new ArrayList
<>();
102 // ------------------------------------------------------------------------
104 // ------------------------------------------------------------------------
107 public void createPartControl(@Nullable Composite parent
) {
108 LamiAnalysisReport report
= fReport
;
109 if (report
== null || parent
== null) {
113 setPartName(report
.getName());
115 fTabFolder
= new CTabFolder(parent
, SWT
.NONE
);
116 fTabFolder
.setSimple(false);
118 for (LamiResultTable table
: report
.getTables()) {
119 String name
= table
.getTableClass().getTableTitle();
121 CTabItem tabItem
= new CTabItem(fTabFolder
, SWT
.NULL
);
122 tabItem
.setText(name
);
124 SashForm sf
= new SashForm(fTabFolder
, SWT
.NONE
);
125 fTabPages
.add(new LamiReportViewTabPage(sf
, table
));
126 tabItem
.setControl(sf
);
129 /* Add toolbar buttons */
130 Action toggleTableAction
= new ToggleTableAction();
131 toggleTableAction
.setText(Messages
.LamiReportView_ActivateTableAction_ButtonName
);
132 toggleTableAction
.setToolTipText(Messages
.LamiReportView_ActivateTableAction_ButtonTooltip
);
133 toggleTableAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath("icons/table.gif")); //$NON-NLS-1$
135 IToolBarManager toolbarMgr
= getViewSite().getActionBars().getToolBarManager();
136 toolbarMgr
.add(toggleTableAction
);
138 IMenuManager menuMgr
= getViewSite().getActionBars().getMenuManager();
139 IAction newBarChartAction
= new NewChartAction(ChartType
.BAR_CHART
);
140 IAction newXYScatterAction
= new NewChartAction(ChartType
.XY_SCATTER
);
142 newBarChartAction
.setText(Messages
.LamiReportView_NewCustomBarChart
);
143 newXYScatterAction
.setText(Messages
.LamiReportView_NewCustomScatterChart
);
146 IAction clearCustomViewsAction
= new Action() {
149 LamiReportViewTabPage tabPage
= getCurrentSelectedPage();
150 if (tabPage
== null) {
153 tabPage
.clearAllCustomViewers();
154 tabPage
.getControl().layout();
157 clearCustomViewsAction
.setText(Messages
.LamiReportView_ClearAllCustomViews
);
159 menuMgr
.add(newBarChartAction
);
160 menuMgr
.add(newXYScatterAction
);
161 menuMgr
.add(new Separator());
162 menuMgr
.add(clearCustomViewsAction
);
164 /* Select the first tab initially */
165 CTabFolder tf
= checkNotNull(fTabFolder
);
166 if (tf
.getItemCount() > 0) {
171 // ------------------------------------------------------------------------
173 // ------------------------------------------------------------------------
176 public void setFocus() {
177 if (fTabFolder
!= null) {
178 fTabFolder
.setFocus();
182 private @Nullable LamiReportViewTabPage
getCurrentSelectedPage() {
183 CTabFolder tf
= fTabFolder
;
187 int idx
= tf
.getSelectionIndex();
188 return fTabPages
.get(idx
);