1 /*******************************************************************************
2 * Copyright (c) 2012 Association for Decentralized Information Management in
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 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.modeling.template2d.ui.adapters;
14 import java.util.ArrayList;
15 import java.util.Collection;
18 import org.simantics.db.Resource;
19 import org.simantics.db.WriteGraph;
20 import org.simantics.db.exception.DatabaseException;
21 import org.simantics.db.layer0.adapter.impl.DefaultPasteHandler;
22 import org.simantics.db.layer0.adapter.impl.DefaultPasteImportAdvisor;
23 import org.simantics.db.layer0.util.ClipboardUtils;
24 import org.simantics.db.layer0.util.PasteEventHandler;
25 import org.simantics.db.layer0.util.SimanticsClipboard.Representation;
26 import org.simantics.db.layer0.util.SimanticsKeys;
27 import org.simantics.graph.db.IImportAdvisor;
28 import org.simantics.graph.db.IImportAdvisor2;
29 import org.simantics.graph.representation.TransferableGraph1;
30 import org.simantics.modeling.template2d.ui.function.LinkSVGImage;
32 public class SVGImagePasteHandler extends DefaultPasteHandler {
34 public SVGImagePasteHandler(Resource resource) {
39 public void onPasteBegin(WriteGraph graph) {
44 public void execute(WriteGraph graph, TransferableGraph1 tg,
45 Resource resource, IImportAdvisor advisor) throws DatabaseException {
49 public Collection<Resource> pasteObject(WriteGraph graph, Set<Representation> object, PasteEventHandler handler) throws DatabaseException {
50 Collection<Resource> result = new ArrayList<Resource>();
51 TransferableGraph1 tg = ClipboardUtils.accept(graph, object, SimanticsKeys.KEY_TRANSFERABLE_GRAPH);
53 DefaultPasteImportAdvisor advisor = new DefaultPasteImportAdvisor((Resource)getAdapter(Resource.class));
55 onPaste(graph, advisor, object);
56 } catch (Throwable e) {
63 public void onPaste(WriteGraph graph, IImportAdvisor2 advisor, Set<Representation> representations) throws DatabaseException {
65 final Resource parent = advisor.getTarget();
66 final Collection<Resource> child = ClipboardUtils.accept(representations, SimanticsKeys.KEY_COPY_RESOURCES);
68 if(child.size() == 1) {
69 LinkSVGImage.linkSVGImage(graph, parent, child.iterator().next());
76 public void onPasteEnd(WriteGraph graph){