Commit | Line | Data |
---|---|---|
b793fbe1 BH |
1 | /********************************************************************** |
2 | * Copyright (c) 2012 Ericsson | |
cfdb727a | 3 | * |
b793fbe1 BH |
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 | |
cfdb727a AM |
8 | * |
9 | * Contributors: | |
b793fbe1 BH |
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; | |
9315aeee | 21 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceSessionState; |
b793fbe1 | 22 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.ControlView; |
b793fbe1 BH |
23 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceDomainComponent; |
24 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent; | |
25 | import org.eclipse.ui.IWorkbenchPage; | |
26 | ||
27 | /** | |
b793fbe1 BH |
28 | * <p> |
29 | * Command handler implementation to add contexts to all channels and all events. | |
30 | * </p> | |
cfdb727a | 31 | * |
dbd4432d | 32 | * @author Bernd Hufmann |
b793fbe1 BH |
33 | */ |
34 | public class AddContextOnDomainHandler extends BaseAddContextHandler { | |
35 | ||
36 | // ------------------------------------------------------------------------ | |
37 | // Attributes | |
38 | // ------------------------------------------------------------------------ | |
cfdb727a | 39 | |
b793fbe1 BH |
40 | // ------------------------------------------------------------------------ |
41 | // Operations | |
42 | // ------------------------------------------------------------------------ | |
43 | /* | |
44 | * (non-Javadoc) | |
45 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseAddContextHandler#addContexts(org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.CommandParameter, java.util.List, org.eclipse.core.runtime.IProgressMonitor) | |
46 | */ | |
47 | @Override | |
48 | public void addContexts(CommandParameter param, List<String> contextNames, IProgressMonitor monitor) throws ExecutionException { | |
49 | if (param instanceof DomainCommandParameter) { | |
50 | TraceDomainComponent domain = ((DomainCommandParameter)param).getDomain(); | |
51 | domain.addContexts(contextNames, monitor); | |
52 | } | |
53 | } | |
54 | ||
55 | /* | |
56 | * (non-Javadoc) | |
57 | * @see org.eclipse.core.commands.AbstractHandler#isEnabled() | |
58 | */ | |
59 | @Override | |
60 | public boolean isEnabled() { | |
cfdb727a | 61 | |
b793fbe1 BH |
62 | // Get workbench page for the Control View |
63 | IWorkbenchPage page = getWorkbenchPage(); | |
64 | if (page == null) { | |
65 | return false; | |
66 | } | |
cfdb727a | 67 | |
b793fbe1 BH |
68 | TraceDomainComponent domain = null; |
69 | TraceSessionComponent session = null; | |
cfdb727a | 70 | |
b793fbe1 BH |
71 | // Check if one domain is selected |
72 | ISelection selection = page.getSelection(ControlView.ID); | |
73 | if (selection instanceof StructuredSelection) { | |
74 | StructuredSelection structered = ((StructuredSelection) selection); | |
75 | for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) { | |
cfdb727a | 76 | Object element = iterator.next(); |
b793fbe1 BH |
77 | if (element instanceof TraceDomainComponent) { |
78 | TraceDomainComponent tmpDomain = (TraceDomainComponent) element; | |
79 | session = (TraceSessionComponent) tmpDomain.getParent(); | |
cfdb727a | 80 | |
b793fbe1 BH |
81 | // Add only TraceDomainComponent whose TraceSessionComponent parent is inactive and not destroyed |
82 | if ((session.getSessionState() == TraceSessionState.INACTIVE) && (!session.isDestroyed())) { | |
83 | domain = tmpDomain; | |
84 | } | |
85 | } | |
86 | } | |
87 | } | |
cfdb727a | 88 | |
b793fbe1 | 89 | boolean isEnabled = domain != null; |
cfdb727a | 90 | |
b793fbe1 BH |
91 | fLock.lock(); |
92 | try { | |
93 | fParam = null; | |
94 | if (isEnabled) { | |
95 | fParam = new DomainCommandParameter(session, domain); | |
96 | } | |
97 | } finally { | |
98 | fLock.unlock(); | |
99 | } | |
100 | ||
101 | return isEnabled; | |
102 | } | |
103 | ||
104 | ||
105 | } |