Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: f5003113ec64bcaa877f5852808b04bc2f43cdee (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*******************************************************************************
 * Copyright (c) 2011, 2012 Wind River Systems, Inc. and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * Contributors:
 *     Wind River Systems - initial API and implementation
 *******************************************************************************/
package org.eclipse.tcf.internal.debug.ui.commands;

import org.eclipse.tcf.internal.debug.ui.model.TCFNode;
import org.eclipse.tcf.internal.debug.ui.model.TCFNodeExecContext;
import org.eclipse.tcf.protocol.IToken;
import org.eclipse.tcf.services.IRunControl;
import org.eclipse.tcf.util.TCFDataCache;
import org.eclipse.tcf.util.TCFTask;

public class DetachCommand extends AbstractActionDelegate {

    private static boolean run(TCFNode[] nodes, final boolean dry_run) {
        if (nodes == null || nodes.length == 0) return false;
        for (TCFNode n : nodes) {
            boolean ok = false;
            while (!ok && n != null) {
                if (n instanceof TCFNodeExecContext) {
                    final TCFNodeExecContext exe = (TCFNodeExecContext)n;
                    ok = new TCFTask<Boolean>(n.getChannel()) {
                        public void run() {
                            TCFDataCache<IRunControl.RunControlContext> ctx_cache = exe.getRunContext();
                            if (!ctx_cache.validate(this)) return;
                            IRunControl.RunControlContext ctx_data = ctx_cache.getData();
                            if (ctx_data != null && ctx_data.canDetach()) {
                                if (dry_run) {
                                    done(true);
                                }
                                else {
                                    ctx_data.detach(new IRunControl.DoneCommand() {
                                        public void doneCommand(IToken token, Exception error) {
                                            if (error != null) {
                                                error(error);
                                            }
                                            else {
                                                exe.getModel().getLaunch().onDetach(exe.getID());
                                                done(true);
                                            }
                                        }
                                    });
                                }
                            }
                            else {
                                done(false);
                            }
                        }
                    }.getE();
                }
                n = n.getParent();
            }
            if (!ok) return false;
        }
        return true;
    }

    @Override
    protected void selectionChanged() {
        setEnabled(run(getSelectedNodes(), true));
    }

    @Override
    protected void run() {
        TCFNode[] nodes = getSelectedNodes();
        if (!run(nodes, true)) return;
        run(nodes, false);
    }
}

Back to the top