--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.diagram.query;\r
+\r
+import org.simantics.db.AsyncReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.ResourceAsyncRead;\r
+import org.simantics.db.procedure.AsyncProcedure;\r
+import org.simantics.diagram.adapter.ElementFactory;\r
+import org.simantics.g2d.canvas.impl.DisposedCanvasContext;\r
+import org.simantics.g2d.diagram.IDiagram;\r
+import org.simantics.g2d.element.ElementClass;\r
+import org.simantics.utils.datastructures.hints.IHintObservable;\r
+\r
+public class ElementClassQuery extends ResourceAsyncRead<ElementClass> {\r
+\r
+ /**\r
+ * External hints for loading an element class.\r
+ */\r
+ IHintObservable hints;\r
+\r
+ public ElementClassQuery(Resource resource, IHintObservable hints) {\r
+ super(resource);\r
+ this.hints = hints;\r
+ }\r
+\r
+ @Override\r
+ public void perform(AsyncReadGraph graph, AsyncProcedure<ElementClass> procedure) {\r
+ graph.forAdapted(resource , ElementFactory.class, createElementClass(procedure));\r
+ }\r
+\r
+ private AsyncProcedure<ElementFactory> createElementClass(final AsyncProcedure<ElementClass> parent) {\r
+ return new AsyncProcedure<ElementFactory>() {\r
+ @Override\r
+ public void exception(AsyncReadGraph graph, Throwable throwable) {\r
+ parent.exception(graph, throwable);\r
+ }\r
+\r
+ @Override\r
+ public void execute(AsyncReadGraph graph, ElementFactory factory) {\r
+ // TODO: remove (IDiagram) cast\r
+ factory.create(graph, DisposedCanvasContext.INSTANCE, (IDiagram) hints, resource, new AsyncProcedure<ElementClass>() {\r
+ @Override\r
+ public void execute(AsyncReadGraph graph, ElementClass result) {\r
+ parent.execute(graph, result);\r
+ }\r
+ @Override\r
+ public void exception(AsyncReadGraph graph, Throwable throwable) {\r
+ parent.exception(graph, throwable);\r
+ }\r
+ });\r
+ }\r
+ };\r
+ }\r
+\r
+}\r