lami: synchronize getter for currentReport
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.lami.ui / src / org / eclipse / tracecompass / internal / provisional / analysis / lami / ui / views / LamiReportViewFactory.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 org.eclipse.jdt.annotation.Nullable;
13 import org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module.LamiAnalysisReport;
14 import org.eclipse.ui.IWorkbenchPage;
15 import org.eclipse.ui.PartInitException;
16 import org.eclipse.ui.PlatformUI;
17
18 /**
19 * Factory to instantiate and display new Lami report views.
20 *
21 * It works by setting a static field, then having the view access it.
22 *
23 * @author Alexandre Montplaisir
24 */
25 public final class LamiReportViewFactory {
26
27 private LamiReportViewFactory() {
28 }
29
30 private static @Nullable LamiAnalysisReport currentReport;
31 private static int secondaryViewId = 1;
32
33 /**
34 * Return the current report. Should be accessed by the view currently being
35 * built.
36 *
37 * @return The current report
38 */
39 public static synchronized @Nullable LamiAnalysisReport getCurrentReport() {
40 return currentReport;
41 }
42
43 /**
44 * Create all the views from a given report
45 *
46 * @param report
47 * The report to open
48 * @throws PartInitException
49 * If there was a problem initializing a view
50 */
51 public static synchronized void createNewView(LamiAnalysisReport report)
52 throws PartInitException {
53 currentReport = report;
54
55 final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
56
57 /*
58 * Doing this in two operations here, instead of using
59 * IWorkbenchPage.VIEW_ACTIVATE, works around a bug where the contextual
60 * menu would get "stuck" until the Project view is defocused and
61 * refocused.
62 */
63 page.showView(LamiReportView.VIEW_ID, String.valueOf(secondaryViewId), IWorkbenchPage.VIEW_VISIBLE);
64 page.activate(page.findView(LamiReportView.VIEW_ID));
65
66 secondaryViewId++;
67
68 currentReport = null;
69 }
70
71 }
This page took 0.031089 seconds and 5 git commands to generate.