]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/TGProgressMonitor.java
Some fixes for resource cleaning spreadsheets in simupedia
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / util / TGProgressMonitor.java
1 /*******************************************************************************
2  * Copyright (c) 2016 Association for Decentralized Information Management in
3  * Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     Semantum Oy - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.db.layer0.util;
13
14 import org.eclipse.core.runtime.IProgressMonitor;
15 import org.simantics.graph.db.TGStatusMonitor;
16
17 /**
18  * @author Tuukka Lehtonen
19  * @since 1.22.1 & 1.24.0
20  */
21 public class TGProgressMonitor implements TGStatusMonitor {
22
23     protected final IProgressMonitor monitor;
24     private int lastPercentage = 0;
25
26     public TGProgressMonitor(IProgressMonitor monitor) {
27         this.monitor = monitor;
28     }
29
30     @Override
31     public void status(int percentage) {
32         if (percentage > lastPercentage) {
33             monitor.worked(percentage - lastPercentage);
34             workDone(percentage);
35             lastPercentage = percentage;
36         }
37     }
38
39     @Override
40     public boolean isCanceled() {
41         return monitor.isCanceled();
42     }
43
44     protected void workDone(int percentage) {
45     }
46
47 }