blob: 8e795f2b1b9a391731f5bba93df031ab10f1252d (
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
/*******************************************************************************
* Copyright (c) 2007, 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.tcf.internal.debug.ui.model;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelSelectionPolicy;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
import org.eclipse.debug.ui.IDebugUIConstants;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.tcf.internal.debug.model.TCFContextState;
import org.eclipse.tcf.services.IRunControl;
import org.eclipse.tcf.util.TCFDataCache;
import org.eclipse.tcf.util.TCFTask;
class TCFModelSelectionPolicy implements IModelSelectionPolicy {
private final TCFModel model;
TCFModelSelectionPolicy(TCFModel model) {
this.model = model;
}
public boolean contains(ISelection selection, IPresentationContext context) {
if (selection instanceof IStructuredSelection) {
IStructuredSelection ss = (IStructuredSelection)selection;
Object e = ss.getFirstElement();
if (e instanceof TCFNode) {
TCFNode n = (TCFNode)e;
return !n.isDisposed() && n.model == model;
}
}
return false;
}
public boolean isSticky(ISelection selection, IPresentationContext context) {
if (selection instanceof IStructuredSelection) {
IStructuredSelection ss = (IStructuredSelection)selection;
Object e = ss.getFirstElement();
if (e instanceof TCFNode) return getSuspendReason((TCFNode)e) != null;
}
return false;
}
private String getSuspendReason(final TCFNode node) {
return new TCFTask<String>() {
public void run() {
TCFNode n = node;
while (n != null && !n.isDisposed()) {
if (n instanceof TCFNodeExecContext) {
TCFDataCache<TCFContextState> cache = ((TCFNodeExecContext)n).getState();
if (!cache.validate(this)) return;
TCFContextState state = cache.getData();
if (state != null && state.is_suspended) {
if (state.suspend_reason == null) {
done(IRunControl.REASON_USER_REQUEST);
}
else {
done(state.suspend_reason);
}
return;
}
}
n = n.parent;
}
done(null);
}
}.getE();
}
public boolean overrides(ISelection existing, ISelection candidate, IPresentationContext context) {
if (IDebugUIConstants.ID_DEBUG_VIEW.equals(context.getId())) {
if (existing instanceof IStructuredSelection && candidate instanceof IStructuredSelection) {
Object el_existing = ((IStructuredSelection)existing).getFirstElement();
Object el_candidate = ((IStructuredSelection)candidate).getFirstElement();
if (el_existing == null) return true;
if (el_existing == el_candidate) return true;
if (el_existing instanceof TCFNode && el_candidate instanceof TCFNode) {
if (el_existing instanceof TCFNodeStackFrame && el_candidate instanceof TCFNodeStackFrame) {
TCFNodeStackFrame curr = (TCFNodeStackFrame)el_existing;
TCFNodeStackFrame next = (TCFNodeStackFrame)el_candidate;
if (curr.parent == next.parent) return true;
}
if (el_existing instanceof TCFNodeStackFrame && el_candidate instanceof TCFNodeExecContext) {
TCFNodeStackFrame curr = (TCFNodeStackFrame)el_existing;
TCFNodeExecContext next = (TCFNodeExecContext)el_candidate;
if (curr.parent == next) return true;
}
String s1 = getSuspendReason((TCFNode)el_existing);
if (s1 == null) return true;
String s2 = getSuspendReason((TCFNode)el_candidate);
if (s2 == null) return false;
if (s2.equals(IRunControl.REASON_USER_REQUEST)) return false;
if (s2.equals(IRunControl.REASON_CONTAINER)) return false;
if (s1.equals(IRunControl.REASON_USER_REQUEST)) return true;
if (s1.equals(IRunControl.REASON_CONTAINER)) return true;
return false;
}
}
}
return true;
}
public ISelection replaceInvalidSelection(ISelection existing, ISelection candidate) {
if (existing instanceof IStructuredSelection && candidate instanceof IStructuredSelection) {
Object el_existing = ((IStructuredSelection)existing).getFirstElement();
Object el_candidate = ((IStructuredSelection)candidate).getFirstElement();
if (el_candidate == null) {
if (el_existing == null) return new StructuredSelection(model.getLaunch());
if (el_existing instanceof TCFNode) {
TCFNode node = (TCFNode)el_existing;
if (node.parent == null || node.parent instanceof TCFNodeLaunch) {
return new StructuredSelection(model.getLaunch());
}
return new StructuredSelection(node.parent);
}
}
}
return candidate;
}
}
|