Fix for bug 382684 (connection re-use)
[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 * <p>
22 * Command handler implementation to delete a target host.
23 * </p>
24 *
25 * @author Bernd Hufmann
26 */
27 abstract public 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 * (non-Javadoc)
42 * @see org.eclipse.core.commands.AbstractHandler#isEnabled()
43 */
44 @Override
45 public boolean isEnabled() {
46
47 // Get workbench page for the Control View
48 IWorkbenchPage page = getWorkbenchPage();
49 if (page == null) {
50 return false;
51 }
52
53 TargetNodeComponent node = null;
54 // Check if the node component is selected
55 ISelection selection = page.getSelection(ControlView.ID);
56 if (selection instanceof StructuredSelection) {
57 Object element = ((StructuredSelection) selection).getFirstElement();
58 node = (element instanceof TargetNodeComponent) ? (TargetNodeComponent) element : null;
59 }
60 boolean isEnabled = node != null;
61 fLock.lock();
62 try {
63 if (isEnabled) {
64 fTargetNode = node;
65 }
66 } finally {
67 fLock.unlock();
68 }
69 return isEnabled;
70 }
71
72
73 }
This page took 0.059016 seconds and 5 git commands to generate.