X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fhandler%2FPasteOperation.java;h=7dee9635a446a790f3376d49deedb8cde4e10402;hb=HEAD;hp=d10fd2141adfb8565a0b3cf46fb26530047cac3d;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/handler/PasteOperation.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/handler/PasteOperation.java index d10fd2141..7dee9635a 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/handler/PasteOperation.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/handler/PasteOperation.java @@ -1,137 +1,137 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.diagram.handler; - -import java.awt.geom.Point2D; -import java.util.Collections; -import java.util.Map; - -import org.simantics.db.Resource; -import org.simantics.g2d.canvas.ICanvasContext; -import org.simantics.g2d.diagram.IDiagram; -import org.simantics.scenegraph.g2d.events.command.Command; - -/** - * - * @author Tuukka Lehtonen - */ -public final class PasteOperation { - - /** - * Optional specifications for the paste operation that can be given through. - */ - public static interface PasteOption {} - - /** - * For forcing pasting of diagram reference elements even when the parent - * element of the reference element is not included in the copied material. - */ - public static enum ForceCopyReferences implements PasteOption { INSTANCE } - - // Input - public final Command command; - public final ICanvasContext ctx; - public final Resource sourceDiagram; - public final Resource targetDiagram; - public final IDiagram target; - public final ElementObjectAssortment ea; - public final boolean cut; - public final Point2D offset; - - public Map initialNodeMap; - - public PasteOption[] options; - - // Output - public final Map copyMap; - - public PasteOperation( - Command command, - ICanvasContext ctx, - Resource sourceDiagram, - Resource targetDiagram, - IDiagram target, - ElementObjectAssortment ea, - boolean cut, - Point2D offset, - Map initialNodeMap, - Map copyMap - ) { - if (sourceDiagram == null) - throw new IllegalArgumentException("null source diagram"); - if (targetDiagram == null) - throw new IllegalArgumentException("null target diagram"); - - this.command = command; - this.ctx = ctx; - this.sourceDiagram = sourceDiagram; - this.targetDiagram = targetDiagram; - this.target = target; - this.ea = ea; - this.cut = cut; - this.offset = offset; - this.copyMap = copyMap; - this.initialNodeMap = initialNodeMap; - } - - public PasteOperation( - Command command, - ICanvasContext ctx, - Resource sourceDiagram, - Resource targetDiagram, - IDiagram target, - ElementObjectAssortment ea, - boolean cut, - Point2D offset, - Map initialNodeMap - ) { - this(command, ctx, sourceDiagram, targetDiagram, target, ea, cut, offset, initialNodeMap, null); - } - - public PasteOperation( - Command command, - ICanvasContext ctx, - Resource sourceDiagram, - Resource targetDiagram, - IDiagram target, - ElementObjectAssortment ea, - boolean cut, - Point2D offset - ) { - this(command, ctx, sourceDiagram, targetDiagram, target, ea, cut, offset, Collections.emptyMap()); - } - - public PasteOperation options(PasteOption... options) { - this.options = options; - return this; - } - - public boolean sameDiagram() { - return sourceDiagram.equals(targetDiagram); - } - - @SuppressWarnings("unchecked") - public T getOption(Class clazz) { - if (options == null) - return null; - for (PasteOption option : options) { - if (clazz.isInstance(option)) - return (T) option; - } - return null; - } - - public boolean hasOption(Class clazz) { - return getOption(clazz) != null; - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.diagram.handler; + +import java.awt.geom.Point2D; +import java.util.Collections; +import java.util.Map; + +import org.simantics.db.Resource; +import org.simantics.g2d.canvas.ICanvasContext; +import org.simantics.g2d.diagram.IDiagram; +import org.simantics.scenegraph.g2d.events.command.Command; + +/** + * + * @author Tuukka Lehtonen + */ +public final class PasteOperation { + + /** + * Optional specifications for the paste operation that can be given through. + */ + public static interface PasteOption {} + + /** + * For forcing pasting of diagram reference elements even when the parent + * element of the reference element is not included in the copied material. + */ + public static enum ForceCopyReferences implements PasteOption { INSTANCE } + + // Input + public final Command command; + public final ICanvasContext ctx; + public final Resource sourceDiagram; + public final Resource targetDiagram; + public final IDiagram target; + public final ElementObjectAssortment ea; + public final boolean cut; + public final Point2D offset; + + public Map initialNodeMap; + + public PasteOption[] options; + + // Output + public final Map copyMap; + + public PasteOperation( + Command command, + ICanvasContext ctx, + Resource sourceDiagram, + Resource targetDiagram, + IDiagram target, + ElementObjectAssortment ea, + boolean cut, + Point2D offset, + Map initialNodeMap, + Map copyMap + ) { + if (sourceDiagram == null) + throw new IllegalArgumentException("null source diagram"); + if (targetDiagram == null) + throw new IllegalArgumentException("null target diagram"); + + this.command = command; + this.ctx = ctx; + this.sourceDiagram = sourceDiagram; + this.targetDiagram = targetDiagram; + this.target = target; + this.ea = ea; + this.cut = cut; + this.offset = offset; + this.copyMap = copyMap; + this.initialNodeMap = initialNodeMap; + } + + public PasteOperation( + Command command, + ICanvasContext ctx, + Resource sourceDiagram, + Resource targetDiagram, + IDiagram target, + ElementObjectAssortment ea, + boolean cut, + Point2D offset, + Map initialNodeMap + ) { + this(command, ctx, sourceDiagram, targetDiagram, target, ea, cut, offset, initialNodeMap, null); + } + + public PasteOperation( + Command command, + ICanvasContext ctx, + Resource sourceDiagram, + Resource targetDiagram, + IDiagram target, + ElementObjectAssortment ea, + boolean cut, + Point2D offset + ) { + this(command, ctx, sourceDiagram, targetDiagram, target, ea, cut, offset, Collections.emptyMap()); + } + + public PasteOperation options(PasteOption... options) { + this.options = options; + return this; + } + + public boolean sameDiagram() { + return sourceDiagram.equals(targetDiagram); + } + + @SuppressWarnings("unchecked") + public T getOption(Class clazz) { + if (options == null) + return null; + for (PasteOption option : options) { + if (clazz.isInstance(option)) + return (T) option; + } + return null; + } + + public boolean hasOption(Class clazz) { + return getOption(clazz) != null; + } + +}