1 /*******************************************************************************
\r
2 * Copyright (c) 2012 Association for Decentralized Information Management in
\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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics;
\r
14 import org.eclipse.core.runtime.jobs.IJobManager;
\r
15 import org.eclipse.core.runtime.jobs.Job;
\r
18 * An Eclipse job that inherently belongs to the
\r
19 * {@link Simantics#DATABASE_JOB_FAMILY} job family.
\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
30 * @author Tuukka Lehtonen
\r
32 public abstract class DatabaseJob extends Job {
\r
34 public static final String DATABASE_JOB_FAMILY = "org.simantics.db.inDatabaseJob";
\r
36 public DatabaseJob(String name) {
\r
41 public boolean belongsTo(Object family) {
\r
42 if (DATABASE_JOB_FAMILY.equals(family))
\r
44 return super.belongsTo(family);
\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