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
1 /**********************************************************************
2 * Copyright (c) 2012, 2015 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
12 package org.eclipse.tracecompass.internal.lttng2.control.ui.views.handlers;
13
14 import java.util.ArrayList;
15 import java.util.List;
16
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;
31
32 /**
33 * <p>
34 * Base implementation of a command handler to enable a trace channel.
35 * </p>
36 *
37 * @author Bernd Hufmann
38 */
39 abstract class BaseEnableChannelHandler extends BaseControlViewHandler {
40
41 // ------------------------------------------------------------------------
42 // Attributes
43 // ------------------------------------------------------------------------
44 protected CommandParameter fParam;
45
46 // ------------------------------------------------------------------------
47 // Operations
48 // ------------------------------------------------------------------------
49
50 /**
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)
62 * @param domain
63 * - indicate the domain type ({@link TraceDomainType})
64 * @param monitor
65 * - a progress monitor
66 * @throws ExecutionException
67 * If something goes wrong when enabling the channel
68 */
69 public abstract void enableChannel(CommandParameter param,
70 List<String> channelNames, IChannelInfo info, TraceDomainType domain,
71 IProgressMonitor monitor) throws ExecutionException;
72
73 /**
74 * @param param - a parameter instance with data for the command execution
75 * @return returns the relevant domain (null if domain is not known)
76 */
77 public abstract TraceDomainComponent getDomain(CommandParameter param);
78
79 @Override
80 public Object execute(ExecutionEvent event) throws ExecutionException {
81 CommandParameter tmpParam = null;
82
83 fLock.lock();
84 try {
85 tmpParam = fParam;
86 if (tmpParam == null) {
87 return null;
88 }
89 tmpParam = tmpParam.clone();
90 } finally {
91 fLock.unlock();
92 }
93 final CommandParameter param = tmpParam;
94
95 final IEnableChannelDialog dialog = TraceControlDialogFactory.getInstance().getEnableChannelDialog();
96 dialog.setTargetNodeComponent(param.getSession().getTargetNode());
97 dialog.setDomainComponent(getDomain(param));
98 dialog.setHasKernel(param.getSession().hasKernelProvider());
99
100 if (dialog.open() != Window.OK) {
101 return null;
102 }
103
104 Job job = new Job(Messages.TraceControl_CreateChannelStateJob) {
105 @Override
106 protected IStatus run(IProgressMonitor monitor) {
107 Exception error = null;
108
109 List<String> channelNames = new ArrayList<>();
110 channelNames.add(dialog.getChannelInfo().getName());
111
112 try {
113 enableChannel(param, channelNames, dialog.getChannelInfo(), dialog.getDomain(), monitor);
114 } catch (ExecutionException e) {
115 error = e;
116 }
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
130 return null;
131 }
132
133 }
This page took 0.051503 seconds and 6 git commands to generate.