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 / EnableChannelOnDomainHandler.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.Iterator;
15 import java.util.List;
16
17 import org.eclipse.core.commands.ExecutionException;
18 import org.eclipse.core.runtime.IProgressMonitor;
19 import org.eclipse.jface.viewers.ISelection;
20 import org.eclipse.jface.viewers.StructuredSelection;
21 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.ControlView;
22 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo;
23 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceSessionState;
24 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceDomainComponent;
25 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent;
26 import org.eclipse.ui.IWorkbenchPage;
27
28 /**
29 * <b><u>EnableChannelOnDomainHandler</u></b>
30 * <p>
31 * Command handler implementation to enable a trace channel for known domain.
32 * </p>
33 */
34 public class EnableChannelOnDomainHandler extends BaseEnableChannelHandler {
35
36 // ------------------------------------------------------------------------
37 // Attributes
38 // ------------------------------------------------------------------------
39
40 // ------------------------------------------------------------------------
41 // Operations
42 // ------------------------------------------------------------------------
43 /*
44 * (non-Javadoc)
45 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseCreateChannelHandler#enableChannel(org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.CommandParameter, java.util.List, org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo, boolean, org.eclipse.core.runtime.IProgressMonitor)
46 */
47 @Override
48 public void enableChannel(CommandParameter param, List<String> channelNames, IChannelInfo info, boolean isKernel, IProgressMonitor monitor) throws ExecutionException {
49 if (param instanceof DomainCommandParameter) {
50 ((DomainCommandParameter)param).getDomain().enableChannels(channelNames, info, monitor);
51 }
52 }
53
54 /*
55 * (non-Javadoc)
56 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseCreateChannelHandler#getDomain(org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.CommandParameter)
57 */
58 @Override
59 public TraceDomainComponent getDomain(CommandParameter param) {
60 if (param instanceof DomainCommandParameter) {
61 return ((DomainCommandParameter)param).getDomain();
62 }
63 return null;
64 }
65
66 /*
67 * (non-Javadoc)
68 * @see org.eclipse.core.commands.AbstractHandler#isEnabled()
69 */
70 @Override
71 public boolean isEnabled() {
72
73 // Get workbench page for the Control View
74 IWorkbenchPage page = getWorkbenchPage();
75 if (page == null) {
76 return false;
77 }
78
79 TraceDomainComponent domain = null;
80 TraceSessionComponent session = null;
81
82 // Check if one domain is selected
83 ISelection selection = page.getSelection(ControlView.ID);
84 if (selection instanceof StructuredSelection) {
85 StructuredSelection structered = ((StructuredSelection) selection);
86 for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) {
87 Object element = (Object) iterator.next();
88 if (element instanceof TraceDomainComponent) {
89 TraceDomainComponent tmpDomain = (TraceDomainComponent) element;
90 session = (TraceSessionComponent) tmpDomain.getParent();
91
92 // Add only TraceDomainComponent whose TraceSessionComponent parent is inactive and not destroyed
93 if ((session.getSessionState() == TraceSessionState.INACTIVE) && (!session.isDestroyed())) {
94 domain = tmpDomain;
95 }
96 }
97 }
98 }
99
100 boolean isEnabled = domain != null;
101
102 fLock.lock();
103 try {
104 fParam = null;
105 if (isEnabled) {
106 fParam = new DomainCommandParameter(session, domain);
107 }
108 } finally {
109 fLock.unlock();
110 }
111
112 return isEnabled;
113 }
114
115 }
This page took 0.032168 seconds and 5 git commands to generate.