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