1dbb47c133f53b93715081b94692731f97d16f3b
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui / src / org / eclipse / linuxtools / internal / lttng2 / ui / views / control / handlers / AddContextOnEventHandler.java
1 /**********************************************************************
2 * Copyright (c) 2012, 2013 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.core.control.model.TraceSessionState;
22 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.ControlView;
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;
26
27 /**
28 * <p>
29 * Command handler implementation to add contexts to a given event.
30 * </p>
31 *
32 * @author Bernd Hufmann
33 */
34 public class AddContextOnEventHandler extends BaseAddContextHandler {
35
36 // ------------------------------------------------------------------------
37 // Attributes
38 // ------------------------------------------------------------------------
39
40 // ------------------------------------------------------------------------
41 // Operations
42 // ------------------------------------------------------------------------
43
44 @Override
45 public void addContexts(CommandParameter param, List<String> contextNames, IProgressMonitor monitor) throws ExecutionException {
46 if (param instanceof EventCommandParameter) {
47 TraceEventComponent event = ((EventCommandParameter)param).getEvent();
48 event.addContexts(contextNames, monitor);
49 }
50 }
51
52 @Override
53 public boolean isEnabled() {
54 // Get workbench page for the Control View
55 IWorkbenchPage page = getWorkbenchPage();
56 if (page == null) {
57 return false;
58 }
59
60 TraceEventComponent event = null;
61 TraceSessionComponent session = null;
62 ISelection selection = page.getSelection(ControlView.ID);
63 if (selection instanceof StructuredSelection) {
64 StructuredSelection structered = ((StructuredSelection) selection);
65 for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) {
66 Object element = iterator.next();
67 if (element instanceof TraceEventComponent) {
68 // Add only if corresponding TraceSessionComponents is inactive and not destroyed
69 TraceEventComponent tmpEvent = (TraceEventComponent) element;
70 session = tmpEvent.getSession();
71 if(session.getSessionState() == TraceSessionState.INACTIVE && !session.isDestroyed()) {
72 event = tmpEvent;
73 }
74 }
75 }
76 }
77
78 boolean isEnabled = (event != null);
79 fLock.lock();
80 try {
81 fParam = null;
82 if(isEnabled) {
83 fParam = new EventCommandParameter(session, event);
84 }
85 } finally {
86 fLock.unlock();
87 }
88 return isEnabled;
89 }
90 }
This page took 0.032373 seconds and 4 git commands to generate.