]> gerrit.simantics Code Review - simantics/sysdyn.git/blob
170d02de59e165a84dbf5d3f86abf584f357507f
[simantics/sysdyn.git] /
1 /*******************************************************************************\r
2  * Copyright (c) 2010 Association for Decentralized Information Management in\r
3  * Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.sysdyn.ui.editor.participant;\r
13 \r
14 import org.simantics.db.ReadGraph;\r
15 import org.simantics.db.Resource;\r
16 import org.simantics.db.Statement;\r
17 import org.simantics.db.WriteGraph;\r
18 import org.simantics.db.exception.DatabaseException;\r
19 import org.simantics.db.exception.ServiceException;\r
20 import org.simantics.diagram.synchronization.ISynchronizationContext;\r
21 import org.simantics.diagram.synchronization.graph.CopyAdvisorUtil;\r
22 import org.simantics.modeling.mapping.ComponentCopyAdvisor;\r
23 import org.simantics.sysdyn.SysdynResource;\r
24 import org.simantics.utils.datastructures.BinaryFunction;\r
25 \r
26 public class SysdynComponentCopyAdvisor extends ComponentCopyAdvisor{\r
27 \r
28     @Override\r
29     public Object copy(ISynchronizationContext context, WriteGraph graph, Resource source, Resource sourceContainer, Resource targetContainer) throws DatabaseException {\r
30         \r
31         BinaryFunction<Boolean, ReadGraph, Statement> tester = new BinaryFunction<Boolean, ReadGraph, Statement>() {\r
32 \r
33                         @Override\r
34                         public Boolean call(ReadGraph graph, Statement statement) {\r
35                                 SysdynResource sr = SysdynResource.getInstance(graph);\r
36                                 try {\r
37                                         if(graph.isInstanceOf(statement.getSubject(), sr.IndependentVariable)) {\r
38                                                 if(statement.getPredicate().equals(sr.HasExpressions))\r
39                                                         return true;\r
40                                         }\r
41                                 } catch (ServiceException e) {\r
42                                         e.printStackTrace();\r
43                                 }\r
44                                 return false;\r
45                         }\r
46                 \r
47         };\r
48         \r
49         Resource copy = CopyAdvisorUtil.copy(graph, source, tester);\r
50         renameComponent(context, graph, source, copy, sourceContainer, targetContainer);\r
51         return copy;\r
52     }\r
53 }\r