1 /**********************************************************************
2 * Copyright (c) 2015 École Polytechnique de Montréal
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 * Patrick-Jeffrey Pollo Guilbert - Added headers, exporting .lttng profiles
11 * William Enright - Added ProfileHandler implementation
12 * William Tri-Khiem Truong - Completed documentation
13 **********************************************************************/
14 package org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.handlers
;
17 import java
.io
.IOException
;
18 import java
.io
.OutputStream
;
19 import java
.nio
.file
.Files
;
20 import java
.util
.ArrayList
;
22 import org
.eclipse
.core
.commands
.ExecutionEvent
;
23 import org
.eclipse
.core
.commands
.ExecutionException
;
24 import org
.eclipse
.core
.commands
.NotEnabledException
;
25 import org
.eclipse
.core
.commands
.NotHandledException
;
26 import org
.eclipse
.core
.commands
.common
.NotDefinedException
;
27 import org
.eclipse
.core
.filesystem
.EFS
;
28 import org
.eclipse
.core
.filesystem
.IFileStore
;
29 import org
.eclipse
.core
.runtime
.CoreException
;
30 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
31 import org
.eclipse
.core
.runtime
.IStatus
;
32 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
33 import org
.eclipse
.core
.runtime
.Path
;
34 import org
.eclipse
.core
.runtime
.Status
;
35 import org
.eclipse
.core
.runtime
.jobs
.Job
;
36 import org
.eclipse
.jface
.viewers
.ISelection
;
37 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
38 import org
.eclipse
.jface
.window
.Window
;
39 import org
.eclipse
.remote
.core
.IRemoteConnectionType
;
40 import org
.eclipse
.remote
.core
.IRemoteFileService
;
41 import org
.eclipse
.swt
.SWT
;
42 import org
.eclipse
.swt
.graphics
.Rectangle
;
43 import org
.eclipse
.swt
.widgets
.Display
;
44 import org
.eclipse
.swt
.widgets
.Shell
;
45 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.Activator
;
46 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.ControlView
;
47 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.dialogs
.ProfileDialog
;
48 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.messages
.Messages
;
49 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TargetNodeComponent
;
50 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceSessionGroup
;
51 import org
.eclipse
.tracecompass
.tmf
.remote
.core
.proxy
.RemoteSystemProxy
;
52 import org
.eclipse
.ui
.IWorkbenchPage
;
53 import org
.eclipse
.ui
.IWorkbenchPart
;
54 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
55 import org
.eclipse
.ui
.handlers
.IHandlerService
;
59 * Profile Handler to select and load session profiles for tracing purposes
62 * @author William Tri-Khiem Truong, William Enright, Patrick-Jeffrey Pollo Guilbert
64 public class ProfileHandler
extends BaseControlViewHandler
{
67 * Id of the parameter for the remote services id.
69 * @see NewConnectionHandler
70 * @see IRemoteConnectionType#getId()
72 public static final String PARAMETER_REMOTE_SERVICES_ID
= "org.eclipse.linuxtools.lttng2.control.ui.remoteServicesIdParameter"; //$NON-NLS-1$
75 * (INewConnectionDialog) wd).getConnection() Id of the parameter for the
76 * name of the remote connection.
78 * @see NewConnectionHandler
79 * @see IRemoteConnectionType#getName()
81 public static final String PARAMETER_CONNECTION_NAME
= "org.eclipse.linuxtools.lttng2.control.ui.connectionNameParameter"; //$NON-NLS-1$
84 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
86 Shell s
= new Shell(SWT
.CENTER
);
88 Rectangle screenSize
= Display
.getCurrent().getPrimaryMonitor().getBounds();
89 s
.setLocation((screenSize
.width
- s
.getBounds().width
) / 2, (screenSize
.height
- s
.getBounds().height
) / 2);
90 s
.setMinimumSize(500, 500);
92 IWorkbenchPage page
= getWorkbenchPage();
97 TargetNodeComponent elementParent
= null;
99 // Check if the session group project is selected
100 ISelection selection
= page
.getSelection(ControlView
.ID
);
101 if (selection
instanceof StructuredSelection
) {
102 Object element
= ((StructuredSelection
) selection
).getFirstElement();
103 final TraceSessionGroup sessionGroup
= (element
instanceof TraceSessionGroup
) ?
(TraceSessionGroup
) element
: null;
104 if (sessionGroup
!= null)
106 if (sessionGroup
.getParent() instanceof TargetNodeComponent
) {
107 elementParent
= (TargetNodeComponent
) sessionGroup
.getParent();
108 final ProfileDialog btd
= new ProfileDialog(s
);
109 if (btd
.open() != Window
.OK
) {
112 final String remotePath
= sessionGroup
.getTargetNode().getRemoteSystemProxy().getRemoteConnection().getProperty("user.home") + "/.lttng/sessions"; //$NON-NLS-1$//$NON-NLS-2$
114 RemoteSystemProxy proxy
= elementParent
.getRemoteSystemProxy();
115 IRemoteFileService fsss
= proxy
.getRemoteConnection().getService(IRemoteFileService
.class);
116 ArrayList
<File
> checkedFiles
= btd
.getCheckedFiles();
118 for (File file
: checkedFiles
) {
119 final IFileStore remoteFolder
= fsss
.getResource(remotePath
);
120 final IFileStore remoteFile
= remoteFolder
.getFileStore(new Path(file
.getName()));
122 try (OutputStream out
= remoteFile
.openOutputStream(EFS
.NONE
, new NullProgressMonitor()))
124 Files
.copy(file
.toPath(), out
);
126 } catch (CoreException e
) {
128 } catch (IOException e
) {
132 Job job
= new Job(Messages
.TraceControl_LoadSessionJob
) {
134 protected IStatus
run(IProgressMonitor monitor
) {
136 sessionGroup
.loadSession(remotePath
+ "/" + remoteFile
.getName(), monitor
); //$NON-NLS-1$
137 } catch (ExecutionException e
) {
138 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.TraceControl_LoadSessionFailure
, e
);
140 return Status
.OK_STATUS
;
152 // Refreshing the sessions in the control view by calling the refresh
155 IWorkbenchPart part
= HandlerUtil
.getActivePartChecked(event
);
157 IHandlerService service
= part
.getSite().getService(IHandlerService
.class);
160 service
.executeCommand("org.eclipse.linuxtools.internal.lttng2.ui.commands.control.refresh", null); //$NON-NLS-1$
161 } catch (NotDefinedException e
) {
163 } catch (NotEnabledException e
) {
165 } catch (NotHandledException e
) {
172 public boolean isEnabled() {
174 // Get workbench page for the Control View
175 IWorkbenchPage page
= getWorkbenchPage();
180 TraceSessionGroup sessionGroup
= null;
182 // Check if the session group project is selected
183 ISelection selection
= page
.getSelection(ControlView
.ID
);
184 if (selection
instanceof StructuredSelection
) {
185 Object element
= ((StructuredSelection
) selection
).getFirstElement();
186 sessionGroup
= (element
instanceof TraceSessionGroup
) ?
(TraceSessionGroup
) element
: null;
189 boolean isEnabled
= sessionGroup
!= null;