1 /*******************************************************************************
2 * Copyright (c) 2020 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 * Semantum Oy- initial API and implementation
11 *******************************************************************************/
12 package org.simantics.modeling.help;
14 import org.simantics.databoard.Bindings;
15 import org.simantics.db.ReadGraph;
16 import org.simantics.db.Resource;
17 import org.simantics.db.exception.DatabaseException;
18 import org.simantics.db.layer0.variable.Variable;
19 import org.simantics.modeling.ModelingResources;
20 import org.simantics.modeling.PropertyVariables;
21 import org.simantics.utils.ui.AdaptionUtils;
24 * @author Tuukka Lehtonen
27 public class HelpContexts {
33 * @param selection optional <code>ISelection</code>
35 * @throws DatabaseException
37 public static String getPossibleId(ReadGraph graph, Resource resource, Variable variable, Object selection) throws DatabaseException {
38 ModelingResources MOD = ModelingResources.getInstance(graph);
39 if (resource != null) {
40 Resource component = graph.getPossibleObject(resource, MOD.ElementToComponent);
41 String id = component != null ? graph.getPossibleRelatedValue2(component, MOD.contextualHelpId, Bindings.STRING) : null;
44 id = graph.getPossibleRelatedValue2(resource, MOD.contextualHelpId, Bindings.STRING);
49 if (variable != null) {
50 String id = variable.getPossiblePropertyValue(graph, MOD.contextualHelpId, Bindings.STRING);
55 // TODO: consider removing this block
56 if (selection != null) {
57 PropertyVariables vars = AdaptionUtils.adaptToSingle(selection, PropertyVariables.class);
58 Variable var = vars != null ? vars.getConfiguration() : null;
59 String id = var != null ? var.getPossiblePropertyValue(graph, MOD.contextualHelpId, Bindings.STRING) : null;
67 public static String getPossibleId(ReadGraph graph, Variable variable, String property) throws DatabaseException {
68 ModelingResources MOD = ModelingResources.getInstance(graph);
69 Variable prop = variable != null ? variable.getPossibleProperty(graph, property) : null;
70 return prop != null ? prop.getPossiblePropertyValue(graph, MOD.contextualHelpId, Bindings.STRING) : null;