blob: 124099a64fc9642742ed1d58bf507d077356865b (
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
52
53
54
55
56
57
58
59
60
61
|
/*****************************************************************************
* 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.tools.util;
import org.eclipse.core.runtime.IProgressMonitor;
/**
* An analogue of the Eclipse JFace {@code IRunnableWithProgress} interface,
* a protocol for executable tasks that can report measurable progress.
* Implementations of the {@link IExecutorService} can supply suitable progress
* reporting to these runnables.
*
* @see IExecutorService
*/
@FunctionalInterface
public interface IProgressRunnable {
/**
* Executes the task.
*
* @param monitor
* for reporting of progress of the task
*/
void run(IProgressMonitor monitor);
/**
* Adapts a plain Java {@code runnable} task to a progress-runnable task.
*
* @param label
* an user-presentable label for the task
* @param runnable
* a plain runnable
*
* @return a progress runnable decorating the plain {@code runnable}
*/
static IProgressRunnable convert(String label, Runnable runnable) {
return progress -> {
if (progress != null) {
progress.beginTask(label, IProgressMonitor.UNKNOWN);
}
try {
runnable.run();
} finally {
if (progress != null) {
progress.done();
}
}
};
}
}
|