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