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%2FLazyTypeAcceptViewpoint.java;h=b03ac89cb1b3a2bef420168fe954011e74b9fe36;hp=82e7f0c8faf60449e81f6cb41b1311e5a2edf456;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/LazyTypeAcceptViewpoint.java b/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/LazyTypeAcceptViewpoint.java index 82e7f0c8f..b03ac89cb 100644 --- a/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/LazyTypeAcceptViewpoint.java +++ b/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/LazyTypeAcceptViewpoint.java @@ -1,96 +1,96 @@ -/******************************************************************************* - * 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.ArrayList; -import java.util.Collection; - -import org.simantics.browsing.ui.NodeContext; -import org.simantics.browsing.ui.PrimitiveQueryUpdater; -import org.simantics.browsing.ui.BuiltinKeys.ViewpointKey; -import org.simantics.browsing.ui.common.NodeContextBuilder; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.exception.DatabaseException; -import org.simantics.layer0.Layer0; - -/** - * A very simple viewpoint that by default browses Consists Of relations and - * accepts as objects any children that are of any of the specified accepted - * types. - * - *

- * The accepted types must be returned through {@link #getAcceptedTypes()} - *

- * - *

- * The children production can be customized by overriding - * {@link #getPotentialChildren(ReadGraph, Resource)}. Whatever is produced by this - * method will be filtered through the list of accepted resource types. - *

- * - *

- * IMPORTANT: it is vital to actually implement this class and override the - * {@link #getAcceptedTypes(ReadGraph)} method in the process. Otherwise the - * equality comparisons of the resource queries used within LazyViewpoint will - * not work properly! - *

- * - * @author Tuukka Lehtonen - */ -public abstract class LazyTypeAcceptViewpoint extends LazyViewpoint { - - public LazyTypeAcceptViewpoint(PrimitiveQueryUpdater updater, NodeContext context, ViewpointKey key) { - super(updater, context, key); - } - - protected abstract Resource[] getAcceptedTypes(ReadGraph g); - - protected Collection getPotentialChildren(ReadGraph g, Resource r) throws DatabaseException { - Layer0 L0 = Layer0.getInstance(g); - return g.getObjects(r, L0.ConsistsOf); - } - - @Override - public NodeContext[] children(ReadGraph g) throws DatabaseException { - Resource input = getInput(Resource.class); - Resource[] accepted = getAcceptedTypes(g); - Collection children = getPotentialChildren(g, input); - ArrayList resultContexts = new ArrayList(); - for (Resource child : children) { - for (Resource acc : accepted) { - if (g.isInstanceOf(child, acc)) - resultContexts.add(NodeContextBuilder.buildWithInput(child)); - } - } - return resultContexts.toArray(new NodeContext[resultContexts.size()]); - } - - @Override - public Boolean hasChildren(ReadGraph g) throws DatabaseException { - return Boolean.valueOf(children(g).length > 0); - } - - /* - public static class Stub extends LazyTypeAcceptViewpoint { - Resource[] acceptedTypes; - public Stub(PrimitiveQueryUpdater updater, INodeContext context, ViewpointKey key, Resource[] acceptedTypes) { - super(updater, context, key); - this.acceptedTypes = acceptedTypes; - } - @Override - protected Resource[] getAcceptedTypes(Graph g) { - return acceptedTypes; - } - } - */ -} +/******************************************************************************* + * 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.ArrayList; +import java.util.Collection; + +import org.simantics.browsing.ui.NodeContext; +import org.simantics.browsing.ui.PrimitiveQueryUpdater; +import org.simantics.browsing.ui.BuiltinKeys.ViewpointKey; +import org.simantics.browsing.ui.common.NodeContextBuilder; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; + +/** + * A very simple viewpoint that by default browses Consists Of relations and + * accepts as objects any children that are of any of the specified accepted + * types. + * + *

+ * The accepted types must be returned through {@link #getAcceptedTypes()} + *

+ * + *

+ * The children production can be customized by overriding + * {@link #getPotentialChildren(ReadGraph, Resource)}. Whatever is produced by this + * method will be filtered through the list of accepted resource types. + *

+ * + *

+ * IMPORTANT: it is vital to actually implement this class and override the + * {@link #getAcceptedTypes(ReadGraph)} method in the process. Otherwise the + * equality comparisons of the resource queries used within LazyViewpoint will + * not work properly! + *

+ * + * @author Tuukka Lehtonen + */ +public abstract class LazyTypeAcceptViewpoint extends LazyViewpoint { + + public LazyTypeAcceptViewpoint(PrimitiveQueryUpdater updater, NodeContext context, ViewpointKey key) { + super(updater, context, key); + } + + protected abstract Resource[] getAcceptedTypes(ReadGraph g); + + protected Collection getPotentialChildren(ReadGraph g, Resource r) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(g); + return g.getObjects(r, L0.ConsistsOf); + } + + @Override + public NodeContext[] children(ReadGraph g) throws DatabaseException { + Resource input = getInput(Resource.class); + Resource[] accepted = getAcceptedTypes(g); + Collection children = getPotentialChildren(g, input); + ArrayList resultContexts = new ArrayList(); + for (Resource child : children) { + for (Resource acc : accepted) { + if (g.isInstanceOf(child, acc)) + resultContexts.add(NodeContextBuilder.buildWithInput(child)); + } + } + return resultContexts.toArray(new NodeContext[resultContexts.size()]); + } + + @Override + public Boolean hasChildren(ReadGraph g) throws DatabaseException { + return Boolean.valueOf(children(g).length > 0); + } + + /* + public static class Stub extends LazyTypeAcceptViewpoint { + Resource[] acceptedTypes; + public Stub(PrimitiveQueryUpdater updater, INodeContext context, ViewpointKey key, Resource[] acceptedTypes) { + super(updater, context, key); + this.acceptedTypes = acceptedTypes; + } + @Override + protected Resource[] getAcceptedTypes(Graph g) { + return acceptedTypes; + } + } + */ +}