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
|
/*****************************************************************
* Copyright (c) 2011 Texas Instruments 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:
* Winnie Lai (Texas Instruments) - Individual Element Number Format (Bug 202556)
*****************************************************************/
package org.eclipse.cdt.tests.dsf.vm;
import java.util.HashSet;
import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor;
import org.eclipse.cdt.dsf.debug.ui.viewmodel.numberformat.IElementFormatProvider;
import org.eclipse.cdt.dsf.debug.ui.viewmodel.update.ElementFormatEvent;
import org.eclipse.cdt.dsf.service.DsfSession;
import org.eclipse.cdt.dsf.ui.viewmodel.AbstractVMAdapter;
import org.eclipse.cdt.dsf.ui.viewmodel.IVMContext;
import org.eclipse.cdt.dsf.ui.viewmodel.IVMNode;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
import org.eclipse.jface.viewers.TreePath;
/**
* Test view model provider that supports element format provider interface.
* This class is used in test cases and can be extended to support other
* optional interfaces
*/
class TestElementFormatVMProvider extends TestModelCachingVMProvider implements IElementFormatProvider {
public int elementFormatApplyDepth = 1;
String myPersistId = "org.eclipse.cdt.tests.dsf.vm.testElementFormatVMProvider";
public TestElementFormatVMProvider(AbstractVMAdapter adapter,
IPresentationContext context, DsfSession session) {
super(adapter, context, session);
}
@Override
public void getActiveFormat(IPresentationContext context, IVMNode node,
Object viewerInput, TreePath elementPath, DataRequestMonitor<String> rm) {
Object p = context.getProperty(myPersistId);
if (p instanceof TestPersistable == false) {
rm.setData(null);
rm.done();
return;
}
TestPersistable persistable = (TestPersistable) p;
int end = elementPath.getSegmentCount();
int start = elementPath.getSegmentCount() - 1;
if (elementFormatApplyDepth == -1) {
start = 0;
} else if (elementFormatApplyDepth >= 1) {
start = elementPath.getSegmentCount() - elementFormatApplyDepth;
}
if (start < 0)
start = 0;
for (int i = end; --i >= start;) {
Object x = elementPath.getSegment(i);
if (x instanceof TestElementVMContext) {
String s = ((TestElementVMContext) x).getElement().getID();
String format = persistable.getFormat(s);
if (format != null) {
rm.setData(format);
rm.done();
return;
}
}
}
rm.setData(null);
rm.done();
}
@Override
public void setActiveFormat(IPresentationContext context, IVMNode[] node,
Object viewerInput, TreePath[] elementPath, String format) {
Object p = context.getProperty(myPersistId);
TestPersistable persistable = null;
if (p instanceof TestPersistable) {
persistable = (TestPersistable) p;
} else {
persistable = new TestPersistable();
context.setProperty(myPersistId, persistable);
}
HashSet<Object> changed = new HashSet<Object>(elementPath.length);
for (int i = 0; i < elementPath.length; i++) {
Object x = elementPath[i].getLastSegment();
if (x instanceof TestElementVMContext) {
String s = ((TestElementVMContext) x).getElement().getID();
persistable.setFormat(s, format);
changed.add(x);
}
}
if (changed.size() > 0) {
// this.refresh();
handleEvent(new ElementFormatEvent(changed, elementFormatApplyDepth));
}
}
@Override
public boolean supportFormat(IVMContext context) {
return true;
}
}
|