]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.browsing.ui.common/src/org/simantics/browsing/ui/common/processors/DefaultPrunedChildrenProcessor.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.browsing.ui.common / src / org / simantics / browsing / ui / common / processors / DefaultPrunedChildrenProcessor.java
index e7b9e0454d57917c082da51806f2f2e53dd49110..a0a5c11609a98f446560aebb7e2e286c442e954b 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.browsing.ui.common.processors;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collection;\r
-import java.util.HashSet;\r
-import java.util.Set;\r
-\r
-import org.simantics.browsing.ui.BuiltinKeys;\r
-import org.simantics.browsing.ui.NodeContext;\r
-import org.simantics.browsing.ui.NodeQueryManager;\r
-import org.simantics.browsing.ui.SelectionRequest;\r
-import org.simantics.browsing.ui.Tester;\r
-import org.simantics.browsing.ui.NodeContext.QueryKey;\r
-import org.simantics.browsing.ui.content.PrunedChildrenResult;\r
-import org.simantics.browsing.ui.content.ViewpointContribution;\r
-\r
-public class DefaultPrunedChildrenProcessor extends AbstractNodeQueryProcessor<PrunedChildrenResult> {\r
-\r
-    @Override\r
-    public QueryKey<PrunedChildrenResult> getIdentifier() {\r
-        return BuiltinKeys.PRUNED_CHILDREN;\r
-    }\r
-\r
-    @Override\r
-    public PrunedChildrenResult query(NodeQueryManager manager, NodeContext context) {\r
-\r
-        Collection<ViewpointContribution> contributions = manager.query(context, BuiltinKeys.VIEWPOINT_CONTRIBUTIONS);\r
-        if (contributions == null)\r
-            return PrunedChildrenResult.EMPTY;\r
-\r
-        Set<NodeContext> childSet = new HashSet<NodeContext>();\r
-        ArrayList<NodeContext> children = new ArrayList<NodeContext>();\r
-\r
-        // Gather NodeContexts from all viewpoint contributions\r
-        // into the 'children' result list to preserve the order.\r
-        // 'childSet' is used to prevent duplicate contributions.\r
-        for (ViewpointContribution contribution : contributions) {\r
-            Class<?> clazz = contribution.getInputClass();\r
-            if (clazz.isInstance(context.getConstant(BuiltinKeys.INPUT))) {\r
-                Tester test = contribution.getNodeContextTester();\r
-                if (test == null || test.test(manager, context)) {\r
-                    Collection<NodeContext> contrib = contribution.getContribution();\r
-                    children.ensureCapacity(children.size() + contrib.size());\r
-                    for (NodeContext nc : contrib)\r
-                        if (childSet.add(nc))\r
-                            children.add(nc);\r
-                }\r
-            }\r
-        }\r
-\r
-//        Viewpoint viewpoint = manager.query(context, BuiltinKeys.SELECTED_VIEWPOINT);\r
-//        if (viewpoint == null)\r
-//            return PrunedChildrenResult.EMPTY;\r
-//\r
-//        INodeContext[] children = viewpoint.getChildren();\r
-\r
-        Collection<SelectionRequest> selectionRequests = manager.query(context, BuiltinKeys.SELECTION_REQUESTS);\r
-        if (selectionRequests == null)\r
-            return new PrunedChildrenResult(children.size(), children.toArray(NodeContext.NONE));\r
-\r
-        SelectionRequest[] reqs = selectionRequests.toArray(new SelectionRequest[selectionRequests.size()]);\r
-\r
-        ArrayList<NodeContext> pruned = new ArrayList<NodeContext>();\r
-        for (NodeContext ctx : children) {\r
-            boolean add = true;\r
-\r
-            if (selectionRequests != null) {\r
-                for(SelectionRequest req : reqs) {\r
-                    if (req.getRequest() == SelectionRequest.Request.FILTER) {\r
-                        if (req.isIncluded(manager, ctx)) {\r
-                            add = false;\r
-                            break;\r
-                        }\r
-                    }\r
-                }\r
-            }\r
-\r
-            if (add)\r
-                pruned.add(ctx);\r
-        }\r
-        return new PrunedChildrenResult(children.size(), pruned.toArray(NodeContext.NONE));\r
-    }\r
-\r
-    @Override\r
-    public String toString() {\r
-        return "PrunedChildrenProcessor";\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.common.processors;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.simantics.browsing.ui.BuiltinKeys;
+import org.simantics.browsing.ui.NodeContext;
+import org.simantics.browsing.ui.NodeQueryManager;
+import org.simantics.browsing.ui.SelectionRequest;
+import org.simantics.browsing.ui.Tester;
+import org.simantics.browsing.ui.NodeContext.QueryKey;
+import org.simantics.browsing.ui.content.PrunedChildrenResult;
+import org.simantics.browsing.ui.content.ViewpointContribution;
+
+public class DefaultPrunedChildrenProcessor extends AbstractNodeQueryProcessor<PrunedChildrenResult> {
+
+    @Override
+    public QueryKey<PrunedChildrenResult> getIdentifier() {
+        return BuiltinKeys.PRUNED_CHILDREN;
+    }
+
+    @Override
+    public PrunedChildrenResult query(NodeQueryManager manager, NodeContext context) {
+
+        Collection<ViewpointContribution> contributions = manager.query(context, BuiltinKeys.VIEWPOINT_CONTRIBUTIONS);
+        if (contributions == null)
+            return PrunedChildrenResult.EMPTY;
+
+        Set<NodeContext> childSet = new HashSet<NodeContext>();
+        ArrayList<NodeContext> children = new ArrayList<NodeContext>();
+
+        // Gather NodeContexts from all viewpoint contributions
+        // into the 'children' result list to preserve the order.
+        // 'childSet' is used to prevent duplicate contributions.
+        for (ViewpointContribution contribution : contributions) {
+            Class<?> clazz = contribution.getInputClass();
+            if (clazz.isInstance(context.getConstant(BuiltinKeys.INPUT))) {
+                Tester test = contribution.getNodeContextTester();
+                if (test == null || test.test(manager, context)) {
+                    Collection<NodeContext> contrib = contribution.getContribution();
+                    children.ensureCapacity(children.size() + contrib.size());
+                    for (NodeContext nc : contrib)
+                        if (childSet.add(nc))
+                            children.add(nc);
+                }
+            }
+        }
+
+//        Viewpoint viewpoint = manager.query(context, BuiltinKeys.SELECTED_VIEWPOINT);
+//        if (viewpoint == null)
+//            return PrunedChildrenResult.EMPTY;
+//
+//        INodeContext[] children = viewpoint.getChildren();
+
+        Collection<SelectionRequest> selectionRequests = manager.query(context, BuiltinKeys.SELECTION_REQUESTS);
+        if (selectionRequests == null)
+            return new PrunedChildrenResult(children.size(), children.toArray(NodeContext.NONE));
+
+        SelectionRequest[] reqs = selectionRequests.toArray(new SelectionRequest[selectionRequests.size()]);
+
+        ArrayList<NodeContext> pruned = new ArrayList<NodeContext>();
+        for (NodeContext ctx : children) {
+            boolean add = true;
+
+            if (selectionRequests != null) {
+                for(SelectionRequest req : reqs) {
+                    if (req.getRequest() == SelectionRequest.Request.FILTER) {
+                        if (req.isIncluded(manager, ctx)) {
+                            add = false;
+                            break;
+                        }
+                    }
+                }
+            }
+
+            if (add)
+                pruned.add(ctx);
+        }
+        return new PrunedChildrenResult(children.size(), pruned.toArray(NodeContext.NONE));
+    }
+
+    @Override
+    public String toString() {
+        return "PrunedChildrenProcessor";
+    }
+
 }
\ No newline at end of file