1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.diagram.query;
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;
24 public class ElementClassQuery extends ResourceAsyncRead<ElementClass> {
27 * External hints for loading an element class.
29 IHintObservable hints;
31 public ElementClassQuery(Resource resource, IHintObservable hints) {
37 public void perform(AsyncReadGraph graph, AsyncProcedure<ElementClass> procedure) {
38 graph.forAdapted(resource , ElementFactory.class, createElementClass(procedure));
41 private AsyncProcedure<ElementFactory> createElementClass(final AsyncProcedure<ElementClass> parent) {
42 return new AsyncProcedure<ElementFactory>() {
44 public void exception(AsyncReadGraph graph, Throwable throwable) {
45 parent.exception(graph, throwable);
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>() {
53 public void execute(AsyncReadGraph graph, ElementClass result) {
54 parent.execute(graph, result);
57 public void exception(AsyncReadGraph graph, Throwable throwable) {
58 parent.exception(graph, throwable);