]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/participant/ElementTransferableProvider.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / diagram / participant / ElementTransferableProvider.java
1 /*******************************************************************************
2  * Copyright (c) 2016 Association for Decentralized Information Management
3  * in 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  *     Semantum Oy - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.g2d.diagram.participant;
13
14 import java.awt.datatransfer.Transferable;
15
16 import org.simantics.g2d.canvas.ICanvasContext;
17 import org.simantics.g2d.element.IElement;
18 import org.simantics.scenegraph.g2d.nodes.TransferableProvider;
19 import org.simantics.ui.dnd.PlaintextTransfer;
20
21 /**
22  * @author Antti Villberg, Tuukka Lehtonen
23  */
24 public class ElementTransferableProvider implements TransferableProvider {
25
26         final private ICanvasContext context;
27         final private IElement element;
28         
29         public ElementTransferableProvider(ICanvasContext context, IElement element) {
30                 this.context = context;
31                 this.element = element;
32         }
33         
34         @Override
35         public Transferable create() {
36                 ElementJSON converter = context.getAtMostOneItemOfClass(ElementJSON.class);
37                 if (converter == null)
38                         return null;
39                 return converter.getJSON(element).map(PlaintextTransfer::new).orElse(null);
40         }
41
42 }