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.BuiltinKeys.ViewpointKey;
20 import org.simantics.browsing.ui.content.Viewpoint;
21 import org.simantics.browsing.ui.content.ViewpointFactory;
22 import org.simantics.db.ReadGraph;
23 import org.simantics.db.Resource;
24 import org.simantics.db.exception.DatabaseException;
26 public abstract class GraphViewpointFactory implements ViewpointFactory {
29 public Viewpoint create(PrimitiveQueryUpdater updater,
30 NodeContext context, ViewpointKey key) {
31 assert(updater != null);
32 assert(context != null);
34 return new LazyViewpoint(updater, context, key) {
36 public NodeContext[] children(ReadGraph graph) throws DatabaseException {
37 return toContextsWithInput(GraphViewpointFactory.this.
38 getChildren(graph, (Resource) context.getConstant(BuiltinKeys.INPUT)));
42 public Boolean hasChildren(ReadGraph graph) throws DatabaseException {
43 return children(graph).length > 0;
47 public String toString() {
48 return GraphViewpointFactory.this.toString();
52 public Object getIdentity() {
53 return GraphViewpointFactory.this.getClass();
59 abstract protected Collection<?> getChildren(ReadGraph g, Resource r) throws DatabaseException;
60 protected boolean hasChildren(ReadGraph g, Resource r) throws DatabaseException {
61 return !getChildren(g, r).isEmpty();