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