1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.browsing.ui.graph.impl;
\r
14 import java.util.Collection;
\r
16 import org.simantics.browsing.ui.BuiltinKeys;
\r
17 import org.simantics.browsing.ui.NodeContext;
\r
18 import org.simantics.browsing.ui.PrimitiveQueryUpdater;
\r
19 import org.simantics.browsing.ui.common.NodeContextBuilder;
\r
20 import org.simantics.browsing.ui.common.NodeContextUtil;
\r
21 import org.simantics.browsing.ui.content.ViewpointContribution;
\r
24 * @author Tuukka Lehtonen
\r
26 public abstract class ContributionStub implements ViewpointContribution {
\r
28 protected Collection<NodeContext> children = ViewpointContribution.PENDING_CONTRIBUTION;
\r
30 public void setChildren(PrimitiveQueryUpdater updater, Collection<NodeContext> children) {
\r
32 if (children == null)
\r
33 throw new NullPointerException("null children produced by " + getClass().getName());
\r
35 for(NodeContext c : children) updater.incRef(c);
\r
36 for(NodeContext c : this.children) updater.decRef(c);
\r
38 this.children = children;
\r
43 * A utility method for transforming an array of objects into an
\r
44 * INodeContext array which is the return value of a ViewpointFactory.
\r
47 * The INodeContext's are constructed using
\r
48 * {@link NodeContextBuilder#buildWithInput(Object)}.
\r
52 * @return the specified children wrapped into simple <code>INodeContext</code>s
\r
54 public NodeContext[] toContextsWithInput(Object... children) {
\r
55 return NodeContextUtil.toContextsWithInput(children);
\r
59 * A utility method for transforming a collection of objects into an
\r
60 * INodeContext array which is the return value of a ViewpointFactory.
\r
63 * The INodeContext's are constructed using
\r
64 * {@link NodeContextBuilder#buildWithInput(Object)}.
\r
68 * @return the specified children wrapped into simple <code>INodeContext</code>s
\r
70 public Collection<NodeContext> toContextsWithInput(Collection<?> children) {
\r
71 return NodeContextUtil.toContextCollectionWithInput(children);
\r
75 * A utility method for transforming a collection of objects into an
\r
76 * INodeContext array which is the return value of a ViewpointFactory.
\r
79 * The INodeContext's are constructed using the specified factory.
\r
83 * @return the specified children wrapped into INodeContext's through the
\r
84 * specified <code>factory</code>
\r
86 public NodeContext[] toContexts(Collection<?> children, NodeContextUtil.NodeContextFactory factory) {
\r
87 return NodeContextUtil.toContexts(children, factory);
\r
93 * @return input of the specified class
\r
94 * @throws ClassCastException if the input class does not match the
\r
96 * @throws NullPointerException if the input is null
\r
98 @SuppressWarnings("unchecked")
\r
99 protected <T> T getInput(NodeContext context) {
\r
100 Object o = context.getConstant(BuiltinKeys.INPUT);
\r
102 throw new NullPointerException("null input");
\r
109 * @return <code>null</code> if input is <code>null</code> or if the class
\r
112 @SuppressWarnings("unchecked")
\r
113 protected <T> T tryGetInput(NodeContext context, Class<T> clazz) {
\r
114 Object o = context.getConstant(BuiltinKeys.INPUT);
\r
115 if (o != null && clazz.isInstance(o))
\r