]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling/src/org/simantics/modeling/actions/Help.java
Merge "(refs #7298) Automatic refresh to SCL Console"
[simantics/platform.git] / bundles / org.simantics.modeling / src / org / simantics / modeling / actions / Help.java
1 /*******************************************************************************
2  * Copyright (c) 2016 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.modeling.actions;
13
14 import org.eclipse.ui.PlatformUI;
15 import org.simantics.Simantics;
16 import org.simantics.databoard.Bindings;
17 import org.simantics.db.Resource;
18 import org.simantics.db.common.primitiverequest.PossibleRelatedValue2;
19 import org.simantics.db.common.utils.Logger;
20 import org.simantics.db.exception.DatabaseException;
21 import org.simantics.db.layer0.adapter.ActionFactory;
22 import org.simantics.modeling.ModelingResources;
23
24 public class Help implements ActionFactory {
25
26         @Override
27         public Runnable create(Object target) {
28
29                 if(!(target instanceof Resource))
30                         return null;
31
32                 final Resource resource = (Resource)target;
33                 
34                 return new Runnable() {
35                         @Override
36                         public void run() {
37                                 
38                                 try {
39                                         ModelingResources MOD = ModelingResources.getInstance(Simantics.getSession());
40                                         String id = Simantics.sync(new PossibleRelatedValue2<String>(resource, MOD.contextualHelpId, Bindings.STRING));
41                                         if(id == null) {
42                                                 PlatformUI.getWorkbench().getHelpSystem().displayDynamicHelp();
43                                                 return;
44                                         }
45                                         PlatformUI.getWorkbench().getHelpSystem().displayHelp(id);
46                                 } catch (DatabaseException e) {
47                                         Logger.defaultLogError(e);
48                                 }
49                                 
50                         }
51                 }; 
52         }
53 }