1 /*******************************************************************************
2 * Copyright (c) 2007, 2017 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 *******************************************************************************/
13 package org.simantics.modeling.ui.modelBrowser.handlers;
15 import org.eclipse.core.commands.AbstractHandler;
16 import org.eclipse.core.commands.ExecutionEvent;
17 import org.eclipse.core.commands.ExecutionException;
18 import org.eclipse.jface.viewers.ISelection;
19 import org.eclipse.ui.PlatformUI;
20 import org.eclipse.ui.handlers.HandlerUtil;
21 import org.simantics.Simantics;
22 import org.simantics.databoard.Bindings;
23 import org.simantics.db.ReadGraph;
24 import org.simantics.db.Resource;
25 import org.simantics.db.common.request.UniqueRead;
26 import org.simantics.db.exception.DatabaseException;
27 import org.simantics.db.layer0.variable.Variable;
28 import org.simantics.modeling.ModelingResources;
29 import org.simantics.modeling.PropertyVariables;
30 import org.simantics.ui.selection.WorkbenchSelectionUtils;
31 import org.simantics.utils.ui.AdaptionUtils;
32 import org.slf4j.LoggerFactory;
34 public class ContextualHelp extends AbstractHandler {
36 private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(ContextualHelp.class);
38 private static String getPossibleId(ExecutionEvent event) {
40 ISelection sel = HandlerUtil.getCurrentSelection(event);
41 Resource resource = WorkbenchSelectionUtils.getPossibleResource(sel);
42 Variable variable = WorkbenchSelectionUtils.getPossibleVariable(sel);
43 if (sel.isEmpty() && resource == null && variable == null)
46 return Simantics.getSession().syncRequest(new UniqueRead<String>() {
48 public String perform(ReadGraph graph) throws DatabaseException {
49 ModelingResources MOD = ModelingResources.getInstance(graph);
50 if (resource != null) {
51 Resource component = graph.getPossibleObject(resource, MOD.ElementToComponent);
52 String id = component != null ? graph.getPossibleRelatedValue2(component, MOD.contextualHelpId, Bindings.STRING) : null;
55 id = graph.getPossibleRelatedValue2(resource, MOD.contextualHelpId, Bindings.STRING);
60 if (variable != null) {
61 String id = variable.getPossiblePropertyValue(graph, MOD.contextualHelpId, Bindings.STRING);
66 // TODO: consider removing this block
68 PropertyVariables vars = AdaptionUtils.adaptToSingle(sel, PropertyVariables.class);
69 Variable var = vars != null ? vars.getConfiguration() : null;
70 String id = var != null ? var.getPossiblePropertyValue(graph, MOD.contextualHelpId, Bindings.STRING) : null;
78 } catch (DatabaseException e) {
85 public Object execute(ExecutionEvent event) throws ExecutionException {
86 String id = getPossibleId(event);
88 PlatformUI.getWorkbench().getHelpSystem().displayHelp(id);