Commit | Line | Data |
---|---|---|
d132bcc7 | 1 | /********************************************************************** |
ed902a2b | 2 | * Copyright (c) 2012, 2014 Ericsson |
cfdb727a | 3 | * |
d132bcc7 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: | |
d132bcc7 BH |
10 | * Bernd Hufmann - Initial API and implementation |
11 | **********************************************************************/ | |
9bc60be7 | 12 | package org.eclipse.tracecompass.internal.lttng2.control.ui.views.handlers; |
d132bcc7 BH |
13 | |
14 | import java.util.Iterator; | |
15 | ||
16 | import org.eclipse.core.commands.ExecutionEvent; | |
17 | import org.eclipse.core.commands.ExecutionException; | |
18 | import org.eclipse.jface.viewers.ISelection; | |
19 | import org.eclipse.jface.viewers.StructuredSelection; | |
9bc60be7 AM |
20 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.TargetNodeState; |
21 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.ControlView; | |
22 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TargetNodeComponent; | |
23 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceControlComponent; | |
d132bcc7 BH |
24 | import org.eclipse.ui.IWorkbenchPage; |
25 | ||
26 | /** | |
d132bcc7 BH |
27 | * <p> |
28 | * Command handler implementation to refresh node configuration. | |
29 | * </p> | |
cfdb727a | 30 | * |
dbd4432d | 31 | * @author Bernd Hufmann |
d132bcc7 BH |
32 | */ |
33 | public class RefreshHandler extends BaseControlViewHandler { | |
34 | ||
35 | // ------------------------------------------------------------------------ | |
36 | // Attributes | |
37 | // ------------------------------------------------------------------------ | |
11252342 | 38 | |
d132bcc7 BH |
39 | /** |
40 | * The node component reference. | |
41 | */ | |
42 | private TargetNodeComponent fNode; | |
cfdb727a | 43 | |
d132bcc7 BH |
44 | // ------------------------------------------------------------------------ |
45 | // Operations | |
46 | // ------------------------------------------------------------------------ | |
47 | ||
d132bcc7 BH |
48 | @Override |
49 | public Object execute(ExecutionEvent event) throws ExecutionException { | |
c56972bb BH |
50 | fLock.lock(); |
51 | try { | |
52 | fNode.refresh(); | |
53 | } finally { | |
54 | fLock.unlock(); | |
55 | } | |
d132bcc7 BH |
56 | return null; |
57 | } | |
58 | ||
d132bcc7 BH |
59 | @Override |
60 | public boolean isEnabled() { | |
d132bcc7 BH |
61 | |
62 | // Get workbench page for the Control View | |
63 | IWorkbenchPage page = getWorkbenchPage(); | |
64 | if (page == null) { | |
65 | return false; | |
66 | } | |
67 | ||
c56972bb | 68 | TargetNodeComponent node = null; |
d132bcc7 BH |
69 | // Check if one or more session are selected |
70 | ISelection selection = page.getSelection(ControlView.ID); | |
71 | if (selection instanceof StructuredSelection) { | |
cfdb727a | 72 | |
d132bcc7 BH |
73 | StructuredSelection structered = ((StructuredSelection) selection); |
74 | for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) { | |
cfdb727a | 75 | Object element = iterator.next(); |
d132bcc7 BH |
76 | if (element instanceof TraceControlComponent) { |
77 | TraceControlComponent component = (TraceControlComponent) element; | |
78 | boolean isConnected = component.getTargetNodeState() == TargetNodeState.CONNECTED; | |
79 | if (isConnected) { | |
80 | while ((component != null) && component.getClass() != TargetNodeComponent.class) { | |
81 | component = (TraceControlComponent) component.getParent(); | |
82 | } | |
83 | if (component != null) { | |
c56972bb | 84 | node = (TargetNodeComponent) component; |
d132bcc7 BH |
85 | } |
86 | } | |
87 | } | |
88 | } | |
89 | } | |
cfdb727a | 90 | |
c56972bb | 91 | boolean isEnabled = node != null; |
cfdb727a | 92 | |
c56972bb BH |
93 | fLock.lock(); |
94 | try { | |
95 | fNode = null; | |
96 | if (isEnabled) { | |
97 | fNode = node; | |
98 | } | |
99 | } finally { | |
100 | fLock.unlock(); | |
101 | } | |
cfdb727a | 102 | |
c56972bb | 103 | return isEnabled; |
d132bcc7 BH |
104 | } |
105 | } |