]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.diagram/src/org/simantics/diagram/symbolcontribution/IndexRootSymbolProviderFactory.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / symbolcontribution / IndexRootSymbolProviderFactory.java
index da9c542a1f71de357f56b51d03d2fa3af2739454..b0c28da10142fab393889f3b1e27af59c51fd674 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.symbolcontribution;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collection;\r
-\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.request.BinaryRead;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.adapter.Instances;\r
-import org.simantics.diagram.stubs.DiagramResource;\r
-import org.simantics.diagram.symbollibrary.ISymbolGroup;\r
-import org.simantics.layer0.Layer0;\r
-\r
-/**\r
- * \r
- * @author Antti Villberg\r
- */\r
-public class IndexRootSymbolProviderFactory implements SymbolProviderFactory {\r
-               \r
-    Resource indexRoot;\r
-    Resource diagram;\r
-\r
-    public IndexRootSymbolProviderFactory(Resource indexRoot, Resource diagram) {\r
-        this.indexRoot = indexRoot;\r
-        this.diagram = diagram;\r
-    }\r
-\r
-       @Override\r
-       public int hashCode() {\r
-               final int prime = 31;\r
-               int result = 1;\r
-               result = prime * result + ((diagram == null) ? 0 : diagram.hashCode());\r
-               result = prime * result + ((indexRoot == null) ? 0 : indexRoot.hashCode());\r
-               return result;\r
-       }\r
-\r
-       @Override\r
-       public boolean equals(Object obj) {\r
-               if (this == obj)\r
-                       return true;\r
-               if (obj == null)\r
-                       return false;\r
-               if (getClass() != obj.getClass())\r
-                       return false;\r
-               IndexRootSymbolProviderFactory other = (IndexRootSymbolProviderFactory) obj;\r
-               if (diagram == null) {\r
-                       if (other.diagram != null)\r
-                               return false;\r
-               } else if (!diagram.equals(other.diagram))\r
-                       return false;\r
-               if (indexRoot == null) {\r
-                       if (other.indexRoot != null)\r
-                               return false;\r
-               } else if (!indexRoot.equals(other.indexRoot))\r
-                       return false;\r
-               return true;\r
-       }\r
-\r
-    @Override\r
-    public ISymbolProvider create(ReadGraph g) throws DatabaseException {\r
-        return g.syncRequest(new LoadRequest(indexRoot, diagram));\r
-    }\r
-\r
-    static class LoadRequest extends BinaryRead<Resource, Resource, ISymbolProvider> {\r
-        public LoadRequest(Resource contribution, Resource diagram) {\r
-            super(contribution, diagram);\r
-        }\r
-        @Override\r
-        public ISymbolProvider perform(ReadGraph graph) throws DatabaseException {\r
-               \r
-               Layer0 L0 = Layer0.getInstance(graph);\r
-            DiagramResource dr = DiagramResource.getInstance(graph);\r
-            \r
-            Collection<ISymbolGroup> groups = new ArrayList<ISymbolGroup>();\r
-            \r
-            if (parameter != null) {\r
-               Instances query = graph.adapt(dr.SymbolReferenceLibrary, Instances.class);\r
-               for(Resource library : query.find(graph, parameter)) {\r
-                    if (SymbolProviderFactories.accept(graph, dr, library, parameter2)) {\r
-                               groups.add(BasicSymbolProviderFactory.createGroup(graph, library, L0.IsRelatedTo, parameter2));\r
-                    }\r
-               }\r
-            }\r
-\r
-            return new SymbolProvider(groups);\r
-        }\r
-    }\r
-\r
-    static class SymbolProvider extends AbstractSymbolProvider {\r
-        public SymbolProvider(Collection<ISymbolGroup> groups) {\r
-            super();\r
-            setSymbolGroup(groups);\r
-            lockGroups();\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.symbolcontribution;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.request.BinaryRead;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.adapter.Instances;
+import org.simantics.diagram.stubs.DiagramResource;
+import org.simantics.diagram.symbollibrary.ISymbolGroup;
+import org.simantics.layer0.Layer0;
+
+/**
+ * 
+ * @author Antti Villberg
+ */
+public class IndexRootSymbolProviderFactory implements SymbolProviderFactory {
+               
+    Resource indexRoot;
+    Resource diagram;
+
+    public IndexRootSymbolProviderFactory(Resource indexRoot, Resource diagram) {
+        this.indexRoot = indexRoot;
+        this.diagram = diagram;
+    }
+
+       @Override
+       public int hashCode() {
+               final int prime = 31;
+               int result = 1;
+               result = prime * result + ((diagram == null) ? 0 : diagram.hashCode());
+               result = prime * result + ((indexRoot == null) ? 0 : indexRoot.hashCode());
+               return result;
+       }
+
+       @Override
+       public boolean equals(Object obj) {
+               if (this == obj)
+                       return true;
+               if (obj == null)
+                       return false;
+               if (getClass() != obj.getClass())
+                       return false;
+               IndexRootSymbolProviderFactory other = (IndexRootSymbolProviderFactory) obj;
+               if (diagram == null) {
+                       if (other.diagram != null)
+                               return false;
+               } else if (!diagram.equals(other.diagram))
+                       return false;
+               if (indexRoot == null) {
+                       if (other.indexRoot != null)
+                               return false;
+               } else if (!indexRoot.equals(other.indexRoot))
+                       return false;
+               return true;
+       }
+
+    @Override
+    public ISymbolProvider create(ReadGraph g) throws DatabaseException {
+        return g.syncRequest(new LoadRequest(indexRoot, diagram));
+    }
+
+    static class LoadRequest extends BinaryRead<Resource, Resource, ISymbolProvider> {
+        public LoadRequest(Resource contribution, Resource diagram) {
+            super(contribution, diagram);
+        }
+        @Override
+        public ISymbolProvider perform(ReadGraph graph) throws DatabaseException {
+               
+               Layer0 L0 = Layer0.getInstance(graph);
+            DiagramResource dr = DiagramResource.getInstance(graph);
+            
+            Collection<ISymbolGroup> groups = new ArrayList<ISymbolGroup>();
+            
+            if (parameter != null) {
+               Instances query = graph.adapt(dr.SymbolReferenceLibrary, Instances.class);
+               for(Resource library : query.find(graph, parameter)) {
+                    if (SymbolProviderFactories.accept(graph, dr, library, parameter2)) {
+                               groups.add(BasicSymbolProviderFactory.createGroup(graph, library, L0.IsRelatedTo, parameter2));
+                    }
+               }
+            }
+
+            return new SymbolProvider(groups);
+        }
+    }
+
+    static class SymbolProvider extends AbstractSymbolProvider {
+        public SymbolProvider(Collection<ISymbolGroup> groups) {
+            super();
+            setSymbolGroup(groups);
+            lockGroups();
+        }
+    }
+
+}