1 /**********************************************************************
2 * Copyright (c) 2012, 2015 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
11 **********************************************************************/
12 package org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.handlers
;
14 import java
.util
.ArrayList
;
15 import java
.util
.List
;
17 import org
.eclipse
.core
.commands
.ExecutionEvent
;
18 import org
.eclipse
.core
.commands
.ExecutionException
;
19 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
20 import org
.eclipse
.core
.runtime
.IStatus
;
21 import org
.eclipse
.core
.runtime
.Status
;
22 import org
.eclipse
.core
.runtime
.jobs
.Job
;
23 import org
.eclipse
.jface
.window
.Window
;
24 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TraceDomainType
;
25 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.IChannelInfo
;
26 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.Activator
;
27 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.dialogs
.IEnableChannelDialog
;
28 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.dialogs
.TraceControlDialogFactory
;
29 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.messages
.Messages
;
30 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceDomainComponent
;
34 * Base implementation of a command handler to enable a trace channel.
37 * @author Bernd Hufmann
39 abstract class BaseEnableChannelHandler
extends BaseControlViewHandler
{
41 // ------------------------------------------------------------------------
43 // ------------------------------------------------------------------------
44 protected CommandParameter fParam
;
46 // ------------------------------------------------------------------------
48 // ------------------------------------------------------------------------
51 * Enables channels with given names which are part of this domain. If a
52 * given channel doesn't exists it creates a new channel with the given
53 * parameters (or default values if given parameter is null).
56 * - a parameter instance with data for the command execution
58 * - a list of channel names to enable on this domain
60 * - channel information to set for the channel (use null for
63 * - indicate the domain type ({@link TraceDomainType})
65 * - a progress monitor
66 * @throws ExecutionException
67 * If something goes wrong when enabling the channel
69 public abstract void enableChannel(CommandParameter param
,
70 List
<String
> channelNames
, IChannelInfo info
, TraceDomainType domain
,
71 IProgressMonitor monitor
) throws ExecutionException
;
74 * @param param - a parameter instance with data for the command execution
75 * @return returns the relevant domain (null if domain is not known)
77 public abstract TraceDomainComponent
getDomain(CommandParameter param
);
80 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
81 CommandParameter tmpParam
= null;
86 if (tmpParam
== null) {
89 tmpParam
= tmpParam
.clone();
93 final CommandParameter param
= tmpParam
;
95 final IEnableChannelDialog dialog
= TraceControlDialogFactory
.getInstance().getEnableChannelDialog();
96 dialog
.setTargetNodeComponent(param
.getSession().getTargetNode());
97 dialog
.setDomainComponent(getDomain(param
));
98 dialog
.setHasKernel(param
.getSession().hasKernelProvider());
100 if (dialog
.open() != Window
.OK
) {
104 Job job
= new Job(Messages
.TraceControl_CreateChannelStateJob
) {
106 protected IStatus
run(IProgressMonitor monitor
) {
107 Exception error
= null;
109 List
<String
> channelNames
= new ArrayList
<>();
110 channelNames
.add(dialog
.getChannelInfo().getName());
113 enableChannel(param
, channelNames
, dialog
.getChannelInfo(), dialog
.getDomain(), monitor
);
114 } catch (ExecutionException e
) {
118 // refresh in all cases
122 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.TraceControl_CreateChannelStateFailure
, error
);
124 return Status
.OK_STATUS
;