control: partly revert commit 0e7ea8ac and use clone in handlers
[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.IChannelInfo;
25 import org.eclipse.tracecompass.internal.lttng2.control.ui.Activator;
26 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.dialogs.IEnableChannelDialog;
27 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.dialogs.TraceControlDialogFactory;
28 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.messages.Messages;
29 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceDomainComponent;
30
31 /**
32 * <p>
33 * Base implementation of a command handler to enable a trace channel.
34 * </p>
35 *
36 * @author Bernd Hufmann
37 */
38 abstract class BaseEnableChannelHandler extends BaseControlViewHandler {
39
40 // ------------------------------------------------------------------------
41 // Attributes
42 // ------------------------------------------------------------------------
43 protected CommandParameter fParam;
44
45 // ------------------------------------------------------------------------
46 // Operations
47 // ------------------------------------------------------------------------
48
49 /**
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).
53 *
54 * @param param
55 * - a parameter instance with data for the command execution
56 * @param channelNames
57 * - a list of channel names to enable on this domain
58 * @param info
59 * - channel information to set for the channel (use null for
60 * default)
61 * @param isKernel
62 * - a flag for indicating kernel or UST.
63 * @param monitor
64 * - a progress monitor
65 * @throws ExecutionException
66 * If something goes wrong when enabling the channel
67 */
68 public abstract void enableChannel(CommandParameter param,
69 List<String> channelNames, IChannelInfo info, boolean isKernel,
70 IProgressMonitor monitor) throws ExecutionException;
71
72 /**
73 * @param param - a parameter instance with data for the command execution
74 * @return returns the relevant domain (null if domain is not known)
75 */
76 public abstract TraceDomainComponent getDomain(CommandParameter param);
77
78 @Override
79 public Object execute(ExecutionEvent event) throws ExecutionException {
80 CommandParameter tmpParam = null;
81
82 fLock.lock();
83 try {
84 tmpParam = fParam;
85 if (tmpParam == null) {
86 return null;
87 }
88 tmpParam = tmpParam.clone();
89 } finally {
90 fLock.unlock();
91 }
92 final CommandParameter param = tmpParam;
93
94 final IEnableChannelDialog dialog = TraceControlDialogFactory.getInstance().getEnableChannelDialog();
95 dialog.setTargetNodeComponent(param.getSession().getTargetNode());
96 dialog.setDomainComponent(getDomain(param));
97 dialog.setHasKernel(param.getSession().hasKernelProvider());
98
99 if (dialog.open() != Window.OK) {
100 return null;
101 }
102
103 Job job = new Job(Messages.TraceControl_CreateChannelStateJob) {
104 @Override
105 protected IStatus run(IProgressMonitor monitor) {
106 Exception error = null;
107
108 List<String> channelNames = new ArrayList<>();
109 channelNames.add(dialog.getChannelInfo().getName());
110
111 try {
112 enableChannel(param, channelNames, dialog.getChannelInfo(), dialog.isKernel(), monitor);
113 } catch (ExecutionException e) {
114 error = e;
115 }
116
117 // refresh in all cases
118 refresh(param);
119
120 if (error != null) {
121 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_CreateChannelStateFailure, error);
122 }
123 return Status.OK_STATUS;
124 }
125 };
126 job.setUser(true);
127 job.schedule();
128
129 return null;
130 }
131
132 }
This page took 0.033676 seconds and 5 git commands to generate.