X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.browsing.ui.graph.impl%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fgraph%2Fimpl%2FContributionStub.java;h=3b6fb52f5c2a4c3f66765db822acec6ad3cec755;hp=27f14392702410fcace1e9b89a22a6a19f319fcf;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=969bd23cab98a79ca9101af33334000879fb60c5 diff --git a/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/ContributionStub.java b/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/ContributionStub.java index 27f143927..3b6fb52f5 100644 --- a/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/ContributionStub.java +++ b/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/ContributionStub.java @@ -1,120 +1,120 @@ -/******************************************************************************* - * 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.Collection; - -import org.simantics.browsing.ui.BuiltinKeys; -import org.simantics.browsing.ui.NodeContext; -import org.simantics.browsing.ui.PrimitiveQueryUpdater; -import org.simantics.browsing.ui.common.NodeContextBuilder; -import org.simantics.browsing.ui.common.NodeContextUtil; -import org.simantics.browsing.ui.content.ViewpointContribution; - -/** - * @author Tuukka Lehtonen - */ -public abstract class ContributionStub implements ViewpointContribution { - - protected Collection children = ViewpointContribution.PENDING_CONTRIBUTION; - - public void setChildren(PrimitiveQueryUpdater updater, Collection children) { - - if (children == null) - throw new NullPointerException("null children produced by " + getClass().getName()); - - for(NodeContext c : children) updater.incRef(c); - for(NodeContext c : this.children) updater.decRef(c); - - this.children = children; - - } - - /** - * A utility method for transforming an array of objects into an - * INodeContext array which is the return value of a ViewpointFactory. - * - *

- * The INodeContext's are constructed using - * {@link NodeContextBuilder#buildWithInput(Object)}. - *

- * - * @param children - * @return the specified children wrapped into simple INodeContexts - */ - public NodeContext[] toContextsWithInput(Object... children) { - return NodeContextUtil.toContextsWithInput(children); - } - - /** - * A utility method for transforming a collection of objects into an - * INodeContext array which is the return value of a ViewpointFactory. - * - *

- * The INodeContext's are constructed using - * {@link NodeContextBuilder#buildWithInput(Object)}. - *

- * - * @param children - * @return the specified children wrapped into simple INodeContexts - */ - public Collection toContextsWithInput(Collection children) { - return NodeContextUtil.toContextCollectionWithInput(children); - } - - /** - * A utility method for transforming a collection of objects into an - * INodeContext array which is the return value of a ViewpointFactory. - * - *

- * The INodeContext's are constructed using the specified factory. - *

- * - * @param children - * @return the specified children wrapped into INodeContext's through the - * specified factory - */ - public NodeContext[] toContexts(Collection children, NodeContextUtil.NodeContextFactory factory) { - return NodeContextUtil.toContexts(children, factory); - } - - /** - * @param - * @param clazz - * @return input of the specified class - * @throws ClassCastException if the input class does not match the - * specified class - * @throws NullPointerException if the input is null - */ - @SuppressWarnings("unchecked") - protected T getInput(NodeContext context) { - Object o = context.getConstant(BuiltinKeys.INPUT); - if (o == null) - throw new NullPointerException("null input"); - return (T) o; - } - - /** - * @param - * @param clazz - * @return null if input is null or if the class - * does not match - */ - @SuppressWarnings("unchecked") - protected T tryGetInput(NodeContext context, Class clazz) { - Object o = context.getConstant(BuiltinKeys.INPUT); - if (o != null && clazz.isInstance(o)) - return (T) o; - return null; - } - -} +/******************************************************************************* + * 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.Collection; + +import org.simantics.browsing.ui.BuiltinKeys; +import org.simantics.browsing.ui.NodeContext; +import org.simantics.browsing.ui.PrimitiveQueryUpdater; +import org.simantics.browsing.ui.common.NodeContextBuilder; +import org.simantics.browsing.ui.common.NodeContextUtil; +import org.simantics.browsing.ui.content.ViewpointContribution; + +/** + * @author Tuukka Lehtonen + */ +public abstract class ContributionStub implements ViewpointContribution { + + protected Collection children = ViewpointContribution.PENDING_CONTRIBUTION; + + public void setChildren(PrimitiveQueryUpdater updater, Collection children) { + + if (children == null) + throw new NullPointerException("null children produced by " + getClass().getName()); + + for(NodeContext c : children) updater.incRef(c); + for(NodeContext c : this.children) updater.decRef(c); + + this.children = children; + + } + + /** + * A utility method for transforming an array of objects into an + * INodeContext array which is the return value of a ViewpointFactory. + * + *

+ * The INodeContext's are constructed using + * {@link NodeContextBuilder#buildWithInput(Object)}. + *

+ * + * @param children + * @return the specified children wrapped into simple INodeContexts + */ + public NodeContext[] toContextsWithInput(Object... children) { + return NodeContextUtil.toContextsWithInput(children); + } + + /** + * A utility method for transforming a collection of objects into an + * INodeContext array which is the return value of a ViewpointFactory. + * + *

+ * The INodeContext's are constructed using + * {@link NodeContextBuilder#buildWithInput(Object)}. + *

+ * + * @param children + * @return the specified children wrapped into simple INodeContexts + */ + public Collection toContextsWithInput(Collection children) { + return NodeContextUtil.toContextCollectionWithInput(children); + } + + /** + * A utility method for transforming a collection of objects into an + * INodeContext array which is the return value of a ViewpointFactory. + * + *

+ * The INodeContext's are constructed using the specified factory. + *

+ * + * @param children + * @return the specified children wrapped into INodeContext's through the + * specified factory + */ + public NodeContext[] toContexts(Collection children, NodeContextUtil.NodeContextFactory factory) { + return NodeContextUtil.toContexts(children, factory); + } + + /** + * @param + * @param clazz + * @return input of the specified class + * @throws ClassCastException if the input class does not match the + * specified class + * @throws NullPointerException if the input is null + */ + @SuppressWarnings("unchecked") + protected T getInput(NodeContext context) { + Object o = context.getConstant(BuiltinKeys.INPUT); + if (o == null) + throw new NullPointerException("null input"); + return (T) o; + } + + /** + * @param + * @param clazz + * @return null if input is null or if the class + * does not match + */ + @SuppressWarnings("unchecked") + protected T tryGetInput(NodeContext context, Class clazz) { + Object o = context.getConstant(BuiltinKeys.INPUT); + if (o != null && clazz.isInstance(o)) + return (T) o; + return null; + } + +}