X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.modeling%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2FNewComponentType.java;h=920c30453f36d54f4befbb97f8115a392f67a21e;hp=b0b2e06e1fa1f33f4c1112d9eaf3ade30bd2a7e7;hb=refs%2Fchanges%2F38%2F238%2F2;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/NewComponentType.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/NewComponentType.java index b0b2e06e1..920c30453 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/NewComponentType.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/NewComponentType.java @@ -1,76 +1,76 @@ -package org.simantics.modeling; - -import org.simantics.databoard.Bindings; -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.common.CommentMetadata; -import org.simantics.db.common.request.PossibleIndexRoot; -import org.simantics.db.common.utils.CommonDBUtils; -import org.simantics.db.common.utils.NameUtils; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.request.InstantiateRequest; -import org.simantics.diagram.stubs.DiagramResource; -import org.simantics.layer0.Layer0; -import org.simantics.operation.Layer0X; -import org.simantics.structural.stubs.StructuralResource2; - -public class NewComponentType { - - public static Resource createComponentType(WriteGraph graph, Resource library) throws DatabaseException { - - ModelingResources MOD = ModelingResources.getInstance(graph); - Layer0 L0 = Layer0.getInstance(graph); - Layer0X L0X = Layer0X.getInstance(graph); - StructuralResource2 STR = StructuralResource2.getInstance(graph); - DiagramResource DIA = DiagramResource.getInstance(graph); - - // New component type - CommonDBUtils.selectClusterSet(graph, library); - Resource componentType = graph.newResource(); - graph.newClusterSet(componentType); - CommonDBUtils.selectClusterSet(graph, componentType); - - graph.claim(componentType, L0.PartOf, library); - - Resource indexRoot = graph.sync(new PossibleIndexRoot(library)); - - // Supertype - Resource supertype = graph.getSingleObject(indexRoot, MOD.StructuralModel_HasComponentTypeSupertype); - graph.claim(componentType, L0.Inherits, null, supertype); - - // Name - String defaultName = graph.getRelatedValue(indexRoot, MOD.StructuralModel_HasDefaultComponentTypeName, Bindings.STRING); - String name = NameUtils.findFreshName(graph, defaultName, library); - graph.claimLiteral(componentType, L0.HasName, name + "@1"); - graph.claimLiteral(componentType, L0X.HasGeneratedNamePrefix, ""); - - // Substructure - Resource substructureType = graph.getSingleObject(indexRoot, MOD.StructuralModel_HasComponentTypeSubstructureType); - Resource composite = new InstantiateRequest(substructureType).perform(graph); - graph.claim(componentType, STR.IsDefinedBy, composite); - // These are added to give the configuration a proper URI. - graph.claimLiteral(composite, L0.HasName, "Configuration"); - graph.claim(componentType, L0.ConsistsOf, composite); - - // Attach trigger to keep component type interface structures up-to-date - Resource diagram = graph.getPossibleObject(composite, MOD.CompositeToDiagram); - if (diagram != null) { - Resource componentTypeUpdater = graph.newResource(); - graph.claim(componentTypeUpdater, L0.InstanceOf, null, MOD.ComponentTypeUpdater); - graph.claim(diagram, L0X.HasTrigger, componentTypeUpdater); - } - - Resource symbolDiagramType = graph.getPossibleObject(indexRoot, MOD.StructuralModel_HasSymbolDiagramType); - if(symbolDiagramType == null) symbolDiagramType = DIA.Composite; - - // Symbol - Resource symbol = new ModelingUtils(graph).createSymbol2("Symbol", symbolDiagramType); - graph.claim(componentType, MOD.ComponentTypeToSymbol, symbol); - graph.claim(componentType, L0.ConsistsOf, symbol); - - CommentMetadata cm = graph.getMetadata(CommentMetadata.class); - graph.addMetadata(cm.add("Created new user component " + name + ", resource " + componentType)); - - return componentType; - } +package org.simantics.modeling; + +import org.simantics.databoard.Bindings; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.CommentMetadata; +import org.simantics.db.common.request.PossibleIndexRoot; +import org.simantics.db.common.utils.CommonDBUtils; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.request.InstantiateRequest; +import org.simantics.diagram.stubs.DiagramResource; +import org.simantics.layer0.Layer0; +import org.simantics.operation.Layer0X; +import org.simantics.structural.stubs.StructuralResource2; + +public class NewComponentType { + + public static Resource createComponentType(WriteGraph graph, Resource library) throws DatabaseException { + + ModelingResources MOD = ModelingResources.getInstance(graph); + Layer0 L0 = Layer0.getInstance(graph); + Layer0X L0X = Layer0X.getInstance(graph); + StructuralResource2 STR = StructuralResource2.getInstance(graph); + DiagramResource DIA = DiagramResource.getInstance(graph); + + // New component type + CommonDBUtils.selectClusterSet(graph, library); + Resource componentType = graph.newResource(); + graph.newClusterSet(componentType); + CommonDBUtils.selectClusterSet(graph, componentType); + + graph.claim(componentType, L0.PartOf, library); + + Resource indexRoot = graph.sync(new PossibleIndexRoot(library)); + + // Supertype + Resource supertype = graph.getSingleObject(indexRoot, MOD.StructuralModel_HasComponentTypeSupertype); + graph.claim(componentType, L0.Inherits, null, supertype); + + // Name + String defaultName = graph.getRelatedValue(indexRoot, MOD.StructuralModel_HasDefaultComponentTypeName, Bindings.STRING); + String name = NameUtils.findFreshName(graph, defaultName, library); + graph.claimLiteral(componentType, L0.HasName, name + "@1"); + graph.claimLiteral(componentType, L0X.HasGeneratedNamePrefix, ""); + + // Substructure + Resource substructureType = graph.getSingleObject(indexRoot, MOD.StructuralModel_HasComponentTypeSubstructureType); + Resource composite = new InstantiateRequest(substructureType).perform(graph); + graph.claim(componentType, STR.IsDefinedBy, composite); + // These are added to give the configuration a proper URI. + graph.claimLiteral(composite, L0.HasName, "Configuration"); + graph.claim(componentType, L0.ConsistsOf, composite); + + // Attach trigger to keep component type interface structures up-to-date + Resource diagram = graph.getPossibleObject(composite, MOD.CompositeToDiagram); + if (diagram != null) { + Resource componentTypeUpdater = graph.newResource(); + graph.claim(componentTypeUpdater, L0.InstanceOf, null, MOD.ComponentTypeUpdater); + graph.claim(diagram, L0X.HasTrigger, componentTypeUpdater); + } + + Resource symbolDiagramType = graph.getPossibleObject(indexRoot, MOD.StructuralModel_HasSymbolDiagramType); + if(symbolDiagramType == null) symbolDiagramType = DIA.Composite; + + // Symbol + Resource symbol = new ModelingUtils(graph).createSymbol2("Symbol", symbolDiagramType); + graph.claim(componentType, MOD.ComponentTypeToSymbol, symbol); + graph.claim(componentType, L0.ConsistsOf, symbol); + + CommentMetadata cm = graph.getMetadata(CommentMetadata.class); + graph.addMetadata(cm.add("Created new user component " + name + ", resource " + componentType)); + + return componentType; + } } \ No newline at end of file