Fix Findbugs warnings
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui / src / org / eclipse / linuxtools / internal / lttng2 / ui / views / control / handlers / BaseCreateChannelHandler.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;
24import org.eclipse.linuxtools.internal.lttng2.ui.Activator;
25import org.eclipse.linuxtools.internal.lttng2.ui.views.control.Messages;
26import org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateChannelDialog;
27import org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.TraceControlDialogFactory;
28import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo;
29import 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 */
37abstract 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
83 Job job = new Job(Messages.TraceControl_ChangeChannelStateJob) {
84 @Override
85 protected IStatus run(IProgressMonitor monitor) {
86 StringBuffer errorString = new StringBuffer();
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 errorString.append(e.toString());
95 errorString.append("\n"); //$NON-NLS-1$
96 }
97
98 // get session configuration in all cases
99 try {
100 param.getSession().getConfigurationFromNode(monitor);
101 } catch (ExecutionException e) {
102 errorString.append(Messages.TraceControl_ListSessionFailure);
103 errorString.append(": "); //$NON-NLS-1$
104 errorString.append(e.toString());
105 }
106
107 if (errorString.length() > 0) {
108 return new Status(Status.ERROR, Activator.PLUGIN_ID, errorString.toString());
109 }
110 return Status.OK_STATUS;
111 }
112 };
113 job.setUser(true);
114 job.schedule();
115 } finally {
116 fLock.unlock();
117 }
118 return null;
119 }
120
121}
This page took 0.035141 seconds and 5 git commands to generate.