analysis.lami: Show one view per report
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.lami.ui / src / org / eclipse / tracecompass / internal / provisional / analysis / lami / ui / views / LamiReportView.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 static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
13
14 import java.util.ArrayList;
15 import java.util.List;
16
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;
33
34 /**
35 * Base view showing output of Babeltrace scripts.
36 *
37 * Implementations can specify which analysis modules to use, which will define
38 * the scripts and parameters to use accordingly.
39 *
40 * @author Alexandre Montplaisir
41 */
42 public final class LamiReportView extends TmfView {
43
44 // ------------------------------------------------------------------------
45 // Attributes
46 // ------------------------------------------------------------------------
47
48 /** View ID */
49 public static final String VIEW_ID = "org.eclipse.tracecompass.analysis.lami.views.reportview"; //$NON-NLS-1$
50
51 private final @Nullable LamiAnalysisReport fReport;
52 private final List<LamiReportViewTabPage> fTabPages;
53
54 private @Nullable CTabFolder fTabFolder;
55
56 // ------------------------------------------------------------------------
57 // Actions
58 // ------------------------------------------------------------------------
59
60 private class ToggleTableAction extends Action {
61 @Override
62 public void run() {
63 LamiReportViewTabPage page = getCurrentSelectedPage();
64 if (page == null) {
65 return;
66 }
67 page.toggleTableViewer();
68 }
69 }
70
71 private class NewChartAction extends Action {
72
73 private final ChartType fChartType;
74
75 public NewChartAction(ChartType chartType) {
76 fChartType = chartType;
77 }
78
79 @Override
80 public void run() {
81 LamiReportViewTabPage page = getCurrentSelectedPage();
82 if (page == null) {
83 return;
84 }
85 page.createNewCustomChart(fChartType);
86 }
87 }
88
89 // ------------------------------------------------------------------------
90 // Constructor
91 // ------------------------------------------------------------------------
92
93 /**
94 * Constructor
95 */
96 public LamiReportView() {
97 super(VIEW_ID);
98 fReport = LamiReportViewFactory.getCurrentReport();
99 fTabPages = new ArrayList<>();
100 }
101
102 // ------------------------------------------------------------------------
103 // ViewPart
104 // ------------------------------------------------------------------------
105
106 @Override
107 public void createPartControl(@Nullable Composite parent) {
108 LamiAnalysisReport report = fReport;
109 if (report == null || parent == null) {
110 return;
111 }
112
113 setPartName(report.getName());
114
115 fTabFolder = new CTabFolder(parent, SWT.NONE);
116 fTabFolder.setSimple(false);
117
118 for (LamiResultTable table : report.getTables()) {
119 String name = table.getTableClass().getTableTitle();
120
121 CTabItem tabItem = new CTabItem(fTabFolder, SWT.NULL);
122 tabItem.setText(name);
123
124 SashForm sf = new SashForm(fTabFolder, SWT.NONE);
125 fTabPages.add(new LamiReportViewTabPage(sf, table));
126 tabItem.setControl(sf);
127 }
128
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$
134
135 IToolBarManager toolbarMgr = getViewSite().getActionBars().getToolBarManager();
136 toolbarMgr.add(toggleTableAction);
137
138 IMenuManager menuMgr = getViewSite().getActionBars().getMenuManager();
139 IAction newBarChartAction = new NewChartAction(ChartType.BAR_CHART);
140 IAction newXYScatterAction = new NewChartAction(ChartType.XY_SCATTER);
141
142 newBarChartAction.setText(Messages.LamiReportView_NewCustomBarChart);
143 newXYScatterAction.setText(Messages.LamiReportView_NewCustomScatterChart);
144
145
146 IAction clearCustomViewsAction = new Action() {
147 @Override
148 public void run() {
149 LamiReportViewTabPage tabPage = getCurrentSelectedPage();
150 if (tabPage == null) {
151 return;
152 }
153 tabPage.clearAllCustomViewers();
154 tabPage.getControl().layout();
155 }
156 };
157 clearCustomViewsAction.setText(Messages.LamiReportView_ClearAllCustomViews);
158
159 menuMgr.add(newBarChartAction);
160 menuMgr.add(newXYScatterAction);
161 menuMgr.add(new Separator());
162 menuMgr.add(clearCustomViewsAction);
163
164 /* Select the first tab initially */
165 CTabFolder tf = checkNotNull(fTabFolder);
166 if (tf.getItemCount() > 0) {
167 tf.setSelection(0);
168 }
169 }
170
171 // ------------------------------------------------------------------------
172 // Operations
173 // ------------------------------------------------------------------------
174
175 @Override
176 public void setFocus() {
177 if (fTabFolder != null) {
178 fTabFolder.setFocus();
179 }
180 }
181
182 private @Nullable LamiReportViewTabPage getCurrentSelectedPage() {
183 CTabFolder tf = fTabFolder;
184 if (tf == null) {
185 return null;
186 }
187 int idx = tf.getSelectionIndex();
188 return fTabPages.get(idx);
189 }
190
191 }
This page took 0.05352 seconds and 5 git commands to generate.