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 // System.out.println("NodeClassRequest " + data.getResourceId());
40 // graph.asyncRequest(new SafeName(data), new Procedure<String>() {
42 // public void exception(Throwable t) {
45 // public void execute(String result) {
46 // System.out.println("NodeClassRequest " + result);
51 graph.forAdapted(data, ElementFactory.class, new AsyncProcedure<ElementFactory>() {
54 public void exception(AsyncReadGraph graph, Throwable throwable) {
55 if (exceptionOnAdaptionFailure)
56 procedure.exception(graph, throwable);
58 procedure.execute(graph, null);
62 public void execute(AsyncReadGraph graph, final ElementFactory factory) {
64 // System.out.println("NodeClassRequest factory " + data.getResourceId() + " = " + factory.getClass().getName());
65 // graph.asyncRequest(new SafeName(data), new Procedure<String>() {
67 // public void exception(Throwable t) {
70 // public void execute(String result) {
71 // System.out.println("NodeClassRequest " + result + " " + factory.getClass().getName());
76 if (factory == null) {
77 // Should never happen since we are using forAdapted
78 System.out.println("No factory in NodeClassRequest! " + this);
79 procedure.execute(graph, null);
83 factory.create(graph, canvas, diagram, data, new AsyncProcedure<ElementClass>() {
86 public void exception(AsyncReadGraph graph, Throwable throwable) {
87 procedure.exception(graph, throwable);
91 public void execute(AsyncReadGraph graph, ElementClass ec) {
92 // System.out.println("Produced element class " + ec);
93 procedure.execute(graph, ec);