1 /**********************************************************************
2 * Copyright (c) 2012 Ericsson
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
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
12 package org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.handlers
;
14 import java
.util
.Iterator
;
15 import java
.util
.List
;
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
.TraceSessionState
;
23 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TraceEventComponent
;
24 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TraceSessionComponent
;
25 import org
.eclipse
.ui
.IWorkbenchPage
;
28 * <b><u>AddContextOnEventHandler</u></b>
30 * Command handler implementation to add contexts to a given event.
33 public class AddContextOnEventHandler
extends BaseAddContextHandler
{
35 // ------------------------------------------------------------------------
37 // ------------------------------------------------------------------------
39 // ------------------------------------------------------------------------
41 // ------------------------------------------------------------------------
44 * @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)
47 public void addContexts(CommandParameter param
, List
<String
> contextNames
, IProgressMonitor monitor
) throws ExecutionException
{
48 if (param
instanceof EventCommandParameter
) {
49 TraceEventComponent event
= ((EventCommandParameter
)param
).getEvent();
50 event
.addContexts(contextNames
, monitor
);
56 * @see org.eclipse.core.commands.AbstractHandler#isEnabled()
59 public boolean isEnabled() {
60 // Get workbench page for the Control View
61 IWorkbenchPage page
= getWorkbenchPage();
66 TraceEventComponent event
= null;
67 TraceSessionComponent session
= null;
68 ISelection selection
= page
.getSelection(ControlView
.ID
);
69 if (selection
instanceof StructuredSelection
) {
70 StructuredSelection structered
= ((StructuredSelection
) selection
);
71 for (Iterator
<?
> iterator
= structered
.iterator(); iterator
.hasNext();) {
72 Object element
= (Object
) iterator
.next();
73 if (element
instanceof TraceEventComponent
) {
74 // Add only if corresponding TraceSessionComponents is inactive and not destroyed
75 TraceEventComponent tmpEvent
= (TraceEventComponent
) element
;
76 session
= tmpEvent
.getSession();
77 if(session
.getSessionState() == TraceSessionState
.INACTIVE
&& !session
.isDestroyed()) {
84 boolean isEnabled
= (event
!= null);
89 fParam
= new EventCommandParameter(session
, event
);