1 package org.simantics.modeling.ui;
\r
3 import java.util.Collection;
\r
5 import org.simantics.db.ReadGraph;
\r
6 import org.simantics.db.Resource;
\r
7 import org.simantics.db.common.request.ObjectsWithType;
\r
8 import org.simantics.db.exception.DatabaseException;
\r
9 import org.simantics.layer0.Layer0;
\r
10 import org.simantics.modeling.ModelingResources;
\r
11 import org.simantics.modeling.ui.actions.NewLibrary;
\r
12 import org.simantics.modeling.ui.actions.NewLocalLibrary;
\r
14 public class SCLLibrary {
\r
16 public static Resource createLibrary(Resource parent) throws DatabaseException {
\r
18 NewLibrary lib = new NewLibrary();
\r
19 Resource library = lib.newLibrary(parent);
\r
23 public static Resource createLibraryInModel(Resource model) throws DatabaseException {
\r
25 NewLocalLibrary lib = new NewLocalLibrary();
\r
26 Resource library = lib.newLibrary(model);
\r
30 public static Resource getLibrary (ReadGraph graph, Resource model, String name) throws DatabaseException {
\r
31 if (name.isEmpty()) {
\r
32 ModelingResources MOD = ModelingResources.getInstance(graph);
\r
33 Resource library = graph.getPossibleObject(model, MOD.HasLocalLibrary);
\r
36 Layer0 L0 = Layer0.getInstance(graph);
\r
37 Collection<Resource> libraries = graph.syncRequest(new ObjectsWithType(model, L0.ConsistsOf, L0.Library));
\r
38 for (Resource library : libraries) {
\r
39 String name1 = graph.getPossibleRelatedValue2(library, L0.HasName);
\r
40 if (name1 != null && name1.equals(name)) {
\r