Copyright header update, 2015 edition
[deliverable/tracecompass.git] / org.eclipse.tracecompass.lttng2.control.ui / src / org / eclipse / tracecompass / internal / lttng2 / control / ui / views / handlers / CreateSessionHandler.java
1 /**********************************************************************
2 * Copyright (c) 2012, 2014 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.tracecompass.internal.lttng2.control.ui.views.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.tracecompass.internal.lttng2.control.ui.Activator;
25 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.ControlView;
26 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.dialogs.ICreateSessionDialog;
27 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.dialogs.TraceControlDialogFactory;
28 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.messages.Messages;
29 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.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 sessionGroup.createSession(dialog.getParameters(), monitor);
74 } catch (ExecutionException e) {
75 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_CreateSessionFailure, e);
76 }
77 return Status.OK_STATUS;
78 }
79 };
80 job.setUser(true);
81 job.schedule();
82 } finally {
83 fLock.unlock();
84 }
85 return null;
86 }
87
88 @Override
89 public boolean isEnabled() {
90
91 // Get workbench page for the Control View
92 IWorkbenchPage page = getWorkbenchPage();
93 if (page == null) {
94 return false;
95 }
96
97 TraceSessionGroup sessionGroup = null;
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();
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();
115 }
116 return isEnabled;
117 }
118 }
This page took 0.03719 seconds and 5 git commands to generate.