Add further support for enabling kernel events
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / ui / views / control / handlers / CreateChannelOnDomainHandler.java
CommitLineData
bbb3538a
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.lttng.ui.views.control.handlers;
13
14import java.util.ArrayList;
15import java.util.Iterator;
16import java.util.List;
17
bbb3538a
BH
18import org.eclipse.core.commands.ExecutionEvent;
19import org.eclipse.core.commands.ExecutionException;
20import org.eclipse.core.runtime.IProgressMonitor;
21import org.eclipse.core.runtime.IStatus;
22import org.eclipse.core.runtime.Status;
23import org.eclipse.core.runtime.jobs.Job;
24import org.eclipse.jface.viewers.ISelection;
25import org.eclipse.jface.viewers.StructuredSelection;
26import org.eclipse.jface.window.Window;
27import org.eclipse.linuxtools.lttng.ui.LTTngUiPlugin;
28import org.eclipse.linuxtools.lttng.ui.views.control.ControlView;
29import org.eclipse.linuxtools.lttng.ui.views.control.Messages;
30import org.eclipse.linuxtools.lttng.ui.views.control.dialogs.CreateChannelDialog;
31import org.eclipse.linuxtools.lttng.ui.views.control.dialogs.ICreateChannelDialog;
32import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceSessionState;
33import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceDomainComponent;
34import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceSessionComponent;
35import org.eclipse.ui.IWorkbenchPage;
bbb3538a
BH
36import org.eclipse.ui.IWorkbenchWindow;
37import org.eclipse.ui.PlatformUI;
38
39/**
40 * <b><u>CreateChannelOnDomainHandler</u></b>
41 * <p>
42 * Command handler implementation to create a trace channel for known domain.
43 * </p>
44 */
498704b3 45public class CreateChannelOnDomainHandler extends BaseControlViewHandler {
bbb3538a
BH
46
47 // ------------------------------------------------------------------------
48 // Attributes
49 // ------------------------------------------------------------------------
50 /**
51 * The the domain component the command is to be executed on.
52 */
53 private TraceDomainComponent fDomain;
54
55 // ------------------------------------------------------------------------
56 // Operations
57 // ------------------------------------------------------------------------
58 /*
59 * (non-Javadoc)
60 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
61 */
62 @Override
63 public Object execute(ExecutionEvent event) throws ExecutionException {
64
65 final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
66
67 if (window == null) {
68 return false;
69 }
70
71 // Get channel information from user
72 final ICreateChannelDialog dialog = new CreateChannelDialog(window.getShell(), fDomain);
73
6503ae0f
BH
74 if (dialog.open() != Window.OK) {
75 return null;
76 }
bbb3538a 77
6503ae0f
BH
78 Job job = new Job(Messages.TraceControl_ChangeChannelStateJob) {
79 @Override
80 protected IStatus run(IProgressMonitor monitor) {
81 String errorString = null;
bbb3538a 82
6503ae0f
BH
83 List<String> channelNames = new ArrayList<String>();
84 channelNames.add(dialog.getChannelInfo().getName());
85
86 try {
87 fDomain.enableChannels(channelNames, dialog.getChannelInfo(), monitor);
88 } catch (ExecutionException e) {
89 if (errorString == null) {
90 errorString = new String();
91 }
92 errorString += e.toString() + "\n"; //$NON-NLS-1$
93 }
94
95 // get session configuration in all cases
96 try {
97 fDomain.getConfigurationFromNode(monitor);
98 } catch (ExecutionException e) {
99 if (errorString == null) {
100 errorString = new String();
bbb3538a 101 }
6503ae0f
BH
102 errorString += Messages.TraceControl_ListSessionFailure + ": " + e.toString(); //$NON-NLS-1$
103 }
104
105 if (errorString != null) {
106 return new Status(Status.ERROR, LTTngUiPlugin.PLUGIN_ID, errorString);
107 }
108 return Status.OK_STATUS;
109 }
110 };
111
112 job.setUser(true);
113 job.schedule();
114
bbb3538a
BH
115 return null;
116 }
117
118 /*
119 * (non-Javadoc)
120 * @see org.eclipse.core.commands.AbstractHandler#isEnabled()
121 */
122 @Override
123 public boolean isEnabled() {
498704b3
BH
124
125 // Get workbench page for the Control View
126 IWorkbenchPage page = getWorkbenchPage();
bbb3538a
BH
127 if (page == null) {
128 return false;
129 }
498704b3 130 fDomain = null;
bbb3538a
BH
131
132 // Check if one domain is selected
133 ISelection selection = page.getSelection(ControlView.ID);
134 if (selection instanceof StructuredSelection) {
135 StructuredSelection structered = ((StructuredSelection) selection);
136 for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) {
137 Object element = (Object) iterator.next();
138 if (element instanceof TraceDomainComponent) {
139 TraceDomainComponent domain = (TraceDomainComponent) element;
140 TraceSessionComponent session = (TraceSessionComponent) domain.getParent();
141 // Add only TraceDomainComponent whose TraceSessionComponent parent is inactive and not destroyed
142 if ((session.getSessionState() == TraceSessionState.INACTIVE) && (!session.isDestroyed())) {
143 fDomain = domain;
144 }
145 }
146 }
147 }
148 return fDomain != null;
149 }
150}
This page took 0.037455 seconds and 5 git commands to generate.