X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.scl.db%2Fscl%2FSimantics%2FDB.scl;h=ae092cfa8d62aafe6cd203d29e20e9a7f9885903;hp=ac50e3e73525dab3bd2f5afb71c59a0ab97800ed;hb=a8758de5bc19e5adb3f618d3038743a164f09912;hpb=80950353e90c09d866b9748a0ad3ddd726d6f3b4 diff --git a/bundles/org.simantics.scl.db/scl/Simantics/DB.scl b/bundles/org.simantics.scl.db/scl/Simantics/DB.scl index ac50e3e73..ae092cfa8 100644 --- a/bundles/org.simantics.scl.db/scl/Simantics/DB.scl +++ b/bundles/org.simantics.scl.db/scl/Simantics/DB.scl @@ -11,31 +11,6 @@ effect WriteGraph "graph" "org.simantics.db.WriteGraph" -importJava "org.simantics.databoard.type.Datatype" where - data Datatype - @JavaName toString - showDatatype :: Datatype -> String - -instance Show Datatype where - show = showDatatype - -importJava "org.simantics.databoard.Bindings" where - @JavaName getBinding - datatypeBinding :: Datatype -> Binding Dynamic - -importJava "org.simantics.databoard.binding.mutable.Variant" where - @JavaName "" - createVariant_ :: Binding Dynamic -> Dynamic -> Variant - @JavaName "type" - variantDatatype :: Variant -> Datatype - -createVariant :: Datatype -> Dynamic -> Variant -createVariant dt v = createVariant_ (datatypeBinding dt) v - -importJava "org.simantics.databoard.Datatypes" where - @JavaName translate - translateDatatype :: String -> Datatype - importJava "org.simantics.db.Resource" where "A resource is a node in a semantic graph." data Resource @@ -47,21 +22,9 @@ importJava "org.simantics.db.Resource" where importJava "org.simantics.db.ReadGraph" where data ReadGraphX -importJava "java.lang.Object" where - @JavaName equals - resourceEquals :: Resource -> Resource -> Boolean - @JavaName hashCode - resourceHash :: Resource -> Integer - -instance Eq Resource where - (==) = resourceEquals - instance Ord Resource where compare a b = compare (resourceId a) (resourceId b) - -instance Hashable Resource where - hashP = hashP . resourceHash - + instance Show Resource where show r = "#" + show (resourceId r) @@ -455,4 +418,28 @@ lift2Write f x y = syncWrite (\_ -> f x y) @inline lift3Write :: (a -> b -> c -> d) -> (a -> b -> c -> d) -lift3Write f x y z = syncWrite (\_ -> f x y z) \ No newline at end of file +lift3Write f x y z = syncWrite (\_ -> f x y z) + +""" +Returns a child Browsable of the specified parent that has that is the child +of the specified parent with the specified name path. +""" +childWithPath :: Browsable a => a -> [String] -> a +childWithPath parent path = + foldl (\r name -> match possibleChild r name with + Just c -> c + Nothing -> fail ("Didn't find " + name + ".") + ) + parent path + +""" +Like `childWithPath` but returns Maybe a which will be `Nothing` if no child +was found. +""" +possibleChildWithPath :: Browsable a => a -> [String] -> Maybe a +possibleChildWithPath parent path = + foldl (\r name -> match r with + Just c -> possibleChild c name + Nothing -> Nothing + ) + (Just parent) path