]> gerrit.simantics Code Review - simantics/district.git/blob - 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
1 /*******************************************************************************
2  * Copyright (c) 2012 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.maps.eclipse;
13
14 import java.awt.Image;
15
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.simantics.maps.query.Query;
21 import org.simantics.maps.tile.ITileProvider;
22 import org.simantics.maps.tile.TileKey;
23
24 /**
25  * @author Tuukka Lehtonen
26  * @see TileJobQueue
27  */
28 public class TileJob extends Job {
29
30     private ITileProvider provider;
31     private Query<TileKey, Image> query;
32
33     public TileJob(Query<TileKey, Image> query, ITileProvider provider) {
34         super("Raster Map Request Job");
35         assert(query != null);
36         this.query = query;
37         this.provider = provider;
38     }
39
40     public Query<TileKey, Image> getQuery() {
41         return query;
42     }
43
44     @Override
45     protected IStatus run(IProgressMonitor monitor) {
46         setThread(Thread.currentThread());
47         monitor.beginTask("Querying map data", 1);
48         try {
49             // Check if canceled
50             if (monitor.isCanceled()) {
51                 cancel();
52                 return Status.CANCEL_STATUS;
53             }
54             // Query
55             try {
56                 monitor.subTask(query.source.toString());
57                 Image result = provider.get(query.source);
58                 query.listener.queryComplete(query, result);
59             } catch (Exception e) {
60                 query.listener.queryFailed(query, e);
61             }
62             monitor.worked(1);
63             monitor.subTask("");
64         } finally {
65             monitor.done();
66         }
67         return Status.OK_STATUS;
68     }
69
70 }