1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 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 *******************************************************************************/
12 package org.simantics.modeling.ui.modelBrowser.handlers;
14 import org.eclipse.core.commands.AbstractHandler;
15 import org.eclipse.core.commands.ExecutionEvent;
16 import org.eclipse.core.commands.ExecutionException;
17 import org.eclipse.jface.viewers.ISelection;
18 import org.eclipse.ui.PlatformUI;
19 import org.eclipse.ui.handlers.HandlerUtil;
20 import org.simantics.Simantics;
21 import org.simantics.databoard.Bindings;
22 import org.simantics.db.ReadGraph;
23 import org.simantics.db.Resource;
24 import org.simantics.db.common.request.ResourceRead;
25 import org.simantics.db.common.utils.Logger;
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;
33 public class ContextualHelp extends AbstractHandler {
35 private static String getPossibleId(ExecutionEvent event) {
38 Resource element = WorkbenchSelectionUtils.getPossibleResource(event);
39 id = Simantics.getSession().syncRequest(new ResourceRead<String>(element) {
42 public String perform(ReadGraph graph) throws DatabaseException {
43 ModelingResources MOD = ModelingResources.getInstance(graph);
44 Resource component = graph.getPossibleObject(element, MOD.ElementToComponent);
45 if (component != null)
46 return graph.getPossibleRelatedValue2(component, MOD.contextualHelpId, Bindings.STRING);
48 Variable var = WorkbenchSelectionUtils.getPossibleVariable(event);
50 return var.getPossiblePropertyValue(graph, MOD.contextualHelpId, Bindings.STRING);
52 ISelection sel = HandlerUtil.getCurrentSelection(event);
54 PropertyVariables vars = AdaptionUtils.adaptToSingle(sel, PropertyVariables.class);
56 var = vars.getConfiguration();
58 var.getPossiblePropertyValue(graph, MOD.contextualHelpId, Bindings.STRING);
64 } catch (DatabaseException e) {
65 Logger.defaultLogError(e);
71 public Object execute(ExecutionEvent event) throws ExecutionException {
73 String id = getPossibleId(event);
75 PlatformUI.getWorkbench().getHelpSystem().displayHelp(id);