Fixed code review findings + upgrade to lttng-tools 2.0-pre20
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / ui / views / control / handlers / BaseNodeHandler.java
CommitLineData
eb1bab5b
BH
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 **********************************************************************/
12package org.eclipse.linuxtools.lttng.ui.views.control.handlers;
13
4775bcbf 14import org.eclipse.core.commands.AbstractHandler;
eb1bab5b
BH
15import org.eclipse.jface.viewers.ISelection;
16import org.eclipse.jface.viewers.StructuredSelection;
17import org.eclipse.linuxtools.lttng.ui.views.control.ControlView;
18import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TargetNodeComponent;
19import org.eclipse.ui.IWorkbenchPage;
20import org.eclipse.ui.IWorkbenchPart;
21import org.eclipse.ui.IWorkbenchWindow;
22import org.eclipse.ui.PlatformUI;
23
24/**
25 * <b><u>BaseNodeHandler</u></b>
26 * <p>
27 * Command handler implementation to delete a target host.
28 * </p>
29 */
4775bcbf 30abstract public class BaseNodeHandler extends AbstractHandler {
eb1bab5b
BH
31
32 // ------------------------------------------------------------------------
33 // Attributes
34 // ------------------------------------------------------------------------
35 /**
36 * The target node component the command is to be executed on.
37 */
38 protected TargetNodeComponent fTargetNode = null;
39
40 // ------------------------------------------------------------------------
41 // Constructors
42 // ------------------------------------------------------------------------
43
44 // ------------------------------------------------------------------------
45 // Accessors
46 // ------------------------------------------------------------------------
47 public TargetNodeComponent getTargetNode() {
48 return fTargetNode;
49 }
50
51 // ------------------------------------------------------------------------
52 // Operations
53 // ------------------------------------------------------------------------
54 /*
55 * (non-Javadoc)
4775bcbf 56 * @see org.eclipse.core.commands.AbstractHandler#isEnabled()
eb1bab5b
BH
57 */
58 @Override
59 public boolean isEnabled() {
60 fTargetNode = null;
61
62 // Check if we are closing down
63 IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
64 if (window == null) {
65 return false;
66 }
67
68 // Check if we are in the Project View
69 IWorkbenchPage page = window.getActivePage();
70 if (page == null) {
71 return false;
72 }
73
74 IWorkbenchPart part = page.getActivePart();
75 if (!(part instanceof ControlView)) {
76 return false;
77 }
78
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;
84 }
85 return fTargetNode != null;
86 }
eb1bab5b 87}
This page took 0.026848 seconds and 5 git commands to generate.