Commit | Line | Data |
---|---|---|
bbb3538a | 1 | /********************************************************************** |
ba3a9bd2 | 2 | * Copyright (c) 2012, 2013 Ericsson |
cfdb727a | 3 | * |
bbb3538a BH |
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 | |
cfdb727a AM |
8 | * |
9 | * Contributors: | |
bbb3538a | 10 | * Bernd Hufmann - Initial API and implementation |
ba3a9bd2 | 11 | * Bernd Hufmann - Updated for support of LTTng Tools 2.1 |
bbb3538a | 12 | **********************************************************************/ |
8e8c0226 | 13 | package org.eclipse.linuxtools.internal.lttng2.control.ui.views.handlers; |
bbb3538a | 14 | |
bbb3538a BH |
15 | import org.eclipse.core.commands.ExecutionEvent; |
16 | import org.eclipse.core.commands.ExecutionException; | |
17 | import org.eclipse.core.runtime.IProgressMonitor; | |
18 | import org.eclipse.core.runtime.IStatus; | |
19 | import org.eclipse.core.runtime.Status; | |
20 | import org.eclipse.core.runtime.jobs.Job; | |
21 | import org.eclipse.jface.viewers.ISelection; | |
22 | import org.eclipse.jface.viewers.StructuredSelection; | |
23 | import org.eclipse.jface.window.Window; | |
8e8c0226 AM |
24 | import org.eclipse.linuxtools.internal.lttng2.control.ui.Activator; |
25 | import org.eclipse.linuxtools.internal.lttng2.control.ui.views.ControlView; | |
26 | import org.eclipse.linuxtools.internal.lttng2.control.ui.views.dialogs.ICreateSessionDialog; | |
27 | import org.eclipse.linuxtools.internal.lttng2.control.ui.views.dialogs.TraceControlDialogFactory; | |
28 | import org.eclipse.linuxtools.internal.lttng2.control.ui.views.messages.Messages; | |
29 | import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TraceSessionGroup; | |
bbb3538a | 30 | import org.eclipse.ui.IWorkbenchPage; |
bbb3538a BH |
31 | |
32 | /** | |
bbb3538a BH |
33 | * <p> |
34 | * Command handler implementation to create a trace session. | |
35 | * </p> | |
cfdb727a | 36 | * |
dbd4432d | 37 | * @author Bernd Hufmann |
bbb3538a | 38 | */ |
498704b3 | 39 | public class CreateSessionHandler extends BaseControlViewHandler { |
bbb3538a BH |
40 | |
41 | // ------------------------------------------------------------------------ | |
42 | // Attributes | |
43 | // ------------------------------------------------------------------------ | |
11252342 | 44 | |
bbb3538a | 45 | /** |
cfdb727a | 46 | * The trace session group the command is to be executed on. |
bbb3538a BH |
47 | */ |
48 | private TraceSessionGroup fSessionGroup = null; | |
cfdb727a | 49 | |
bbb3538a BH |
50 | // ------------------------------------------------------------------------ |
51 | // Operations | |
52 | // ------------------------------------------------------------------------ | |
11252342 | 53 | |
bbb3538a BH |
54 | @Override |
55 | public Object execute(ExecutionEvent event) throws ExecutionException { | |
bbb3538a | 56 | |
c56972bb BH |
57 | fLock.lock(); |
58 | try { | |
cfdb727a AM |
59 | final TraceSessionGroup sessionGroup = fSessionGroup; |
60 | ||
c56972bb | 61 | // Open dialog box for the node name and address |
f3b33d40 BH |
62 | final ICreateSessionDialog dialog = TraceControlDialogFactory.getInstance().getCreateSessionDialog(); |
63 | dialog.initialize(sessionGroup); | |
bbb3538a | 64 | |
c56972bb BH |
65 | if (dialog.open() != Window.OK) { |
66 | return null; | |
67 | } | |
6503ae0f | 68 | |
c56972bb BH |
69 | Job job = new Job(Messages.TraceControl_CreateSessionJob) { |
70 | @Override | |
71 | protected IStatus run(IProgressMonitor monitor) { | |
72 | try { | |
f7d4d450 | 73 | sessionGroup.createSession(dialog.getParameters(), monitor); |
c56972bb | 74 | } catch (ExecutionException e) { |
cfdb727a AM |
75 | return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_CreateSessionFailure, e); |
76 | } | |
c56972bb BH |
77 | return Status.OK_STATUS; |
78 | } | |
79 | }; | |
80 | job.setUser(true); | |
81 | job.schedule(); | |
82 | } finally { | |
83 | fLock.unlock(); | |
84 | } | |
bbb3538a BH |
85 | return null; |
86 | } | |
87 | ||
bbb3538a BH |
88 | @Override |
89 | public boolean isEnabled() { | |
cfdb727a | 90 | |
498704b3 BH |
91 | // Get workbench page for the Control View |
92 | IWorkbenchPage page = getWorkbenchPage(); | |
bbb3538a BH |
93 | if (page == null) { |
94 | return false; | |
95 | } | |
96 | ||
c56972bb | 97 | TraceSessionGroup sessionGroup = null; |
bbb3538a BH |
98 | |
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(); | |
c56972bb BH |
103 | sessionGroup = (element instanceof TraceSessionGroup) ? (TraceSessionGroup) element : null; |
104 | } | |
105 | ||
106 | boolean isEnabled = sessionGroup != null; | |
107 | fLock.lock(); | |
108 | try { | |
109 | fSessionGroup = null; | |
110 | if(isEnabled) { | |
111 | fSessionGroup = sessionGroup; | |
112 | } | |
113 | } finally { | |
114 | fLock.unlock(); | |
bbb3538a | 115 | } |
c56972bb | 116 | return isEnabled; |
bbb3538a BH |
117 | } |
118 | } |