1 /*******************************************************************************
2 * Copyright (c) 2007, 2018 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.spreadsheet.graph;
14 import java.util.ArrayList;
15 import java.util.Collection;
16 import java.util.Collections;
17 import java.util.List;
19 import java.util.function.Consumer;
21 import org.eclipse.e4.core.contexts.IEclipseContext;
22 import org.eclipse.e4.ui.di.UISynchronize;
23 import org.eclipse.jface.dialogs.Dialog;
24 import org.eclipse.ui.PlatformUI;
25 import org.simantics.Simantics;
26 import org.simantics.databoard.Bindings;
27 import org.simantics.databoard.binding.Binding;
28 import org.simantics.databoard.binding.mutable.MutableVariant;
29 import org.simantics.databoard.binding.mutable.Variant;
30 import org.simantics.db.AsyncReadGraph;
31 import org.simantics.db.ReadGraph;
32 import org.simantics.db.RequestProcessor;
33 import org.simantics.db.Resource;
34 import org.simantics.db.WriteGraph;
35 import org.simantics.db.common.procedure.adapter.AsyncListenerSupport;
36 import org.simantics.db.common.procedure.adapter.ListenerSupport;
37 import org.simantics.db.common.procedure.adapter.SyncListenerSupport;
38 import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;
39 import org.simantics.db.common.procedure.single.SingleSetSyncListenerDelegate;
40 import org.simantics.db.common.request.ReadRequest;
41 import org.simantics.db.common.request.ResourceRead;
42 import org.simantics.db.common.request.UnaryRead;
43 import org.simantics.db.common.request.UniqueRead;
44 import org.simantics.db.common.request.WriteRequest;
45 import org.simantics.db.common.request.WriteResultRequest;
46 import org.simantics.db.common.session.SessionEventListenerAdapter;
47 import org.simantics.db.exception.DatabaseException;
48 import org.simantics.db.layer0.request.PossibleURIVariable;
49 import org.simantics.db.layer0.request.VariableName;
50 import org.simantics.db.layer0.request.VariableRead;
51 import org.simantics.db.layer0.variable.ProxyVariables;
52 import org.simantics.db.layer0.variable.Variable;
53 import org.simantics.db.layer0.variable.Variables;
54 import org.simantics.db.procedure.SyncListener;
55 import org.simantics.db.request.Write;
56 import org.simantics.db.service.SessionEventSupport;
57 import org.simantics.layer0.Layer0;
58 import org.simantics.simulator.toolkit.StandardRealm;
59 import org.simantics.spreadsheet.Adaptable;
60 import org.simantics.spreadsheet.CellEditor;
61 import org.simantics.spreadsheet.ClientModel;
62 import org.simantics.spreadsheet.ClientModel.OperationMode;
63 import org.simantics.spreadsheet.SheetCommands;
64 import org.simantics.spreadsheet.event.model.RemoveCellHandler;
65 import org.simantics.spreadsheet.resource.SpreadsheetResource;
66 import org.simantics.spreadsheet.solver.SheetNode;
67 import org.simantics.spreadsheet.solver.SpreadsheetBook;
68 import org.simantics.ui.selection.WorkbenchSelectionUtils;
69 import org.simantics.utils.datastructures.Pair;
70 import org.simantics.utils.strings.AlphanumComparator;
71 import org.simantics.utils.threads.logger.ITask;
72 import org.simantics.utils.threads.logger.ThreadLogger;
73 import org.slf4j.Logger;
74 import org.slf4j.LoggerFactory;
76 import gnu.trove.map.hash.THashMap;
77 import gnu.trove.map.hash.TObjectIntHashMap;
79 class FilteredVariableProperties extends UnaryRead<Variable, Collection<Pair<String,Variable>>> {
81 final static String CLASSIFICATION = SpreadsheetResource.URIs.Attribute;
83 public FilteredVariableProperties(Variable variable) {
88 public Collection<Pair<String,Variable>> perform(ReadGraph graph) throws DatabaseException {
89 ArrayList<Pair<String,Variable>> result = new ArrayList<Pair<String,Variable>>();
90 for(Variable var : parameter.getProperties(graph, CLASSIFICATION)) {
91 String name = var.getName(graph);
92 String uri = var.getURI(graph);
93 result.add(Pair.make(name, var));
94 Variable expression = var.getPossibleProperty(graph, "expression");
95 if(expression != null)
96 result.add(Pair.make(name + "#expression", expression));
97 Variable editable = var.getPossibleProperty(graph, "editable");
99 result.add(Pair.make(name + "#editable", editable));
106 public class GraphUI implements Adaptable, ListenerSupport, AsyncListenerSupport, SyncListenerSupport {
108 private static final Logger LOGGER = LoggerFactory.getLogger(GraphUI.class);
110 final public static boolean DEBUG = false;
112 final private RequestProcessor processor;
114 private CellEditor<Write> cellEditor;
116 private Variable run;
117 private ClientModel client;
119 private Map<String, PropertyListener> listenerCache = new THashMap<>();
121 public GraphUI(RequestProcessor processor) {
122 this.processor = processor;
125 public void addCell(ReadGraph graph, Pair<String, Variable> child, final ClientModel client) throws DatabaseException {
127 if(DEBUG) System.out.println("GraphUI adds cell " + child.second.getURI(graph));
129 final String childName = child.second.getName(graph);
130 Boolean immutable = child.second.getPossiblePropertyValue(graph, "immutable", Bindings.BOOLEAN);
131 if(immutable != null && immutable) {
132 Collection<Variable> properties = child.second.getProperties(graph, FilteredVariableProperties.CLASSIFICATION);
133 addProperties(graph, properties, client, childName);
135 PropertyListener listener = listenerCache.get(child.first);
136 if (listener == null) {
137 listener = propertyListener(client, childName);
138 listenerCache.put(child.first, listener);
140 graph.syncRequest(new FilteredVariableProperties(child.second), listener);
145 public void removeCell(ReadGraph graph, Pair<String, Variable> child, final ClientModel client) throws DatabaseException {
147 if(DEBUG) System.out.println("GraphUI removed cell " + child.first);
149 client.clear(child.first);
150 PropertyListener listener = listenerCache.remove(child.first);
151 if (listener != null)
156 public void loadCells(ReadGraph graph, Variable container, boolean immutable, final ClientModel client) throws DatabaseException {
158 if(DEBUG) System.out.println("GraphUI loads cells from " + container.getURI(graph));
161 for(Pair<String, Variable> cell : graph.syncRequest(new Cells(container), TransientCacheAsyncListener.<Collection<Pair<String, Variable>>>instance())) {
162 addCell(graph, cell, client);
165 graph.syncRequest(new Cells(container), new SingleSetSyncListenerDelegate<Pair<String, Variable>>(GraphUI.this) {
168 public void add(ReadGraph graph, final Pair<String, Variable> child) throws DatabaseException {
169 addCell(graph, child, client);
173 public void remove(ReadGraph graph, final Pair<String, Variable> child) throws DatabaseException {
174 removeCell(graph, child, client);
181 private SessionEventListenerAdapter listener;
183 private String currentSource;
185 private boolean disposed;
187 public Resource load(final Variable variable, final ClientModel client) throws DatabaseException {
189 // for (PropertyListener listener : listenerCache.values())
190 // listener.dispose();
192 // listenerCache.clear();
196 assert(variable != null);
199 this.client = client;
201 SessionEventSupport support = processor.getService(SessionEventSupport.class);
203 for (PropertyListener listener : listenerCache.values()) {
206 listenerCache.clear();
209 support.removeListener(listener);
211 listener = new SessionEventListenerAdapter() {
214 public void writeTransactionFinished() {
220 support.addListener(listener);
222 this.cellEditor = processor.sync(new VariableRead<CellEditor<Write>>(variable) {
225 public CellEditor<Write> perform(ReadGraph graph) throws DatabaseException {
226 SpreadsheetResource SHEET = SpreadsheetResource.getInstance(graph);
227 return variable.getPropertyValue(graph, SHEET.cellEditor);
232 final ITask task = ThreadLogger.getInstance().begin("GraphUI.init");
236 Map<String,Variable> sources = processor.syncRequest(new Sources(variable));
238 List<String> sheetList = processor.syncRequest(new Sheets(variable));
239 String currentSheet = processor.syncRequest(new VariableName(variable));
241 Map<String, Resource> stateList = processor.syncRequest(new SpreadsheetStates(variable));
243 if(currentSource == null) currentSource = "Sheet";
245 ArrayList<String> sourceList = new ArrayList<String>(sources.keySet());
247 Collections.sort(sourceList, AlphanumComparator.CASE_INSENSITIVE_COMPARATOR);
248 if(!sourceList.contains(currentSource)) sourceList.add(currentSource);
250 client.setProperty(ClientModel.SOURCES, ClientModel.SOURCES_AVAILABLE, sourceList.toArray(new String[sourceList.size()]));
251 client.setProperty(ClientModel.SOURCES, ClientModel.SOURCES_CURRENT, currentSource);
253 client.setProperty(ClientModel.SHEETS, ClientModel.SHEETS_AVAILABLE, sheetList.toArray(new String[sheetList.size()]));
254 client.setProperty(ClientModel.SHEETS, ClientModel.SHEETS_CURRENT, currentSheet);
256 client.setProperty(ClientModel.STATES, ClientModel.STATES_AVAILABLE, stateList.keySet().toArray(new String[stateList.size()]));
258 client.setProperty(ClientModel.CONTEXT, ClientModel.CONTEXT_CURRENT, variable);
260 client.setProperty(ClientModel.MODE, ClientModel.MODE_CURRENT, OperationMode.OPERATION);
262 String currentState = processor.syncRequest(new UniqueRead<String>() {
265 public String perform(ReadGraph graph) throws DatabaseException {
266 Resource book = variable.getParent(graph).getRepresents(graph);
267 Resource ic = graph.getPossibleObject(book, SpreadsheetResource.getInstance(graph).Book_HasDefaultInitialCondition);
270 return graph.getRelatedValue2(ic, Layer0.getInstance(graph).HasName, Bindings.STRING);
274 client.setProperty(ClientModel.STATES, ClientModel.STATES_CURRENT, currentState);
276 processor.syncRequest(new ReadRequest() {
279 public void run(ReadGraph graph) throws DatabaseException {
281 loadCells(graph, variable, false, client);
283 graph.syncRequest(new Ranges(variable), new SingleSetSyncListenerDelegate<Variable>(GraphUI.this) {
286 public void add(ReadGraph graph, final Variable range) throws DatabaseException {
288 if(DEBUG) System.out.println("GraphUI adds range " + range.getURI(graph));
290 Boolean immutable = range.getPossiblePropertyValue(graph, "immutable", Bindings.BOOLEAN);
291 loadCells(graph, range, immutable != null && immutable, client);
296 public void remove(ReadGraph graph, final Variable range) throws DatabaseException {
303 graph.syncRequest(new SheetLines(variable), new SingleSetSyncListenerDelegate<Variable>(GraphUI.this) {
306 public void add(ReadGraph graph, final Variable range) throws DatabaseException {
308 if(DEBUG) System.out.println("GraphUI adds line " + range.getURI(graph));
310 Boolean immutable = range.getPossiblePropertyValue(graph, "immutable", Bindings.BOOLEAN);
311 loadCells(graph, range, immutable != null && immutable, client);
316 public void remove(ReadGraph graph, final Variable range) throws DatabaseException {
324 // public void remove(ReadGraph graph, Variable child) throws DatabaseException {
326 // String location = locations.get(cellResource);
327 // assert(location != null);
329 // client.setProperty(location, "Label", null);
330 // client.setProperty(location, "Expression", null);
344 private static class PropertyListener extends SingleSetSyncListenerDelegate<Pair<String,Variable>> {
346 private static final Logger LOGGER = LoggerFactory.getLogger(PropertyListener.class);
348 private ClientModel client;
349 private String childName;
350 private boolean listenerDisposed;
352 public PropertyListener(SyncListenerSupport support, ClientModel client, String childName) {
354 this.client = client;
355 this.childName = childName;
359 public void add(ReadGraph graph, final Pair<String,Variable> property) throws DatabaseException {
362 System.out.println("GraphUI adds property " + property.second.getURI(graph));
364 graph.syncRequest(new CellValue(property.second), new SyncListener<Object>() {
367 public void execute(ReadGraph graph, final Object value) throws DatabaseException {
369 String propertyName = property.first;
372 System.out.println("GraphUI detected content change(1) at " + childName + " - " + propertyName + " -> " + value);
373 client.setProperty(childName, propertyName, value);
378 public void exception(ReadGraph graph, Throwable throwable) throws DatabaseException {
380 LOGGER.error("PropertyListener.exception", throwable);
382 String propertyName = property.first;
383 if("content".equals(propertyName)) {
384 if(throwable == null) throwable = new Exception();
385 String message = throwable.getMessage();
386 if(message == null) message = throwable.toString();
387 client.setProperty(childName, propertyName, Variant.ofInstance(message));
389 client.setProperty(childName, propertyName, null);
395 public boolean isDisposed() {
396 return listenerDisposed;
402 public void dispose() {
403 listenerDisposed = true;
407 public String toString() {
408 return super.toString() + ":" + childName;
413 private PropertyListener propertyListener(final ClientModel client, final String childName) {
414 return new PropertyListener(this, client, childName);
417 private void addProperties(ReadGraph graph, final Collection<Variable> properties, final ClientModel client, final String childName) throws DatabaseException {
419 for(Variable property : properties) {
421 if(DEBUG) System.out.println("GraphUI adds immutable property " + property.getURI(graph));
423 final String propertyName = property.getName(graph);
425 Object value = property.getValue(graph);
427 if(DEBUG) System.out.println("GraphUI detected change at " + childName + " - " + propertyName + " -> " + value);
428 client.setProperty(childName, propertyName, value);
430 String expression = property.getPossiblePropertyValue(graph, "expression", Bindings.STRING);
431 if(expression != null) {
432 if(DEBUG) System.out.println("GraphUI detected change at " + childName + " - " + (propertyName + "#expression") + " -> " + value);
433 client.setProperty(childName, propertyName + "#expression", expression);
436 Boolean editable = property.getPossiblePropertyValue(graph, "editable", Bindings.STRING);
437 if(editable != null) {
438 if(DEBUG) System.out.println("GraphUI detected change at " + childName + " - " + (propertyName + "#editable") + " -> " + value);
439 client.setProperty(childName, propertyName + "#editable", editable);
446 @SuppressWarnings("unchecked")
448 public <T> T getAdapter(Class<T> clazz) {
450 if(Variable.class == clazz) {
454 } else if(RemoveCellHandler.class == clazz) {
456 return (T) new RemoveCellHandler() {
459 public void handle(final String location) {
462 processor.syncRequest(new ReadRequest() {
465 public void run(ReadGraph graph) throws DatabaseException {
467 Variable cellVariable = run.getPossibleChild(graph, location);
468 if(cellVariable != null) {
469 final Resource config = cellVariable.getPossiblePropertyValue(graph, "Represents");
472 graph.asyncRequest(new WriteRequest() {
475 public void perform(WriteGraph graph) throws DatabaseException {
477 Layer0 l0 = Layer0.getInstance(graph);
478 // SpreadsheetResource sr = SpreadsheetResource.getInstance(graph);
479 graph.deny(config, l0.PartOf);
480 // graph.deny(config, sr.RowOf);
481 // graph.deny(config, sr.ColumnOf);
493 } catch (DatabaseException e) {
494 LOGGER.error("Unexpected exception while removing cell", e);
501 } else if(CellEditor.class == clazz) {
503 return (T)new CellEditor<Write>() {
506 public <E> void edit(Transaction<Write> transaction, String location, String property, E value, Binding binding, Consumer<?> callback) {
508 if (ClientModel.ITERATION_ENABLED.equals(location)) {
509 Simantics.getSession().asyncRequest(new ReadRequest() {
511 public void run(ReadGraph graph) throws DatabaseException {
512 getBook(graph).setIterationEnabled((boolean)value);
518 if (ClientModel.MODE.equals(location)) {
519 if (ClientModel.MODE_CURRENT.equals(property)) {
520 client.setProperty(location, property, value);
526 if (ClientModel.CONTEXT.equals(location)) {
527 if(ClientModel.CONTEXT_CURRENT.equals(property)) {
528 if(value instanceof String) {
530 Variable newContext = processor.syncRequest(new UnaryRead<String, Variable>((String)value) {
533 public Variable perform(ReadGraph graph) throws DatabaseException {
535 String sheetName = run.getName(graph);
537 Variable book = Variables.getContext(graph, run);
538 Resource bookResource = book.getRepresents(graph);
540 Variable input = Variables.getVariable(graph, parameter);
541 Variable proxy = ProxyVariables.makeProxyVariable(graph, Variables.getVariable(graph, bookResource), input);
543 return proxy.getChild(graph, sheetName);
545 // return variable.getParent(graph).getChild(graph, parameter);
550 load(newContext, client);
552 } catch (DatabaseException e) {
553 LOGGER.error("edit failed for model key '" + ClientModel.CONTEXT_CURRENT + "'", e);
559 if(ClientModel.SHEETS.equals(location)) {
560 if(ClientModel.SHEETS_CURRENT.equals(property)) {
562 if(value instanceof String) {
566 Variable newInput = processor.syncRequest(new UnaryRead<String, Variable>((String)value) {
569 public Variable perform(ReadGraph graph) throws DatabaseException {
570 return run.getParent(graph).getChild(graph, parameter);
575 load(newInput, client);
577 } catch (DatabaseException e) {
578 LOGGER.error("edit failed for model key '" + ClientModel.SHEETS_CURRENT + "'", e);
584 if(ClientModel.STATES.equals(location)) {
585 if(ClientModel.STATES_CURRENT.equals(property)) {
586 if(value instanceof String) {
587 final String parameter = (String) value;
590 String uri = processor.syncRequest(new WriteResultRequest<String>() {
593 public String perform(WriteGraph graph) throws DatabaseException {
595 Map<String, Resource> states = graph.syncRequest(new SpreadsheetStates(run));
597 Resource state = null;
598 for (Map.Entry<String, Resource> entry : states.entrySet()) {
599 if (entry.getKey().equals(parameter)) {
600 state = entry.getValue();
605 Variable context = Variables.getContext(graph, run);
606 Resource bookResource = context.getRepresents(graph);
607 SpreadsheetGraphUtils.setDefaultInitialConditionForBook(graph, bookResource, state);
609 String contextURI = context.getURI(graph);
611 String sessionName = context.getParent(graph).getURI(graph);
612 SpreadsheetSessionManager.getInstance().removeRealm(graph, sessionName);
613 SpreadsheetSessionManager.getInstance().getOrCreateRealm(graph, sessionName);
616 return run.getURI(graph);
619 Variable newInput = processor.syncRequest(new PossibleURIVariable(uri));
620 load(newInput, client);
621 // fullSynchronize();
623 } catch (DatabaseException e) {
624 LOGGER.error("edit failed for model key '" + ClientModel.STATES_CURRENT + "'", e);
630 if(ClientModel.SOURCES.equals(location)) {
631 if(ClientModel.SOURCES_CURRENT.equals(property)) {
633 Resource res = WorkbenchSelectionUtils.getPossibleResource(value);
636 Variable newInput = processor.syncRequest(new ResourceRead<Variable>(res) {
639 public Variable perform(ReadGraph graph) throws DatabaseException {
640 Variable base = ProxyVariables.proxyVariableBase(graph, run);
641 Variable in = Variables.getVariable(graph, resource);
642 currentSource = in.getURI(graph);
643 return ProxyVariables.makeProxyVariable(graph, base, in);
648 load(newInput, client);
652 } else if(value instanceof String) {
654 Variable newInput = processor.syncRequest(new UnaryRead<String, Variable>((String)value) {
657 public Variable perform(ReadGraph graph) throws DatabaseException {
659 Variable base = ProxyVariables.proxyVariableBase(graph, run);
660 Map<String,Variable> sources = graph.syncRequest(new Sources(base));
662 Variable found = sources.get(parameter);
663 if(found == null) return null;
665 currentSource = parameter;
667 return ProxyVariables.makeProxyVariable(graph, base, found);
673 load(newInput, client);
677 } catch (DatabaseException e) {
678 LOGGER.error("edit failed for model key '" + ClientModel.SOURCES_CURRENT + "'", e);
683 boolean needsCommit = false;
684 if (transaction == null) {
685 OperationMode mode = client.getPropertyAt(ClientModel.MODE, ClientModel.MODE_CURRENT);
686 transaction = startTransaction(mode);
687 // if (mode.equals(OperationMode.OPERATION))
688 transaction.setContext(run);
691 final Transaction<Write> finalTransaction = transaction;
692 cellEditor.edit(transaction, location, property, value, binding, new Consumer<Object>() {
695 public void accept(Object param) {
696 if (finalTransaction.needSynchronization() != null)
697 synchronize(finalTransaction.needSynchronization());
701 transaction.commit();
705 public void edit(Transaction<Write> transaction, String location, Variant variant, Consumer<?> callback) {
706 boolean needsCommit = false;
707 if (transaction == null) {
708 OperationMode mode = client.getPropertyAt(ClientModel.MODE, ClientModel.MODE_CURRENT);
709 transaction = startTransaction(mode);
710 // if (mode.equals(OperationMode.OPERATION))
711 transaction.setContext(run);
714 final Transaction<Write> finalTransaction = transaction;
715 cellEditor.edit(transaction, location, variant, new Consumer<Object>() {
718 public void accept(Object param) {
719 if (finalTransaction.needSynchronization() != null)
720 synchronize(finalTransaction.needSynchronization());
724 transaction.commit();
728 public void copy(final Transaction<Write> transaction, String location, MutableVariant variant, Consumer<?> callback) {
729 cellEditor.edit(transaction, location, variant, new Consumer<Object>() {
732 public void accept(Object param) {
733 if (transaction.needSynchronization() != null)
734 synchronize(transaction.needSynchronization());
740 public Transaction<Write> startTransaction(OperationMode mode) {
741 return cellEditor.startTransaction(mode);
746 } else if (SheetCommands.class == clazz ) {
748 return (T) new SheetCommands() {
751 public void saveState() {
753 Simantics.getSession().asyncRequest(new ReadRequest() {
756 public void run(ReadGraph graph) throws DatabaseException {
757 IEclipseContext context = PlatformUI.getWorkbench().getService(IEclipseContext.class);
759 Resource uiContextResource = run.getRepresents(graph);
760 Resource bookResource = Variables.getContext(graph, run).getRepresents(graph);
761 Layer0 L0 = Layer0.getInstance(graph);
762 String uiContextName = graph.getRelatedValue2(uiContextResource, L0.HasName, Bindings.STRING);
763 String bookName = graph.getRelatedValue2(bookResource, L0.HasName, Bindings.STRING);
765 UISynchronize synchronizer = context.get(UISynchronize.class);
766 synchronizer.asyncExec(() -> {
767 Pair<String, Resource>[] pairs = new Pair[] {Pair.make(uiContextName, uiContextResource), Pair.make(bookName, bookResource) };
768 SaveSpreadsheetStateDialog dialog = new SaveSpreadsheetStateDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().getSite(), "Save Spreadsheet state", pairs);
769 if (dialog.open() == Dialog.OK) {
770 Object[] result = dialog.getSelection();
771 if (result != null) {
772 Pair<Resource, String> p = (Pair<Resource, String>) result[0];
773 Simantics.getSession().asyncRequest(new WriteRequest() {
776 public void perform(WriteGraph graph) throws DatabaseException {
778 Variable parent = run.getParent(graph);
779 Variable base = ProxyVariables.proxyVariableBase(graph, parent);
780 SpreadsheetGraphUtils.saveInitialCondition(graph, parent, p.first, p.second);
799 public void exception(Throwable t) {
800 LOGGER.error("Failed to read properties.", t);
804 public boolean isDisposed() {
809 public void exception(AsyncReadGraph graph, Throwable t) {
810 LOGGER.error("Failed to read properties.", t);
814 public void exception(ReadGraph graph, Throwable t) {
815 LOGGER.error("Failed to read properties.", t);
818 public void dispose() {
819 for (PropertyListener listener : listenerCache.values())
822 listenerCache.clear();
823 SessionEventSupport support = processor.getService(SessionEventSupport.class);
824 support.removeListener(listener);
828 private void synchronize(List<Object> list) {
829 Simantics.getSession().asyncRequest(new FullSynchronizeBook(run, list));
832 public static class FullSynchronizeBook extends ReadRequest {
834 private final Variable run;
835 private final List<Object> location;
837 public FullSynchronizeBook(Variable run, List<Object> cellLocation) {
839 this.location = cellLocation;
843 public void run(ReadGraph graph) throws DatabaseException {
844 String uri = run.getURI(graph);
845 String parentUri = run.getParent(graph).getURI(graph);
846 System.err.println("Full sync for book " + parentUri);
848 Resource sheetResource = run.getRepresents(graph);
849 Variable sheetVariable = Variables.getVariable(graph, sheetResource);
851 TObjectIntHashMap<Variable> changes = null;
852 if (location != null) {
853 changes = new TObjectIntHashMap<>(location.size());
854 for (Object loc : location) {
855 Variable var = (Variable) loc;
859 SpreadsheetGraphUtils.partialSynchronization(graph, run.getParent(graph), changes);
864 private SpreadsheetBook getBook(ReadGraph graph) throws DatabaseException {
865 String sessionName = run.getParent(graph).getParent(graph).getURI(graph);
866 StandardRealm<SheetNode, SpreadsheetBook> realm = SpreadsheetSessionManager.getInstance().getOrCreateRealm(graph, sessionName);
867 SpreadsheetBook book = realm.getEngine();