]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/LazyTypeAcceptViewpoint.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.browsing.ui.graph.impl / src / org / simantics / browsing / ui / graph / impl / LazyTypeAcceptViewpoint.java
index 82e7f0c8faf60449e81f6cb41b1311e5a2edf456..b03ac89cb1b3a2bef420168fe954011e74b9fe36 100644 (file)
@@ -1,96 +1,96 @@
-/*******************************************************************************\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.browsing.ui.graph.impl;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collection;\r
-\r
-import org.simantics.browsing.ui.NodeContext;\r
-import org.simantics.browsing.ui.PrimitiveQueryUpdater;\r
-import org.simantics.browsing.ui.BuiltinKeys.ViewpointKey;\r
-import org.simantics.browsing.ui.common.NodeContextBuilder;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.layer0.Layer0;\r
-\r
-/**\r
- * A very simple viewpoint that by default browses Consists Of relations and\r
- * accepts as objects any children that are of any of the specified accepted\r
- * types.\r
- * \r
- * <p>\r
- * The accepted types must be returned through {@link #getAcceptedTypes()}\r
- * </p>\r
- * \r
- * <p>\r
- * The children production can be customized by overriding\r
- * {@link #getPotentialChildren(ReadGraph, Resource)}. Whatever is produced by this\r
- * method will be filtered through the list of accepted resource types.\r
- * </p>\r
- * \r
- * <p>\r
- * IMPORTANT: it is vital to actually implement this class and override the\r
- * {@link #getAcceptedTypes(ReadGraph)} method in the process. Otherwise the\r
- * equality comparisons of the resource queries used within LazyViewpoint will\r
- * not work properly!\r
- * </p>\r
- * \r
- * @author Tuukka Lehtonen\r
- */\r
-public abstract class LazyTypeAcceptViewpoint extends LazyViewpoint {\r
-    \r
-    public LazyTypeAcceptViewpoint(PrimitiveQueryUpdater updater, NodeContext context, ViewpointKey key) {\r
-        super(updater, context, key);\r
-    }\r
-\r
-    protected abstract Resource[] getAcceptedTypes(ReadGraph g);\r
-    \r
-    protected Collection<Resource> getPotentialChildren(ReadGraph g, Resource r) throws DatabaseException {\r
-       Layer0 L0 = Layer0.getInstance(g);\r
-        return g.getObjects(r, L0.ConsistsOf);\r
-    }\r
-\r
-    @Override\r
-    public NodeContext[] children(ReadGraph g) throws DatabaseException {\r
-        Resource input = getInput(Resource.class);\r
-        Resource[] accepted = getAcceptedTypes(g);\r
-        Collection<Resource> children = getPotentialChildren(g, input);\r
-        ArrayList<NodeContext> resultContexts = new ArrayList<NodeContext>();\r
-        for (Resource child : children) {\r
-            for (Resource acc : accepted) {\r
-                if (g.isInstanceOf(child, acc))\r
-                    resultContexts.add(NodeContextBuilder.buildWithInput(child));\r
-            }\r
-        }\r
-        return resultContexts.toArray(new NodeContext[resultContexts.size()]);\r
-    }\r
-\r
-    @Override\r
-    public Boolean hasChildren(ReadGraph g) throws DatabaseException {\r
-        return Boolean.valueOf(children(g).length > 0);\r
-    }\r
-\r
-    /*\r
-    public static class Stub extends LazyTypeAcceptViewpoint {\r
-        Resource[] acceptedTypes;\r
-        public Stub(PrimitiveQueryUpdater updater, INodeContext context, ViewpointKey key, Resource[] acceptedTypes) {\r
-            super(updater, context, key);\r
-            this.acceptedTypes = acceptedTypes;\r
-        }\r
-        @Override\r
-        protected Resource[] getAcceptedTypes(Graph g) {\r
-            return acceptedTypes;\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.browsing.ui.graph.impl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.simantics.browsing.ui.NodeContext;
+import org.simantics.browsing.ui.PrimitiveQueryUpdater;
+import org.simantics.browsing.ui.BuiltinKeys.ViewpointKey;
+import org.simantics.browsing.ui.common.NodeContextBuilder;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.layer0.Layer0;
+
+/**
+ * A very simple viewpoint that by default browses Consists Of relations and
+ * accepts as objects any children that are of any of the specified accepted
+ * types.
+ * 
+ * <p>
+ * The accepted types must be returned through {@link #getAcceptedTypes()}
+ * </p>
+ * 
+ * <p>
+ * The children production can be customized by overriding
+ * {@link #getPotentialChildren(ReadGraph, Resource)}. Whatever is produced by this
+ * method will be filtered through the list of accepted resource types.
+ * </p>
+ * 
+ * <p>
+ * IMPORTANT: it is vital to actually implement this class and override the
+ * {@link #getAcceptedTypes(ReadGraph)} method in the process. Otherwise the
+ * equality comparisons of the resource queries used within LazyViewpoint will
+ * not work properly!
+ * </p>
+ * 
+ * @author Tuukka Lehtonen
+ */
+public abstract class LazyTypeAcceptViewpoint extends LazyViewpoint {
+    
+    public LazyTypeAcceptViewpoint(PrimitiveQueryUpdater updater, NodeContext context, ViewpointKey key) {
+        super(updater, context, key);
+    }
+
+    protected abstract Resource[] getAcceptedTypes(ReadGraph g);
+    
+    protected Collection<Resource> getPotentialChildren(ReadGraph g, Resource r) throws DatabaseException {
+       Layer0 L0 = Layer0.getInstance(g);
+        return g.getObjects(r, L0.ConsistsOf);
+    }
+
+    @Override
+    public NodeContext[] children(ReadGraph g) throws DatabaseException {
+        Resource input = getInput(Resource.class);
+        Resource[] accepted = getAcceptedTypes(g);
+        Collection<Resource> children = getPotentialChildren(g, input);
+        ArrayList<NodeContext> resultContexts = new ArrayList<NodeContext>();
+        for (Resource child : children) {
+            for (Resource acc : accepted) {
+                if (g.isInstanceOf(child, acc))
+                    resultContexts.add(NodeContextBuilder.buildWithInput(child));
+            }
+        }
+        return resultContexts.toArray(new NodeContext[resultContexts.size()]);
+    }
+
+    @Override
+    public Boolean hasChildren(ReadGraph g) throws DatabaseException {
+        return Boolean.valueOf(children(g).length > 0);
+    }
+
+    /*
+    public static class Stub extends LazyTypeAcceptViewpoint {
+        Resource[] acceptedTypes;
+        public Stub(PrimitiveQueryUpdater updater, INodeContext context, ViewpointKey key, Resource[] acceptedTypes) {
+            super(updater, context, key);
+            this.acceptedTypes = acceptedTypes;
+        }
+        @Override
+        protected Resource[] getAcceptedTypes(Graph g) {
+            return acceptedTypes;
+        }
+    }
+    */
+}