1 /**********************************************************************
2 * Copyright (c) 2013 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
.ArrayList
;
15 import java
.util
.Iterator
;
16 import java
.util
.List
;
18 import org
.eclipse
.core
.commands
.ExecutionEvent
;
19 import org
.eclipse
.core
.commands
.ExecutionException
;
20 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
21 import org
.eclipse
.core
.runtime
.IStatus
;
22 import org
.eclipse
.core
.runtime
.MultiStatus
;
23 import org
.eclipse
.core
.runtime
.Status
;
24 import org
.eclipse
.core
.runtime
.jobs
.Job
;
25 import org
.eclipse
.jface
.viewers
.ISelection
;
26 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.TraceSessionState
;
28 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.Activator
;
29 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.ControlView
;
30 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.messages
.Messages
;
31 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TraceSessionComponent
;
32 import org
.eclipse
.ui
.IWorkbenchPage
;
36 * Command handler implementation to record a snapshot.
39 * @author Bernd Hufmann
41 public class SnaphshotHandler
extends BaseControlViewHandler
{
43 // ------------------------------------------------------------------------
45 // ------------------------------------------------------------------------
47 * The list of session components the command is to be executed on.
49 protected List
<TraceSessionComponent
> fSessions
= new ArrayList
<>();
51 // ------------------------------------------------------------------------
53 // ------------------------------------------------------------------------
56 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
59 // Make a copy for thread safety
60 final List
<TraceSessionComponent
> sessions
= new ArrayList
<>();
61 sessions
.addAll(fSessions
);
63 Job job
= new Job(Messages
.TraceControl_RecordSnapshotJob
) {
65 protected IStatus
run(IProgressMonitor monitor
) {
66 MultiStatus status
= new MultiStatus(Activator
.PLUGIN_ID
, IStatus
.OK
, null, null);
67 for (Iterator
<TraceSessionComponent
> iterator
= sessions
.iterator(); iterator
.hasNext();) {
69 // record snapshot for all selected sessions sequentially
70 TraceSessionComponent session
= iterator
.next();
71 session
.recordSnapshot(monitor
);
72 if (monitor
.isCanceled()) {
73 status
.add(Status
.CANCEL_STATUS
);
76 } catch (ExecutionException e
) {
77 status
.add(new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.TraceControl_RecordSnapshotFailure
, e
));
92 public boolean isEnabled() {
93 // Get workbench page for the Control View
94 IWorkbenchPage page
= getWorkbenchPage();
99 List
<TraceSessionComponent
> sessions
= new ArrayList
<>(0);
101 // Check if one session is selected
102 ISelection selection
= page
.getSelection(ControlView
.ID
);
103 if (selection
instanceof StructuredSelection
) {
104 StructuredSelection structered
= ((StructuredSelection
) selection
);
105 for (Iterator
<?
> iterator
= structered
.iterator(); iterator
.hasNext();) {
106 Object element
= iterator
.next();
107 if (element
instanceof TraceSessionComponent
) {
108 // Add only if corresponding TraceSessionComponent is an active snapshot session and not destroyed
109 TraceSessionComponent session
= (TraceSessionComponent
) element
;
110 if(session
.isSnapshotSession() &&
111 session
.getSessionState() == TraceSessionState
.ACTIVE
&&
112 !session
.isDestroyed()) {
113 sessions
.add(session
);
118 boolean isEnabled
= !sessions
.isEmpty();
123 fSessions
= sessions
;