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; | |
9315aeee | 16 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.TargetNodeState; |
115b4a01 | 17 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent; |
eb1bab5b BH |
18 | |
19 | /** | |
eb1bab5b BH |
20 | * <p> |
21 | * Command handler implementation to delete a target host. | |
22 | * </p> | |
dbd4432d BH |
23 | * |
24 | * @author Bernd Hufmann | |
eb1bab5b BH |
25 | */ |
26 | public class DeleteHandler extends BaseNodeHandler { | |
27 | ||
28 | // ------------------------------------------------------------------------ | |
29 | // Operations | |
30 | // ------------------------------------------------------------------------ | |
31 | /* | |
32 | * (non-Javadoc) | |
115b4a01 | 33 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseNodeHandler#execute(org.eclipse.core.commands.ExecutionEvent) |
eb1bab5b BH |
34 | */ |
35 | @Override | |
36 | public Object execute(ExecutionEvent event) throws ExecutionException { | |
c56972bb BH |
37 | fLock.lock(); |
38 | try { | |
39 | ITraceControlComponent root = fTargetNode.getParent(); | |
40 | fTargetNode.removeAllChildren(); | |
8577ed1e | 41 | fTargetNode.deregister(); |
c56972bb BH |
42 | root.removeChild(fTargetNode); |
43 | } finally { | |
44 | fLock.unlock(); | |
45 | } | |
eb1bab5b BH |
46 | return null; |
47 | } | |
48 | ||
49 | /* | |
50 | * (non-Javadoc) | |
115b4a01 | 51 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseNodeHandler#isEnabled() |
eb1bab5b BH |
52 | */ |
53 | @Override | |
54 | public boolean isEnabled() { | |
c56972bb BH |
55 | boolean isEnabled = false; |
56 | fLock.lock(); | |
57 | try { | |
58 | isEnabled = (super.isEnabled() && (fTargetNode.getTargetNodeState() == TargetNodeState.DISCONNECTED)); | |
59 | } finally { | |
60 | fLock.unlock(); | |
61 | } | |
62 | return isEnabled; | |
eb1bab5b BH |
63 | } |
64 | } |