]> gerrit.simantics Code Review - simantics/sysdyn.git/blob
40c3835025f122a44bc6c5d3f650ce6fc7b249ba
[simantics/sysdyn.git] /
1 package org.simantics.sysdyn.ui.editor.participant;\r
2 \r
3 import org.simantics.databoard.Bindings;\r
4 import org.simantics.db.Resource;\r
5 import org.simantics.db.WriteGraph;\r
6 import org.simantics.db.common.utils.NameUtils;\r
7 import org.simantics.db.exception.DatabaseException;\r
8 import org.simantics.diagram.synchronization.ISynchronizationContext;\r
9 import org.simantics.layer0.Layer0;\r
10 import org.simantics.modeling.ComponentUtils;\r
11 \r
12 /**\r
13  * Copy advisor for copying sysdyn elements with custom prefix and/or suffix\r
14  * @author Teemu Lempinen\r
15  *\r
16  */\r
17 public class SysdynSpecialComponentCopyAdvisor extends SysdynComponentCopyAdvisor {\r
18     \r
19     private String prefix = "";\r
20     private String suffix = "";\r
21     \r
22     public SysdynSpecialComponentCopyAdvisor(String prefix, String suffix) {\r
23         this.prefix = prefix;\r
24         this.suffix = suffix;\r
25     }\r
26     \r
27     @Override\r
28     public String rename(ISynchronizationContext context, WriteGraph graph, Resource source,\r
29             Resource copy, Resource sourceContainer, Resource targetContainer) throws DatabaseException {\r
30         Layer0 l0 = Layer0.getInstance(graph);\r
31         String copyName = NameUtils.getSafeName(graph, copy);\r
32         Resource configurationRoot = ComponentUtils.getCompositeConfigurationRoot(graph, targetContainer);\r
33         \r
34         if(prefix == null)\r
35             prefix = "";\r
36         if(suffix == null)\r
37             suffix = "";\r
38         \r
39         String name =  NameUtils.findFreshName(graph, prefix + copyName + suffix, configurationRoot, l0.ConsistsOf, "%s%d");\r
40         graph.claimLiteral(copy, l0.HasName, name, Bindings.STRING);\r
41         return name;\r
42     }\r
43 \r
44 }\r