public boolean test(Object receiver, String property, Object[] arg2, Object expectedValue) {
// Reusing this property tester to test visibility and enablement of the 'migrated' popup menu commands/handlers.
// The receiver can be a structured selection (TreeSelection) or a List.
IServerModule serverModule = null;
IServer server = null;
CloudFoundryServer cloudFoundryServer = null;
// Handle the TreeSelection
if (receiver instanceof StructuredSelection) {
Object obj = ((StructuredSelection)receiver).getFirstElement();
if (obj instanceof IServer) {
server = (IServer) obj;
cloudFoundryServer = (CloudFoundryServer) server.loadAdapter(CloudFoundryServer.class, null);
} else if (obj instanceof IServerModule) {
serverModule = (IServerModule)obj;
cloudFoundryServer = getCloudFoundryServer(serverModule);
}
} // Handle the List
else if (receiver instanceof List) {
List<?> arr = (List<?>) receiver;
if (!arr.isEmpty()) {
Object obj = arr.get(0);
if (obj instanceof IServer) {
server = (IServer) obj;
cloudFoundryServer = (CloudFoundryServer) server.loadAdapter(CloudFoundryServer.class, null);
}
}
} else { // This is the default behaviour, as before
serverModule = getServerModule(receiver);
if (serverModule != null) {
cloudFoundryServer = getCloudFoundryServer(serverModule);
}
}
// Only perform property testing for Cloud Foundry servers.
if (cloudFoundryServer != null) {
CloudFoundryProperties cfProperty = CloudFoundryProperties.valueOf(property);
if (cfProperty != null && expectedValue instanceof Boolean) {
return ((Boolean) expectedValue).booleanValue() == cfProperty.testProperty(serverModule != null ? serverModule.getModule() : null,
cloudFoundryServer);
}
}
return false;