1 /**********************************************************************
2 * Copyright (c) 2012 Ericsson
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
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
12 package org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.handlers
;
14 import java
.util
.Iterator
;
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
;
28 * Command handler implementation to refresh node configuration.
31 * @author Bernd Hufmann
33 public class RefreshHandler
extends BaseControlViewHandler
{
35 // ------------------------------------------------------------------------
37 // ------------------------------------------------------------------------
39 * The node component reference.
41 private TargetNodeComponent fNode
;
43 // ------------------------------------------------------------------------
45 // ------------------------------------------------------------------------
49 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
52 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
64 * @see org.eclipse.core.commands.AbstractHandler#isEnabled()
67 public boolean isEnabled() {
69 // Get workbench page for the Control View
70 IWorkbenchPage page
= getWorkbenchPage();
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
) {
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
;
87 while ((component
!= null) && component
.getClass() != TargetNodeComponent
.class) {
88 component
= (TraceControlComponent
) component
.getParent();
90 if (component
!= null) {
91 node
= (TargetNodeComponent
) component
;
98 boolean isEnabled
= node
!= null;