]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram/src/org/simantics/diagram/handler/DefaultCopyPasteStrategy.java
Merge "Add missing javax.servlet-api bundle requirement for jersey bundles"
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / handler / DefaultCopyPasteStrategy.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in 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.diagram.handler;
13
14 import org.simantics.Simantics;
15 import org.simantics.db.Session;
16 import org.simantics.db.exception.DatabaseException;
17 import org.simantics.db.layer0.util.SimanticsClipboardImpl;
18 import org.simantics.utils.ui.ErrorLogger;
19
20 /**
21  * The default strategy for pasting diagram elements.
22  * 
23  * @author Tuukka Lehtonen
24  */
25 public class DefaultCopyPasteStrategy implements CopyPasteStrategy {
26
27     @Override
28     public void paste(final PasteOperation op) {
29         try {
30             if (op.sameDiagram() && op.cut) {
31                 CopyPasteUtil.localCutPaste(op);
32             } else {
33                 Session session = Simantics.getSession();
34                 if (CopyPasteUtil.onlyFlagsWithoutCorrespondence(session, op.ea)
35                         && CopyPasteUtil.checkFlagExternality(session, op.ea.flags, false)) {
36                     CopyPasteUtil.continueFlags(op);
37                 } else {
38                     CopyPasteUtil.performDefaultPaste(op);
39                 }
40             }
41         } catch (DatabaseException e) {
42             ErrorLogger.defaultLogError(e);
43         }
44     }
45
46     @Override
47     public void copyToClipboard(DiagramSelection selection) {
48         
49         Simantics.setClipboard( new SimanticsClipboardImpl( new DiagramSelectionRepresentation(selection) ) );
50         
51     }
52     
53 }