Commit | Line | Data |
---|---|---|
eb1bab5b BH |
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 | **********************************************************************/ | |
115b4a01 | 12 | package org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers; |
eb1bab5b BH |
13 | |
14 | import org.eclipse.core.commands.ExecutionEvent; | |
15 | import org.eclipse.core.commands.ExecutionException; | |
115b4a01 | 16 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TargetNodeState; |
eb1bab5b BH |
17 | |
18 | /** | |
19 | * <b><u>DisconnectHandler</u></b> | |
20 | * <p> | |
21 | * Command handler implementation to disconnect from a target host. | |
22 | * </p> | |
23 | */ | |
24 | public class DisconnectHandler extends BaseNodeHandler { | |
25 | ||
26 | // ------------------------------------------------------------------------ | |
27 | // Operations | |
28 | // ------------------------------------------------------------------------ | |
29 | ||
30 | /* | |
31 | * (non-Javadoc) | |
115b4a01 | 32 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseNodeHandler#execute(org.eclipse.core.commands.ExecutionEvent) |
eb1bab5b BH |
33 | */ |
34 | @Override | |
35 | public Object execute(ExecutionEvent event) throws ExecutionException { | |
c56972bb BH |
36 | fLock.lock(); |
37 | try { | |
c56972bb | 38 | fTargetNode.disconnect(); |
c56972bb BH |
39 | } finally { |
40 | fLock.unlock(); | |
41 | } | |
eb1bab5b BH |
42 | return null; |
43 | } | |
44 | ||
45 | /* | |
46 | * (non-Javadoc) | |
115b4a01 | 47 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseNodeHandler#isEnabled() |
eb1bab5b BH |
48 | */ |
49 | @Override | |
50 | public boolean isEnabled() { | |
c56972bb BH |
51 | boolean isEnabled = false; |
52 | fLock.lock(); | |
53 | try { | |
54 | isEnabled = super.isEnabled() && (fTargetNode.getTargetNodeState() == TargetNodeState.CONNECTED); | |
55 | } finally { | |
56 | fLock.unlock(); | |
57 | } | |
58 | return isEnabled; | |
eb1bab5b BH |
59 | } |
60 | } |