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