Commit | Line | Data |
---|---|---|
eb1bab5b | 1 | /********************************************************************** |
ed902a2b | 2 | * Copyright (c) 2012, 2014 Ericsson |
11252342 | 3 | * |
eb1bab5b BH |
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 | |
11252342 AM |
8 | * |
9 | * Contributors: | |
eb1bab5b BH |
10 | * Bernd Hufmann - Initial API and implementation |
11 | **********************************************************************/ | |
9bc60be7 | 12 | package org.eclipse.tracecompass.internal.lttng2.control.ui.views.handlers; |
eb1bab5b | 13 | |
eb1bab5b BH |
14 | import org.eclipse.jface.viewers.ISelection; |
15 | import org.eclipse.jface.viewers.StructuredSelection; | |
9bc60be7 AM |
16 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.ControlView; |
17 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TargetNodeComponent; | |
eb1bab5b | 18 | import org.eclipse.ui.IWorkbenchPage; |
eb1bab5b BH |
19 | |
20 | /** | |
eb1bab5b BH |
21 | * <p> |
22 | * Command handler implementation to delete a target host. | |
23 | * </p> | |
11252342 | 24 | * |
dbd4432d | 25 | * @author Bernd Hufmann |
eb1bab5b | 26 | */ |
77735e82 | 27 | public abstract class BaseNodeHandler extends BaseControlViewHandler { |
eb1bab5b BH |
28 | |
29 | // ------------------------------------------------------------------------ | |
30 | // Attributes | |
31 | // ------------------------------------------------------------------------ | |
32 | /** | |
11252342 | 33 | * The target node component the command is to be executed on. |
eb1bab5b BH |
34 | */ |
35 | protected TargetNodeComponent fTargetNode = null; | |
11252342 | 36 | |
eb1bab5b BH |
37 | // ------------------------------------------------------------------------ |
38 | // Operations | |
39 | // ------------------------------------------------------------------------ | |
11252342 | 40 | |
eb1bab5b BH |
41 | @Override |
42 | public boolean isEnabled() { | |
eb1bab5b | 43 | |
498704b3 BH |
44 | // Get workbench page for the Control View |
45 | IWorkbenchPage page = getWorkbenchPage(); | |
eb1bab5b BH |
46 | if (page == null) { |
47 | return false; | |
48 | } | |
49 | ||
c56972bb | 50 | TargetNodeComponent node = null; |
bbb3538a | 51 | // Check if the node component is selected |
eb1bab5b BH |
52 | ISelection selection = page.getSelection(ControlView.ID); |
53 | if (selection instanceof StructuredSelection) { | |
54 | Object element = ((StructuredSelection) selection).getFirstElement(); | |
c56972bb | 55 | node = (element instanceof TargetNodeComponent) ? (TargetNodeComponent) element : null; |
eb1bab5b | 56 | } |
c56972bb BH |
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; | |
eb1bab5b | 67 | } |
498704b3 | 68 | |
11252342 | 69 | |
eb1bab5b | 70 | } |