lttng: Enable project-specific compiler settings
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui / src / org / eclipse / linuxtools / internal / lttng2 / ui / views / control / handlers / BaseAddContextHandler.java
CommitLineData
b793fbe1
BH
1/**********************************************************************
2 * Copyright (c) 2012 Ericsson
cfdb727a 3 *
b793fbe1
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:
b793fbe1
BH
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
12package org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers;
13
14import java.util.List;
15
16import org.eclipse.core.commands.ExecutionEvent;
17import org.eclipse.core.commands.ExecutionException;
18import org.eclipse.core.runtime.IProgressMonitor;
19import org.eclipse.core.runtime.IStatus;
20import org.eclipse.core.runtime.Status;
21import org.eclipse.core.runtime.jobs.Job;
22import org.eclipse.jface.window.Window;
23import org.eclipse.linuxtools.internal.lttng2.ui.Activator;
b793fbe1
BH
24import org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IAddContextDialog;
25import org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.TraceControlDialogFactory;
9315aeee 26import org.eclipse.linuxtools.internal.lttng2.ui.views.control.messages.Messages;
b793fbe1
BH
27import org.eclipse.ui.IWorkbenchWindow;
28import org.eclipse.ui.PlatformUI;
29import org.eclipse.ui.progress.UIJob;
30
31/**
b793fbe1
BH
32 * <p>
33 * Base command handler implementation to add contexts.
34 * </p>
cfdb727a 35 *
dbd4432d 36 * @author Bernd Hufmann
b793fbe1
BH
37 */
38abstract public class BaseAddContextHandler extends BaseControlViewHandler {
39
40 // ------------------------------------------------------------------------
41 // Attributes
42 // ------------------------------------------------------------------------
43 /**
44 * The command execution parameter.
45 */
46 protected CommandParameter fParam = null;
47
48 // ------------------------------------------------------------------------
49 // Operations
50 // ------------------------------------------------------------------------
cfdb727a 51
b793fbe1 52 /**
cfdb727a
AM
53 * Adds contexts to channel(s) and/or event(s)
54 *
55 * @param param
56 * - a parameter instance with data for the command execution
57 * @param contextNames
58 * - list contexts to add
59 * @param monitor
60 * - a progress monitor
b793fbe1 61 * @throws ExecutionException
cfdb727a 62 * If something goes wrong
b793fbe1
BH
63 */
64 abstract public void addContexts(CommandParameter param, List<String> contextNames, IProgressMonitor monitor) throws ExecutionException;
cfdb727a 65
b793fbe1
BH
66 /*
67 * (non-Javadoc)
68 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
69 */
70 @Override
71 public Object execute(ExecutionEvent event) throws ExecutionException {
72
73 final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
74
75 if (window == null) {
76 return false;
77 }
78 fLock.lock();
79 try {
80 // Make a copy for thread safety
81 final CommandParameter param = fParam.clone();
82
83 UIJob getJob = new UIJob(Messages.TraceControl_GetContextJob) {
84 @Override
85 public IStatus runInUIThread(IProgressMonitor monitor) {
86
87 try {
88 final List<String> availableContexts = param.getSession().getContextList(monitor);
89 final IAddContextDialog dialog = TraceControlDialogFactory.getInstance().getAddContextDialog();
cfdb727a 90 dialog.setAvalibleContexts(availableContexts);
b793fbe1
BH
91
92 if ((dialog.open() != Window.OK) || (dialog.getContexts().isEmpty())) {
93 return Status.OK_STATUS;
94 }
95
96 Job addJob = new Job(Messages.TraceControl_AddContextJob) {
97 @Override
98 protected IStatus run(IProgressMonitor monitor) {
f455db37 99 Exception error = null;
b793fbe1
BH
100
101 try {
102 List<String> contextNames = dialog.getContexts();
103 addContexts(param, contextNames, monitor);
104
105 } catch (ExecutionException e) {
f455db37 106 error = e;
b793fbe1
BH
107 }
108
109 // get session configuration in all cases
f455db37 110 refresh(param);
cfdb727a 111
f455db37 112 if (error != null) {
cfdb727a 113 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_AddContextFailure, error);
b793fbe1
BH
114 }
115 return Status.OK_STATUS;
116 }
117 };
118 addJob.setUser(true);
119 addJob.schedule();
120 } catch (ExecutionException e) {
cfdb727a 121 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_GetContextFailure, e);
b793fbe1
BH
122 }
123
124 return Status.OK_STATUS;
125 }
126 };
127 getJob.setUser(false);
128 getJob.schedule();
129
130 } finally {
131 fLock.unlock();
132 }
133 return null;
134 }
135}
This page took 0.033518 seconds and 5 git commands to generate.