Merge branch 'master' into lttng_2_0_control_dev
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / internal / lttng / ui / views / control / handlers / CreateSessionHandler.java
CommitLineData
bbb3538a
BH
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 **********************************************************************/
31a6a4e4 12package org.eclipse.linuxtools.internal.lttng.ui.views.control.handlers;
bbb3538a 13
bbb3538a
BH
14import org.eclipse.core.commands.ExecutionEvent;
15import org.eclipse.core.commands.ExecutionException;
16import org.eclipse.core.runtime.IProgressMonitor;
17import org.eclipse.core.runtime.IStatus;
18import org.eclipse.core.runtime.Status;
19import org.eclipse.core.runtime.jobs.Job;
20import org.eclipse.jface.viewers.ISelection;
21import org.eclipse.jface.viewers.StructuredSelection;
22import org.eclipse.jface.window.Window;
31a6a4e4
BH
23import org.eclipse.linuxtools.internal.lttng.ui.Activator;
24import org.eclipse.linuxtools.internal.lttng.ui.views.control.ControlView;
25import org.eclipse.linuxtools.internal.lttng.ui.views.control.Messages;
26import org.eclipse.linuxtools.internal.lttng.ui.views.control.dialogs.ICreateSessionDialog;
27import org.eclipse.linuxtools.internal.lttng.ui.views.control.dialogs.TraceControlDialogFactory;
28import org.eclipse.linuxtools.internal.lttng.ui.views.control.model.impl.TraceSessionGroup;
bbb3538a 29import org.eclipse.ui.IWorkbenchPage;
bbb3538a
BH
30
31/**
32 * <b><u>CreateSessionHandler</u></b>
33 * <p>
34 * Command handler implementation to create a trace session.
35 * </p>
36 */
498704b3 37public class CreateSessionHandler extends BaseControlViewHandler {
bbb3538a
BH
38
39 // ------------------------------------------------------------------------
40 // Attributes
41 // ------------------------------------------------------------------------
42 /**
43 * The trace session group the command is to be executed on.
44 */
45 private TraceSessionGroup fSessionGroup = null;
46
47 // ------------------------------------------------------------------------
48 // Operations
49 // ------------------------------------------------------------------------
50 /*
51 * (non-Javadoc)
52 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
53 */
54 @Override
55 public Object execute(ExecutionEvent event) throws ExecutionException {
bbb3538a
BH
56
57 // Open dialog box for the node name and address
d132bcc7
BH
58 ICreateSessionDialog dialog = TraceControlDialogFactory.getInstance().getCreateSessionDialog();
59 dialog.setTraceSessionGroup(fSessionGroup);
bbb3538a 60
6503ae0f
BH
61 if (dialog.open() != Window.OK) {
62 return null;
bbb3538a 63 }
6503ae0f
BH
64
65 final String sessionName = dialog.getSessionName();
66 final String sessionPath = dialog.isDefaultSessionPath() ? null : dialog.getSessionPath();
67
68 Job job = new Job(Messages.TraceControl_CreateSessionJob) {
69 @Override
70 protected IStatus run(IProgressMonitor monitor) {
71 try {
72 fSessionGroup.createSession(sessionName, sessionPath, monitor);
73 } catch (ExecutionException e) {
31a6a4e4 74 return new Status(Status.ERROR, Activator.PLUGIN_ID, e.toString());
6503ae0f
BH
75 }
76 return Status.OK_STATUS;
77 }
78 };
79 job.setUser(true);
80 job.schedule();
bbb3538a
BH
81
82 return null;
83 }
84
85 /*
86 * (non-Javadoc)
87 * @see org.eclipse.core.commands.AbstractHandler#isEnabled()
88 */
89 @Override
90 public boolean isEnabled() {
498704b3
BH
91
92 // Get workbench page for the Control View
93 IWorkbenchPage page = getWorkbenchPage();
bbb3538a
BH
94 if (page == null) {
95 return false;
96 }
97
498704b3 98 fSessionGroup = null;
bbb3538a
BH
99
100 // Check if the session group project is selected
101 ISelection selection = page.getSelection(ControlView.ID);
102 if (selection instanceof StructuredSelection) {
103 Object element = ((StructuredSelection) selection).getFirstElement();
104 fSessionGroup = (element instanceof TraceSessionGroup) ? (TraceSessionGroup) element : null;
105 }
106 return fSessionGroup != null;
107 }
108}
This page took 0.052333 seconds and 5 git commands to generate.