1 /*******************************************************************************
2 * Copyright (c) 2016 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 * Semantum Oy - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.g2d.diagram.participant;
14 import java.awt.datatransfer.Transferable;
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;
22 * @author Antti Villberg, Tuukka Lehtonen
24 public class ElementTransferableProvider implements TransferableProvider {
26 final private ICanvasContext context;
27 final private IElement element;
29 public ElementTransferableProvider(ICanvasContext context, IElement element) {
30 this.context = context;
31 this.element = element;
35 public Transferable create() {
36 ElementJSON converter = context.getAtMostOneItemOfClass(ElementJSON.class);
37 if (converter == null)
39 return converter.getJSON(element).map(PlaintextTransfer::new).orElse(null);