Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: c4a762c15fe26c7a9b004790483ea41fbfdf33ae (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
/*******************************************************************************
 * Copyright (c) 2006 Wind River Systems 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.dd.dsf.ui.viewmodel.datamodel;

import org.eclipse.dd.dsf.datamodel.DMContexts;
import org.eclipse.dd.dsf.datamodel.IDMContext;
import org.eclipse.dd.dsf.datamodel.IDMEvent;
import org.eclipse.dd.dsf.ui.viewmodel.AbstractVMProvider;
import org.eclipse.dd.dsf.ui.viewmodel.IRootVMNode;
import org.eclipse.dd.dsf.ui.viewmodel.RootVMNode;

/**
 * This is is a standard root node which listens to the selection in Debug View.
 * Views such as variables and registers base their content on the 
 * selection in Debug view, and this node provides tracking of that selection.
 * <p>
 * Note: The variables/registers views track the selection using the same 
 * IDebugContextListener interface, but they only use the first element of the 
 * selection, as in IStructuredSelection.getFirstElement().  Therefore the root 
 * node also has to use the first element as the root object instead of the 
 * whole selection. 
 */
public class RootDMVMNode extends RootVMNode 
    implements IRootVMNode
{
    public RootDMVMNode(AbstractVMProvider provider) {
        super(provider);
    }

    /**
     * If the input object is a Data Model context, and the event is a DMC event.
     * Then we can filter the event to make sure that the view does not
     * react to events that relate to objects outside this view.
     * 
     * The logic is such: 
     * - iterate through the full hierarchy of the DMC in the event,
     * - for each DMC in event, search for a DMC of the same type in the input 
     * event,
     * - if an ancestor of that type is found, it indicates that the event 
     * and the input object share the same hierarchy
     * - finally compare the DMContexts from the event to the DMC from the input 
     * object, 
     * - if there is a match then we know that the event relates
     * to the hierarchy in view,  
     * - if there is no match, then we know that the event related to a
     * some sibling of the input object, and no delta should be generated,
     * - if none of the ancestor types matched, then the event is completely
     * unrelated to the input object, and the layout nodes in the view must
     * determine whether a delta is needed. 
     */
    @Override
    public boolean isDeltaEvent(Object rootObject, Object event) {
        if (rootObject instanceof IDMVMContext) {
            IDMContext inputDmc = ((IDMVMContext)rootObject).getDMContext();
            if (event instanceof IDMEvent && inputDmc != null) {
                boolean potentialMatchFound = false;
                boolean matchFound = false;
                
                IDMContext eventDmc = ((IDMEvent<?>)event).getDMContext();
                for (IDMContext eventDmcAncestor : DMContexts.toList(eventDmc)) {
                    IDMContext inputDmcAncestor = DMContexts.getAncestorOfType(inputDmc, eventDmcAncestor.getClass()); 
                    if (inputDmcAncestor != null) {
                        potentialMatchFound = true;
                        if (inputDmcAncestor.equals(eventDmcAncestor)) {
                            return true;
                        }
                    }
                }
                if (potentialMatchFound && !matchFound) {
                    return false;
                }
            }
        }
        
        return true;
    }
    
}

Back to the top