Add utility class org.simantics.modeling.help.HelpContexts
[simantics/platform.git] / bundles / org.simantics.modeling / src / org / simantics / modeling / actions / Help.java
index 20a2e997551638232776dac570d0b6a36acfd815..22327aeb3f71b833ea002af5705ca7080a87ac96 100644 (file)
@@ -1,53 +1,51 @@
-/*******************************************************************************\r
- * Copyright (c) 2016 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     Semantum Oy - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.modeling.actions;\r
-\r
-import org.eclipse.ui.PlatformUI;\r
-import org.simantics.Simantics;\r
-import org.simantics.databoard.Bindings;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.primitiverequest.PossibleRelatedValue2;\r
-import org.simantics.db.common.utils.Logger;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.adapter.ActionFactory;\r
-import org.simantics.modeling.ModelingResources;\r
-\r
-public class Help implements ActionFactory {\r
-\r
-       @Override\r
-       public Runnable create(Object target) {\r
-\r
-               if(!(target instanceof Resource))\r
-                       return null;\r
-\r
-               final Resource resource = (Resource)target;\r
-               \r
-               return new Runnable() {\r
-                       @Override\r
-                       public void run() {\r
-                               \r
-                               try {\r
-                                       ModelingResources MOD = ModelingResources.getInstance(Simantics.getSession());\r
-                                       String id = Simantics.sync(new PossibleRelatedValue2<String>(resource, MOD.contextualHelpId, Bindings.STRING));\r
-                                       if(id == null) {\r
-                                               PlatformUI.getWorkbench().getHelpSystem().displayDynamicHelp();\r
-                                               return;\r
-                                       }\r
-                                       PlatformUI.getWorkbench().getHelpSystem().displayHelp(id);\r
-                               } catch (DatabaseException e) {\r
-                                       Logger.defaultLogError(e);\r
-                               }\r
-                               \r
-                       }\r
-               }; \r
-       }\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2016 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     Semantum Oy - initial API and implementation
+ *******************************************************************************/
+package org.simantics.modeling.actions;
+
+import org.eclipse.ui.PlatformUI;
+import org.simantics.Simantics;
+import org.simantics.databoard.Bindings;
+import org.simantics.db.Resource;
+import org.simantics.db.common.primitiverequest.PossibleRelatedValue2;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.adapter.ActionFactory;
+import org.simantics.modeling.ModelingResources;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class Help implements ActionFactory {
+
+       private static final Logger LOGGER = LoggerFactory.getLogger(Help.class);
+
+       @Override
+       public Runnable create(Object target) {
+               if (!(target instanceof Resource))
+                       return null;
+
+               final Resource resource = (Resource) target;
+
+               return () -> {
+                       try {
+                               ModelingResources MOD = ModelingResources.getInstance(Simantics.getSession());
+                               String id = Simantics.sync(new PossibleRelatedValue2<String>(resource, MOD.contextualHelpId, Bindings.STRING));
+                               if (id == null) {
+                                       PlatformUI.getWorkbench().getHelpSystem().displayDynamicHelp();
+                                       return;
+                               }
+                               PlatformUI.getWorkbench().getHelpSystem().displayHelp(id);
+                       } catch (DatabaseException e) {
+                               LOGGER.error("Failed to display help for resource {}", resource, e);
+                       }
+               }; 
+       }
+
+}