1 /*******************************************************************************
2 * Copyright (c) 2013 Association for Decentralized Information Management
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
10 * Semantum Oy - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.browsing.ui.swt;
14 import java.util.concurrent.atomic.AtomicBoolean;
16 import org.eclipse.core.runtime.IProgressMonitor;
17 import org.eclipse.core.runtime.IStatus;
18 import org.eclipse.core.runtime.Status;
19 import org.eclipse.core.runtime.jobs.Job;
20 import org.eclipse.ui.progress.IProgressConstants;
21 import org.simantics.DatabaseJob;
24 * @author Tuukka Lehtonen
26 public class ImageLoaderJob extends DatabaseJob {
28 private GraphExplorerImplBase ge;
29 private AtomicBoolean isScheduled = new AtomicBoolean();
31 public ImageLoaderJob(GraphExplorerImplBase ge) {
32 super("Image Loader");
36 setPriority(Job.DECORATE);
37 setProperty(IProgressConstants.NO_IMMEDIATE_ERROR_PROMPT_PROPERTY, Boolean.TRUE);
41 * Schedules the job with {@link Job#schedule()} if necessary, i.e. if
42 * not already scheduled. This method avoids some unnecessary overhead
43 * caused by repeatedly invoking {@link Job#schedule()}.
45 * @return <code>true</code> if scheduled, <code>false</code> otherwise
47 public boolean scheduleIfNecessary(long delay) {
48 if (isScheduled.compareAndSet(false, true)) {
56 public boolean shouldRun() {
61 public boolean shouldSchedule() {
66 protected IStatus run(IProgressMonitor monitor) {
68 isScheduled.set(false);
69 GraphExplorerImplBase ge = this.ge;
70 return (ge != null) ? ge.setPendingImages(monitor) : Status.CANCEL_STATUS;
76 public void dispose() {