Commit | Line | Data |
---|---|---|
498704b3 | 1 | /********************************************************************** |
77735e82 | 2 | * Copyright (c) 2012, 2013 Ericsson |
cfdb727a | 3 | * |
498704b3 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: | |
498704b3 BH |
10 | * Bernd Hufmann - Initial API and implementation |
11 | **********************************************************************/ | |
115b4a01 | 12 | package org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers; |
498704b3 | 13 | |
c56972bb BH |
14 | import java.util.concurrent.locks.ReentrantLock; |
15 | ||
498704b3 | 16 | import org.eclipse.core.commands.AbstractHandler; |
f455db37 BH |
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.linuxtools.internal.lttng2.ui.Activator; | |
115b4a01 | 23 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.ControlView; |
9315aeee | 24 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.messages.Messages; |
498704b3 BH |
25 | import org.eclipse.ui.IWorkbenchPage; |
26 | import org.eclipse.ui.IWorkbenchPart; | |
27 | import org.eclipse.ui.IWorkbenchWindow; | |
28 | import org.eclipse.ui.PlatformUI; | |
29 | ||
30 | /** | |
498704b3 BH |
31 | * <p> |
32 | * Abstract Command handler implementation for all control view handlers. | |
33 | * </p> | |
cfdb727a | 34 | * |
dbd4432d | 35 | * @author Bernd Hufmann |
498704b3 | 36 | */ |
77735e82 | 37 | public abstract class BaseControlViewHandler extends AbstractHandler { |
498704b3 | 38 | |
c56972bb BH |
39 | // ------------------------------------------------------------------------ |
40 | // Attributes | |
41 | // ------------------------------------------------------------------------ | |
42 | /** | |
43 | * The synchronization lock. | |
44 | */ | |
77735e82 | 45 | protected final ReentrantLock fLock = new ReentrantLock(); |
cfdb727a | 46 | |
498704b3 BH |
47 | // ------------------------------------------------------------------------ |
48 | // Operations | |
49 | // ------------------------------------------------------------------------ | |
50 | /** | |
51 | * @return returns the workbench page for the Control View | |
52 | */ | |
53 | protected IWorkbenchPage getWorkbenchPage() { | |
54 | // Check if we are closing down | |
55 | IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); | |
56 | if (window == null) { | |
57 | return null; | |
58 | } | |
59 | ||
60 | // Check if we are in the Project View | |
61 | IWorkbenchPage page = window.getActivePage(); | |
62 | if (page == null) { | |
63 | return null; | |
64 | } | |
65 | ||
66 | IWorkbenchPart part = page.getActivePart(); | |
67 | if (!(part instanceof ControlView)) { | |
68 | return null; | |
69 | } | |
70 | return page; | |
71 | } | |
f455db37 BH |
72 | |
73 | /** | |
74 | * Refreshes the session information based on given session (in CommandParameter) | |
75 | * @param param - command parameter containing the session to refresh | |
76 | */ | |
77 | protected void refresh(final CommandParameter param) { | |
78 | Job job = new Job(Messages.TraceControl_RetrieveNodeConfigurationJob) { | |
cfdb727a | 79 | |
f455db37 BH |
80 | @Override |
81 | protected IStatus run(IProgressMonitor monitor) { | |
82 | try { | |
83 | param.getSession().getConfigurationFromNode(monitor); | |
84 | } catch (ExecutionException e) { | |
cfdb727a AM |
85 | return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_ListSessionFailure, e); |
86 | } | |
f455db37 BH |
87 | return Status.OK_STATUS; |
88 | } | |
89 | }; | |
90 | job.setUser(true); | |
91 | job.schedule(); | |
92 | } | |
93 | ||
498704b3 | 94 | } |