Commit | Line | Data |
---|---|---|
498704b3 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 | **********************************************************************/ | |
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; |
f455db37 | 24 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.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 | /** | |
31 | * <b><u>BaseControlViewHandler</u></b> | |
32 | * <p> | |
33 | * Abstract Command handler implementation for all control view handlers. | |
34 | * </p> | |
35 | */ | |
36 | abstract public class BaseControlViewHandler extends AbstractHandler { | |
37 | ||
c56972bb BH |
38 | // ------------------------------------------------------------------------ |
39 | // Attributes | |
40 | // ------------------------------------------------------------------------ | |
41 | /** | |
42 | * The synchronization lock. | |
43 | */ | |
afe13e7a | 44 | final protected ReentrantLock fLock = new ReentrantLock(); |
c56972bb | 45 | |
498704b3 BH |
46 | // ------------------------------------------------------------------------ |
47 | // Operations | |
48 | // ------------------------------------------------------------------------ | |
49 | /** | |
50 | * @return returns the workbench page for the Control View | |
51 | */ | |
52 | protected IWorkbenchPage getWorkbenchPage() { | |
53 | // Check if we are closing down | |
54 | IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); | |
55 | if (window == null) { | |
56 | return null; | |
57 | } | |
58 | ||
59 | // Check if we are in the Project View | |
60 | IWorkbenchPage page = window.getActivePage(); | |
61 | if (page == null) { | |
62 | return null; | |
63 | } | |
64 | ||
65 | IWorkbenchPart part = page.getActivePart(); | |
66 | if (!(part instanceof ControlView)) { | |
67 | return null; | |
68 | } | |
69 | return page; | |
70 | } | |
f455db37 BH |
71 | |
72 | /** | |
73 | * Refreshes the session information based on given session (in CommandParameter) | |
74 | * @param param - command parameter containing the session to refresh | |
75 | */ | |
76 | protected void refresh(final CommandParameter param) { | |
77 | Job job = new Job(Messages.TraceControl_RetrieveNodeConfigurationJob) { | |
78 | ||
79 | @Override | |
80 | protected IStatus run(IProgressMonitor monitor) { | |
81 | try { | |
82 | param.getSession().getConfigurationFromNode(monitor); | |
83 | } catch (ExecutionException e) { | |
84 | return new Status(Status.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_ListSessionFailure, e); | |
85 | } | |
86 | return Status.OK_STATUS; | |
87 | } | |
88 | }; | |
89 | job.setUser(true); | |
90 | job.schedule(); | |
91 | } | |
92 | ||
498704b3 | 93 | } |