]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/ConnectionInfoRequest.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / adapter / ConnectionInfoRequest.java
index 6b27eb2913e69469d1bf0429c21800ed8cd9d827..826d55e30336d4d0980606b335a7af46597fa370 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 java.util.concurrent.atomic.AtomicInteger;\r
-\r
-import org.simantics.db.AsyncReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.request.UnaryAsyncRead;\r
-import org.simantics.db.procedure.AsyncProcedure;\r
-import org.simantics.diagram.connection.ConnectionSegmentEnd;\r
-import org.simantics.diagram.connection.ConnectionSegmentType;\r
-import org.simantics.diagram.content.EdgeResource;\r
-import org.simantics.diagram.stubs.DiagramResource;\r
-\r
-/**\r
- * @author Antti Villberg\r
- *\r
- */\r
-public class ConnectionInfoRequest extends UnaryAsyncRead<EdgeResource, ConnectionInfo> {\r
-\r
-    static class SingleConnectionInfo {\r
-        public Resource connection;\r
-        public ConnectionSegmentEnd end;\r
-    }\r
-\r
-    final DiagramResource dr;\r
-\r
-    private SingleConnectionInfo first;\r
-    private SingleConnectionInfo second;\r
-\r
-    public ConnectionInfoRequest(DiagramResource dr, EdgeResource resource) {\r
-        super(resource);\r
-        this.dr = dr;\r
-    }\r
-\r
-    public void fillPossibleType(AsyncReadGraph graph, Resource resource, final AsyncProcedure<ConnectionInfo> procedure, final ConnectionInfo result) {\r
-        if (resource == null) {\r
-            procedure.execute(graph, result);\r
-        } else {\r
-            graph.forSingleType(resource, dr.Connection, new AsyncProcedure<Resource>() {\r
-                @Override\r
-                public void exception(AsyncReadGraph graph, Throwable throwable) {\r
-                    procedure.exception(graph, throwable);\r
-                }\r
-\r
-                @Override\r
-                public void execute(AsyncReadGraph graph, Resource type) {\r
-                    result.connectionType = type;\r
-                    procedure.execute(graph, result);\r
-                }\r
-            });\r
-        }\r
-    }\r
-\r
-    ConnectionInfo createConnectionInfo(Resource connection) {\r
-        ConnectionInfo info = new ConnectionInfo();\r
-        info.connection = connection;\r
-        info.firstEnd = first.end;\r
-        info.secondEnd = second.end;\r
-        info.segmentType = ConnectionSegmentType.toSegmentType(first.end, second.end);\r
-        return info;\r
-    }\r
-\r
-    public void isBranchPointOf(AsyncReadGraph graph, Resource resource, final AsyncProcedure<ConnectionInfo> procedure, final SingleConnectionInfo result, final AtomicInteger ready) {\r
-\r
-        graph.forPossibleObject(resource, dr.IsBranchPointOf, new AsyncProcedure<Resource>() {\r
-            @Override\r
-            public void exception(AsyncReadGraph graph, Throwable throwable) {\r
-                procedure.exception(graph, throwable);\r
-            }\r
-\r
-            @Override\r
-            public void execute(AsyncReadGraph graph, Resource connection) {\r
-                result.end = ConnectionSegmentEnd.BRANCH;\r
-                result.connection = connection;\r
-                if (ready.decrementAndGet() == 0) {\r
-                    ConnectionInfo info = createConnectionInfo(connection);\r
-                    fillPossibleType(graph, connection, procedure, info);\r
-                }\r
-            }\r
-        });\r
-\r
-    }\r
-\r
-    public void isConnectorOf(AsyncReadGraph graph, final Resource resource, final AsyncProcedure<ConnectionInfo> procedure, final SingleConnectionInfo result, final AtomicInteger ready) {\r
-\r
-        graph.forPossibleObject(resource, dr.IsConnectorOf, new AsyncProcedure<Resource>() {\r
-            @Override\r
-            public void exception(AsyncReadGraph graph, Throwable throwable) {\r
-                procedure.exception(graph, throwable);\r
-            }\r
-\r
-            @Override\r
-            public void execute(AsyncReadGraph graph, Resource connection) {\r
-                if (connection != null) {\r
-                    result.end = ConnectionSegmentEnd.CONNECTOR;\r
-                    result.connection = connection;\r
-                    if (ready.decrementAndGet() == 0) {\r
-                        ConnectionInfo info = createConnectionInfo(connection);\r
-                        fillPossibleType(graph, connection, procedure, info);\r
-                    }\r
-                } else {\r
-                    isBranchPointOf(graph, resource, procedure, result, ready);\r
-                }\r
-            }\r
-        });\r
-\r
-    }\r
-\r
-    @Override\r
-    public void perform(AsyncReadGraph graph, AsyncProcedure<ConnectionInfo> procedure) {\r
-        AtomicInteger ready = new AtomicInteger(2);\r
-        first = new SingleConnectionInfo();\r
-        second = new SingleConnectionInfo();\r
-        isConnectorOf(graph, parameter.first(), procedure, first, ready);\r
-        isConnectorOf(graph, parameter.second(), procedure, second, ready);\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 java.util.concurrent.atomic.AtomicInteger;
+
+import org.simantics.db.AsyncReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.request.UnaryAsyncRead;
+import org.simantics.db.procedure.AsyncProcedure;
+import org.simantics.diagram.connection.ConnectionSegmentEnd;
+import org.simantics.diagram.connection.ConnectionSegmentType;
+import org.simantics.diagram.content.EdgeResource;
+import org.simantics.diagram.stubs.DiagramResource;
+
+/**
+ * @author Antti Villberg
+ *
+ */
+public class ConnectionInfoRequest extends UnaryAsyncRead<EdgeResource, ConnectionInfo> {
+
+    static class SingleConnectionInfo {
+        public Resource connection;
+        public ConnectionSegmentEnd end;
+    }
+
+    final DiagramResource dr;
+
+    private SingleConnectionInfo first;
+    private SingleConnectionInfo second;
+
+    public ConnectionInfoRequest(DiagramResource dr, EdgeResource resource) {
+        super(resource);
+        this.dr = dr;
+    }
+
+    public void fillPossibleType(AsyncReadGraph graph, Resource resource, final AsyncProcedure<ConnectionInfo> procedure, final ConnectionInfo result) {
+        if (resource == null) {
+            procedure.execute(graph, result);
+        } else {
+            graph.forSingleType(resource, dr.Connection, new AsyncProcedure<Resource>() {
+                @Override
+                public void exception(AsyncReadGraph graph, Throwable throwable) {
+                    procedure.exception(graph, throwable);
+                }
+
+                @Override
+                public void execute(AsyncReadGraph graph, Resource type) {
+                    result.connectionType = type;
+                    procedure.execute(graph, result);
+                }
+            });
+        }
+    }
+
+    ConnectionInfo createConnectionInfo(Resource connection) {
+        ConnectionInfo info = new ConnectionInfo();
+        info.connection = connection;
+        info.firstEnd = first.end;
+        info.secondEnd = second.end;
+        info.segmentType = ConnectionSegmentType.toSegmentType(first.end, second.end);
+        return info;
+    }
+
+    public void isBranchPointOf(AsyncReadGraph graph, Resource resource, final AsyncProcedure<ConnectionInfo> procedure, final SingleConnectionInfo result, final AtomicInteger ready) {
+
+        graph.forPossibleObject(resource, dr.IsBranchPointOf, new AsyncProcedure<Resource>() {
+            @Override
+            public void exception(AsyncReadGraph graph, Throwable throwable) {
+                procedure.exception(graph, throwable);
+            }
+
+            @Override
+            public void execute(AsyncReadGraph graph, Resource connection) {
+                result.end = ConnectionSegmentEnd.BRANCH;
+                result.connection = connection;
+                if (ready.decrementAndGet() == 0) {
+                    ConnectionInfo info = createConnectionInfo(connection);
+                    fillPossibleType(graph, connection, procedure, info);
+                }
+            }
+        });
+
+    }
+
+    public void isConnectorOf(AsyncReadGraph graph, final Resource resource, final AsyncProcedure<ConnectionInfo> procedure, final SingleConnectionInfo result, final AtomicInteger ready) {
+
+        graph.forPossibleObject(resource, dr.IsConnectorOf, new AsyncProcedure<Resource>() {
+            @Override
+            public void exception(AsyncReadGraph graph, Throwable throwable) {
+                procedure.exception(graph, throwable);
+            }
+
+            @Override
+            public void execute(AsyncReadGraph graph, Resource connection) {
+                if (connection != null) {
+                    result.end = ConnectionSegmentEnd.CONNECTOR;
+                    result.connection = connection;
+                    if (ready.decrementAndGet() == 0) {
+                        ConnectionInfo info = createConnectionInfo(connection);
+                        fillPossibleType(graph, connection, procedure, info);
+                    }
+                } else {
+                    isBranchPointOf(graph, resource, procedure, result, ready);
+                }
+            }
+        });
+
+    }
+
+    @Override
+    public void perform(AsyncReadGraph graph, AsyncProcedure<ConnectionInfo> procedure) {
+        AtomicInteger ready = new AtomicInteger(2);
+        first = new SingleConnectionInfo();
+        second = new SingleConnectionInfo();
+        isConnectorOf(graph, parameter.first(), procedure, first, ready);
+        isConnectorOf(graph, parameter.second(), procedure, second, ready);
+    }
+
+}