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
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 **********************************************************************/
12 package org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers;
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;
20 import org.eclipse.linuxtools.internal.lttng2.core.control.model.TargetNodeState;
21 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.ControlView;
22 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TargetNodeComponent;
23 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent;
24 import org.eclipse.ui.IWorkbenchPage;
25
26 /**
27 * <p>
28 * Command handler implementation to refresh node configuration.
29 * </p>
30 *
31 * @author Bernd Hufmann
32 */
33 public class RefreshHandler extends BaseControlViewHandler {
34
35 // ------------------------------------------------------------------------
36 // Attributes
37 // ------------------------------------------------------------------------
38 /**
39 * The node component reference.
40 */
41 private TargetNodeComponent fNode;
42
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 {
53 fLock.lock();
54 try {
55 fNode.refresh();
56 } finally {
57 fLock.unlock();
58 }
59 return null;
60 }
61
62 /*
63 * (non-Javadoc)
64 * @see org.eclipse.core.commands.AbstractHandler#isEnabled()
65 */
66 @Override
67 public boolean isEnabled() {
68
69 // Get workbench page for the Control View
70 IWorkbenchPage page = getWorkbenchPage();
71 if (page == null) {
72 return false;
73 }
74
75 TargetNodeComponent node = null;
76 // Check if one or more session are selected
77 ISelection selection = page.getSelection(ControlView.ID);
78 if (selection instanceof StructuredSelection) {
79
80 StructuredSelection structered = ((StructuredSelection) selection);
81 for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) {
82 Object element = iterator.next();
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) {
91 node = (TargetNodeComponent) component;
92 }
93 }
94 }
95 }
96 }
97
98 boolean isEnabled = node != null;
99
100 fLock.lock();
101 try {
102 fNode = null;
103 if (isEnabled) {
104 fNode = node;
105 }
106 } finally {
107 fLock.unlock();
108 }
109
110 return isEnabled;
111 }
112 }
This page took 0.0333 seconds and 5 git commands to generate.