X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.modeling%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fhelp%2FHelpContexts.java;fp=bundles%2Forg.simantics.modeling%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fhelp%2FHelpContexts.java;h=ca25cf417fc07a4d2e3492c0d621f51064feff5e;hp=0000000000000000000000000000000000000000;hb=ac218cd884b2c9c42e503f4a0212d56323a52291;hpb=b643293df21959d6416d0ba42637419c33a1dbad diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/help/HelpContexts.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/help/HelpContexts.java new file mode 100644 index 000000000..ca25cf417 --- /dev/null +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/help/HelpContexts.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (c) 2020 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: + * Semantum Oy- initial API and implementation + *******************************************************************************/ +package org.simantics.modeling.help; + +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.modeling.ModelingResources; +import org.simantics.modeling.PropertyVariables; +import org.simantics.utils.ui.AdaptionUtils; + +/** + * @author Tuukka Lehtonen + * @since 1.46.0 + */ +public class HelpContexts { + + /** + * @param graph + * @param resource + * @param variable + * @param selection optional ISelection + * @return + * @throws DatabaseException + */ + public static String getPossibleId(ReadGraph graph, Resource resource, Variable variable, Object selection) throws DatabaseException { + ModelingResources MOD = ModelingResources.getInstance(graph); + if (resource != null) { + Resource component = graph.getPossibleObject(resource, MOD.ElementToComponent); + String id = component != null ? graph.getPossibleRelatedValue2(component, MOD.contextualHelpId, Bindings.STRING) : null; + if (id != null) + return id; + id = graph.getPossibleRelatedValue2(resource, MOD.contextualHelpId, Bindings.STRING); + if (id != null) + return id; + } + + if (variable != null) { + String id = variable.getPossiblePropertyValue(graph, MOD.contextualHelpId, Bindings.STRING); + if (id != null) + return id; + } + + // TODO: consider removing this block + if (selection != null) { + PropertyVariables vars = AdaptionUtils.adaptToSingle(selection, PropertyVariables.class); + Variable var = vars != null ? vars.getConfiguration() : null; + String id = var != null ? var.getPossiblePropertyValue(graph, MOD.contextualHelpId, Bindings.STRING) : null; + if (id != null) + return id; + } + + return null; + } + + public static String getPossibleId(ReadGraph graph, Variable variable, String property) throws DatabaseException { + ModelingResources MOD = ModelingResources.getInstance(graph); + Variable prop = variable != null ? variable.getPossibleProperty(graph, property) : null; + return prop != null ? prop.getPossiblePropertyValue(graph, MOD.contextualHelpId, Bindings.STRING) : null; + } + +}