1 package org.simantics.sysdyn.ui.editor.participant;
\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
13 * Copy advisor for copying sysdyn elements with custom prefix and/or suffix
\r
14 * @author Teemu Lempinen
\r
17 public class SysdynSpecialComponentCopyAdvisor extends SysdynComponentCopyAdvisor {
\r
19 private String prefix = "";
\r
20 private String suffix = "";
\r
22 public SysdynSpecialComponentCopyAdvisor(String prefix, String suffix) {
\r
23 this.prefix = prefix;
\r
24 this.suffix = suffix;
\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
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