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.graph.impl;
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.PrimitiveQueryUpdater;
19 import org.simantics.browsing.ui.common.NodeContextBuilder;
20 import org.simantics.browsing.ui.common.NodeContextUtil;
21 import org.simantics.browsing.ui.content.ViewpointContribution;
24 * @author Tuukka Lehtonen
26 public abstract class ContributionStub implements ViewpointContribution {
28 protected Collection<NodeContext> children = ViewpointContribution.PENDING_CONTRIBUTION;
30 public void setChildren(PrimitiveQueryUpdater updater, Collection<NodeContext> children) {
33 throw new NullPointerException("null children produced by " + getClass().getName());
35 for(NodeContext c : children) updater.incRef(c);
36 for(NodeContext c : this.children) updater.decRef(c);
38 this.children = children;
43 * A utility method for transforming an array of objects into an
44 * INodeContext array which is the return value of a ViewpointFactory.
47 * The INodeContext's are constructed using
48 * {@link NodeContextBuilder#buildWithInput(Object)}.
52 * @return the specified children wrapped into simple <code>INodeContext</code>s
54 public NodeContext[] toContextsWithInput(Object... children) {
55 return NodeContextUtil.toContextsWithInput(children);
59 * A utility method for transforming a collection of objects into an
60 * INodeContext array which is the return value of a ViewpointFactory.
63 * The INodeContext's are constructed using
64 * {@link NodeContextBuilder#buildWithInput(Object)}.
68 * @return the specified children wrapped into simple <code>INodeContext</code>s
70 public Collection<NodeContext> toContextsWithInput(Collection<?> children) {
71 return NodeContextUtil.toContextCollectionWithInput(children);
75 * A utility method for transforming a collection of objects into an
76 * INodeContext array which is the return value of a ViewpointFactory.
79 * The INodeContext's are constructed using the specified factory.
83 * @return the specified children wrapped into INodeContext's through the
84 * specified <code>factory</code>
86 public NodeContext[] toContexts(Collection<?> children, NodeContextUtil.NodeContextFactory factory) {
87 return NodeContextUtil.toContexts(children, factory);
93 * @return input of the specified class
94 * @throws ClassCastException if the input class does not match the
96 * @throws NullPointerException if the input is null
98 @SuppressWarnings("unchecked")
99 protected <T> T getInput(NodeContext context) {
100 Object o = context.getConstant(BuiltinKeys.INPUT);
102 throw new NullPointerException("null input");
109 * @return <code>null</code> if input is <code>null</code> or if the class
112 @SuppressWarnings("unchecked")
113 protected <T> T tryGetInput(NodeContext context, Class<T> clazz) {
114 Object o = context.getConstant(BuiltinKeys.INPUT);
115 if (o != null && clazz.isInstance(o))