]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling/src/org/simantics/modeling/NewSymbol.java
Multiple readers and variable optimization
[simantics/platform.git] / bundles / org.simantics.modeling / src / org / simantics / modeling / NewSymbol.java
1 package org.simantics.modeling;
2
3 import org.simantics.db.Resource;
4 import org.simantics.db.WriteGraph;
5 import org.simantics.db.common.CommentMetadata;
6 import org.simantics.db.common.request.PossibleIndexRoot;
7 import org.simantics.db.common.utils.CommonDBUtils;
8 import org.simantics.db.common.utils.NameUtils;
9 import org.simantics.db.exception.DatabaseException;
10 import org.simantics.diagram.stubs.DiagramResource;
11 import org.simantics.layer0.Layer0;
12
13 /**
14  * @author Tuukka Lehtonen
15  */
16 public class NewSymbol {
17
18         public static Resource createSymbol(WriteGraph graph, Resource componentType) throws DatabaseException {
19
20                 ModelingResources MOD = ModelingResources.getInstance(graph);
21                 Layer0 L0 = Layer0.getInstance(graph);
22                 DiagramResource DIA = DiagramResource.getInstance(graph);
23
24                 // New component type
25                 CommonDBUtils.selectClusterSet(graph, componentType);
26
27                 Resource indexRoot = graph.sync(new PossibleIndexRoot(componentType));
28
29                 Resource symbolDiagramType = graph.getPossibleObject(indexRoot, MOD.StructuralModel_HasSymbolDiagramType);
30                 if(symbolDiagramType == null) symbolDiagramType = DIA.Composite;
31
32                 // Symbol
33                 String symbolName = NameUtils.findFreshName(graph, "Symbol", componentType);
34                 Resource symbol = new ModelingUtils(graph).createSymbol2(symbolName, symbolDiagramType);
35                 graph.claim(componentType, MOD.ComponentTypeToSymbol, symbol);
36                 graph.claim(componentType, L0.ConsistsOf, symbol);
37
38                 CommentMetadata cm = graph.getMetadata(CommentMetadata.class);
39                 graph.addMetadata(cm.add("Created new user component symbol " + symbolName + ", resource " + symbol));
40
41                 return componentType;
42         }
43
44 }