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
|
/*******************************************************************************
* Copyright (c) 2008, 2012 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.cdt.dsf.debug.internal.ui.viewmodel.actions;
import org.eclipse.cdt.dsf.debug.ui.viewmodel.actions.VMHandlerUtils;
import org.eclipse.cdt.dsf.ui.viewmodel.IVMContext;
import org.eclipse.cdt.dsf.ui.viewmodel.IVMProvider;
import org.eclipse.cdt.dsf.ui.viewmodel.update.ICachingVMProvider;
import org.eclipse.cdt.dsf.ui.viewmodel.update.IVMUpdatePolicy;
import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.debug.ui.IDebugView;
import org.eclipse.ui.IWorkbenchPart;
/**
* Property tester for update policy information available through the given
* object. The object being tested should be either an {@link IVMContext},
* through which an instance of {@link ICachingVMProvider} could be obtained.
* Or it could be an {@link IWorkbenchPart}, which is tested to see if it
* is a debug view through which a caching VM provider can be obtained.
* The Caching View Model provider is used to test the given property.
* <p>
* Three properties are supported:
* <ul>
* <li> "areUpdatePoliciesSupported" - Checks whether update policies are
* available at all given the receiver.</li>
* <li> "isUpdatePolicyAvailable" - Checks whether the update policy in the
* expected value is available for the given receiver.</li>
* <li> "isUpdatePolicyActive" - Checks whether the policy given in the expected
* value is the currently active policy for the given receiver.</li>
* </ul>
* </p>
*/
public class UpdatePoliciesPropertyTester extends PropertyTester {
private static final String SUPPORTED = "areUpdatePoliciesSupported"; //$NON-NLS-1$
private static final String AVAILABLE = "isUpdatePolicyAvailable"; //$NON-NLS-1$
private static final String ACTIVE = "isUpdatePolicyActive"; //$NON-NLS-1$
@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
if (receiver instanceof IVMContext) {
IVMProvider provider = ((IVMContext)receiver).getVMNode().getVMProvider();
if (provider instanceof ICachingVMProvider) {
return testProvider((ICachingVMProvider)provider, property, expectedValue);
}
} else if (receiver instanceof IDebugView) {
IVMProvider provider = VMHandlerUtils.getVMProviderForPart((IDebugView)receiver);
if (provider instanceof ICachingVMProvider) {
return testProvider((ICachingVMProvider)provider, property, expectedValue);
}
}
return false;
}
private boolean testProvider(ICachingVMProvider provider, String property, Object expectedValue) {
if (SUPPORTED.equals(property)) {
return true;
} else if (AVAILABLE.equals(property)) {
for (IVMUpdatePolicy policy : provider.getAvailableUpdatePolicies()) {
if (policy.getID().equals(expectedValue)) {
return true;
}
return false;
}
} else if (ACTIVE.equals(property)) {
return expectedValue != null && expectedValue.equals(provider.getActiveUpdatePolicy().getID());
}
return false;
}
}
|