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
.LamiResultTable
;
31 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.TmfView
;
34 * Base view showing output of Babeltrace scripts.
36 * Implementations can specify which analysis modules to use, which will define
37 * the scripts and parameters to use accordingly.
39 * @author Alexandre Montplaisir
41 public final class LamiReportView
extends TmfView
{
43 // ------------------------------------------------------------------------
45 // ------------------------------------------------------------------------
48 public static final String VIEW_ID
= "org.eclipse.tracecompass.analysis.lami.views.reportview"; //$NON-NLS-1$
50 private final @Nullable LamiAnalysisReport fReport
;
51 private final List
<LamiReportViewTabPage
> fTabPages
;
53 private @Nullable CTabFolder fTabFolder
;
55 // ------------------------------------------------------------------------
57 // ------------------------------------------------------------------------
59 private class ToggleTableAction
extends Action
{
62 LamiReportViewTabPage page
= getCurrentSelectedPage();
66 page
.toggleTableViewer();
70 private class NewCustomChartAction
extends Action
{
74 LamiReportViewTabPage page
= getCurrentSelectedPage();
78 page
.createNewCustomChart();
82 // ------------------------------------------------------------------------
84 // ------------------------------------------------------------------------
89 public LamiReportView() {
91 fReport
= LamiReportViewFactory
.getCurrentReport();
92 fTabPages
= new ArrayList
<>();
95 // ------------------------------------------------------------------------
97 // ------------------------------------------------------------------------
100 public void createPartControl(@Nullable Composite parent
) {
101 LamiAnalysisReport report
= fReport
;
102 if (report
== null || parent
== null) {
106 setPartName(report
.getName());
108 fTabFolder
= new CTabFolder(parent
, SWT
.NONE
);
109 fTabFolder
.setSimple(false);
111 for (LamiResultTable table
: report
.getTables()) {
112 String name
= table
.getTableClass().getTableTitle();
114 CTabItem tabItem
= new CTabItem(fTabFolder
, SWT
.NULL
);
115 tabItem
.setText(name
);
117 SashForm sf
= new SashForm(fTabFolder
, SWT
.NONE
);
118 fTabPages
.add(new LamiReportViewTabPage(sf
, table
));
119 tabItem
.setControl(sf
);
122 /* Add toolbar buttons */
123 Action toggleTableAction
= new ToggleTableAction();
124 toggleTableAction
.setText(Messages
.LamiReportView_ActivateTableAction_ButtonName
);
125 toggleTableAction
.setToolTipText(Messages
.LamiReportView_ActivateTableAction_ButtonTooltip
);
126 toggleTableAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath("icons/table.gif")); //$NON-NLS-1$
128 IToolBarManager toolbarMgr
= getViewSite().getActionBars().getToolBarManager();
129 toolbarMgr
.add(toggleTableAction
);
131 IMenuManager menuMgr
= getViewSite().getActionBars().getMenuManager();
133 IAction newChartAction
= new NewCustomChartAction();
134 newChartAction
.setText(Messages
.LamiReportView_NewCustomChart
);
136 IAction clearCustomViewsAction
= new Action() {
139 LamiReportViewTabPage tabPage
= getCurrentSelectedPage();
140 if (tabPage
== null) {
143 tabPage
.clearAllCustomViewers();
144 tabPage
.getControl().layout();
147 clearCustomViewsAction
.setText(Messages
.LamiReportView_ClearAllCustomViews
);
149 menuMgr
.add(newChartAction
);
150 menuMgr
.add(new Separator());
151 menuMgr
.add(clearCustomViewsAction
);
153 /* Select the first tab initially */
154 CTabFolder tf
= checkNotNull(fTabFolder
);
155 if (tf
.getItemCount() > 0) {
160 // ------------------------------------------------------------------------
162 // ------------------------------------------------------------------------
165 public void setFocus() {
166 if (fTabFolder
!= null) {
167 fTabFolder
.setFocus();
171 @Nullable LamiReportViewTabPage
getCurrentSelectedPage() {
172 CTabFolder tf
= fTabFolder
;
176 int idx
= tf
.getSelectionIndex();
177 return fTabPages
.get(idx
);