]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/DefaultConnectionClassFactory.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / adapter / DefaultConnectionClassFactory.java
index 8c460c8734a0a4839156c74fc810c360e724c7d5..196d710fc8851db3818191c8dcadd34a0425f308 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.diagram.adapter;\r
-\r
-import org.simantics.db.AsyncReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.procedure.guarded.GuardedAsyncProcedureWrapper;\r
-import org.simantics.db.procedure.AsyncProcedure;\r
-import org.simantics.diagram.stubs.DiagramResource;\r
-import org.simantics.diagram.synchronization.graph.DiagramGraphUtil;\r
-import org.simantics.g2d.canvas.ICanvasContext;\r
-import org.simantics.g2d.diagram.DiagramHints;\r
-import org.simantics.g2d.diagram.IDiagram;\r
-import org.simantics.g2d.element.ElementClass;\r
-import org.simantics.g2d.element.IElement;\r
-import org.simantics.g2d.element.handler.impl.StaticObjectAdapter;\r
-import org.simantics.g2d.elementclass.connection.ConnectionClass;\r
-import org.simantics.g2d.routing.IRouter2;\r
-import org.simantics.structural.stubs.StructuralResource2;\r
-\r
-/**\r
- * An element class for single connection entity elements. A connection entity\r
- * consists of connection edge segments and branch points as its children.\r
- * \r
- * @author Tuukka Lehtonen\r
- */\r
-public class DefaultConnectionClassFactory extends ElementFactoryAdapter {\r
-\r
-    public static final ElementClass CLASS = ConnectionClass.CLASS;\r
-\r
-    @Override\r
-    public void create(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementType, final AsyncProcedure<ElementClass> procedure) {\r
-        procedure.execute(graph, ConnectionClass.CLASS.newClassWith(false, new StaticObjectAdapter(elementType)));\r
-    }\r
-\r
-    @Override\r
-    protected Resource getElementClassBaseType(AsyncReadGraph graph) {\r
-        return graph.getService(DiagramResource.class).Connection;\r
-    }\r
-\r
-    @Override\r
-    public void load(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, final Resource elementResource,\r
-            final IElement element, final AsyncProcedure<IElement> procedure) {\r
-        final GuardedAsyncProcedureWrapper<IElement> guard = new GuardedAsyncProcedureWrapper<IElement>(procedure, 1);\r
-\r
-        // Get custom routing algorithm for connection if necessary.\r
-        DiagramGraphUtil.getPossibleRouter(graph, elementResource, new AsyncProcedure<IRouter2>() {\r
-            @Override\r
-            public void exception(AsyncReadGraph graph, Throwable throwable) {\r
-                guard.exception(graph, throwable);\r
-            }\r
-            @Override\r
-            public void execute(AsyncReadGraph graph, IRouter2 router) {\r
-                if (router != null) {\r
-                    element.setHint(DiagramHints.ROUTE_ALGORITHM, router);\r
-                    procedure.execute(graph, element);\r
-                } else {\r
-                    loadConnectionTypeDefaultRouting(graph, element, elementResource, guard);\r
-                }\r
-            }\r
-        });\r
-    }\r
-\r
-    protected void loadConnectionTypeDefaultRouting(AsyncReadGraph graph, final IElement element, Resource elementResource, final AsyncProcedure<IElement> guard) {\r
-        StructuralResource2 STR = graph.getService(StructuralResource2.class);\r
-        graph.forPossibleObject(elementResource, STR.HasConnectionType, new AsyncProcedure<Resource>() {\r
-            @Override\r
-            public void exception(AsyncReadGraph graph, Throwable throwable) {\r
-                guard.exception(graph, throwable);\r
-            }\r
-            @Override\r
-            public void execute(AsyncReadGraph graph, Resource connectionType) {\r
-                DiagramResource DIA = graph.getService(DiagramResource.class);\r
-                if (connectionType != null) {\r
-                    graph.forPossibleObject(connectionType, DIA.HasDefaultRouting, new AsyncProcedure<Resource>() {\r
-                        @Override\r
-                        public void exception(AsyncReadGraph graph, Throwable throwable) {\r
-                            guard.exception(graph, throwable);\r
-                        }\r
-                        @Override\r
-                        public void execute(AsyncReadGraph graph, Resource routing) {\r
-                            if (routing != null) {\r
-                                graph.forPossibleAdapted(routing, IRouter2.class, new AsyncProcedure<IRouter2>() {\r
-                                    @Override\r
-                                    public void exception(AsyncReadGraph graph, Throwable throwable) {\r
-                                        guard.exception(graph, throwable);\r
-                                    }\r
-                                    @Override\r
-                                    public void execute(AsyncReadGraph graph, IRouter2 router) {\r
-                                        if (router != null)\r
-                                            element.setHint(DiagramHints.ROUTE_ALGORITHM, router);\r
-                                        guard.execute(graph, element);\r
-                                    }\r
-                                });\r
-                            } else {\r
-                                guard.execute(graph, element);\r
-                            }\r
-                        }\r
-                    });\r
-                } else {\r
-                    guard.execute(graph, element);\r
-                }\r
-            }\r
-        });\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.Resource;
+import org.simantics.db.common.procedure.guarded.GuardedAsyncProcedureWrapper;
+import org.simantics.db.procedure.AsyncProcedure;
+import org.simantics.diagram.stubs.DiagramResource;
+import org.simantics.diagram.synchronization.graph.DiagramGraphUtil;
+import org.simantics.g2d.canvas.ICanvasContext;
+import org.simantics.g2d.diagram.DiagramHints;
+import org.simantics.g2d.diagram.IDiagram;
+import org.simantics.g2d.element.ElementClass;
+import org.simantics.g2d.element.IElement;
+import org.simantics.g2d.element.handler.impl.StaticObjectAdapter;
+import org.simantics.g2d.elementclass.connection.ConnectionClass;
+import org.simantics.g2d.routing.IRouter2;
+import org.simantics.structural.stubs.StructuralResource2;
+
+/**
+ * An element class for single connection entity elements. A connection entity
+ * consists of connection edge segments and branch points as its children.
+ * 
+ * @author Tuukka Lehtonen
+ */
+public class DefaultConnectionClassFactory extends ElementFactoryAdapter {
+
+    public static final ElementClass CLASS = ConnectionClass.CLASS;
+
+    @Override
+    public void create(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementType, final AsyncProcedure<ElementClass> procedure) {
+        procedure.execute(graph, ConnectionClass.CLASS.newClassWith(false, new StaticObjectAdapter(elementType)));
+    }
+
+    @Override
+    protected Resource getElementClassBaseType(AsyncReadGraph graph) {
+        return graph.getService(DiagramResource.class).Connection;
+    }
+
+    @Override
+    public void load(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, final Resource elementResource,
+            final IElement element, final AsyncProcedure<IElement> procedure) {
+        final GuardedAsyncProcedureWrapper<IElement> guard = new GuardedAsyncProcedureWrapper<IElement>(procedure, 1);
+
+        // Get custom routing algorithm for connection if necessary.
+        DiagramGraphUtil.getPossibleRouter(graph, elementResource, new AsyncProcedure<IRouter2>() {
+            @Override
+            public void exception(AsyncReadGraph graph, Throwable throwable) {
+                guard.exception(graph, throwable);
+            }
+            @Override
+            public void execute(AsyncReadGraph graph, IRouter2 router) {
+                if (router != null) {
+                    element.setHint(DiagramHints.ROUTE_ALGORITHM, router);
+                    procedure.execute(graph, element);
+                } else {
+                    loadConnectionTypeDefaultRouting(graph, element, elementResource, guard);
+                }
+            }
+        });
+    }
+
+    protected void loadConnectionTypeDefaultRouting(AsyncReadGraph graph, final IElement element, Resource elementResource, final AsyncProcedure<IElement> guard) {
+        StructuralResource2 STR = graph.getService(StructuralResource2.class);
+        graph.forPossibleObject(elementResource, STR.HasConnectionType, new AsyncProcedure<Resource>() {
+            @Override
+            public void exception(AsyncReadGraph graph, Throwable throwable) {
+                guard.exception(graph, throwable);
+            }
+            @Override
+            public void execute(AsyncReadGraph graph, Resource connectionType) {
+                DiagramResource DIA = graph.getService(DiagramResource.class);
+                if (connectionType != null) {
+                    graph.forPossibleObject(connectionType, DIA.HasDefaultRouting, new AsyncProcedure<Resource>() {
+                        @Override
+                        public void exception(AsyncReadGraph graph, Throwable throwable) {
+                            guard.exception(graph, throwable);
+                        }
+                        @Override
+                        public void execute(AsyncReadGraph graph, Resource routing) {
+                            if (routing != null) {
+                                graph.forPossibleAdapted(routing, IRouter2.class, new AsyncProcedure<IRouter2>() {
+                                    @Override
+                                    public void exception(AsyncReadGraph graph, Throwable throwable) {
+                                        guard.exception(graph, throwable);
+                                    }
+                                    @Override
+                                    public void execute(AsyncReadGraph graph, IRouter2 router) {
+                                        if (router != null)
+                                            element.setHint(DiagramHints.ROUTE_ALGORITHM, router);
+                                        guard.execute(graph, element);
+                                    }
+                                });
+                            } else {
+                                guard.execute(graph, element);
+                            }
+                        }
+                    });
+                } else {
+                    guard.execute(graph, element);
+                }
+            }
+        });
+    }
+
+}