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