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
.ui
.Activator
;
25 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.Messages
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.dialogs
.ICreateChannelDialog
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.dialogs
.TraceControlDialogFactory
;
28 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.IChannelInfo
;
29 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TraceDomainComponent
;
32 * <b><u>BaseCreateChannelHandler</u></b>
34 * Base implementation of aCommand handler implementation to create a trace channel.
37 abstract class BaseCreateChannelHandler
extends BaseControlViewHandler
{
39 // ------------------------------------------------------------------------
41 // ------------------------------------------------------------------------
42 protected CommandParameter fParam
;
44 // ------------------------------------------------------------------------
46 // ------------------------------------------------------------------------
48 * Enables channels with given names which are part of this domain. If a given channel
49 * doesn't exists it creates a new channel with the given parameters (or default values
50 * if given parameter is null).
51 * @param - a parameter instance with data for the command execution
52 * @param channelNames - a list of channel names to enable on this domain
53 * @param info - channel information to set for the channel (use null for default)
54 * @param isKernel - a flag for indicating kernel or UST.
55 * @param monitor - a progress monitor
56 * @throws ExecutionException
58 abstract public void enableChannel(CommandParameter param
, List
<String
> channelNames
, IChannelInfo info
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
;
61 * @param - a parameter instance with data for the command execution
62 * @return returns the relevant domain (null if domain is not known)
64 abstract public TraceDomainComponent
getDomain(CommandParameter param
);
68 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
71 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
74 final CommandParameter param
= fParam
.clone();
76 final ICreateChannelDialog dialog
= TraceControlDialogFactory
.getInstance().getCreateChannelDialog();
77 dialog
.setDomainComponent(getDomain(param
));
79 if (dialog
.open() != Window
.OK
) {
83 Job job
= new Job(Messages
.TraceControl_ChangeChannelStateJob
) {
85 protected IStatus
run(IProgressMonitor monitor
) {
86 StringBuffer errorString
= new StringBuffer();
88 List
<String
> channelNames
= new ArrayList
<String
>();
89 channelNames
.add(dialog
.getChannelInfo().getName());
92 enableChannel(param
, channelNames
, dialog
.getChannelInfo(), dialog
.isKernel(), monitor
);
93 } catch (ExecutionException e
) {
94 errorString
.append(e
.toString());
95 errorString
.append("\n"); //$NON-NLS-1$
98 // get session configuration in all cases
100 param
.getSession().getConfigurationFromNode(monitor
);
101 } catch (ExecutionException e
) {
102 errorString
.append(Messages
.TraceControl_ListSessionFailure
);
103 errorString
.append(": "); //$NON-NLS-1$
104 errorString
.append(e
.toString());
107 if (errorString
.length() > 0) {
108 return new Status(Status
.ERROR
, Activator
.PLUGIN_ID
, errorString
.toString());
110 return Status
.OK_STATUS
;