]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/GraphBackend.java
Remove usage of deprecated SimanticsUI-methods
[simantics/platform.git] / bundles / org.simantics.spreadsheet.graph / src / org / simantics / spreadsheet / graph / GraphBackend.java
index 929d9ce62c897eebe712256764a83f9b2d3d6477..f57142b843a097de570fcd634b237069b7cea2eb 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.spreadsheet.graph;\r
-\r
-import org.simantics.db.AsyncReadGraph;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.RequestProcessor;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.VirtualGraph;\r
-import org.simantics.db.common.procedure.adapter.AsyncListenerSupport;\r
-import org.simantics.db.common.procedure.adapter.ListenerSupport;\r
-import org.simantics.db.common.procedure.adapter.SyncListenerSupport;\r
-import org.simantics.db.common.processor.MergingDelayedWriteProcessor;\r
-import org.simantics.db.common.processor.MergingWriteOnlyProcessor;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.variable.Variable;\r
-import org.simantics.spreadsheet.Adaptable;\r
-import org.simantics.spreadsheet.CellEditor;\r
-import org.simantics.ui.SimanticsUI;\r
-\r
-public class GraphBackend implements Adaptable, ListenerSupport, AsyncListenerSupport, SyncListenerSupport {\r
-\r
-       final private RequestProcessor processor;\r
-\r
-       final private VirtualGraph virtualGraph;\r
-\r
-       private Resource model;\r
-//     private Resource spreadsheet;\r
-//     private Variable sheet;\r
-//     private ModelCellManager creator;\r
-       private CellEditor editor;\r
-       private boolean disposed = false;\r
-\r
-       final private MergingDelayedWriteProcessor delayedMerger;\r
-       final private MergingWriteOnlyProcessor writeOnlyMerger;\r
-       \r
-       public GraphBackend(RequestProcessor processor, VirtualGraph virtualGraph) {\r
-               this.processor = processor;\r
-               this.virtualGraph = virtualGraph;\r
-               delayedMerger = new MergingDelayedWriteProcessor(SimanticsUI.getSessionContext().getSession(), 5);\r
-               writeOnlyMerger = new MergingWriteOnlyProcessor(SimanticsUI.getSessionContext().getSession(), virtualGraph, 5);\r
-       }\r
-       \r
-       public RequestProcessor getModifier() {\r
-               return delayedMerger;\r
-       }\r
-\r
-       public RequestProcessor getWriteOnlyModifier() {\r
-               return writeOnlyMerger;\r
-       }\r
-\r
-       public void load(RequestProcessor proc, final Resource model, final Variable sheet) throws DatabaseException {\r
-\r
-//             final ITask task = ThreadLogger.getInstance().begin("GraphBackend.load");\r
-//             \r
-//             this.model = model;\r
-//\r
-//             processor.asyncRequest(new ReadRequest() {\r
-//\r
-//                     @Override\r
-//                     public void run(ReadGraph graph) throws DatabaseException {\r
-//\r
-//                             Layer0 l0 = Layer0.getInstance(graph);\r
-//\r
-//                             SpreadsheetResource sr = SpreadsheetResource.getInstance(graph);\r
-//\r
-//                             final Resource realization = sheet.getInterface(graph, Resource.class);\r
-//                             Resource config = graph.getPossibleObject(realization, L0X.Represents);\r
-//\r
-//                             // TODO : remove this and make the request persistent\r
-//                             processor.asyncRequest(new Rows(config), new CacheListener<RowsColumnsIndex>(GraphBackend.this));\r
-//\r
-//                             creator = new DefaultCellCreator(processor, config);\r
-//                             editor = new DefaultCellEditor(processor, config);\r
-//\r
-//                             graph.forObjectSet(config, sr.HasCell, new AsyncSetListenerDelegate<Resource>(GraphBackend.this) {\r
-//\r
-//                                     @Override\r
-//                                     public void add(AsyncReadGraph graph, final Resource cellResource) {\r
-//\r
-//                                             graph.forAdapted(cellResource, ServerCell.class, new ResourceAsyncListenerDelegate<ServerCell>(cellResource, GraphBackend.this) {\r
-//\r
-//                                                     @Override\r
-//                                                     public void execute(AsyncReadGraph graph, final ServerCell cell) {\r
-//\r
-//                                                             cell.register(graph.getSession(), delayedMerger, cellResource);\r
-//\r
-//                                                             graph.getSession().asyncRequest(new WriteRequest(virtualGraph) {\r
-//\r
-//                                                                     @Override\r
-//                                                                     public void perform(WriteGraph graph) throws DatabaseException {\r
-//\r
-//                                                                             Layer0 L0 = Layer0.getInstance(graph);\r
-//                                                                             SpreadsheetResource sr = SpreadsheetResource.getInstance(graph);\r
-//\r
-//                                                                             Map<Resource, Resource> map = graph.syncRequest(new MappedParts(realization));\r
-//                                                                             Resource resource = map.get(cellResource);\r
-//                                                                             Resource realizationType = graph.syncRequest(new RealizationType(cellResource, sr.Realization));\r
-//\r
-//                                                                             if(resource == null) {\r
-//                                                                                     resource = graph.newResource();\r
-//                                                                                     graph.claim(resource, L0.InstanceOf, null, realizationType);\r
-//                                                                                     graph.claim(resource, L0X.Represents, null, cellResource);\r
-//                                                                                     graph.addLiteral(resource, sr.Label, sr.LabelOf, L0.String, "", Bindings.STRING );\r
-//                                                                                     graph.addLiteral(resource, sr.Content, sr.ContentOf, L0.String, "", Bindings.STRING );\r
-//                                                                                     graph.claim(realization, L0.ConsistsOf, L0.PartOf, resource);\r
-//                                                                             }\r
-//\r
-//                                                                             final AdaptionService service = graph.peekService(AdaptionService.class);\r
-//\r
-//                                                                             class Modifier implements ResourceAdapter<StringModifier> {\r
-//\r
-//                                                                                     public void adapt(AsyncReadGraph graph, Resource source, Resource r, AsyncProcedure<StringModifier> procedure) {\r
-//\r
-//                                                                                             procedure.execute(graph, new StringModifier() {\r
-//\r
-//                                                                                                     @Override\r
-//                                                                                                     public String isValid(String newValue) {\r
-//                                                                                                             return null;\r
-//                                                                                                     }\r
-//\r
-//                                                                                                     @Override\r
-//                                                                                                     public void modify(WriteGraph graph, String value) throws DatabaseException {\r
-//\r
-//                                                                                                             StringModifier modifier = graph.adapt(cellResource, StringModifier.class);\r
-//                                                                                                             modifier.modify(graph, value);\r
-//\r
-//                                                                                                     }\r
-//\r
-//                                                                                             });\r
-//\r
-//                                                                                     }\r
-//\r
-//                                                                             };\r
-//\r
-//                                                                             service.addInstanceAdapter(resource, StringModifier.class, new Modifier());\r
-//\r
-//                                                                             cell.listen(GraphBackend.this, graph, resource);\r
-//\r
-//                                                                     }\r
-//\r
-//                                                             });\r
-//\r
-//                                                     }\r
-//\r
-//                                             });\r
-//\r
-//\r
-//                                     }\r
-//\r
-//                                     @Override\r
-//                                     public void remove(AsyncReadGraph graph, final Resource cellResource) {\r
-//\r
-//                                     }\r
-//\r
-//                             });\r
-//                             \r
-//                             task.finish();\r
-//\r
-//                     }\r
-//\r
-//             });\r
-\r
-       }\r
-\r
-       @Override\r
-       public <T> T getAdapter(Class<T> clazz) {\r
-\r
-/*             if(ModelCellManager.class == clazz) return (T)creator;\r
-               else if(CellEditor.class == clazz) return (T)editor;\r
-               else*/ return null;\r
-\r
-       }\r
-\r
-       @Override\r
-       public void exception(Throwable t) {\r
-               t.printStackTrace();\r
-       }\r
-\r
-       @Override\r
-       public boolean isDisposed() {\r
-               return disposed;\r
-       }\r
-\r
-       @Override\r
-       public void exception(AsyncReadGraph graph, Throwable t) {\r
-               t.printStackTrace();\r
-       }\r
-\r
-       @Override\r
-       public void exception(ReadGraph graph, Throwable t) {\r
-               t.printStackTrace();\r
-       }\r
-\r
-       public VirtualGraph getVirtualGraph() {\r
-               return virtualGraph;\r
-       }\r
-\r
-       public Resource getModel() {\r
-               return model;\r
-       }\r
-       \r
-       public void dispose() {\r
-               disposed = true;\r
-       }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.spreadsheet.graph;
+
+import org.simantics.Simantics;
+import org.simantics.db.AsyncReadGraph;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.RequestProcessor;
+import org.simantics.db.Resource;
+import org.simantics.db.VirtualGraph;
+import org.simantics.db.common.procedure.adapter.AsyncListenerSupport;
+import org.simantics.db.common.procedure.adapter.ListenerSupport;
+import org.simantics.db.common.procedure.adapter.SyncListenerSupport;
+import org.simantics.db.common.processor.MergingDelayedWriteProcessor;
+import org.simantics.db.common.processor.MergingWriteOnlyProcessor;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.variable.Variable;
+import org.simantics.spreadsheet.Adaptable;
+import org.simantics.spreadsheet.CellEditor;
+
+public class GraphBackend implements Adaptable, ListenerSupport, AsyncListenerSupport, SyncListenerSupport {
+
+       final private RequestProcessor processor;
+
+       final private VirtualGraph virtualGraph;
+
+       private Resource model;
+//     private Resource spreadsheet;
+//     private Variable sheet;
+//     private ModelCellManager creator;
+       private CellEditor editor;
+       private boolean disposed = false;
+
+       final private MergingDelayedWriteProcessor delayedMerger;
+       final private MergingWriteOnlyProcessor writeOnlyMerger;
+       
+       public GraphBackend(RequestProcessor processor, VirtualGraph virtualGraph) {
+               this.processor = processor;
+               this.virtualGraph = virtualGraph;
+               delayedMerger = new MergingDelayedWriteProcessor(Simantics.getSessionContext().getSession(), 5);
+               writeOnlyMerger = new MergingWriteOnlyProcessor(Simantics.getSessionContext().getSession(), virtualGraph, 5);
+       }
+       
+       public RequestProcessor getModifier() {
+               return delayedMerger;
+       }
+
+       public RequestProcessor getWriteOnlyModifier() {
+               return writeOnlyMerger;
+       }
+
+       public void load(RequestProcessor proc, final Resource model, final Variable sheet) throws DatabaseException {
+
+//             final ITask task = ThreadLogger.getInstance().begin("GraphBackend.load");
+//             
+//             this.model = model;
+//
+//             processor.asyncRequest(new ReadRequest() {
+//
+//                     @Override
+//                     public void run(ReadGraph graph) throws DatabaseException {
+//
+//                             Layer0 l0 = Layer0.getInstance(graph);
+//
+//                             SpreadsheetResource sr = SpreadsheetResource.getInstance(graph);
+//
+//                             final Resource realization = sheet.getInterface(graph, Resource.class);
+//                             Resource config = graph.getPossibleObject(realization, L0X.Represents);
+//
+//                             // TODO : remove this and make the request persistent
+//                             processor.asyncRequest(new Rows(config), new CacheListener<RowsColumnsIndex>(GraphBackend.this));
+//
+//                             creator = new DefaultCellCreator(processor, config);
+//                             editor = new DefaultCellEditor(processor, config);
+//
+//                             graph.forObjectSet(config, sr.HasCell, new AsyncSetListenerDelegate<Resource>(GraphBackend.this) {
+//
+//                                     @Override
+//                                     public void add(AsyncReadGraph graph, final Resource cellResource) {
+//
+//                                             graph.forAdapted(cellResource, ServerCell.class, new ResourceAsyncListenerDelegate<ServerCell>(cellResource, GraphBackend.this) {
+//
+//                                                     @Override
+//                                                     public void execute(AsyncReadGraph graph, final ServerCell cell) {
+//
+//                                                             cell.register(graph.getSession(), delayedMerger, cellResource);
+//
+//                                                             graph.getSession().asyncRequest(new WriteRequest(virtualGraph) {
+//
+//                                                                     @Override
+//                                                                     public void perform(WriteGraph graph) throws DatabaseException {
+//
+//                                                                             Layer0 L0 = Layer0.getInstance(graph);
+//                                                                             SpreadsheetResource sr = SpreadsheetResource.getInstance(graph);
+//
+//                                                                             Map<Resource, Resource> map = graph.syncRequest(new MappedParts(realization));
+//                                                                             Resource resource = map.get(cellResource);
+//                                                                             Resource realizationType = graph.syncRequest(new RealizationType(cellResource, sr.Realization));
+//
+//                                                                             if(resource == null) {
+//                                                                                     resource = graph.newResource();
+//                                                                                     graph.claim(resource, L0.InstanceOf, null, realizationType);
+//                                                                                     graph.claim(resource, L0X.Represents, null, cellResource);
+//                                                                                     graph.addLiteral(resource, sr.Label, sr.LabelOf, L0.String, "", Bindings.STRING );
+//                                                                                     graph.addLiteral(resource, sr.Content, sr.ContentOf, L0.String, "", Bindings.STRING );
+//                                                                                     graph.claim(realization, L0.ConsistsOf, L0.PartOf, resource);
+//                                                                             }
+//
+//                                                                             final AdaptionService service = graph.peekService(AdaptionService.class);
+//
+//                                                                             class Modifier implements ResourceAdapter<StringModifier> {
+//
+//                                                                                     public void adapt(AsyncReadGraph graph, Resource source, Resource r, AsyncProcedure<StringModifier> procedure) {
+//
+//                                                                                             procedure.execute(graph, new StringModifier() {
+//
+//                                                                                                     @Override
+//                                                                                                     public String isValid(String newValue) {
+//                                                                                                             return null;
+//                                                                                                     }
+//
+//                                                                                                     @Override
+//                                                                                                     public void modify(WriteGraph graph, String value) throws DatabaseException {
+//
+//                                                                                                             StringModifier modifier = graph.adapt(cellResource, StringModifier.class);
+//                                                                                                             modifier.modify(graph, value);
+//
+//                                                                                                     }
+//
+//                                                                                             });
+//
+//                                                                                     }
+//
+//                                                                             };
+//
+//                                                                             service.addInstanceAdapter(resource, StringModifier.class, new Modifier());
+//
+//                                                                             cell.listen(GraphBackend.this, graph, resource);
+//
+//                                                                     }
+//
+//                                                             });
+//
+//                                                     }
+//
+//                                             });
+//
+//
+//                                     }
+//
+//                                     @Override
+//                                     public void remove(AsyncReadGraph graph, final Resource cellResource) {
+//
+//                                     }
+//
+//                             });
+//                             
+//                             task.finish();
+//
+//                     }
+//
+//             });
+
+       }
+
+       @Override
+       public <T> T getAdapter(Class<T> clazz) {
+
+/*             if(ModelCellManager.class == clazz) return (T)creator;
+               else if(CellEditor.class == clazz) return (T)editor;
+               else*/ return null;
+
+       }
+
+       @Override
+       public void exception(Throwable t) {
+               t.printStackTrace();
+       }
+
+       @Override
+       public boolean isDisposed() {
+               return disposed;
+       }
+
+       @Override
+       public void exception(AsyncReadGraph graph, Throwable t) {
+               t.printStackTrace();
+       }
+
+       @Override
+       public void exception(ReadGraph graph, Throwable t) {
+               t.printStackTrace();
+       }
+
+       public VirtualGraph getVirtualGraph() {
+               return virtualGraph;
+       }
+
+       public Resource getModel() {
+               return model;
+       }
+       
+       public void dispose() {
+               disposed = true;
+       }
+
+}