Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.modeling / src / org / simantics / modeling / actions / Help.java
1 /*******************************************************************************\r
2  * Copyright (c) 2016 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     Semantum Oy - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.modeling.actions;\r
13 \r
14 import org.eclipse.ui.PlatformUI;\r
15 import org.simantics.Simantics;\r
16 import org.simantics.databoard.Bindings;\r
17 import org.simantics.db.Resource;\r
18 import org.simantics.db.common.primitiverequest.PossibleRelatedValue2;\r
19 import org.simantics.db.common.utils.Logger;\r
20 import org.simantics.db.exception.DatabaseException;\r
21 import org.simantics.db.layer0.adapter.ActionFactory;\r
22 import org.simantics.modeling.ModelingResources;\r
23 \r
24 public class Help implements ActionFactory {\r
25 \r
26         @Override\r
27         public Runnable create(Object target) {\r
28 \r
29                 if(!(target instanceof Resource))\r
30                         return null;\r
31 \r
32                 final Resource resource = (Resource)target;\r
33                 \r
34                 return new Runnable() {\r
35                         @Override\r
36                         public void run() {\r
37                                 \r
38                                 try {\r
39                                         ModelingResources MOD = ModelingResources.getInstance(Simantics.getSession());\r
40                                         String id = Simantics.sync(new PossibleRelatedValue2<String>(resource, MOD.contextualHelpId, Bindings.STRING));\r
41                                         if(id == null) {\r
42                                                 PlatformUI.getWorkbench().getHelpSystem().displayDynamicHelp();\r
43                                                 return;\r
44                                         }\r
45                                         PlatformUI.getWorkbench().getHelpSystem().displayHelp(id);\r
46                                 } catch (DatabaseException e) {\r
47                                         Logger.defaultLogError(e);\r
48                                 }\r
49                                 \r
50                         }\r
51                 }; \r
52         }\r
53 }\r