]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/Sheets.java
First step to enable reading of cache when not writing
[simantics/platform.git] / bundles / org.simantics.spreadsheet.graph / src / org / simantics / spreadsheet / graph / Sheets.java
1 package org.simantics.spreadsheet.graph;
2
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.List;
6
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;
16
17 public class Sheets extends VariableRead<List<String>> {
18
19         public Sheets(Variable variable) {
20                 super(variable);
21         }
22
23         @Override
24         public List<String> perform(ReadGraph graph) throws DatabaseException {
25                 Resource book = variable.getParent(graph).getRepresents(graph);
26                 Layer0 L0 = Layer0.getInstance(graph);
27                 Collection<Resource> sheets = graph.syncRequest(new ObjectsWithType(book, L0.ConsistsOf, SpreadsheetResource.getInstance(graph).Spreadsheet));
28                 List<String> result = new ArrayList<>(sheets.size());
29                 sheets.forEach(sheet -> {
30                     try {
31                 String name = graph.getPossibleRelatedValue(sheet, L0.HasName, Bindings.STRING);
32                 result.add(name);
33             } catch (Exception e) {
34                 e.printStackTrace();
35             }
36                 });
37                 return result;
38                 
39         }
40         
41 }