--- /dev/null
+package org.simantics.spreadsheet.graph;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+import java.util.List;\r
+\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.ObjectsWithType;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.request.VariableRead;\r
+import org.simantics.db.layer0.variable.Variable;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.spreadsheet.resource.SpreadsheetResource;\r
+\r
+public class Sheets extends VariableRead<List<String>> {\r
+\r
+ public Sheets(Variable variable) {\r
+ super(variable);\r
+ }\r
+\r
+ @Override\r
+ public List<String> perform(ReadGraph graph) throws DatabaseException {\r
+ Resource book = variable.getParent(graph).getRepresents(graph);\r
+ Layer0 L0 = Layer0.getInstance(graph);\r
+ Collection<Resource> sheets = graph.syncRequest(new ObjectsWithType(book, L0.ConsistsOf, SpreadsheetResource.getInstance(graph).Spreadsheet));\r
+ List<String> result = new ArrayList<>(sheets.size());\r
+ sheets.forEach(sheet -> {\r
+ try {\r
+ String name = graph.getPossibleRelatedValue(sheet, L0.HasName, Bindings.STRING);\r
+ result.add(name);\r
+ } catch (Exception e) {\r
+ e.printStackTrace();\r
+ }\r
+ });\r
+ return result;\r
+ \r
+ }\r
+ \r
+}\r