]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.issues.ui/src/org/simantics/issues/ui/handler/Help.java
Externalize strings
[simantics/platform.git] / bundles / org.simantics.issues.ui / src / org / simantics / issues / ui / handler / Help.java
1 /*******************************************************************************
2  * Copyright (c) 2017 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     Semantum Oy - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.issues.ui.handler;
13
14 import org.eclipse.ui.PlatformUI;
15 import org.simantics.Simantics;
16 import org.simantics.databoard.Bindings;
17 import org.simantics.databoard.binding.Binding;
18 import org.simantics.db.ReadGraph;
19 import org.simantics.db.common.request.TernaryRead;
20 import org.simantics.db.common.utils.Logger;
21 import org.simantics.db.exception.DatabaseException;
22 import org.simantics.db.layer0.adapter.ActionFactory;
23 import org.simantics.db.layer0.variable.Variable;
24
25 /**
26  * @author Tuukka Lehtonen
27  * @since 1.27.0
28  */
29 public class Help implements ActionFactory {
30
31         @Override
32         public Runnable create(Object target) {
33                 if (target instanceof Variable) {
34                         return () -> {
35                                 try {
36                                         String id = Simantics.sync(new PossibleVariablePropertyValue<String>((Variable) target, "contextualHelpId", Bindings.STRING)); //$NON-NLS-1$
37                                         if (id == null) {
38                                                 PlatformUI.getWorkbench().getHelpSystem().displayDynamicHelp();
39                                                 return;
40                                         }
41                                         PlatformUI.getWorkbench().getHelpSystem().displayHelp(id);
42                                 } catch (DatabaseException e) {
43                                         Logger.defaultLogError(e);
44                                 }
45                         };
46                 }
47
48                 return null;
49         }
50
51         static class PossibleVariablePropertyValue<T> extends TernaryRead<Variable, String, Binding, T> {
52
53                 public PossibleVariablePropertyValue(Variable variable, String property, Binding binding) {
54                         super(variable, property, binding);
55                 }
56
57                 @Override
58                 public T perform(ReadGraph graph) throws DatabaseException {
59                         return parameter.getPossiblePropertyValue(graph, parameter2, parameter3);
60                 }
61
62         }
63
64 }