Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 6658ec5da3ac19169682deb47f5422592db50b12 (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
77
78
79
80
81
82
83
84
85
86
87
/*******************************************************************************
 * Copyright (c) 2011 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 org.eclipse.tm.internal.tcf.debug.ui.commands;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.debug.ui.IDebugUIConstants;
import org.eclipse.debug.ui.IDebugView;
import org.eclipse.debug.ui.memory.IMemoryRenderingSite;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.tm.internal.tcf.debug.ui.model.TCFModel;
import org.eclipse.tm.internal.tcf.debug.ui.model.TCFNode;
import org.eclipse.tm.internal.tcf.debug.ui.model.TCFNodeExecContext;
import org.eclipse.tm.tcf.util.TCFDataCache;
import org.eclipse.tm.tcf.util.TCFTask;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchPartSite;
import org.eclipse.ui.handlers.HandlerUtil;

public class RefreshHandler extends AbstractHandler {

    public Object execute(ExecutionEvent event) throws ExecutionException {
        Object input = null;
        final IWorkbenchPart part = HandlerUtil.getActivePart(event);
        if (part instanceof IMemoryRenderingSite) {
            IWorkbenchPartSite site = part.getSite();
            if (site != null) {
                ISelection selection = DebugUITools.getDebugContextManager().getContextService(
                        site.getWorkbenchWindow()).getActiveContext();
                if (selection instanceof IStructuredSelection) {
                    input = ((IStructuredSelection)selection).getFirstElement();
                }
            }
        }
        else if (part instanceof IDebugView) {
            IWorkbenchPartSite site = part.getSite();
            if (site != null && IDebugUIConstants.ID_DEBUG_VIEW.equals(site.getId())) {
                ISelection selection = HandlerUtil.getCurrentSelection(event);
                if (selection instanceof IStructuredSelection) {
                    Object obj = ((IStructuredSelection)selection).getFirstElement();
                    if (obj instanceof TCFNode) input = ((TCFNode)obj).getModel().getRootNode();
                }
            }
            else {
                input = ((IDebugView)part).getViewer().getInput();
            }
        }
        if (input instanceof TCFNode) {
            final TCFNode node = (TCFNode)input;
            return new TCFTask<Object>(node.getChannel()) {
                public void run() {
                    TCFModel model = node.getModel();
                    TCFNode ref_node = node;
                    if (part instanceof IMemoryRenderingSite) {
                        // Search memory node
                        TCFDataCache<TCFNodeExecContext> mem_cache = model.searchMemoryContext(node);
                        if (mem_cache == null) {
                            done(null);
                            return;
                        }
                        if (!mem_cache.validate(this)) return;
                        ref_node = mem_cache.getData();
                    }
                    if (ref_node != null) {
                        ref_node.refresh(part);
                        if (model.clearLock(part)) {
                            model.setLock(part);
                        }
                    }
                    done(null);
                }
            }.getE();
        }
        return null;
    }
}

Back to the top