lttng.control: Replacing isKernel with an enum for the domain type
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.control.ui / src / org / eclipse / tracecompass / internal / lttng2 / control / ui / views / handlers / BaseEnableChannelHandler.java
CommitLineData
c56972bb 1/**********************************************************************
68d1057b 2 * Copyright (c) 2012, 2015 Ericsson
cfdb727a 3 *
c56972bb
BH
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
cfdb727a
AM
8 *
9 * Contributors:
c56972bb
BH
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
9bc60be7 12package org.eclipse.tracecompass.internal.lttng2.control.ui.views.handlers;
c56972bb
BH
13
14import java.util.ArrayList;
15import java.util.List;
16
17import org.eclipse.core.commands.ExecutionEvent;
18import org.eclipse.core.commands.ExecutionException;
19import org.eclipse.core.runtime.IProgressMonitor;
20import org.eclipse.core.runtime.IStatus;
21import org.eclipse.core.runtime.Status;
22import org.eclipse.core.runtime.jobs.Job;
23import org.eclipse.jface.window.Window;
1bc37054 24import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceDomainType;
9bc60be7
AM
25import org.eclipse.tracecompass.internal.lttng2.control.core.model.IChannelInfo;
26import org.eclipse.tracecompass.internal.lttng2.control.ui.Activator;
27import org.eclipse.tracecompass.internal.lttng2.control.ui.views.dialogs.IEnableChannelDialog;
28import org.eclipse.tracecompass.internal.lttng2.control.ui.views.dialogs.TraceControlDialogFactory;
29import org.eclipse.tracecompass.internal.lttng2.control.ui.views.messages.Messages;
30import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceDomainComponent;
c56972bb
BH
31
32/**
c56972bb 33 * <p>
cfdb727a 34 * Base implementation of a command handler to enable a trace channel.
c56972bb 35 * </p>
cfdb727a 36 *
dbd4432d 37 * @author Bernd Hufmann
c56972bb 38 */
d62bfa55 39abstract class BaseEnableChannelHandler extends BaseControlViewHandler {
c56972bb
BH
40
41 // ------------------------------------------------------------------------
42 // Attributes
43 // ------------------------------------------------------------------------
44 protected CommandParameter fParam;
45
46 // ------------------------------------------------------------------------
47 // Operations
48 // ------------------------------------------------------------------------
cfdb727a 49
c56972bb 50 /**
cfdb727a
AM
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).
54 *
55 * @param param
56 * - a parameter instance with data for the command execution
57 * @param channelNames
58 * - a list of channel names to enable on this domain
59 * @param info
60 * - channel information to set for the channel (use null for
61 * default)
1bc37054
BR
62 * @param domain
63 * - indicate the domain type ({@link TraceDomainType})
cfdb727a
AM
64 * @param monitor
65 * - a progress monitor
c56972bb 66 * @throws ExecutionException
cfdb727a 67 * If something goes wrong when enabling the channel
c56972bb 68 */
77735e82 69 public abstract void enableChannel(CommandParameter param,
1bc37054 70 List<String> channelNames, IChannelInfo info, TraceDomainType domain,
cfdb727a
AM
71 IProgressMonitor monitor) throws ExecutionException;
72
c56972bb 73 /**
cfdb727a 74 * @param param - a parameter instance with data for the command execution
c56972bb
BH
75 * @return returns the relevant domain (null if domain is not known)
76 */
77735e82 77 public abstract TraceDomainComponent getDomain(CommandParameter param);
c56972bb 78
c56972bb
BH
79 @Override
80 public Object execute(ExecutionEvent event) throws ExecutionException {
68d1057b
BH
81 CommandParameter tmpParam = null;
82
c56972bb
BH
83 fLock.lock();
84 try {
68d1057b
BH
85 tmpParam = fParam;
86 if (tmpParam == null) {
c56972bb
BH
87 return null;
88 }
b8dbc09c 89 tmpParam = tmpParam.clone();
68d1057b
BH
90 } finally {
91 fLock.unlock();
92 }
93 final CommandParameter param = tmpParam;
c56972bb 94
68d1057b
BH
95 final IEnableChannelDialog dialog = TraceControlDialogFactory.getInstance().getEnableChannelDialog();
96 dialog.setTargetNodeComponent(param.getSession().getTargetNode());
97 dialog.setDomainComponent(getDomain(param));
98 dialog.setHasKernel(param.getSession().hasKernelProvider());
c56972bb 99
68d1057b
BH
100 if (dialog.open() != Window.OK) {
101 return null;
102 }
c56972bb 103
68d1057b
BH
104 Job job = new Job(Messages.TraceControl_CreateChannelStateJob) {
105 @Override
106 protected IStatus run(IProgressMonitor monitor) {
107 Exception error = null;
c56972bb 108
68d1057b
BH
109 List<String> channelNames = new ArrayList<>();
110 channelNames.add(dialog.getChannelInfo().getName());
c56972bb 111
68d1057b 112 try {
1bc37054 113 enableChannel(param, channelNames, dialog.getChannelInfo(), dialog.getDomain(), monitor);
68d1057b
BH
114 } catch (ExecutionException e) {
115 error = e;
c56972bb 116 }
68d1057b
BH
117
118 // refresh in all cases
119 refresh(param);
120
121 if (error != null) {
122 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_CreateChannelStateFailure, error);
123 }
124 return Status.OK_STATUS;
125 }
126 };
127 job.setUser(true);
128 job.schedule();
129
c56972bb
BH
130 return null;
131 }
132
133}
This page took 0.090838 seconds and 5 git commands to generate.