Update enable channel and event dialogs and handlers
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui / src / org / eclipse / linuxtools / internal / lttng2 / ui / views / control / handlers / BaseEnableChannelHandler.java
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.IEnableChannelDialog;
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>BaseEnableChannelHandler</u></b>
33 * <p>
34 * Base implementation of a command handler to enable a trace channel.
35 * </p>
36 */
37 abstract class BaseEnableChannelHandler 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 IEnableChannelDialog dialog = TraceControlDialogFactory.getInstance().getEnableChannelDialog();
77 dialog.setDomainComponent(getDomain(param));
78
79 if (dialog.open() != Window.OK) {
80 return null;
81 }
82
83 Job job = new Job(Messages.TraceControl_CreateChannelStateJob) {
84 @Override
85 protected IStatus run(IProgressMonitor monitor) {
86 Exception error = null;
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) {
94 error = e;
95 }
96
97 // refresh in all cases
98 refresh(param);
99
100 if (error != null) {
101 return new Status(Status.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_CreateChannelStateFailure, error);
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 }
This page took 0.032199 seconds and 5 git commands to generate.