import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.handlers.HandlerUtil;
import org.simantics.Simantics;
-import org.simantics.databoard.Bindings;
import org.simantics.db.ReadGraph;
import org.simantics.db.Resource;
import org.simantics.db.common.request.UniqueRead;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.layer0.variable.Variable;
-import org.simantics.modeling.ModelingResources;
-import org.simantics.modeling.PropertyVariables;
+import org.simantics.modeling.help.HelpContexts;
import org.simantics.ui.selection.WorkbenchSelectionUtils;
-import org.simantics.utils.ui.AdaptionUtils;
import org.slf4j.LoggerFactory;
public class ContextualHelp extends AbstractHandler {
return Simantics.getSession().syncRequest(new UniqueRead<String>() {
@Override
public String perform(ReadGraph graph) throws DatabaseException {
- return getPossibleId(graph, resource, variable, sel);
+ return HelpContexts.getPossibleId(graph, resource, variable, sel);
}
});
} catch (DatabaseException e) {
return null;
}
+ /**
+ * @deprecated use {@link HelpContexts#getPossibleId(ReadGraph, Resource, Variable, Object)} instead
+ */
+ @Deprecated
public static String getPossibleId(ReadGraph graph, Resource resource, Variable variable, ISelection sel) throws DatabaseException {
- ModelingResources MOD = ModelingResources.getInstance(graph);
- if (resource != null) {
- Resource component = graph.getPossibleObject(resource, MOD.ElementToComponent);
- String id = component != null ? graph.getPossibleRelatedValue2(component, MOD.contextualHelpId, Bindings.STRING) : null;
- if (id != null)
- return id;
- id = graph.getPossibleRelatedValue2(resource, MOD.contextualHelpId, Bindings.STRING);
- if (id != null)
- return id;
- }
-
- if (variable != null) {
- String id = variable.getPossiblePropertyValue(graph, MOD.contextualHelpId, Bindings.STRING);
- if (id != null)
- return id;
- }
-
- // TODO: consider removing this block
- if (sel != null) {
- PropertyVariables vars = AdaptionUtils.adaptToSingle(sel, PropertyVariables.class);
- Variable var = vars != null ? vars.getConfiguration() : null;
- String id = var != null ? var.getPossiblePropertyValue(graph, MOD.contextualHelpId, Bindings.STRING) : null;
- if (id != null)
- return id;
- }
-
- return null;
+ return HelpContexts.getPossibleId(graph, resource, variable, sel);
}
}
org.simantics.modeling.adapters,
org.simantics.modeling.export,
org.simantics.modeling.flags,
+ org.simantics.modeling.help,
org.simantics.modeling.mapping,
org.simantics.modeling.migration,
org.simantics.modeling.preferences,
import org.simantics.databoard.Bindings;
import org.simantics.db.Resource;
import org.simantics.db.common.primitiverequest.PossibleRelatedValue2;
-import org.simantics.db.common.utils.Logger;
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))
+ if (!(target instanceof Resource))
return null;
- final Resource resource = (Resource)target;
-
- return new Runnable() {
- @Override
- public void run() {
-
- 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.defaultLogError(e);
+ 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);
}
};
}
+
}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2020 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.help;
+
+import org.simantics.databoard.Bindings;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.variable.Variable;
+import org.simantics.modeling.ModelingResources;
+import org.simantics.modeling.PropertyVariables;
+import org.simantics.utils.ui.AdaptionUtils;
+
+/**
+ * @author Tuukka Lehtonen
+ * @since 1.46.0
+ */
+public class HelpContexts {
+
+ /**
+ * @param graph
+ * @param resource
+ * @param variable
+ * @param selection optional <code>ISelection</code>
+ * @return
+ * @throws DatabaseException
+ */
+ public static String getPossibleId(ReadGraph graph, Resource resource, Variable variable, Object selection) throws DatabaseException {
+ ModelingResources MOD = ModelingResources.getInstance(graph);
+ if (resource != null) {
+ Resource component = graph.getPossibleObject(resource, MOD.ElementToComponent);
+ String id = component != null ? graph.getPossibleRelatedValue2(component, MOD.contextualHelpId, Bindings.STRING) : null;
+ if (id != null)
+ return id;
+ id = graph.getPossibleRelatedValue2(resource, MOD.contextualHelpId, Bindings.STRING);
+ if (id != null)
+ return id;
+ }
+
+ if (variable != null) {
+ String id = variable.getPossiblePropertyValue(graph, MOD.contextualHelpId, Bindings.STRING);
+ if (id != null)
+ return id;
+ }
+
+ // TODO: consider removing this block
+ if (selection != null) {
+ PropertyVariables vars = AdaptionUtils.adaptToSingle(selection, PropertyVariables.class);
+ Variable var = vars != null ? vars.getConfiguration() : null;
+ String id = var != null ? var.getPossiblePropertyValue(graph, MOD.contextualHelpId, Bindings.STRING) : null;
+ if (id != null)
+ return id;
+ }
+
+ return null;
+ }
+
+ public static String getPossibleId(ReadGraph graph, Variable variable, String property) throws DatabaseException {
+ ModelingResources MOD = ModelingResources.getInstance(graph);
+ Variable prop = variable != null ? variable.getPossibleProperty(graph, property) : null;
+ return prop != null ? prop.getPossiblePropertyValue(graph, MOD.contextualHelpId, Bindings.STRING) : null;
+ }
+
+}