gdbtrace: Move plugins to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.control.ui / src / org / eclipse / linuxtools / internal / lttng2 / control / ui / views / handlers / RefreshHandler.java
CommitLineData
d132bcc7 1/**********************************************************************
11252342 2 * Copyright (c) 2012, 2013 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 **********************************************************************/
8e8c0226 12package org.eclipse.linuxtools.internal.lttng2.control.ui.views.handlers;
d132bcc7
BH
13
14import java.util.Iterator;
15
16import org.eclipse.core.commands.ExecutionEvent;
17import org.eclipse.core.commands.ExecutionException;
18import org.eclipse.jface.viewers.ISelection;
19import org.eclipse.jface.viewers.StructuredSelection;
8e8c0226
AM
20import org.eclipse.linuxtools.internal.lttng2.control.core.model.TargetNodeState;
21import org.eclipse.linuxtools.internal.lttng2.control.ui.views.ControlView;
22import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TargetNodeComponent;
23import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TraceControlComponent;
d132bcc7
BH
24import 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 */
33public 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}
This page took 0.080519 seconds and 5 git commands to generate.