tmf: Use tabs in statistics view for each traces
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / internal / lttng / ui / tracecontrol / wizards / ConfigureTraceWizard.java
1 /*******************************************************************************
2 * Copyright (c) 2011 Ericsson
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 * Bernd Hufmann - Initial API and implementation
11 *
12 *******************************************************************************/
13 package org.eclipse.linuxtools.internal.lttng.ui.tracecontrol.wizards;
14
15 import java.util.Iterator;
16 import java.util.concurrent.TimeUnit;
17
18 import org.eclipse.jface.viewers.IStructuredSelection;
19 import org.eclipse.jface.wizard.Wizard;
20 import org.eclipse.linuxtools.internal.lttng.core.tracecontrol.model.TraceResource;
21 import org.eclipse.linuxtools.internal.lttng.core.tracecontrol.model.config.TraceChannel;
22 import org.eclipse.linuxtools.internal.lttng.core.tracecontrol.model.config.TraceChannels;
23 import org.eclipse.linuxtools.internal.lttng.core.tracecontrol.model.config.TraceConfig;
24 import org.eclipse.linuxtools.internal.lttng.core.tracecontrol.service.ILttControllerService;
25 import org.eclipse.linuxtools.internal.lttng.ui.Activator;
26 import org.eclipse.linuxtools.internal.lttng.ui.tracecontrol.TraceControlConstants;
27 import org.eclipse.linuxtools.internal.lttng.ui.tracecontrol.subsystems.TraceSubSystem;
28 import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
29 import org.eclipse.rse.ui.SystemBasePlugin;
30 import org.eclipse.tcf.protocol.IToken;
31 import org.eclipse.tcf.util.TCFTask;
32 import org.eclipse.ui.INewWizard;
33 import org.eclipse.ui.IWorkbench;
34
35 /**
36 * <b><u>ConfigureTraceWizard</u></b>
37 * <p>
38 * Wizard implementation to configure a trace.
39 * </p>
40 */
41 public class ConfigureTraceWizard extends Wizard implements INewWizard {
42
43 // ------------------------------------------------------------------------
44 // Attributes
45 // ------------------------------------------------------------------------
46
47 ITraceChannelConfigurationPage channelConfigPage;
48 TraceConfigurationPage traceConfigPage;
49
50 private TraceResource fSelectedTrace = null;
51
52 // ------------------------------------------------------------------------
53 // Constructors
54 // ------------------------------------------------------------------------
55
56 public ConfigureTraceWizard() {
57 super();
58 }
59
60 // ------------------------------------------------------------------------
61 // Operations
62 // ------------------------------------------------------------------------
63
64 /*
65 * (non-Javadoc)
66 * @see org.eclipse.jface.wizard.Wizard#performFinish()
67 */
68 @Override
69 public boolean performFinish() {
70 return true;
71 }
72
73 /*
74 * (non-Javadoc)
75 * @see org.eclipse.jface.wizard.Wizard#addPages()
76 */
77 @Override
78 public void addPages() {
79 traceConfigPage = new TraceConfigurationPage(this);
80 addPage(traceConfigPage);
81
82 if (fSelectedTrace.isUst()) {
83 // User space trace
84 TraceChannels channels = null;
85 if ((fSelectedTrace.getTraceConfig()) != null && fSelectedTrace.getTraceConfig().getTraceChannels() != null) {
86 channels = fSelectedTrace.getTraceConfig().getTraceChannels().clone();
87 }
88 else {
89 channels = new TraceChannels();
90 channels.put(TraceChannel.UST_TRACE_CHANNEL_NAME, new TraceChannel(TraceChannel.UST_TRACE_CHANNEL_NAME));
91 }
92 channelConfigPage = new UstTraceChannelConfigurationPage(channels);
93 addPage(channelConfigPage);
94 } else {
95 // Kernel trace
96 TraceChannels channels = null;
97 if ((fSelectedTrace.getTraceConfig()) != null && (fSelectedTrace.getTraceConfig().getTraceChannels() != null)) {
98 channels = fSelectedTrace.getTraceConfig().getTraceChannels().clone();
99 }
100 else {
101 String[] channelNames = new String[0];
102 try {
103 final ILttControllerService service = ((TraceSubSystem)fSelectedTrace.getSubSystem()).getControllerService();
104 channelNames = new TCFTask<String[]>() {
105 @Override
106 public void run() {
107 // Get targets using Lttng controller service proxy
108 service.getChannels(fSelectedTrace.getParent().getParent().getName(), fSelectedTrace.getParent().getName(), fSelectedTrace.getName(), new ILttControllerService.DoneGetChannels() {
109
110 @Override
111 public void doneGetChannels(IToken token, Exception error, String[] str) {
112 if (error != null) {
113 // Notify with error
114 error(error);
115 return;
116 }
117 // Notify with active trace list
118 done(str);
119 }
120 });
121 }}.get(TraceControlConstants.DEFAULT_TCF_TASK_TIMEOUT, TimeUnit.SECONDS);
122 } catch (Exception e) {
123 if (e instanceof SystemMessageException) {
124 SystemBasePlugin.logError("Trace Configuration", e); //$NON-NLS-1$;
125 }
126 else {
127 SystemBasePlugin.logError("TraceSubSystem", new SystemMessageException(Activator.getDefault().getMessage(e))); //$NON-NLS-1$
128 }
129 }
130
131 channels = new TraceChannels();
132 channels.putAll(channelNames);
133 }
134
135 channelConfigPage = new KernelTraceChannelConfigurationPage(channels, fSelectedTrace.getTraceState());
136 addPage(channelConfigPage);
137 }
138
139 getShell().setImage(Activator.getDefault().getImage(Activator.ICON_ID_CONFIG_TRACE));
140 }
141
142 /*
143 * (non-Javadoc)
144 * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
145 */
146 @Override
147 @SuppressWarnings("unchecked")
148 public void init(IWorkbench workbench, IStructuredSelection selection) {
149
150 fSelectedTrace = null;
151
152 // store the selected targets to be used when running
153 Iterator<IStructuredSelection> theSet = selection.iterator();
154 while (theSet.hasNext()) {
155 Object obj = theSet.next();
156 if (obj instanceof TraceResource) {
157 fSelectedTrace = (TraceResource)obj;
158 break; // only one is allowed
159 }
160 }
161 }
162
163 /**
164 * Gets the relevant selected trace that will be configured.
165 *
166 * @return selected trace.
167 */
168 public TraceResource getSelectedTrace() {
169 return fSelectedTrace;
170 }
171
172 /**
173 * Gets the new trace configuration of the trace.
174 *
175 * @return trace configuration
176 */
177 public TraceConfig getTraceConfig() {
178 TraceConfig config = traceConfigPage.getTraceConfig();
179 config.setTraceChannels(channelConfigPage.getTraceChannels());
180 return config;
181 }
182 }
This page took 0.03639 seconds and 5 git commands to generate.