1 /*******************************************************************************
2 * Copyright (c) 2007, 2018 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 * Semantum Oy - #7116 regression fix
12 * Semantum Oy - gitlab #147 - expose getPossibleId implementation
13 *******************************************************************************/
14 package org.simantics.modeling.ui.modelBrowser.handlers;
16 import org.eclipse.core.commands.AbstractHandler;
17 import org.eclipse.core.commands.ExecutionEvent;
18 import org.eclipse.core.commands.ExecutionException;
19 import org.eclipse.jface.viewers.ISelection;
20 import org.eclipse.ui.PlatformUI;
21 import org.eclipse.ui.handlers.HandlerUtil;
22 import org.simantics.Simantics;
23 import org.simantics.databoard.Bindings;
24 import org.simantics.db.ReadGraph;
25 import org.simantics.db.Resource;
26 import org.simantics.db.common.request.UniqueRead;
27 import org.simantics.db.exception.DatabaseException;
28 import org.simantics.db.layer0.variable.Variable;
29 import org.simantics.modeling.ModelingResources;
30 import org.simantics.modeling.PropertyVariables;
31 import org.simantics.ui.selection.WorkbenchSelectionUtils;
32 import org.simantics.utils.ui.AdaptionUtils;
33 import org.slf4j.LoggerFactory;
35 public class ContextualHelp extends AbstractHandler {
37 private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(ContextualHelp.class);
39 private static String getPossibleId(ExecutionEvent event) {
41 ISelection sel = HandlerUtil.getCurrentSelection(event);
42 Resource resource = WorkbenchSelectionUtils.getPossibleResource(sel);
43 Variable variable = WorkbenchSelectionUtils.getPossibleVariable(sel);
44 if (sel.isEmpty() && resource == null && variable == null)
47 return Simantics.getSession().syncRequest(new UniqueRead<String>() {
49 public String perform(ReadGraph graph) throws DatabaseException {
50 return getPossibleId(graph, resource, variable, sel);
53 } catch (DatabaseException e) {
60 public Object execute(ExecutionEvent event) throws ExecutionException {
61 String id = getPossibleId(event);
63 PlatformUI.getWorkbench().getHelpSystem().displayHelp(id);
67 public static String getPossibleId(ReadGraph graph, Resource resource, Variable variable, ISelection sel) throws DatabaseException {
68 ModelingResources MOD = ModelingResources.getInstance(graph);
69 if (resource != null) {
70 Resource component = graph.getPossibleObject(resource, MOD.ElementToComponent);
71 String id = component != null ? graph.getPossibleRelatedValue2(component, MOD.contextualHelpId, Bindings.STRING) : null;
74 id = graph.getPossibleRelatedValue2(resource, MOD.contextualHelpId, Bindings.STRING);
79 if (variable != null) {
80 String id = variable.getPossiblePropertyValue(graph, MOD.contextualHelpId, Bindings.STRING);
85 // TODO: consider removing this block
87 PropertyVariables vars = AdaptionUtils.adaptToSingle(sel, PropertyVariables.class);
88 Variable var = vars != null ? vars.getConfiguration() : null;
89 String id = var != null ? var.getPossiblePropertyValue(graph, MOD.contextualHelpId, Bindings.STRING) : null;