1 package org.simantics.graph.db;
\r
3 public interface TGStatusMonitor {
\r
5 void status(int percentage);
\r
6 boolean isCanceled();
\r
8 public static class NullMonitor implements TGStatusMonitor {
\r
10 public void status(int percentage) {
\r
13 public boolean isCanceled() {
\r
18 public static final TGStatusMonitor NULL_MONITOR = new NullMonitor();
\r
20 public static class Updater {
\r
21 private final TGStatusMonitor monitor;
\r
22 private final int total;
\r
23 private int percentage;
\r
26 public Updater(TGStatusMonitor monitor, int total) {
\r
27 this.monitor = monitor;
\r
31 public int worked(int work) {
\r
33 return percentage = updatePercentage(monitor, percentage, worked, total);
\r
37 public static int updatePercentage(TGStatusMonitor monitor, int oldPercentage, int done, int total) {
\r
38 int current = (100 * done) / total;
\r
39 if (current > oldPercentage) {
\r
40 oldPercentage = current;
\r
41 if (monitor != null)
\r
42 monitor.status(oldPercentage);
\r
44 return oldPercentage;
\r