]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.browsing.ui.common/src/org/simantics/browsing/ui/common/processors/ComparableSelectorQueryProcessor.java
7f73143a337a8136f45a16b55dfcf0a910e739bd
[simantics/platform.git] / bundles / org.simantics.browsing.ui.common / src / org / simantics / browsing / ui / common / processors / ComparableSelectorQueryProcessor.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.browsing.ui.common.processors;
13
14 import java.util.Collection;
15
16 import org.simantics.browsing.ui.BuiltinKeys;
17 import org.simantics.browsing.ui.NodeContext;
18 import org.simantics.browsing.ui.NodeQueryManager;
19 import org.simantics.browsing.ui.NodeContext.QueryKey;
20 import org.simantics.browsing.ui.content.ComparableContext;
21 import org.simantics.browsing.ui.content.ComparableContextFactory;
22 import org.simantics.browsing.ui.content.PrunedChildrenResult;
23
24 public class ComparableSelectorQueryProcessor extends AbstractNodeQueryProcessor<ComparableContext[]> {
25
26     @Override
27     public QueryKey<ComparableContext[]> getIdentifier() {
28         return BuiltinKeys.COMPARABLE_CHILDREN;
29     }
30
31     private ComparableContext[] build(NodeQueryManager manager, NodeContext context, ComparableContextFactory factory) {
32         PrunedChildrenResult pruned = manager.query(context, BuiltinKeys.PRUNED_CHILDREN);
33         NodeContext[] prunedChildren = pruned.getPrunedChildren();
34         return factory.create(manager, context, prunedChildren);
35     }
36
37     @Override
38     public ComparableContext[] query(NodeQueryManager manager, NodeContext context) {
39         Collection<ComparableContextFactory> comparators = manager.query(context, BuiltinKeys.COMPARABLE_FACTORIES);
40         if (comparators.isEmpty())
41             return null;
42
43         ComparableContextFactory selectedFactory = manager.query(context, new BuiltinKeys.SelectedComparableFactoryKey(comparators));
44         if (selectedFactory == null)
45             return null;
46
47         return build(manager, context, selectedFactory);
48     }
49
50     @Override
51     public String toString() {
52         return "SelectedComparableProcessor";
53     }
54
55 }