1 /*******************************************************************************
2 * Copyright (c) 2011 Ericsson
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 * Bernd Hufmann - Initial API and implementation
12 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.internal
.lttng
.ui
.tracecontrol
.wizards
;
15 import java
.util
.Iterator
;
16 import java
.util
.concurrent
.TimeUnit
;
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
.tm
.tcf
.protocol
.IToken
;
31 import org
.eclipse
.tm
.tcf
.util
.TCFTask
;
32 import org
.eclipse
.ui
.INewWizard
;
33 import org
.eclipse
.ui
.IWorkbench
;
36 * <b><u>ConfigureTraceWizard</u></b>
38 * Wizard implementation to configure a trace.
41 public class ConfigureTraceWizard
extends Wizard
implements INewWizard
{
43 // ------------------------------------------------------------------------
45 // ------------------------------------------------------------------------
47 ITraceChannelConfigurationPage channelConfigPage
;
48 TraceConfigurationPage traceConfigPage
;
50 private TraceResource fSelectedTrace
= null;
52 // ------------------------------------------------------------------------
54 // ------------------------------------------------------------------------
56 public ConfigureTraceWizard() {
60 // ------------------------------------------------------------------------
62 // ------------------------------------------------------------------------
66 * @see org.eclipse.jface.wizard.Wizard#performFinish()
69 public boolean performFinish() {
75 * @see org.eclipse.jface.wizard.Wizard#addPages()
78 public void addPages() {
79 traceConfigPage
= new TraceConfigurationPage(this);
80 addPage(traceConfigPage
);
82 if (fSelectedTrace
.isUst()) {
84 TraceChannels channels
= null;
85 if ((fSelectedTrace
.getTraceConfig()) != null && fSelectedTrace
.getTraceConfig().getTraceChannels() != null) {
86 channels
= fSelectedTrace
.getTraceConfig().getTraceChannels().clone();
89 channels
= new TraceChannels();
90 channels
.put(TraceChannel
.UST_TRACE_CHANNEL_NAME
, new TraceChannel(TraceChannel
.UST_TRACE_CHANNEL_NAME
));
92 channelConfigPage
= new UstTraceChannelConfigurationPage(channels
);
93 addPage(channelConfigPage
);
96 TraceChannels channels
= null;
97 if ((fSelectedTrace
.getTraceConfig()) != null && (fSelectedTrace
.getTraceConfig().getTraceChannels() != null)) {
98 channels
= fSelectedTrace
.getTraceConfig().getTraceChannels().clone();
101 String
[] channelNames
= new String
[0];
103 final ILttControllerService service
= ((TraceSubSystem
)fSelectedTrace
.getSubSystem()).getControllerService();
104 channelNames
= new TCFTask
<String
[]>() {
107 // Get targets using Lttng controller service proxy
108 service
.getChannels(fSelectedTrace
.getParent().getParent().getName(), fSelectedTrace
.getParent().getName(), fSelectedTrace
.getName(), new ILttControllerService
.DoneGetChannels() {
111 public void doneGetChannels(IToken token
, Exception error
, String
[] str
) {
117 // Notify with active trace list
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$;
127 SystemBasePlugin
.logError("TraceSubSystem", new SystemMessageException(Activator
.getDefault().getMessage(e
))); //$NON-NLS-1$
131 channels
= new TraceChannels();
132 channels
.putAll(channelNames
);
135 channelConfigPage
= new KernelTraceChannelConfigurationPage(channels
, fSelectedTrace
.getTraceState());
136 addPage(channelConfigPage
);
139 getShell().setImage(Activator
.getDefault().getImage(Activator
.ICON_ID_CONFIG_TRACE
));
144 * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
147 @SuppressWarnings("unchecked")
148 public void init(IWorkbench workbench
, IStructuredSelection selection
) {
150 fSelectedTrace
= null;
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
164 * Gets the relevant selected trace that will be configured.
166 * @return selected trace.
168 public TraceResource
getSelectedTrace() {
169 return fSelectedTrace
;
173 * Gets the new trace configuration of the trace.
175 * @return trace configuration
177 public TraceConfig
getTraceConfig() {
178 TraceConfig config
= traceConfigPage
.getTraceConfig();
179 config
.setTraceChannels(channelConfigPage
.getTraceChannels());