]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/CreateElementClassRequest.java
Merge "Fixed diagram copy/paste implementations to re-identify diagram elements"
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / adapter / CreateElementClassRequest.java
1 /*******************************************************************************
2  * Copyright (c) 2012 Association for Decentralized Information Management in
3  * Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.diagram.adapter;
13
14 import org.simantics.db.AsyncReadGraph;
15 import org.simantics.db.Resource;
16 import org.simantics.db.common.request.BinaryAsyncRead;
17 import org.simantics.db.procedure.AsyncProcedure;
18 import org.simantics.g2d.canvas.ICanvasContext;
19 import org.simantics.g2d.diagram.IDiagram;
20 import org.simantics.g2d.element.ElementClass;
21
22 /**
23  * A request for retrieving an ElementClass based on an {@link ElementFactory},
24  * an element type (Resource), {@link ICanvasContext} and {@link IDiagram}. Only
25  * the canvas context and the element type are considered to identify the
26  * request uniquely. ElementFactory is not a part of the identification since
27  * element factories are originally resolved from element types and the at least
28  * the current implementations do not have proper equals/hashCode
29  * implementations which of destroys the possibility of DB request caching.
30  * 
31  * @author Tuukka Lehtonen
32  */
33 class CreateElementClassRequest extends BinaryAsyncRead<Resource, ICanvasContext, ElementClass> {
34
35     private final ElementFactory elementFactory;
36     private final IDiagram       diagram;
37
38     public CreateElementClassRequest(ElementFactory elementFactory, Resource elementType, ICanvasContext canvas, IDiagram diagram) {
39         super(elementType, canvas);
40         this.elementFactory = elementFactory;
41         this.diagram = diagram;
42     }
43
44     @Override
45     public void perform(AsyncReadGraph graph, AsyncProcedure<ElementClass> procedure) {
46         elementFactory.create(graph, parameter2, diagram, parameter, procedure);
47     }
48
49 }