]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.district.maps/src/org/simantics/maps/eclipse/TileJob.java
Share some projects for Simantics District
[simantics/district.git] / org.simantics.district.maps / src / org / simantics / maps / eclipse / TileJob.java
diff --git a/org.simantics.district.maps/src/org/simantics/maps/eclipse/TileJob.java b/org.simantics.district.maps/src/org/simantics/maps/eclipse/TileJob.java
new file mode 100644 (file)
index 0000000..e73c6a5
--- /dev/null
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * 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<TileKey, Image> query;
+
+    public TileJob(Query<TileKey, Image> query, ITileProvider provider) {
+        super("Raster Map Request Job");
+        assert(query != null);
+        this.query = query;
+        this.provider = provider;
+    }
+
+    public Query<TileKey, Image> 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;
+    }
+
+}