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.adapter;
14 import org.simantics.db.AsyncReadGraph;
15 import org.simantics.db.Resource;
16 import org.simantics.db.procedure.AsyncProcedure;
17 import org.simantics.g2d.canvas.ICanvasContext;
18 import org.simantics.g2d.diagram.IDiagram;
19 import org.simantics.g2d.element.ElementClass;
21 public class NodeClassRequest extends BaseRequest2<Resource, ElementClass> {
23 private final IDiagram diagram;
24 private final boolean exceptionOnAdaptionFailure;
26 public NodeClassRequest(ICanvasContext canvas, IDiagram diagram, Resource resource) {
27 this(canvas, diagram, resource, false);
30 public NodeClassRequest(ICanvasContext canvas, IDiagram diagram, Resource resource, boolean exceptionOnAdaptionFailure) {
31 super(canvas, resource);
32 this.diagram = diagram;
33 this.exceptionOnAdaptionFailure = exceptionOnAdaptionFailure;
37 public void perform(AsyncReadGraph graph, final AsyncProcedure<ElementClass> procedure) {
39 graph.forAdapted(data, ElementFactory.class, new AsyncProcedure<ElementFactory>() {
42 public void exception(AsyncReadGraph graph, Throwable throwable) {
43 if (exceptionOnAdaptionFailure)
44 procedure.exception(graph, throwable);
46 procedure.execute(graph, null);
50 public void execute(AsyncReadGraph graph, final ElementFactory factory) {
52 if (factory == null) {
53 // Should never happen since we are using forAdapted
54 System.out.println("No factory in NodeClassRequest! " + this);
55 procedure.execute(graph, null);
59 factory.create(graph, canvas, diagram, data, new AsyncProcedure<ElementClass>() {
62 public void exception(AsyncReadGraph graph, Throwable throwable) {
63 procedure.exception(graph, throwable);
67 public void execute(AsyncReadGraph graph, ElementClass ec) {
68 // System.out.println("Produced element class " + ec);
69 procedure.execute(graph, ec);