lttng: Fix Javadoc and formatting in lttng2.ui
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui / src / org / eclipse / linuxtools / internal / lttng2 / ui / views / control / handlers / RefreshHandler.java
CommitLineData
d132bcc7
BH
1/**********************************************************************
2 * Copyright (c) 2012 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 **********************************************************************/
115b4a01 12package org.eclipse.linuxtools.internal.lttng2.ui.views.control.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;
9315aeee 20import org.eclipse.linuxtools.internal.lttng2.core.control.model.TargetNodeState;
115b4a01 21import org.eclipse.linuxtools.internal.lttng2.ui.views.control.ControlView;
115b4a01
BH
22import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TargetNodeComponent;
23import org.eclipse.linuxtools.internal.lttng2.ui.views.control.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 // ------------------------------------------------------------------------
38 /**
39 * The node component reference.
40 */
41 private TargetNodeComponent fNode;
cfdb727a 42
d132bcc7
BH
43 // ------------------------------------------------------------------------
44 // Operations
45 // ------------------------------------------------------------------------
46
47 /*
48 * (non-Javadoc)
49 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
50 */
51 @Override
52 public Object execute(ExecutionEvent event) throws ExecutionException {
c56972bb
BH
53 fLock.lock();
54 try {
55 fNode.refresh();
56 } finally {
57 fLock.unlock();
58 }
d132bcc7
BH
59 return null;
60 }
61
62 /*
63 * (non-Javadoc)
64 * @see org.eclipse.core.commands.AbstractHandler#isEnabled()
65 */
66 @Override
67 public boolean isEnabled() {
d132bcc7
BH
68
69 // Get workbench page for the Control View
70 IWorkbenchPage page = getWorkbenchPage();
71 if (page == null) {
72 return false;
73 }
74
c56972bb 75 TargetNodeComponent node = null;
d132bcc7
BH
76 // Check if one or more session are selected
77 ISelection selection = page.getSelection(ControlView.ID);
78 if (selection instanceof StructuredSelection) {
cfdb727a 79
d132bcc7
BH
80 StructuredSelection structered = ((StructuredSelection) selection);
81 for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) {
cfdb727a 82 Object element = iterator.next();
d132bcc7
BH
83 if (element instanceof TraceControlComponent) {
84 TraceControlComponent component = (TraceControlComponent) element;
85 boolean isConnected = component.getTargetNodeState() == TargetNodeState.CONNECTED;
86 if (isConnected) {
87 while ((component != null) && component.getClass() != TargetNodeComponent.class) {
88 component = (TraceControlComponent) component.getParent();
89 }
90 if (component != null) {
c56972bb 91 node = (TargetNodeComponent) component;
d132bcc7
BH
92 }
93 }
94 }
95 }
96 }
cfdb727a 97
c56972bb 98 boolean isEnabled = node != null;
cfdb727a 99
c56972bb
BH
100 fLock.lock();
101 try {
102 fNode = null;
103 if (isEnabled) {
104 fNode = node;
105 }
106 } finally {
107 fLock.unlock();
108 }
cfdb727a 109
c56972bb 110 return isEnabled;
d132bcc7
BH
111 }
112}
This page took 0.033498 seconds and 5 git commands to generate.