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