1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 École Polytechnique de Montréal
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
10 * Geneviève Bastien - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.analysis
;
15 import java
.util
.HashMap
;
18 import org
.eclipse
.core
.runtime
.CoreException
;
19 import org
.eclipse
.core
.runtime
.IConfigurationElement
;
20 import org
.eclipse
.core
.runtime
.IExecutableExtension
;
21 import org
.eclipse
.jdt
.annotation
.NonNull
;
22 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Activator
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.analysis
.IAnalysisOutput
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.analysis
.TmfAnalysisModuleOutputs
;
25 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.Messages
;
26 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TraceUtils
;
27 import org
.eclipse
.swt
.widgets
.Display
;
28 import org
.eclipse
.ui
.IViewPart
;
29 import org
.eclipse
.ui
.IWorkbench
;
30 import org
.eclipse
.ui
.IWorkbenchPage
;
31 import org
.eclipse
.ui
.PartInitException
;
32 import org
.eclipse
.ui
.PlatformUI
;
33 import org
.eclipse
.ui
.part
.WorkbenchPart
;
34 import org
.eclipse
.ui
.views
.IViewDescriptor
;
37 * Class that implements analysis output as a view. This just opens the view.
38 * The view itself needs to manage how and when it will execute the analysis and
39 * display which output.
41 * @author Geneviève Bastien
44 public class TmfAnalysisViewOutput
implements IAnalysisOutput
, IExecutableExtension
{
46 private String fViewId
;
47 private final Map
<String
, String
> fProperties
= new HashMap
<>();
52 public TmfAnalysisViewOutput() {
60 * id of the view to display as output
62 public TmfAnalysisViewOutput(String viewid
) {
67 * Returns the view id of the corresponding view
71 public String
getViewId() {
76 public String
getName() {
77 IViewDescriptor descr
= PlatformUI
.getWorkbench().getViewRegistry().find(fViewId
);
78 String viewName
= (descr
!= null) ? descr
.getLabel() : fViewId
+ Messages
.TmfAnalysisViewOutput_ViewUnavailable
;
83 public void requestOutput() {
84 Display
.getDefault().asyncExec(new Runnable() {
89 final IWorkbench wb
= PlatformUI
.getWorkbench();
90 final IWorkbenchPage activePage
= wb
.getActiveWorkbenchWindow().getActivePage();
92 IViewPart view
= activePage
.showView(fViewId
);
93 if (!(fProperties
.isEmpty()) && (view
instanceof WorkbenchPart
)) {
94 WorkbenchPart wbPart
= (WorkbenchPart
) view
;
95 for (String key
: fProperties
.keySet()) {
96 wbPart
.setPartProperty(key
, fProperties
.get(key
));
100 } catch (final PartInitException e
) {
101 TraceUtils
.displayErrorMsg(Messages
.TmfAnalysisViewOutput_Title
, "Error opening view " + getName() + e
.getMessage()); //$NON-NLS-1$
102 Activator
.getDefault().logError("Error opening view " + getName(), e
); //$NON-NLS-1$
109 public void setOutputProperty(@NonNull String key
, String value
, boolean immediate
) {
111 fProperties
.remove(key
);
113 fProperties
.put(key
, value
);
115 * If the property is immediate, we forward it to the view if the
119 final IWorkbench wb
= PlatformUI
.getWorkbench();
120 final IWorkbenchPage activePage
= wb
.getActiveWorkbenchWindow().getActivePage();
121 IViewPart view
= activePage
.findView(fViewId
);
122 if (view
instanceof WorkbenchPart
) {
123 ((WorkbenchPart
) view
).setPartProperty(key
, value
);
130 public void setInitializationData(IConfigurationElement config
, String propertyName
, Object data
) throws CoreException
{
131 fViewId
= config
.getAttribute(TmfAnalysisModuleOutputs
.ID_ATTR
);