| 1 | /********************************************************************** |
| 2 | * Copyright (c) 2012, 2013 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.core.commands.ExecutionEvent; |
| 15 | import org.eclipse.core.commands.ExecutionException; |
| 16 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.TargetNodeState; |
| 17 | |
| 18 | /** |
| 19 | * <p> |
| 20 | * Command handler implementation to disconnect from a target host. |
| 21 | * </p> |
| 22 | * |
| 23 | * @author Bernd Hufmann |
| 24 | */ |
| 25 | public class DisconnectHandler extends BaseNodeHandler { |
| 26 | |
| 27 | // ------------------------------------------------------------------------ |
| 28 | // Operations |
| 29 | // ------------------------------------------------------------------------ |
| 30 | |
| 31 | @Override |
| 32 | public Object execute(ExecutionEvent event) throws ExecutionException { |
| 33 | fLock.lock(); |
| 34 | try { |
| 35 | fTargetNode.disconnect(); |
| 36 | } finally { |
| 37 | fLock.unlock(); |
| 38 | } |
| 39 | return null; |
| 40 | } |
| 41 | |
| 42 | @Override |
| 43 | public boolean isEnabled() { |
| 44 | boolean isEnabled = false; |
| 45 | fLock.lock(); |
| 46 | try { |
| 47 | isEnabled = super.isEnabled() && (fTargetNode.getTargetNodeState() == TargetNodeState.CONNECTED); |
| 48 | } finally { |
| 49 | fLock.unlock(); |
| 50 | } |
| 51 | return isEnabled; |
| 52 | } |
| 53 | } |