X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.structural2%2Fsrc%2Forg%2Fsimantics%2Fstructural2%2Futils%2FStructuralUtils.java;h=aac19a7f176b663c9297e9e3b820e86e44392992;hp=9b9dc6cb67ec862501598cc4e10252e7d2c3469f;hb=06aeb7cad707d1fed2c21c1ad9413aa97e901da7;hpb=3a10ce856f7124f83cf03d6e7f7576da237a7cbb diff --git a/bundles/org.simantics.structural2/src/org/simantics/structural2/utils/StructuralUtils.java b/bundles/org.simantics.structural2/src/org/simantics/structural2/utils/StructuralUtils.java index 9b9dc6cb6..aac19a7f1 100644 --- a/bundles/org.simantics.structural2/src/org/simantics/structural2/utils/StructuralUtils.java +++ b/bundles/org.simantics.structural2/src/org/simantics/structural2/utils/StructuralUtils.java @@ -1,3 +1,14 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ package org.simantics.structural2.utils; import java.util.ArrayList; @@ -7,7 +18,6 @@ import java.util.List; import java.util.Set; import org.simantics.databoard.Bindings; -import org.simantics.datatypes.literal.GUID; import org.simantics.db.ReadGraph; import org.simantics.db.RequestProcessor; import org.simantics.db.Resource; @@ -24,6 +34,7 @@ import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.db.layer0.variable.Variable; import org.simantics.layer0.Layer0; import org.simantics.structural.stubs.StructuralResource2; +import org.simantics.structural2.Functions.StructuralOverrideData; import org.simantics.structural2.internal.queries.ConnectedTo; import org.simantics.structural2.internal.queries.RelatedConnections; import org.simantics.structural2.internal.queries.RelatedConnectionsOfConnectionJoin; @@ -40,6 +51,25 @@ import gnu.trove.set.hash.THashSet; */ public class StructuralUtils { + public static enum StructuralComponentClass { + + PRIMITIVE,REPLACEABLE,DEFINED,PROCEDURAL; + + public static StructuralComponentClass get(ReadGraph graph, Resource componentType) throws DatabaseException { + StructuralResource2 STR = StructuralResource2.getInstance(graph); + Set types = graph.getTypes(componentType); + if(types.contains(STR.ProceduralComponentType)) + return StructuralComponentClass.PROCEDURAL; + else if(graph.hasStatement(componentType, STR.IsDefinedBy)) + return StructuralComponentClass.DEFINED; + else if(types.contains(STR.ReplaceableDefinedComponentType)) + return StructuralComponentClass.REPLACEABLE; + else + return StructuralComponentClass.PRIMITIVE; + } + + } + public static Collection getConnectionRelations(ReadGraph graph, Resource componentType) throws DatabaseException { Layer0 L0 = Layer0.getInstance(graph); StructuralResource2 STR = StructuralResource2.getInstance(graph); @@ -142,8 +172,7 @@ public class StructuralUtils { g.claim(component, L0.HasName, Layer0Utils.literal(g, name)); g.claim(component, L0.HasLabel, Layer0Utils.literal(g, "")); g.claim(parent, L0.ConsistsOf, component); - // Add identifier - Layer0Utils.addL0Identifier(g, component); + Layer0Utils.claimNewIdentifier(g, component, true); // Add comment to change set. CommentMetadata cm = g.getMetadata(CommentMetadata.class); g.addMetadata(cm.add("Created component " + component)); @@ -170,6 +199,7 @@ public class StructuralUtils { * Returns the component type of the given component or null if the * parameter is not a component. */ + @Deprecated public static Resource getComponentType(ReadGraph g, Resource component) throws DatabaseException { StructuralResource2 STR = StructuralResource2.getInstance(g); return g.getPossibleType(component, STR.Component); @@ -278,11 +308,13 @@ public class StructuralUtils { } public static boolean isImmutable(ReadGraph graph, Resource r) throws DatabaseException { + // Marking a resource L0.readOnly also makes it immutable + if (graph.isImmutable(r) || Layer0Utils.isMarkedReadOnly(graph, r)) + return true; StructuralResource2 STR = StructuralResource2.getInstance(graph); Resource uc = graph.syncRequest(new PossibleTypedParent(r, STR.ComponentType)); - return graph.isImmutable(r) - // Anything under a published or locked user component is published as well - || (uc != null && (Layer0Utils.isPublished(graph, uc) + return // Anything under a published or locked user component is published as well + (uc != null && (Layer0Utils.isPublished(graph, uc) || graph.hasStatement(uc, STR.ComponentType_Locked))) // Anything under a published container (shared library) is published as well || Layer0Utils.isContainerPublished(graph, r) @@ -290,7 +322,27 @@ public class StructuralUtils { } public static List structuralConnectionConnectionPoints(ReadGraph graph, Connection conn, Resource relationType) throws DatabaseException { - return new ArrayList(conn.getConnectionPoints(graph, relationType)); + return new ArrayList(conn.getConnectionPoints(graph, relationType)); + } + + public static Resource structuralTypeResource(ReadGraph graph, Variable component, Resource baseType) throws DatabaseException { + StructuralOverrideData od = StructuralOverrideData.compute(graph, component); + if (od != null) + return od.type(); + return null; + } + + public static Resource getComponentType(ReadGraph graph, Variable configuration, Resource component) throws DatabaseException { + Variable componentVariable = configuration.browse(graph, component); + return componentVariable.getType(graph); } + public static Resource getPossibleComponentType(ReadGraph graph, Variable configuration, Resource component) throws DatabaseException { + Variable componentVariable = configuration.browsePossible(graph, component); + if(componentVariable == null) return null; + StructuralResource2 STR = StructuralResource2.getInstance(graph); + return componentVariable.getPossibleType(graph, STR.Component); + } + + }