Update internal packages export in LTTng 2.0 control + update java doc
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui / src / org / eclipse / linuxtools / internal / lttng2 / ui / views / control / handlers / BaseEnableChannelHandler.java
CommitLineData
c56972bb
BH
1/**********************************************************************
2 * Copyright (c) 2012 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 **********************************************************************/
12package org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers;
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;
9315aeee 24import org.eclipse.linuxtools.internal.lttng2.core.control.model.IChannelInfo;
c56972bb 25import org.eclipse.linuxtools.internal.lttng2.ui.Activator;
d62bfa55 26import org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableChannelDialog;
c56972bb 27import org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.TraceControlDialogFactory;
9315aeee 28import org.eclipse.linuxtools.internal.lttng2.ui.views.control.messages.Messages;
c56972bb
BH
29import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceDomainComponent;
30
31/**
c56972bb 32 * <p>
d62bfa55 33 * Base implementation of a command handler to enable a trace channel.
c56972bb 34 * </p>
dbd4432d
BH
35 *
36 * @author Bernd Hufmann
c56972bb 37 */
d62bfa55 38abstract class BaseEnableChannelHandler extends BaseControlViewHandler {
c56972bb
BH
39
40 // ------------------------------------------------------------------------
41 // Attributes
42 // ------------------------------------------------------------------------
43 protected CommandParameter fParam;
44
45 // ------------------------------------------------------------------------
46 // Operations
47 // ------------------------------------------------------------------------
48 /**
49 * Enables channels with given names which are part of this domain. If a given channel
50 * doesn't exists it creates a new channel with the given parameters (or default values
51 * if given parameter is null).
52 * @param - a parameter instance with data for the command execution
53 * @param channelNames - a list of channel names to enable on this domain
54 * @param info - channel information to set for the channel (use null for default)
55 * @param isKernel - a flag for indicating kernel or UST.
56 * @param monitor - a progress monitor
57 * @throws ExecutionException
58 */
59 abstract public void enableChannel(CommandParameter param, List<String> channelNames, IChannelInfo info, boolean isKernel, IProgressMonitor monitor) throws ExecutionException;
60
61 /**
62 * @param - a parameter instance with data for the command execution
63 * @return returns the relevant domain (null if domain is not known)
64 */
65 abstract public TraceDomainComponent getDomain(CommandParameter param);
66
67 /*
68 * (non-Javadoc)
69 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
70 */
71 @Override
72 public Object execute(ExecutionEvent event) throws ExecutionException {
73 fLock.lock();
74 try {
75 final CommandParameter param = fParam.clone();
76
d62bfa55 77 final IEnableChannelDialog dialog = TraceControlDialogFactory.getInstance().getEnableChannelDialog();
c56972bb
BH
78 dialog.setDomainComponent(getDomain(param));
79
80 if (dialog.open() != Window.OK) {
81 return null;
82 }
83
f455db37 84 Job job = new Job(Messages.TraceControl_CreateChannelStateJob) {
c56972bb
BH
85 @Override
86 protected IStatus run(IProgressMonitor monitor) {
f455db37 87 Exception error = null;
c56972bb
BH
88
89 List<String> channelNames = new ArrayList<String>();
90 channelNames.add(dialog.getChannelInfo().getName());
91
92 try {
93 enableChannel(param, channelNames, dialog.getChannelInfo(), dialog.isKernel(), monitor);
94 } catch (ExecutionException e) {
f455db37 95 error = e;
c56972bb
BH
96 }
97
f455db37
BH
98 // refresh in all cases
99 refresh(param);
c56972bb 100
f455db37
BH
101 if (error != null) {
102 return new Status(Status.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_CreateChannelStateFailure, error);
c56972bb
BH
103 }
104 return Status.OK_STATUS;
105 }
106 };
107 job.setUser(true);
108 job.schedule();
109 } finally {
110 fLock.unlock();
111 }
112 return null;
113 }
114
115}
This page took 0.033039 seconds and 5 git commands to generate.