Move alltests plugin to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / analysis / TmfAnalysisViewOutput.java
1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 École Polytechnique de Montréal
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 * Contributors:
10 * Geneviève Bastien - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.ui.analysis;
14
15 import java.util.HashMap;
16 import java.util.Map;
17
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;
35
36 /**
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.
40 *
41 * @author Geneviève Bastien
42 * @since 3.0
43 */
44 public class TmfAnalysisViewOutput implements IAnalysisOutput, IExecutableExtension {
45
46 private String fViewId;
47 private final Map<String, String> fProperties = new HashMap<>();
48
49 /**
50 * Default constructor
51 */
52 public TmfAnalysisViewOutput() {
53
54 }
55
56 /**
57 * Constructor
58 *
59 * @param viewid
60 * id of the view to display as output
61 */
62 public TmfAnalysisViewOutput(String viewid) {
63 fViewId = viewid;
64 }
65
66 /**
67 * Returns the view id of the corresponding view
68 *
69 * @return The view id
70 */
71 public String getViewId() {
72 return fViewId;
73 }
74
75 @Override
76 public String getName() {
77 IViewDescriptor descr = PlatformUI.getWorkbench().getViewRegistry().find(fViewId);
78 String viewName = (descr != null) ? descr.getLabel() : fViewId + Messages.TmfAnalysisViewOutput_ViewUnavailable;
79 return viewName;
80 }
81
82 @Override
83 public void requestOutput() {
84 Display.getDefault().asyncExec(new Runnable() {
85 @Override
86 public void run() {
87
88 try {
89 final IWorkbench wb = PlatformUI.getWorkbench();
90 final IWorkbenchPage activePage = wb.getActiveWorkbenchWindow().getActivePage();
91
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));
97 }
98 }
99
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$
103 }
104 }
105 });
106 }
107
108 @Override
109 public void setOutputProperty(@NonNull String key, String value, boolean immediate) {
110 if (value == null) {
111 fProperties.remove(key);
112 } else {
113 fProperties.put(key, value);
114 /*
115 * If the property is immediate, we forward it to the view if the
116 * view is active
117 */
118 if (immediate) {
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);
124 }
125 }
126 }
127 }
128
129 @Override
130 public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException {
131 fViewId = config.getAttribute(TmfAnalysisModuleOutputs.ID_ATTR);
132 }
133 }
This page took 0.034453 seconds and 5 git commands to generate.