blob: a08be8c70de67860647a42d86fd8a767254199dd (
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
|
/*****************************************************************************
* Copyright (c) 2016 Christian W. Damus 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:
* Christian W. Damus - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.infra.core.utils;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.papyrus.infra.core.services.ServiceException;
import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
import org.eclipse.papyrus.infra.tools.util.IProgressRunnable;
/**
* Protocol for a runnable in the Papyrus context.
*
* @since 2.0
*/
@FunctionalInterface
public interface IPapyrusRunnable extends IProgressRunnable, IServiceRegistryProvider {
@Override
default ServicesRegistry getServiceRegistry() {
try {
return ServiceUtils.getInstance().getServiceRegistry(null);
} catch (ServiceException e) {
return null;
}
}
static IPapyrusRunnable inContext(ServicesRegistry registry, IPapyrusRunnable runnable) {
return new IPapyrusRunnable() {
@Override
public void run(IProgressMonitor monitor) {
runnable.run(monitor);
}
@Override
public ServicesRegistry getServiceRegistry() {
return registry;
}
};
}
}
|