]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/SyncElementFactory.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / adapter / SyncElementFactory.java
index be03b91256295349d1f954e4900a47b2f3eb056d..5e9d2204dcdab61c881c1e5e07f215f8871bb5d6 100644 (file)
@@ -1,72 +1,72 @@
-/*******************************************************************************\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.diagram.adapter;\r
-\r
-import org.simantics.db.AsyncReadGraph;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.request.UniqueRead;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.procedure.AsyncProcedure;\r
-import org.simantics.g2d.canvas.ICanvasContext;\r
-import org.simantics.g2d.diagram.IDiagram;\r
-import org.simantics.g2d.element.ElementClass;\r
-import org.simantics.g2d.element.IElement;\r
-\r
-/**\r
- * A synchronous graph request wrapper for {@link ElementFactory} and\r
- * {@link ElementFactoryAdapter}. Using it will provide simpler but slower\r
- * implementations.\r
- * \r
- * @author Tuukka Lehtonen\r
- */\r
-public class SyncElementFactory extends ElementFactoryAdapter {\r
-\r
-    @Override\r
-    public void create(AsyncReadGraph graph, final ICanvasContext canvas, final IDiagram diagram,\r
-            final Resource elementType, final AsyncProcedure<ElementClass> procedure) {\r
-        graph.asyncRequest(new UniqueRead<ElementClass>() {\r
-            @Override\r
-            public ElementClass perform(ReadGraph graph) throws DatabaseException {\r
-                return create(graph, canvas, diagram, elementType);\r
-            }\r
-        }, procedure);\r
-    }\r
-\r
-    @Override\r
-    public void load(AsyncReadGraph graph, final ICanvasContext canvas, final IDiagram diagram,\r
-            final Resource elementResource, final IElement element, final AsyncProcedure<IElement> procedure) {\r
-        graph.asyncRequest(new UniqueRead<IElement>() {\r
-            @Override\r
-            public IElement perform(ReadGraph graph) throws DatabaseException {\r
-               if(isOk(graph, elementResource))\r
-                       load(graph, canvas, diagram, elementResource, element);\r
-                return element;\r
-            }\r
-        }, procedure);\r
-    }\r
-\r
-    public ElementClass create(ReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementType)\r
-    throws DatabaseException {\r
-        throw new UnsupportedOperationException();\r
-    }\r
-    \r
-    public boolean isOk(ReadGraph graph, Resource elementResource) throws DatabaseException {\r
-       return graph.hasStatement(elementResource);\r
-    }\r
-\r
-    public void load(ReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementResource, IElement element)\r
-    throws DatabaseException {\r
-        throw new UnsupportedOperationException();\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.diagram.adapter;
+
+import org.simantics.db.AsyncReadGraph;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.request.UniqueRead;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.procedure.AsyncProcedure;
+import org.simantics.g2d.canvas.ICanvasContext;
+import org.simantics.g2d.diagram.IDiagram;
+import org.simantics.g2d.element.ElementClass;
+import org.simantics.g2d.element.IElement;
+
+/**
+ * A synchronous graph request wrapper for {@link ElementFactory} and
+ * {@link ElementFactoryAdapter}. Using it will provide simpler but slower
+ * implementations.
+ * 
+ * @author Tuukka Lehtonen
+ */
+public class SyncElementFactory extends ElementFactoryAdapter {
+
+    @Override
+    public void create(AsyncReadGraph graph, final ICanvasContext canvas, final IDiagram diagram,
+            final Resource elementType, final AsyncProcedure<ElementClass> procedure) {
+        graph.asyncRequest(new UniqueRead<ElementClass>() {
+            @Override
+            public ElementClass perform(ReadGraph graph) throws DatabaseException {
+                return create(graph, canvas, diagram, elementType);
+            }
+        }, procedure);
+    }
+
+    @Override
+    public void load(AsyncReadGraph graph, final ICanvasContext canvas, final IDiagram diagram,
+            final Resource elementResource, final IElement element, final AsyncProcedure<IElement> procedure) {
+        graph.asyncRequest(new UniqueRead<IElement>() {
+            @Override
+            public IElement perform(ReadGraph graph) throws DatabaseException {
+               if(isOk(graph, elementResource))
+                       load(graph, canvas, diagram, elementResource, element);
+                return element;
+            }
+        }, procedure);
+    }
+
+    public ElementClass create(ReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementType)
+    throws DatabaseException {
+        throw new UnsupportedOperationException("This method should be implemented by subclass " + getClass().getName());
+    }
+    
+    public boolean isOk(ReadGraph graph, Resource elementResource) throws DatabaseException {
+       return graph.hasStatement(elementResource);
+    }
+
+    public void load(ReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementResource, IElement element)
+    throws DatabaseException {
+        throw new UnsupportedOperationException("This method should be implemented by subclass " + getClass().getName());
+    }
+
+}