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
.lttng
.ui
.views
.control
.handlers
;
14 import org
.eclipse
.core
.commands
.AbstractHandler
;
15 import org
.eclipse
.jface
.viewers
.ISelection
;
16 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
17 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.ControlView
;
18 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.impl
.TargetNodeComponent
;
19 import org
.eclipse
.ui
.IWorkbenchPage
;
20 import org
.eclipse
.ui
.IWorkbenchPart
;
21 import org
.eclipse
.ui
.IWorkbenchWindow
;
22 import org
.eclipse
.ui
.PlatformUI
;
25 * <b><u>BaseNodeHandler</u></b>
27 * Command handler implementation to delete a target host.
30 abstract public class BaseNodeHandler
extends AbstractHandler
{
32 // ------------------------------------------------------------------------
34 // ------------------------------------------------------------------------
36 * The target node component the command is to be executed on.
38 protected TargetNodeComponent fTargetNode
= null;
40 // ------------------------------------------------------------------------
42 // ------------------------------------------------------------------------
44 // ------------------------------------------------------------------------
46 // ------------------------------------------------------------------------
47 public TargetNodeComponent
getTargetNode() {
51 // ------------------------------------------------------------------------
53 // ------------------------------------------------------------------------
56 * @see org.eclipse.core.commands.AbstractHandler#isEnabled()
59 public boolean isEnabled() {
62 // Check if we are closing down
63 IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
68 // Check if we are in the Project View
69 IWorkbenchPage page
= window
.getActivePage();
74 IWorkbenchPart part
= page
.getActivePart();
75 if (!(part
instanceof ControlView
)) {
79 // Check if a project is selected
80 ISelection selection
= page
.getSelection(ControlView
.ID
);
81 if (selection
instanceof StructuredSelection
) {
82 Object element
= ((StructuredSelection
) selection
).getFirstElement();
83 fTargetNode
= (element
instanceof TargetNodeComponent
) ?
(TargetNodeComponent
) element
: null;
85 return fTargetNode
!= null;