X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.selectionview%2Fsrc%2Forg%2Fsimantics%2Fselectionview%2FSelectionViewUtils.java;fp=bundles%2Forg.simantics.selectionview%2Fsrc%2Forg%2Fsimantics%2Fselectionview%2FSelectionViewUtils.java;h=c9c38d1794c37c6b2f8e766871fc47c91ecf5a0d;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.selectionview/src/org/simantics/selectionview/SelectionViewUtils.java b/bundles/org.simantics.selectionview/src/org/simantics/selectionview/SelectionViewUtils.java new file mode 100644 index 000000000..c9c38d179 --- /dev/null +++ b/bundles/org.simantics.selectionview/src/org/simantics/selectionview/SelectionViewUtils.java @@ -0,0 +1,50 @@ +package org.simantics.selectionview; + +import java.util.List; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.db.layer0.variable.Variables; +import org.simantics.db.layer0.variable.Variables.Role; +import org.simantics.scl.runtime.SCLContext; +import org.simantics.scl.runtime.function.Function1; + +public class SelectionViewUtils { + + public static Variable getSpecialCategory(ReadGraph graph, Resource rule, Variable info) throws DatabaseException { + + SelectionViewResources SEL = SelectionViewResources.getInstance(graph); + Resource categoryResource = info.getPossibleRepresents(graph); + + if(SEL.CategoryHidden.equals(categoryResource)) { + + Variable property = info.getParent(graph); + Variable parent = property.getParent(graph); + if(Role.PROPERTY.equals(parent.getPossibleRole(graph))) return null; + + Resource predicate = property.getPossiblePredicateResource(graph); + Variable ruleVariable = Variables.getVariable(graph, rule); + + Function1> getSpecialCategory = ruleVariable.getPossiblePropertyValue(graph, SEL.getSpecialCategory); + if(getSpecialCategory == null) return null; + + SCLContext sclContext = SCLContext.getCurrent(); + Object oldGraph = sclContext.get("graph"); + try { + sclContext.put("graph", graph); + Resource cat = (Resource)getSpecialCategory.apply(predicate); + if(cat != null) return Variables.getVariable(graph, cat); + } catch (Throwable t) { + throw new DatabaseException(t); + } finally { + sclContext.put("graph", oldGraph); + } + } + + return null; + + } + +}