diff options
Diffstat (limited to 'plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/utils/IPapyrusRunnable.java')
-rw-r--r-- | plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/utils/IPapyrusRunnable.java | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/utils/IPapyrusRunnable.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/utils/IPapyrusRunnable.java new file mode 100644 index 00000000000..4c8d2f1d008 --- /dev/null +++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/utils/IPapyrusRunnable.java @@ -0,0 +1,49 @@ +/***************************************************************************** + * 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. + */ +@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; + } + }; + } +} |