1 /**********************************************************************
2 * Copyright (c) 2012 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
.linuxtools
.internal
.lttng2
.ui
.views
.control
.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
.linuxtools
.internal
.lttng2
.core
.control
.model
.IChannelInfo
;
25 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.Activator
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.dialogs
.IEnableChannelDialog
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.dialogs
.TraceControlDialogFactory
;
28 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.messages
.Messages
;
29 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TraceDomainComponent
;
33 * Base implementation of a command handler to enable a trace channel.
36 * @author Bernd Hufmann
38 abstract class BaseEnableChannelHandler
extends BaseControlViewHandler
{
40 // ------------------------------------------------------------------------
42 // ------------------------------------------------------------------------
43 protected CommandParameter fParam
;
45 // ------------------------------------------------------------------------
47 // ------------------------------------------------------------------------
50 * Enables channels with given names which are part of this domain. If a
51 * given channel doesn't exists it creates a new channel with the given
52 * parameters (or default values if given parameter is null).
55 * - a parameter instance with data for the command execution
57 * - a list of channel names to enable on this domain
59 * - channel information to set for the channel (use null for
62 * - a flag for indicating kernel or UST.
64 * - a progress monitor
65 * @throws ExecutionException
66 * If something goes wrong when enabling the channel
68 abstract public void enableChannel(CommandParameter param
,
69 List
<String
> channelNames
, IChannelInfo info
, boolean isKernel
,
70 IProgressMonitor monitor
) throws ExecutionException
;
73 * @param param - a parameter instance with data for the command execution
74 * @return returns the relevant domain (null if domain is not known)
76 abstract public TraceDomainComponent
getDomain(CommandParameter param
);
80 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
83 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
86 final CommandParameter param
= fParam
.clone();
88 final IEnableChannelDialog dialog
= TraceControlDialogFactory
.getInstance().getEnableChannelDialog();
89 dialog
.setDomainComponent(getDomain(param
));
90 dialog
.setHasKernel(param
.getSession().hasKernelProvider());
92 if (dialog
.open() != Window
.OK
) {
96 Job job
= new Job(Messages
.TraceControl_CreateChannelStateJob
) {
98 protected IStatus
run(IProgressMonitor monitor
) {
99 Exception error
= null;
101 List
<String
> channelNames
= new ArrayList
<String
>();
102 channelNames
.add(dialog
.getChannelInfo().getName());
105 enableChannel(param
, channelNames
, dialog
.getChannelInfo(), dialog
.isKernel(), monitor
);
106 } catch (ExecutionException e
) {
110 // refresh in all cases
114 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.TraceControl_CreateChannelStateFailure
, error
);
116 return Status
.OK_STATUS
;