Merge branch 'master' into lttng_2_0_control_dev
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui / src / org / eclipse / linuxtools / internal / lttng2 / ui / views / control / handlers / BaseNodeHandler.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 org.eclipse.jface.viewers.ISelection;
15 import org.eclipse.jface.viewers.StructuredSelection;
16 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.ControlView;
17 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TargetNodeComponent;
18 import org.eclipse.ui.IWorkbenchPage;
19
20 /**
21 * <b><u>BaseNodeHandler</u></b>
22 * <p>
23 * Command handler implementation to delete a target host.
24 * </p>
25 */
26 abstract public class BaseNodeHandler extends BaseControlViewHandler {
27
28 // ------------------------------------------------------------------------
29 // Attributes
30 // ------------------------------------------------------------------------
31 /**
32 * The target node component the command is to be executed on.
33 */
34 protected TargetNodeComponent fTargetNode = null;
35
36 // ------------------------------------------------------------------------
37 // Operations
38 // ------------------------------------------------------------------------
39 /*
40 * (non-Javadoc)
41 * @see org.eclipse.core.commands.AbstractHandler#isEnabled()
42 */
43 @Override
44 public boolean isEnabled() {
45
46 // Get workbench page for the Control View
47 IWorkbenchPage page = getWorkbenchPage();
48 if (page == null) {
49 return false;
50 }
51
52 TargetNodeComponent node = null;
53 // Check if the node component is selected
54 ISelection selection = page.getSelection(ControlView.ID);
55 if (selection instanceof StructuredSelection) {
56 Object element = ((StructuredSelection) selection).getFirstElement();
57 node = (element instanceof TargetNodeComponent) ? (TargetNodeComponent) element : null;
58 }
59 boolean isEnabled = node != null;
60 fLock.lock();
61 try {
62 if (isEnabled) {
63 fTargetNode = node;
64 }
65 } finally {
66 fLock.unlock();
67 }
68 return isEnabled;
69 }
70
71
72 }
This page took 0.032559 seconds and 6 git commands to generate.