Add new LTTng commands (create/destroy/start/stop session,
[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
eb1bab5b
BH
40 // ------------------------------------------------------------------------
41 // Operations
42 // ------------------------------------------------------------------------
43 /*
44 * (non-Javadoc)
4775bcbf 45 * @see org.eclipse.core.commands.AbstractHandler#isEnabled()
eb1bab5b
BH
46 */
47 @Override
48 public boolean isEnabled() {
49 fTargetNode = null;
50
51 // Check if we are closing down
52 IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
53 if (window == null) {
54 return false;
55 }
56
57 // Check if we are in the Project View
58 IWorkbenchPage page = window.getActivePage();
59 if (page == null) {
60 return false;
61 }
62
63 IWorkbenchPart part = page.getActivePart();
64 if (!(part instanceof ControlView)) {
65 return false;
66 }
67
bbb3538a 68 // Check if the node component is selected
eb1bab5b
BH
69 ISelection selection = page.getSelection(ControlView.ID);
70 if (selection instanceof StructuredSelection) {
71 Object element = ((StructuredSelection) selection).getFirstElement();
72 fTargetNode = (element instanceof TargetNodeComponent) ? (TargetNodeComponent) element : null;
73 }
74 return fTargetNode != null;
75 }
eb1bab5b 76}
This page took 0.026688 seconds and 5 git commands to generate.