]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling.template2d.ui/src/org/simantics/modeling/template2d/ui/adapters/SVGImagePasteHandler.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.modeling.template2d.ui / src / org / simantics / modeling / template2d / ui / adapters / SVGImagePasteHandler.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.modeling.template2d.ui.adapters;
13
14 import java.util.ArrayList;
15 import java.util.Collection;
16 import java.util.Set;
17
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;
31
32 public class SVGImagePasteHandler extends DefaultPasteHandler {
33
34         public SVGImagePasteHandler(Resource resource) {
35                 super(resource);
36         }
37
38         @Override
39         public void onPasteBegin(WriteGraph graph) {
40                 
41         }
42
43         @Override
44         public void execute(WriteGraph graph, TransferableGraph1 tg,
45                 Resource resource, IImportAdvisor advisor) throws DatabaseException {
46         }
47
48         @Override
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);
52         if (tg != null) {
53             DefaultPasteImportAdvisor advisor = new DefaultPasteImportAdvisor((Resource)getAdapter(Resource.class)); 
54             try {
55                 onPaste(graph, advisor, object);
56             } catch (Throwable e) {
57             }
58         }
59         return result;
60     }
61
62     @Override
63         public void onPaste(WriteGraph graph, IImportAdvisor2 advisor, Set<Representation> representations) throws DatabaseException {
64                 
65                 final Resource parent = advisor.getTarget();
66                 final Collection<Resource> child = ClipboardUtils.accept(representations, SimanticsKeys.KEY_COPY_RESOURCES);
67                 if(child != null) {
68                     if(child.size() == 1) {
69                         LinkSVGImage.linkSVGImage(graph, parent, child.iterator().next());
70                     }
71                 }
72                 
73     }
74
75         @Override
76         public void onPasteEnd(WriteGraph graph){
77                 
78         }
79 }