Commit | Line | Data |
---|---|---|
c56972bb BH |
1 | /********************************************************************** |
2 | * Copyright (c) 2012 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 | **********************************************************************/ | |
12 | package org.eclipse.linuxtools.internal.lttng2.ui.views.control.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; | |
9315aeee | 24 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.IChannelInfo; |
c56972bb | 25 | import org.eclipse.linuxtools.internal.lttng2.ui.Activator; |
d62bfa55 | 26 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableChannelDialog; |
c56972bb | 27 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.TraceControlDialogFactory; |
9315aeee | 28 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.messages.Messages; |
c56972bb BH |
29 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceDomainComponent; |
30 | ||
31 | /** | |
c56972bb | 32 | * <p> |
cfdb727a | 33 | * Base implementation of a command handler to enable a trace channel. |
c56972bb | 34 | * </p> |
cfdb727a | 35 | * |
dbd4432d | 36 | * @author Bernd Hufmann |
c56972bb | 37 | */ |
d62bfa55 | 38 | abstract class BaseEnableChannelHandler extends BaseControlViewHandler { |
c56972bb BH |
39 | |
40 | // ------------------------------------------------------------------------ | |
41 | // Attributes | |
42 | // ------------------------------------------------------------------------ | |
43 | protected CommandParameter fParam; | |
44 | ||
45 | // ------------------------------------------------------------------------ | |
46 | // Operations | |
47 | // ------------------------------------------------------------------------ | |
cfdb727a | 48 | |
c56972bb | 49 | /** |
cfdb727a AM |
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 | |
c56972bb | 65 | * @throws ExecutionException |
cfdb727a | 66 | * If something goes wrong when enabling the channel |
c56972bb | 67 | */ |
cfdb727a AM |
68 | abstract public void enableChannel(CommandParameter param, |
69 | List<String> channelNames, IChannelInfo info, boolean isKernel, | |
70 | IProgressMonitor monitor) throws ExecutionException; | |
71 | ||
c56972bb | 72 | /** |
cfdb727a | 73 | * @param param - a parameter instance with data for the command execution |
c56972bb BH |
74 | * @return returns the relevant domain (null if domain is not known) |
75 | */ | |
76 | abstract public TraceDomainComponent getDomain(CommandParameter param); | |
77 | ||
78 | /* | |
79 | * (non-Javadoc) | |
80 | * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent) | |
81 | */ | |
82 | @Override | |
83 | public Object execute(ExecutionEvent event) throws ExecutionException { | |
84 | fLock.lock(); | |
85 | try { | |
86 | final CommandParameter param = fParam.clone(); | |
87 | ||
d62bfa55 | 88 | final IEnableChannelDialog dialog = TraceControlDialogFactory.getInstance().getEnableChannelDialog(); |
c56972bb BH |
89 | dialog.setDomainComponent(getDomain(param)); |
90 | ||
91 | if (dialog.open() != Window.OK) { | |
92 | return null; | |
93 | } | |
94 | ||
f455db37 | 95 | Job job = new Job(Messages.TraceControl_CreateChannelStateJob) { |
c56972bb BH |
96 | @Override |
97 | protected IStatus run(IProgressMonitor monitor) { | |
f455db37 | 98 | Exception error = null; |
c56972bb | 99 | |
cfdb727a | 100 | List<String> channelNames = new ArrayList<String>(); |
c56972bb BH |
101 | channelNames.add(dialog.getChannelInfo().getName()); |
102 | ||
103 | try { | |
104 | enableChannel(param, channelNames, dialog.getChannelInfo(), dialog.isKernel(), monitor); | |
105 | } catch (ExecutionException e) { | |
f455db37 | 106 | error = e; |
c56972bb BH |
107 | } |
108 | ||
f455db37 BH |
109 | // refresh in all cases |
110 | refresh(param); | |
c56972bb | 111 | |
f455db37 | 112 | if (error != null) { |
cfdb727a | 113 | return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_CreateChannelStateFailure, error); |
c56972bb BH |
114 | } |
115 | return Status.OK_STATUS; | |
116 | } | |
117 | }; | |
118 | job.setUser(true); | |
119 | job.schedule(); | |
120 | } finally { | |
121 | fLock.unlock(); | |
122 | } | |
123 | return null; | |
124 | } | |
125 | ||
126 | } |