]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram/src/org/simantics/diagram/query/ElementClassQuery.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / query / ElementClassQuery.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 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.diagram.query;
13
14 import org.simantics.db.AsyncReadGraph;
15 import org.simantics.db.Resource;
16 import org.simantics.db.common.request.ResourceAsyncRead;
17 import org.simantics.db.procedure.AsyncProcedure;
18 import org.simantics.diagram.adapter.ElementFactory;
19 import org.simantics.g2d.canvas.impl.DisposedCanvasContext;
20 import org.simantics.g2d.diagram.IDiagram;
21 import org.simantics.g2d.element.ElementClass;
22 import org.simantics.utils.datastructures.hints.IHintObservable;
23
24 public class ElementClassQuery extends ResourceAsyncRead<ElementClass> {
25
26     /**
27      * External hints for loading an element class.
28      */
29     IHintObservable hints;
30
31     public ElementClassQuery(Resource resource, IHintObservable hints) {
32         super(resource);
33         this.hints = hints;
34     }
35
36     @Override
37     public void perform(AsyncReadGraph graph, AsyncProcedure<ElementClass> procedure) {
38         graph.forAdapted(resource , ElementFactory.class, createElementClass(procedure));
39     }
40
41     private AsyncProcedure<ElementFactory> createElementClass(final AsyncProcedure<ElementClass> parent) {
42         return new AsyncProcedure<ElementFactory>() {
43             @Override
44             public void exception(AsyncReadGraph graph, Throwable throwable) {
45                 parent.exception(graph, throwable);
46             }
47
48             @Override
49             public void execute(AsyncReadGraph graph, ElementFactory factory) {
50                 // TODO: remove (IDiagram) cast
51                 factory.create(graph, DisposedCanvasContext.INSTANCE, (IDiagram) hints, resource, new AsyncProcedure<ElementClass>() {
52                     @Override
53                     public void execute(AsyncReadGraph graph, ElementClass result) {
54                         parent.execute(graph, result);
55                     }
56                     @Override
57                     public void exception(AsyncReadGraph graph, Throwable throwable) {
58                         parent.exception(graph, throwable);
59                     }
60                 });
61             }
62         };
63     }
64
65 }