1 package org.simantics.modeling;
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;
14 * @author Tuukka Lehtonen
16 public class NewSymbol {
18 public static Resource createSymbol(WriteGraph graph, Resource componentType) throws DatabaseException {
20 ModelingResources MOD = ModelingResources.getInstance(graph);
21 Layer0 L0 = Layer0.getInstance(graph);
22 DiagramResource DIA = DiagramResource.getInstance(graph);
25 CommonDBUtils.selectClusterSet(graph, componentType);
27 Resource indexRoot = graph.sync(new PossibleIndexRoot(componentType));
29 Resource symbolDiagramType = graph.getPossibleObject(indexRoot, MOD.StructuralModel_HasSymbolDiagramType);
30 if(symbolDiagramType == null) symbolDiagramType = DIA.Composite;
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);
38 CommentMetadata cm = graph.getMetadata(CommentMetadata.class);
39 graph.addMetadata(cm.add("Created new user component symbol " + symbolName + ", resource " + symbol));