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