1 package org.simantics.district.selection;
6 import org.simantics.Simantics;
7 import org.simantics.databoard.Bindings;
8 import org.simantics.db.RequestProcessor;
9 import org.simantics.db.Resource;
10 import org.simantics.db.WriteGraph;
11 import org.simantics.db.exception.DatabaseException;
12 import org.simantics.db.layer0.QueryIndexUtils;
13 import org.simantics.db.layer0.request.PossibleActiveModel;
14 import org.simantics.db.request.WriteResult;
15 import org.simantics.layer0.Layer0;
17 public class ElementSelectionUtils {
18 public static Resource ensureSelectionLibrary(RequestProcessor graph) throws DatabaseException {
19 return graph.syncRequest(new WriteResult<Resource>() {
21 public Resource perform(WriteGraph graph) throws DatabaseException {
22 ElementSelectionResource ES = ElementSelectionResource.getInstance(graph);
24 Resource model = graph.sync(new PossibleActiveModel(Simantics.getProjectResource()));
25 if (model == null) return null;
27 List<Resource> libs = QueryIndexUtils.searchByTypeShallow(graph, model, ES.SelectionLibrary);
29 Resource lib = graph.newResource();
30 Layer0 L0 = Layer0.getInstance(graph);
31 graph.claim(lib, L0.InstanceOf, ES.SelectionLibrary);
32 graph.claim(model, L0.ConsistsOf, lib);
33 graph.claimLiteral(lib, L0.HasName, L0.String, UUID.randomUUID().toString(), Bindings.STRING);