1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.browsing.ui.common.processors;
14 import java.util.Collection;
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;
24 public class ComparableSelectorQueryProcessor extends AbstractNodeQueryProcessor<ComparableContext[]> {
27 public QueryKey<ComparableContext[]> getIdentifier() {
28 return BuiltinKeys.COMPARABLE_CHILDREN;
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);
38 public ComparableContext[] query(NodeQueryManager manager, NodeContext context) {
39 Collection<ComparableContextFactory> comparators = manager.query(context, BuiltinKeys.COMPARABLE_FACTORIES);
40 if (comparators.isEmpty())
43 ComparableContextFactory selectedFactory = manager.query(context, new BuiltinKeys.SelectedComparableFactoryKey(comparators));
44 if (selectedFactory == null)
47 return build(manager, context, selectedFactory);
51 public String toString() {
52 return "SelectedComparableProcessor";