1 /**********************************************************************
2 * Copyright (c) 2015 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
.tracecompass
.internal
.lttng2
.control
.ui
.views
.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
.Status
;
23 import org
.eclipse
.core
.runtime
.jobs
.Job
;
24 import org
.eclipse
.jface
.viewers
.ISelection
;
25 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
26 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TraceSessionState
;
27 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.Activator
;
28 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.ControlView
;
29 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.messages
.Messages
;
30 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceSessionComponent
;
31 import org
.eclipse
.ui
.IWorkbenchPage
;
32 import org
.eclipse
.ui
.IWorkbenchWindow
;
33 import org
.eclipse
.ui
.PlatformUI
;
37 * Command handler for saving sessions
38 * @author Bernd Hufmann
41 public class SaveHandler
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
{
58 IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
67 final List
<TraceSessionComponent
> sessions
= new ArrayList
<>();
68 sessions
.addAll(fSessions
);
70 Job job
= new Job(Messages
.TraceControl_SaveJob
) {
72 protected IStatus
run(IProgressMonitor monitor
) {
74 for (TraceSessionComponent session
: sessions
) {
75 session
.saveSession(null, null, true, monitor
);
77 } catch (ExecutionException e
) {
78 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.TraceControl_SaveFailure
, e
);
80 return Status
.OK_STATUS
;
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 or more session are 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 TraceSessionComponents that are inactive and not destroyed
109 TraceSessionComponent session
= (TraceSessionComponent
) element
;
110 if ((session
.getSessionState() == TraceSessionState
.INACTIVE
) && (!session
.isDestroyed())) {
111 sessions
.add(session
);
116 boolean isEnabled
= !sessions
.isEmpty();
121 fSessions
= sessions
;