1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 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 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.diagram.handler;
14 import java.awt.geom.Point2D;
15 import java.util.Collections;
18 import org.simantics.db.Resource;
19 import org.simantics.g2d.canvas.ICanvasContext;
20 import org.simantics.g2d.diagram.IDiagram;
21 import org.simantics.scenegraph.g2d.events.command.Command;
25 * @author Tuukka Lehtonen
27 public final class PasteOperation {
30 * Optional specifications for the paste operation that can be given through.
32 public static interface PasteOption {}
35 * For forcing pasting of diagram reference elements even when the parent
36 * element of the reference element is not included in the copied material.
38 public static enum ForceCopyReferences implements PasteOption { INSTANCE }
41 public final Command command;
42 public final ICanvasContext ctx;
43 public final Resource sourceDiagram;
44 public final Resource targetDiagram;
45 public final IDiagram target;
46 public final ElementObjectAssortment ea;
47 public final boolean cut;
48 public final Point2D offset;
50 public Map<Resource, Resource> initialNodeMap;
52 public PasteOption[] options;
55 public final Map<Object, Object> copyMap;
57 public PasteOperation(
60 Resource sourceDiagram,
61 Resource targetDiagram,
63 ElementObjectAssortment ea,
66 Map<Resource, Resource> initialNodeMap,
67 Map<Object, Object> copyMap
69 if (sourceDiagram == null)
70 throw new IllegalArgumentException("null source diagram");
71 if (targetDiagram == null)
72 throw new IllegalArgumentException("null target diagram");
74 this.command = command;
76 this.sourceDiagram = sourceDiagram;
77 this.targetDiagram = targetDiagram;
82 this.copyMap = copyMap;
83 this.initialNodeMap = initialNodeMap;
86 public PasteOperation(
89 Resource sourceDiagram,
90 Resource targetDiagram,
92 ElementObjectAssortment ea,
95 Map<Resource, Resource> initialNodeMap
97 this(command, ctx, sourceDiagram, targetDiagram, target, ea, cut, offset, initialNodeMap, null);
100 public PasteOperation(
103 Resource sourceDiagram,
104 Resource targetDiagram,
106 ElementObjectAssortment ea,
110 this(command, ctx, sourceDiagram, targetDiagram, target, ea, cut, offset, Collections.<Resource, Resource>emptyMap());
113 public PasteOperation options(PasteOption... options) {
114 this.options = options;
118 public boolean sameDiagram() {
119 return sourceDiagram.equals(targetDiagram);
122 @SuppressWarnings("unchecked")
123 public <T extends PasteOption> T getOption(Class<T> clazz) {
126 for (PasteOption option : options) {
127 if (clazz.isInstance(option))
133 public <T extends PasteOption> boolean hasOption(Class<T> clazz) {
134 return getOption(clazz) != null;