]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics/src/org/simantics/DatabaseJob.java
Upgrade pdfbox to 2.0.3 and fastutil to 7.0.13 in target platform defs
[simantics/platform.git] / bundles / org.simantics / src / org / simantics / DatabaseJob.java
1 /*******************************************************************************\r
2  * Copyright (c) 2012 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  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics;\r
13 \r
14 import org.eclipse.core.runtime.jobs.IJobManager;\r
15 import org.eclipse.core.runtime.jobs.Job;\r
16 \r
17 /**\r
18  * An Eclipse job that inherently belongs to the\r
19  * {@link Simantics#DATABASE_JOB_FAMILY} job family.\r
20  * \r
21  * <p>\r
22  * Use {@link #inProgress()} to check whether there are currently any\r
23  * {@link DatabaseJob}s running in the platform's job manager. Checks should be\r
24  * performed if any synchronous database requests must be initiated in the UI\r
25  * thread but it is not 100% necessary to return an accurate result right at\r
26  * that moment. Performing too much synchronous requests in the UI thread will\r
27  * currently inevitably get the UI completely stuck and therefore offloading\r
28  * database work to database job worker threads is highly recommended.\r
29  * \r
30  * @author Tuukka Lehtonen\r
31  */\r
32 public abstract class DatabaseJob extends Job {\r
33 \r
34     public static final String DATABASE_JOB_FAMILY = "org.simantics.db.inDatabaseJob";\r
35 \r
36     public DatabaseJob(String name) {\r
37         super(name);\r
38     }\r
39 \r
40     @Override\r
41     public boolean belongsTo(Object family) {\r
42         if (DATABASE_JOB_FAMILY.equals(family))\r
43             return true;\r
44         return super.belongsTo(family);\r
45     }\r
46 \r
47     public static boolean inProgress() {\r
48         IJobManager manager = Job.getJobManager();\r
49         Job[] jobs = manager.find(DATABASE_JOB_FAMILY);\r
50         for (Job job : jobs)\r
51             if (job.getState() == Job.RUNNING)\r
52                 return true;\r
53         return false;\r
54     }\r
55 \r
56 }\r