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%2FPropertyViewpointFactory.java;fp=bundles%2Forg.simantics.browsing.ui.graph.impl%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fgraph%2Fimpl%2FPropertyViewpointFactory.java;h=29c50faa5a382067ee63bd2a296c880ca268aff2;hp=0000000000000000000000000000000000000000;hb=969bd23cab98a79ca9101af33334000879fb60c5;hpb=866dba5cd5a3929bbeae85991796acb212338a08 diff --git a/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/PropertyViewpointFactory.java b/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/PropertyViewpointFactory.java new file mode 100644 index 000000000..29c50faa5 --- /dev/null +++ b/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/PropertyViewpointFactory.java @@ -0,0 +1,119 @@ +/******************************************************************************* + * 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 java.util.HashSet; +import java.util.Set; + +import org.simantics.browsing.ui.BuiltinKeys.ViewpointKey; +import org.simantics.browsing.ui.NodeContext; +import org.simantics.browsing.ui.PrimitiveQueryUpdater; +import org.simantics.browsing.ui.common.property.IProperty; +import org.simantics.browsing.ui.content.Viewpoint; +import org.simantics.browsing.ui.content.ViewpointFactory; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Statement; +import org.simantics.db.common.ResourceArray; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.impl.RelationContextImpl; +import org.simantics.layer0.Layer0; + +/** + * A basic viewpoint which follows the Has Property relation to show properties + * of resources. + * + *
+ * The viewpoint generates {@link ResourceArrayProperty} output for Value instances that contain array values. + *
+ * + * @see ArrayPropertyValueViewpointFactory viewpoint with IArrayProperty support + */ +public class PropertyViewpointFactory implements ViewpointFactory { + @Override + public Viewpoint create(PrimitiveQueryUpdater provider, final NodeContext context, ViewpointKey key) { + return new LazyViewpoint(provider, context, key) { + @Override + public NodeContext[] children(ReadGraph graph) throws DatabaseException { + Object in = getInput(Object.class); + Resource input = null; + if (in instanceof Resource) { + input = (Resource) in; + } else if (in instanceof ResourceArray) { + ResourceArray ra = (ResourceArray) in; + if (ra.isEmpty()) + return NodeContext.NONE; + input = ra.resources[0]; + } else if (in instanceof Statement) { + input = ((Statement) in).getObject(); + } else { + return NodeContext.NONE; + } + +// // First see if this is a Value resource. +// NodeContext[] valueChildren = GraphPropertyUtil.tryValueGetChildren(graph, input, new ResourcePropertyFactory(IProperty.Type.DIRECT, input)); +// if (valueChildren != null) +// return valueChildren; + + // If not, then go look for properties, either direct or asserted. + Collection