lttng: Add snapshot support - LTTng Tools v2.3
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui / src / org / eclipse / linuxtools / internal / lttng2 / ui / views / control / handlers / CreateSessionHandler.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 * Bernd Hufmann - Updated for support of LTTng Tools 2.1
12 **********************************************************************/
13 package org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers;
14
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;
24 import org.eclipse.linuxtools.internal.lttng2.ui.Activator;
25 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.ControlView;
26 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateSessionDialog;
27 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.TraceControlDialogFactory;
28 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.messages.Messages;
29 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionGroup;
30 import org.eclipse.ui.IWorkbenchPage;
31
32 /**
33 * <p>
34 * Command handler implementation to create a trace session.
35 * </p>
36 *
37 * @author Bernd Hufmann
38 */
39 public class CreateSessionHandler extends BaseControlViewHandler {
40
41 // ------------------------------------------------------------------------
42 // Attributes
43 // ------------------------------------------------------------------------
44
45 /**
46 * The trace session group the command is to be executed on.
47 */
48 private TraceSessionGroup fSessionGroup = null;
49
50 // ------------------------------------------------------------------------
51 // Operations
52 // ------------------------------------------------------------------------
53
54 @Override
55 public Object execute(ExecutionEvent event) throws ExecutionException {
56
57 fLock.lock();
58 try {
59 final TraceSessionGroup sessionGroup = fSessionGroup;
60
61 // Open dialog box for the node name and address
62 final ICreateSessionDialog dialog = TraceControlDialogFactory.getInstance().getCreateSessionDialog();
63 dialog.initialize(sessionGroup);
64
65 if (dialog.open() != Window.OK) {
66 return null;
67 }
68
69 Job job = new Job(Messages.TraceControl_CreateSessionJob) {
70 @Override
71 protected IStatus run(IProgressMonitor monitor) {
72 try {
73 if (dialog.isStreamedTrace()) {
74 sessionGroup.createSession(dialog.getSessionName(), dialog.getNetworkUrl(), dialog.getControlUrl(),
75 dialog.getDataUrl(), dialog.isSnapshot(), monitor);
76 } else {
77 String sessionPath = dialog.isDefaultSessionPath() ? null : dialog.getSessionPath();
78 sessionGroup.createSession(dialog.getSessionName(), sessionPath, dialog.isSnapshot(), monitor);
79 }
80 } catch (ExecutionException e) {
81 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_CreateSessionFailure, e);
82 }
83 return Status.OK_STATUS;
84 }
85 };
86 job.setUser(true);
87 job.schedule();
88 } finally {
89 fLock.unlock();
90 }
91 return null;
92 }
93
94 @Override
95 public boolean isEnabled() {
96
97 // Get workbench page for the Control View
98 IWorkbenchPage page = getWorkbenchPage();
99 if (page == null) {
100 return false;
101 }
102
103 TraceSessionGroup sessionGroup = null;
104
105 // Check if the session group project is selected
106 ISelection selection = page.getSelection(ControlView.ID);
107 if (selection instanceof StructuredSelection) {
108 Object element = ((StructuredSelection) selection).getFirstElement();
109 sessionGroup = (element instanceof TraceSessionGroup) ? (TraceSessionGroup) element : null;
110 }
111
112 boolean isEnabled = sessionGroup != null;
113 fLock.lock();
114 try {
115 fSessionGroup = null;
116 if(isEnabled) {
117 fSessionGroup = sessionGroup;
118 }
119 } finally {
120 fLock.unlock();
121 }
122 return isEnabled;
123 }
124 }
This page took 0.034155 seconds and 5 git commands to generate.