1 package org.simantics.modeling;
\r
3 import org.simantics.db.Resource;
\r
4 import org.simantics.db.WriteGraph;
\r
5 import org.simantics.db.common.CommentMetadata;
\r
6 import org.simantics.db.common.request.PossibleIndexRoot;
\r
7 import org.simantics.db.common.utils.CommonDBUtils;
\r
8 import org.simantics.db.common.utils.NameUtils;
\r
9 import org.simantics.db.exception.DatabaseException;
\r
10 import org.simantics.diagram.stubs.DiagramResource;
\r
11 import org.simantics.layer0.Layer0;
\r
14 * @author Tuukka Lehtonen
\r
16 public class NewSymbol {
\r
18 public static Resource createSymbol(WriteGraph graph, Resource componentType) throws DatabaseException {
\r
20 ModelingResources MOD = ModelingResources.getInstance(graph);
\r
21 Layer0 L0 = Layer0.getInstance(graph);
\r
22 DiagramResource DIA = DiagramResource.getInstance(graph);
\r
24 // New component type
\r
25 CommonDBUtils.selectClusterSet(graph, componentType);
\r
27 Resource indexRoot = graph.sync(new PossibleIndexRoot(componentType));
\r
29 Resource symbolDiagramType = graph.getPossibleObject(indexRoot, MOD.StructuralModel_HasSymbolDiagramType);
\r
30 if(symbolDiagramType == null) symbolDiagramType = DIA.Composite;
\r
33 String symbolName = NameUtils.findFreshName(graph, "Symbol", componentType);
\r
34 Resource symbol = new ModelingUtils(graph).createSymbol2(symbolName, symbolDiagramType);
\r
35 graph.claim(componentType, MOD.ComponentTypeToSymbol, symbol);
\r
36 graph.claim(componentType, L0.ConsistsOf, symbol);
\r
38 CommentMetadata cm = graph.getMetadata(CommentMetadata.class);
\r
39 graph.addMetadata(cm.add("Created new user component symbol " + symbolName + ", resource " + symbol));
\r
41 return componentType;
\r