Merge "Ensure GetElementClassRequest is not constructed without elementFactory"
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / adapter / GetElementClassRequest.java
1 /*******************************************************************************\r
2  * Copyright (c) 2012 Association for Decentralized Information Management in\r
3  * 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
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.diagram.adapter;\r
13 \r
14 import org.simantics.db.AsyncReadGraph;\r
15 import org.simantics.db.Resource;\r
16 import org.simantics.db.common.request.BinaryAsyncRead;\r
17 import org.simantics.db.procedure.AsyncProcedure;\r
18 import org.simantics.g2d.canvas.ICanvasContext;\r
19 import org.simantics.g2d.diagram.IDiagram;\r
20 import org.simantics.g2d.element.ElementClass;\r
21 \r
22 /**\r
23  * @author Tuukka Lehtonen\r
24  * \r
25  * @see CreateElementClassRequest\r
26  * @see NodeRequest\r
27  * @see ConnectionRequest\r
28  */\r
29 class GetElementClassRequest extends BinaryAsyncRead<Resource, ICanvasContext, ElementClass> {\r
30 \r
31     private final ElementFactory elementFactory;\r
32     private final IDiagram       diagram;\r
33 \r
34     public GetElementClassRequest(ElementFactory elementFactory, Resource element, ICanvasContext canvas, IDiagram diagram) {\r
35         super(element, canvas);\r
36         if (elementFactory == null)\r
37             throw new IllegalArgumentException("elementFactory == null for " + element + " in diagram " + diagram + " with context " + canvas);\r
38         this.elementFactory = elementFactory; \r
39         this.diagram = diagram;\r
40     }\r
41 \r
42     @Override\r
43     public void perform(AsyncReadGraph graph, AsyncProcedure<ElementClass> procedure) {\r
44         elementFactory.getClass(graph, parameter2, diagram, parameter, procedure);\r
45     }\r
46 \r
47 }