Commit | Line | Data |
---|---|---|
4208b510 AM |
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; | |
4208b510 AM |
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 | ||
f95c9345 | 30 | private static @Nullable LamiAnalysisReport currentReport; |
4208b510 AM |
31 | private static int secondaryViewId = 1; |
32 | ||
33 | /** | |
f95c9345 AM |
34 | * Return the current report. Should be accessed by the view currently being |
35 | * built. | |
4208b510 | 36 | * |
f95c9345 | 37 | * @return The current report |
4208b510 | 38 | */ |
fbe6f2d3 | 39 | public static synchronized @Nullable LamiAnalysisReport getCurrentReport() { |
f95c9345 | 40 | return currentReport; |
4208b510 AM |
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 | */ | |
f95c9345 AM |
51 | public static synchronized void createNewView(LamiAnalysisReport report) |
52 | throws PartInitException { | |
53 | currentReport = report; | |
4208b510 | 54 | |
f95c9345 | 55 | final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); |
4208b510 | 56 | |
f95c9345 AM |
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)); | |
4208b510 | 65 | |
f95c9345 | 66 | secondaryViewId++; |
4208b510 | 67 | |
f95c9345 | 68 | currentReport = null; |
4208b510 AM |
69 | } |
70 | ||
71 | } |