1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 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 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.diagram.query;
\r
14 import org.simantics.db.AsyncReadGraph;
\r
15 import org.simantics.db.Resource;
\r
16 import org.simantics.db.common.request.ResourceAsyncRead;
\r
17 import org.simantics.db.procedure.AsyncProcedure;
\r
18 import org.simantics.diagram.adapter.ElementFactory;
\r
19 import org.simantics.g2d.canvas.impl.DisposedCanvasContext;
\r
20 import org.simantics.g2d.diagram.IDiagram;
\r
21 import org.simantics.g2d.element.ElementClass;
\r
22 import org.simantics.utils.datastructures.hints.IHintObservable;
\r
24 public class ElementClassQuery extends ResourceAsyncRead<ElementClass> {
\r
27 * External hints for loading an element class.
\r
29 IHintObservable hints;
\r
31 public ElementClassQuery(Resource resource, IHintObservable hints) {
\r
37 public void perform(AsyncReadGraph graph, AsyncProcedure<ElementClass> procedure) {
\r
38 graph.forAdapted(resource , ElementFactory.class, createElementClass(procedure));
\r
41 private AsyncProcedure<ElementFactory> createElementClass(final AsyncProcedure<ElementClass> parent) {
\r
42 return new AsyncProcedure<ElementFactory>() {
\r
44 public void exception(AsyncReadGraph graph, Throwable throwable) {
\r
45 parent.exception(graph, throwable);
\r
49 public void execute(AsyncReadGraph graph, ElementFactory factory) {
\r
50 // TODO: remove (IDiagram) cast
\r
51 factory.create(graph, DisposedCanvasContext.INSTANCE, (IDiagram) hints, resource, new AsyncProcedure<ElementClass>() {
\r
53 public void execute(AsyncReadGraph graph, ElementClass result) {
\r
54 parent.execute(graph, result);
\r
57 public void exception(AsyncReadGraph graph, Throwable throwable) {
\r
58 parent.exception(graph, throwable);
\r