1 package org.simantics.graph.db;
3 public interface TGStatusMonitor {
5 void status(int percentage);
8 public static class NullMonitor implements TGStatusMonitor {
10 public void status(int percentage) {
13 public boolean isCanceled() {
18 public static final TGStatusMonitor NULL_MONITOR = new NullMonitor();
20 public static class Updater {
21 private final TGStatusMonitor monitor;
22 private final int total;
28 public Updater(TGStatusMonitor monitor, int lowPercentage, int highPercentage, int totalWork) {
29 this.monitor = monitor;
30 this.low = lowPercentage;
31 this.high = highPercentage;
32 this.total = totalWork;
35 public int worked(int work) {
37 return current = updatePercentage(monitor, low, high, current, worked, total);
41 public static int updatePercentage(TGStatusMonitor monitor, int low, int high, int oldPercentage, int done, int total) {
42 int range = high - low;
43 int current = low + (range * done) / total;
44 if (current != oldPercentage) {
45 oldPercentage = current;
47 monitor.status(oldPercentage);