/******************************************************************************* * Copyright (c) 2012 Association for Decentralized Information Management * in Industry THTH ry. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ package org.simantics.maps.eclipse; import java.awt.Image; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; import org.simantics.maps.query.Query; import org.simantics.maps.tile.ITileProvider; import org.simantics.maps.tile.TileKey; /** * @author Tuukka Lehtonen * @see TileJobQueue */ public class TileJob extends Job { private ITileProvider provider; private Query query; public TileJob(Query query, ITileProvider provider) { super("Raster Map Request Job"); assert(query != null); this.query = query; this.provider = provider; } public Query getQuery() { return query; } @Override protected IStatus run(IProgressMonitor monitor) { setThread(Thread.currentThread()); monitor.beginTask("Querying map data", 1); try { // Check if canceled if (monitor.isCanceled()) { cancel(); return Status.CANCEL_STATUS; } // Query try { monitor.subTask(query.source.toString()); Image result = provider.get(query.source); query.listener.queryComplete(query, result); } catch (Exception e) { query.listener.queryFailed(query, e); } monitor.worked(1); monitor.subTask(""); } finally { monitor.done(); } return Status.OK_STATUS; } }