analysis.lami: Implementation of LAMI plugins
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.lami.ui / src / org / eclipse / tracecompass / internal / provisional / analysis / lami / ui / handler / OpenReportHandler.java
1 /*******************************************************************************
2 * Copyright (c) 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.handler;
11
12 import java.util.List;
13 import java.util.stream.Collectors;
14
15 import org.eclipse.core.commands.AbstractHandler;
16 import org.eclipse.core.commands.ExecutionEvent;
17 import org.eclipse.core.commands.ExecutionException;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.eclipse.jface.viewers.ISelection;
20 import org.eclipse.jface.viewers.IStructuredSelection;
21 import org.eclipse.swt.widgets.Display;
22 import org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module.LamiAnalysisReport;
23 import org.eclipse.tracecompass.internal.provisional.analysis.lami.ui.views.LamiReportViewFactory;
24 import org.eclipse.tracecompass.tmf.core.analysis.ondemand.IOnDemandAnalysisReport;
25 import org.eclipse.tracecompass.tmf.ui.project.model.TmfReportElement;
26 import org.eclipse.ui.PartInitException;
27 import org.eclipse.ui.handlers.HandlerUtil;
28
29 /**
30 * The command handler for the "Open Report" menu option for Report project
31 * model elements.
32 *
33 * Double-clicking should also call this handler.
34 *
35 * @author Alexandre Montplaisir
36 */
37 public class OpenReportHandler extends AbstractHandler {
38
39 @Override
40 public @Nullable Object execute(@Nullable ExecutionEvent event) throws ExecutionException {
41
42 /* Types should have been checked by the plugin.xml already */
43 ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
44 List<?> elements = ((IStructuredSelection) selection).toList();
45 List<TmfReportElement> reportElements = elements.stream()
46 .filter(elem -> elem instanceof TmfReportElement)
47 .map(elem -> (TmfReportElement) elem)
48 .collect(Collectors.toList());
49
50 for (TmfReportElement reportElem : reportElements) {
51 IOnDemandAnalysisReport report = reportElem.getReport();
52 if (!(report instanceof LamiAnalysisReport)) {
53 /* This handler deals with LAMI reports only */
54 continue;
55 }
56 LamiAnalysisReport lamiReport = (LamiAnalysisReport) report;
57
58 Display.getDefault().syncExec(() -> {
59 try {
60 LamiReportViewFactory.createNewViews(lamiReport);
61 } catch (PartInitException e) {
62 }
63 });
64 }
65
66 return null;
67 }
68 }
This page took 0.032641 seconds and 5 git commands to generate.