Fix findbugs warnings + address concurrency issues in handlers
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui / src / org / eclipse / linuxtools / internal / lttng2 / ui / views / control / handlers / DeleteHandler.java
CommitLineData
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 12package org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers;
eb1bab5b
BH
13
14import org.eclipse.core.commands.ExecutionEvent;
15import org.eclipse.core.commands.ExecutionException;
115b4a01
BH
16import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent;
17import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TargetNodeState;
eb1bab5b
BH
18
19/**
20 * <b><u>DeleteHandler</u></b>
21 * <p>
22 * Command handler implementation to delete a target host.
23 * </p>
24 */
25public class DeleteHandler extends BaseNodeHandler {
26
27 // ------------------------------------------------------------------------
28 // Operations
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 {
38 ITraceControlComponent root = fTargetNode.getParent();
39 fTargetNode.removeAllChildren();
40 root.removeChild(fTargetNode);
41 } finally {
42 fLock.unlock();
43 }
eb1bab5b
BH
44 return null;
45 }
46
47 /*
48 * (non-Javadoc)
115b4a01 49 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseNodeHandler#isEnabled()
eb1bab5b
BH
50 */
51 @Override
52 public boolean isEnabled() {
c56972bb
BH
53 boolean isEnabled = false;
54 fLock.lock();
55 try {
56 isEnabled = (super.isEnabled() && (fTargetNode.getTargetNodeState() == TargetNodeState.DISCONNECTED));
57 } finally {
58 fLock.unlock();
59 }
60 return isEnabled;
eb1bab5b
BH
61 }
62}
This page took 0.035153 seconds and 5 git commands to generate.