1 package org.simantics.spreadsheet.graph;
3 import java.util.Collection;
4 import java.util.HashMap;
7 import org.simantics.databoard.Bindings;
8 import org.simantics.db.ReadGraph;
9 import org.simantics.db.Resource;
10 import org.simantics.db.common.request.ObjectsWithType;
11 import org.simantics.db.exception.DatabaseException;
12 import org.simantics.db.layer0.request.VariableRead;
13 import org.simantics.db.layer0.variable.Variable;
14 import org.simantics.layer0.Layer0;
15 import org.simantics.spreadsheet.resource.SpreadsheetResource;
17 public class SpreadsheetStates extends VariableRead<Map<String, Resource>> {
19 public SpreadsheetStates(Variable variable) {
24 public Map<String, Resource> perform(ReadGraph graph) throws DatabaseException {
25 Resource book = variable.getParent(graph).getRepresents(graph);
26 Layer0 L0 = Layer0.getInstance(graph);
27 Collection<Resource> states = graph.syncRequest(new ObjectsWithType(book, L0.ConsistsOf, SpreadsheetResource.getInstance(graph).InitialCondition));
28 Map<String, Resource> result = new HashMap<>(states.size());
29 states.forEach(state -> {
31 String name = graph.getPossibleRelatedValue(state, L0.HasName, Bindings.STRING);
32 result.put(name, state);
33 } catch (Exception e) {