X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.browsing.ui.swt%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fswt%2FDefaultIsCheckedProcessor2.java;h=48809e156dd6be4da27ef3a1a9d811c242649822;hb=HEAD;hp=aa9b5c031777a494880787ab6f23fa59199260de;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/DefaultIsCheckedProcessor2.java b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/DefaultIsCheckedProcessor2.java index aa9b5c031..48809e156 100644 --- a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/DefaultIsCheckedProcessor2.java +++ b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/DefaultIsCheckedProcessor2.java @@ -1,97 +1,97 @@ -/******************************************************************************* - * 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.swt; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; - -import org.simantics.browsing.ui.BuiltinKeys; -import org.simantics.browsing.ui.CheckedState; -import org.simantics.browsing.ui.NodeContext; -import org.simantics.browsing.ui.NodeQueryManager; -import org.simantics.browsing.ui.NodeQueryProcessor; -import org.simantics.browsing.ui.Tester; -import org.simantics.browsing.ui.BuiltinKeys.CheckedStateKey; -import org.simantics.browsing.ui.NodeContext.QueryKey; -import org.simantics.browsing.ui.common.EvaluatorData; -import org.simantics.browsing.ui.common.Preference; -import org.simantics.browsing.ui.common.EvaluatorData.Evaluator; -import org.simantics.browsing.ui.common.EvaluatorData.EvaluatorTree; -import org.simantics.browsing.ui.content.CheckedStateFactory; -import org.simantics.utils.datastructures.collections.CollectionUtils; - -/** - * @author Antti Villberg - */ -public class DefaultIsCheckedProcessor2 implements NodeQueryProcessor { - - private final EvaluatorData data; - - public DefaultIsCheckedProcessor2(EvaluatorData data) { - this.data = data; - } - - @Override - public QueryKey getIdentifier() { - return BuiltinKeys.IS_CHECKED; - } - - @Override - public CheckedState query(final NodeQueryManager manager, final NodeContext context) { - assert context != null; - - Object input = context.getConstant(BuiltinKeys.INPUT); - assert input != null; - - Collection evals = data.get(input); - if (evals.isEmpty()) - return null; - - ArrayList> factories = new ArrayList>(4); - for (Evaluator eval : evals) { - evaluateTree(manager, context, eval.getCheckStateTree(), factories); - } - - if (factories.isEmpty()) - return null; - - if (factories.size() >= 1) { - Collections.sort(factories); - return manager.query(context, new CheckedStateKey(factories.get(0).object)); - } else { - return null; - } - - } - - protected void evaluateTree(NodeQueryManager manager, NodeContext context, EvaluatorTree tree, Collection> result) { - Tester test = tree.getTester(); - - if (test.test(manager, context)) { - CollectionUtils.checkedAdd(tree.getAcceptedFactories(), result); - - Collection> children = tree.getChildren(); - if (children == null) - return; - for (EvaluatorTree e : children) { - evaluateTree(manager, context, e, result); - } - } - } - - @Override - public String toString() { - return "IsCheckedProcessor"; - } - +/******************************************************************************* + * 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.swt; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; + +import org.simantics.browsing.ui.BuiltinKeys; +import org.simantics.browsing.ui.CheckedState; +import org.simantics.browsing.ui.NodeContext; +import org.simantics.browsing.ui.NodeQueryManager; +import org.simantics.browsing.ui.NodeQueryProcessor; +import org.simantics.browsing.ui.Tester; +import org.simantics.browsing.ui.BuiltinKeys.CheckedStateKey; +import org.simantics.browsing.ui.NodeContext.QueryKey; +import org.simantics.browsing.ui.common.EvaluatorData; +import org.simantics.browsing.ui.common.Preference; +import org.simantics.browsing.ui.common.EvaluatorData.Evaluator; +import org.simantics.browsing.ui.common.EvaluatorData.EvaluatorTree; +import org.simantics.browsing.ui.content.CheckedStateFactory; +import org.simantics.utils.datastructures.collections.CollectionUtils; + +/** + * @author Antti Villberg + */ +public class DefaultIsCheckedProcessor2 implements NodeQueryProcessor { + + private final EvaluatorData data; + + public DefaultIsCheckedProcessor2(EvaluatorData data) { + this.data = data; + } + + @Override + public QueryKey getIdentifier() { + return BuiltinKeys.IS_CHECKED; + } + + @Override + public CheckedState query(final NodeQueryManager manager, final NodeContext context) { + assert context != null; + + Object input = context.getConstant(BuiltinKeys.INPUT); + assert input != null; + + Collection evals = data.get(input); + if (evals.isEmpty()) + return null; + + ArrayList> factories = new ArrayList>(4); + for (Evaluator eval : evals) { + evaluateTree(manager, context, eval.getCheckStateTree(), factories); + } + + if (factories.isEmpty()) + return null; + + if (factories.size() >= 1) { + Collections.sort(factories); + return manager.query(context, new CheckedStateKey(factories.get(0).object)); + } else { + return null; + } + + } + + protected void evaluateTree(NodeQueryManager manager, NodeContext context, EvaluatorTree tree, Collection> result) { + Tester test = tree.getTester(); + + if (test.test(manager, context)) { + CollectionUtils.checkedAdd(tree.getAcceptedFactories(), result); + + Collection> children = tree.getChildren(); + if (children == null) + return; + for (EvaluatorTree e : children) { + evaluateTree(manager, context, e, result); + } + } + } + + @Override + public String toString() { + return "IsCheckedProcessor"; + } + } \ No newline at end of file