]> gerrit.simantics Code Review - simantics/sysdyn.git/blob
436127a8d81308a6d12672849e5e463ebc718b88
[simantics/sysdyn.git] /
1 package org.simantics.sysdyn.ui.editor.participant;\r
2 \r
3 import org.simantics.db.ReadGraph;\r
4 import org.simantics.db.Resource;\r
5 import org.simantics.db.Statement;\r
6 import org.simantics.db.WriteGraph;\r
7 import org.simantics.db.exception.DatabaseException;\r
8 import org.simantics.db.exception.ServiceException;\r
9 import org.simantics.diagram.synchronization.ISynchronizationContext;\r
10 import org.simantics.diagram.synchronization.graph.CopyAdvisorUtil;\r
11 import org.simantics.modeling.mapping.ComponentCopyAdvisor;\r
12 import org.simantics.sysdyn.SysdynResource;\r
13 import org.simantics.utils.datastructures.BinaryFunction;\r
14 \r
15 public class SysdynComponentCopyAdvisor extends ComponentCopyAdvisor{\r
16 \r
17     @Override\r
18     public Object copy(ISynchronizationContext context, WriteGraph graph, Resource source) throws DatabaseException {\r
19         \r
20         BinaryFunction<Boolean, ReadGraph, Statement> tester = new BinaryFunction<Boolean, ReadGraph, Statement>() {\r
21 \r
22                         @Override\r
23                         public Boolean call(ReadGraph graph, Statement statement) {\r
24                                 SysdynResource sr = SysdynResource.getInstance(graph);\r
25                                 try {\r
26                                         if(graph.isInstanceOf(statement.getSubject(), sr.IndependentVariable)) {\r
27                                                 if(statement.getPredicate().equals(sr.HasExpression))\r
28                                                         return true;\r
29                                         }\r
30                                 } catch (ServiceException e) {\r
31                                         e.printStackTrace();\r
32                                 }\r
33                                 return false;\r
34                         }\r
35                 \r
36         };\r
37         \r
38         Resource copy = CopyAdvisorUtil.copy(graph, source, tester);\r
39         renameComponent(context, graph, source, copy);\r
40         return copy;\r
41     }\r
42 }\r