+/*******************************************************************************
+ * 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;
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;
*/
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<Resource> 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<Resource> getConnectionRelations(ReadGraph graph, Resource componentType) throws DatabaseException {
Layer0 L0 = Layer0.getInstance(graph);
StructuralResource2 STR = StructuralResource2.getInstance(graph);
* 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);
}
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)
}
public static List<Variable> structuralConnectionConnectionPoints(ReadGraph graph, Connection conn, Resource relationType) throws DatabaseException {
- return new ArrayList<Variable>(conn.getConnectionPoints(graph, relationType));
+ return new ArrayList<Variable>(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);
+ }
+
+
}