Commit | Line | Data |
---|---|---|
d132bcc7 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 | **********************************************************************/ | |
31a6a4e4 | 12 | package org.eclipse.linuxtools.internal.lttng.ui.views.control.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; | |
31a6a4e4 BH |
20 | import org.eclipse.linuxtools.internal.lttng.ui.views.control.ControlView; |
21 | import org.eclipse.linuxtools.internal.lttng.ui.views.control.model.TargetNodeState; | |
22 | import org.eclipse.linuxtools.internal.lttng.ui.views.control.model.impl.TargetNodeComponent; | |
23 | import org.eclipse.linuxtools.internal.lttng.ui.views.control.model.impl.TraceControlComponent; | |
d132bcc7 BH |
24 | import org.eclipse.ui.IWorkbenchPage; |
25 | ||
26 | /** | |
27 | * <b><u>RefreshHandler</u></b> | |
28 | * <p> | |
29 | * Command handler implementation to refresh node configuration. | |
30 | * </p> | |
31 | */ | |
32 | public class RefreshHandler extends BaseControlViewHandler { | |
33 | ||
34 | // ------------------------------------------------------------------------ | |
35 | // Attributes | |
36 | // ------------------------------------------------------------------------ | |
37 | /** | |
38 | * The node component reference. | |
39 | */ | |
40 | private TargetNodeComponent fNode; | |
41 | ||
42 | // ------------------------------------------------------------------------ | |
43 | // Operations | |
44 | // ------------------------------------------------------------------------ | |
45 | ||
46 | /* | |
47 | * (non-Javadoc) | |
48 | * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent) | |
49 | */ | |
50 | @Override | |
51 | public Object execute(ExecutionEvent event) throws ExecutionException { | |
52 | fNode.refresh(); | |
53 | return null; | |
54 | } | |
55 | ||
56 | /* | |
57 | * (non-Javadoc) | |
58 | * @see org.eclipse.core.commands.AbstractHandler#isEnabled() | |
59 | */ | |
60 | @Override | |
61 | public boolean isEnabled() { | |
62 | fNode = null; | |
63 | ||
64 | // Get workbench page for the Control View | |
65 | IWorkbenchPage page = getWorkbenchPage(); | |
66 | if (page == null) { | |
67 | return false; | |
68 | } | |
69 | ||
70 | // Check if one or more session are selected | |
71 | ISelection selection = page.getSelection(ControlView.ID); | |
72 | if (selection instanceof StructuredSelection) { | |
73 | ||
74 | StructuredSelection structered = ((StructuredSelection) selection); | |
75 | for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) { | |
76 | Object element = (Object) iterator.next(); | |
77 | if (element instanceof TraceControlComponent) { | |
78 | TraceControlComponent component = (TraceControlComponent) element; | |
79 | boolean isConnected = component.getTargetNodeState() == TargetNodeState.CONNECTED; | |
80 | if (isConnected) { | |
81 | while ((component != null) && component.getClass() != TargetNodeComponent.class) { | |
82 | component = (TraceControlComponent) component.getParent(); | |
83 | } | |
84 | if (component != null) { | |
85 | fNode = (TargetNodeComponent) component; | |
86 | } | |
87 | } | |
88 | } | |
89 | } | |
90 | } | |
91 | return fNode != null; | |
92 | } | |
93 | } |