Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 3ef011689021814dc173f3996c6b9db0ce8e4dba (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
/*******************************************************************************
 * Copyright (c) 2007 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 v1.0 
 * which accompanies this distribution, and is available at 
 * http://www.eclipse.org/legal/epl-v10.html 
 *  
 * Contributors:
 *     Wind River Systems - initial API and implementation
 *******************************************************************************/
package com.windriver.debug.tcf.ui.commands;

import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.commands.IDebugCommandRequest;
import org.eclipse.debug.core.commands.IDisconnectHandler;
import org.eclipse.debug.core.commands.IEnabledStateRequest;

import com.windriver.debug.tcf.ui.model.TCFModel;
import com.windriver.debug.tcf.ui.model.TCFRunnable;

public class DisconnectCommand implements IDisconnectHandler {

    private final TCFModel model;

    public DisconnectCommand(TCFModel model) {
        this.model = model;
    }

    public void canExecute(final IEnabledStateRequest monitor) {
        new TCFRunnable(model.getDisplay(), monitor) {
            public void run() {
                monitor.setEnabled(model.getLaunch().canDisconnect());
                monitor.setStatus(Status.OK_STATUS);
                done();
            }
        };
    }

    public boolean execute(final IDebugCommandRequest monitor) {
        new TCFRunnable(model.getDisplay(), monitor) {
            public void run() {
                try {
                    model.getLaunch().disconnect();
                    monitor.setStatus(Status.OK_STATUS);
                }
                catch (DebugException x) {
                    monitor.setStatus(x.getStatus());
                }
                done();
            }
        };
        return false;
    }
}

Back to the top