org.simantics.issues.ontology;bundle-version="1.2.0",
org.simantics.simulator.variable;bundle-version="1.0.0",
org.simantics.scl.osgi;bundle-version="1.0.4",
- org.simantics.scl.compiler;bundle-version="0.4.0"
+ org.simantics.scl.compiler;bundle-version="0.4.0",
+ org.slf4j.api
Export-Package: org.simantics.db.layer0,
org.simantics.db.layer0.adapter,
org.simantics.db.layer0.adapter.impl,
import org.simantics.db.WriteGraph;
import org.simantics.db.common.issue.StandardIssue;
import org.simantics.db.common.primitiverequest.PossibleRelatedValueImplied2;
+import org.simantics.db.common.primitiverequest.PossibleResource;
import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;
import org.simantics.db.common.procedure.adapter.TransientCacheListener;
import org.simantics.db.common.request.IsEnumeratedValue;
-import org.simantics.db.common.request.ObjectsWithType;
import org.simantics.db.common.uri.UnescapedChildMapOfResource;
import org.simantics.db.common.utils.CommonDBUtils;
import org.simantics.db.common.utils.Functions;
import org.simantics.db.layer0.request.PossibleURI;
import org.simantics.db.layer0.request.PropertyInfo;
import org.simantics.db.layer0.request.PropertyInfoRequest;
+import org.simantics.db.layer0.request.UnescapedAssertedPropertyMapOfResource;
import org.simantics.db.layer0.request.UnescapedPropertyMapOfResource;
import org.simantics.db.layer0.scl.CompileResourceValueRequest;
import org.simantics.db.layer0.scl.CompileValueRequest;
import org.simantics.db.layer0.variable.ChildVariableMapRequest;
import org.simantics.db.layer0.variable.ExternalSetValue;
import org.simantics.db.layer0.variable.PropertyVariableMapRequest;
+import org.simantics.db.layer0.variable.StandardAssertedGraphPropertyVariable;
import org.simantics.db.layer0.variable.StandardComposedProperty;
import org.simantics.db.layer0.variable.StandardGraphChildVariable;
import org.simantics.db.layer0.variable.StandardGraphPropertyVariable;
if (variable.isAsserted()) {
if (variable.parentResource != null) {
- Layer0 L0 = Layer0.getInstance(graph);
- for(Resource assertion : graph.syncRequest(new ObjectsWithType(variable.parentResource, L0.Asserts, L0.Assertion))) {
- if(variable.property.predicate.equals(graph.getSingleObject(assertion, L0.HasPredicate))) {
- return graph.getRelatedValue2(assertion, L0.HasObject, variable);
+ Map<String, Pair<PropertyInfo, Resource>> assertions = graph.syncRequest(
+ new UnescapedAssertedPropertyMapOfResource(variable.parentResource),
+ TransientCacheAsyncListener.instance());
+
+ // NOTE: This optimization assumes the property
+ // variable's representation is the asserted object.
+ Resource object = variable.getPossibleRepresents(graph);
+ if (object != null) {
+ return graph.getValue2(object, variable);
+ } else {
+ for (Pair<PropertyInfo, Resource> assertion : assertions.values()) {
+ if (assertion.first.predicate.equals(variable.property.predicate)) {
+ return graph.getValue2(assertion.second, variable);
+ }
}
}
}
try {
- Layer0 L0 = Layer0.getInstance(graph);
-
if(variable.property.hasEnumerationRange) {
Resource object = variable.getRepresents(graph);
if(graph.sync(new IsEnumeratedValue(object))) {
+ Layer0 L0 = Layer0.getInstance(graph);
if(graph.isInstanceOf(object, L0.Literal)) {
- return graph.getValue(object);
+ return graph.getValue(object, binding);
} else {
return graph.getRelatedValue2(variable.getRepresents(graph), L0.HasLabel, binding);
}
if (variable.isAsserted()) {
if (variable.parentResource != null) {
- for(Resource assertion : graph.syncRequest(new ObjectsWithType(variable.parentResource, L0.Asserts, L0.Assertion))) {
- if(variable.property.predicate.equals(graph.getSingleObject(assertion, L0.HasPredicate))) {
- return graph.getRelatedValue2(assertion, L0.HasObject, context);
- }
- }
+ Map<String, Pair<PropertyInfo, Resource>> assertions = graph.syncRequest(
+ new UnescapedAssertedPropertyMapOfResource(variable.parentResource),
+ TransientCacheAsyncListener.instance());
+
+ // NOTE: This optimization assumes the property
+ // variable's representation is the asserted object.
+ Resource object = variable.getPossibleRepresents(graph);
+ if (object != null) {
+ return graph.getValue2(object, variable, binding);
+ } else {
+ for (Pair<PropertyInfo, Resource> assertion : assertions.values()) {
+ if (assertion.first.predicate.equals(variable.property.predicate)) {
+ return graph.getValue2(assertion.second, variable, binding);
+ }
+ }
+ }
}
}
// Fallback: try to ask property resource uri from NodeManager
return createStandardGraphPropertyVariable(graph, variable, propertyNode);
}
+ // Final fallback: check types corresponding to
+ // node classification(s) and look for asserted
+ // properties from the URIs specified.
+ if (variable.node != null) {
+ try {
+ @SuppressWarnings("unchecked")
+ Set<String> classifications = variable.node.support.manager.getClassifications(variable.node.node);
+ if (!classifications.isEmpty()) {
+ for (String uri : classifications) {
+ Resource type = graph.syncRequest(
+ new PossibleResource(uri),
+ TransientCacheAsyncListener.instance());
+ if (type == null)
+ continue;
+ Map<String, Pair<PropertyInfo, Resource>> pm = graph.syncRequest(
+ new UnescapedAssertedPropertyMapOfResource(type),
+ TransientCacheAsyncListener.instance());
+ Pair<PropertyInfo, Resource> pi = pm.get(name);
+ if (pi != null) {
+ return new StandardAssertedGraphPropertyVariable(graph, context, null, type, pi.first.predicate, pi.second);
+ }
+ }
+ }
+ } catch(NodeManagerException e) {
+ throw new DatabaseException(e);
+ }
+ }
return null;
}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2017 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.db.layer0.request;
+
+ import gnu.trove.map.hash.THashMap;
+
+import java.util.Collection;
+import java.util.Map;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.Statement;
+import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;
+import org.simantics.db.common.request.ResourceRead;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.layer0.Layer0;
+import org.simantics.utils.datastructures.Pair;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @author Tuukka Lehtonen
+ * @since 1.27.0
+ */
+public class UnescapedAssertedPropertyMapOfResource extends ResourceRead<Map<String, Pair<PropertyInfo, Resource>>> {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(UnescapedAssertedPropertyMapOfResource.class);
+
+ public UnescapedAssertedPropertyMapOfResource(Resource resource) {
+ super(resource);
+ }
+
+ @Override
+ public Map<String,Pair<PropertyInfo, Resource>> perform(ReadGraph graph) throws DatabaseException {
+ Layer0 L0 = Layer0.getInstance(graph);
+ Collection<Statement> assertions = graph.getAssertedStatements(resource, L0.HasProperty);
+ THashMap<String, Pair<PropertyInfo, Resource>> result = new THashMap<>(assertions.size());
+ for (Statement stm : assertions) {
+ PropertyInfo info = graph.syncRequest(new PropertyInfoRequest(stm.getPredicate()), TransientCacheAsyncListener.<PropertyInfo>instance());
+ if (info != null && info.isHasProperty) {
+ String name = info.name;
+ // Use putIfAbsent because we want to prefer the results that are first,
+ // i.e. the ones deeper in the type inheritance chain.
+ if (result.putIfAbsent(name, Pair.make(info, stm.getObject())) != null) {
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug(this + ": The database resource $" + resource.getResourceId()
+ + " asserts the multiple properties with the same name " + name + " (resource=$"
+ + info.predicate.getResourceId() + ").");
+ }
+ }
+ }
+ }
+ return result;
+ }
+
+}
return IssueUtils.pathString(uri, modelURI.length()+1);
}
}
-
+
+ @SCLValue(type = "ReadGraph -> Resource -> Variable -> [Resource]")
+ public static List<Resource> standardIssueContexts(ReadGraph graph, Resource converter, Variable property) throws DatabaseException {
+ return IssueUtils.getContextsForProperty(graph, property);
+ }
+
}
L0.InverseOf ISSUE.Issue.HasContext.Inverse <R L0.IsRelatedTo
>-- ISSUE.Issue.HasSeverity --> ISSUE.Severity <R L0.DependsOn : L0.FunctionalRelation
>-- ISSUE.Issue.HasContexts --> L0.List <R L0.DependsOn
+ >-- ISSUE.Issue.contexts ==> "[Resource]" <R L0.HasProperty : L0.FunctionalRelation
>-- ISSUE.Issue.severity ==> "String" <R L0.HasProperty : L0.FunctionalRelation
>-- ISSUE.Issue.resource ==> "String" <R L0.HasProperty : L0.FunctionalRelation
>-- ISSUE.Issue.path ==> "String" <R L0.HasProperty : L0.FunctionalRelation
@L0.assert ISSUE.Issue.path
ISSUE.Functions.standardIssuePath : L0.Function
L0.HasValueType "String"
+ @L0.assert ISSUE.Issue.contexts
+ ISSUE.Functions.standardIssueContexts : L0.Function
+ L0.HasValueType "[Resource]"
ISSUE.UserIssue
L0.HasDescription "A tag for marking issues as manually added, i.e. so called user issues."
public final Resource Functions;
public final Resource Functions_defaultDescription;
public final Resource Functions_dependencyBaseRealizationFunction;
+ public final Resource Functions_standardIssueContexts;
public final Resource Functions_standardIssuePath;
public final Resource Functions_standardIssueResource;
public final Resource Functions_standardIssueSeverity;
public final Resource Issue_HasContexts_Inverse;
public final Resource Issue_HasSeverity;
public final Resource Issue_HasSeverity_Inverse;
+ public final Resource Issue_contexts;
+ public final Resource Issue_contexts_Inverse;
public final Resource Issue_creationTime;
public final Resource Issue_creationTime_Inverse;
public final Resource Issue_path;
public static final String Functions = "http://www.simantics.org/Issue-1.2/Functions";
public static final String Functions_defaultDescription = "http://www.simantics.org/Issue-1.2/Functions/defaultDescription";
public static final String Functions_dependencyBaseRealizationFunction = "http://www.simantics.org/Issue-1.2/Functions/dependencyBaseRealizationFunction";
+ public static final String Functions_standardIssueContexts = "http://www.simantics.org/Issue-1.2/Functions/standardIssueContexts";
public static final String Functions_standardIssuePath = "http://www.simantics.org/Issue-1.2/Functions/standardIssuePath";
public static final String Functions_standardIssueResource = "http://www.simantics.org/Issue-1.2/Functions/standardIssueResource";
public static final String Functions_standardIssueSeverity = "http://www.simantics.org/Issue-1.2/Functions/standardIssueSeverity";
public static final String Issue_HasContexts_Inverse = "http://www.simantics.org/Issue-1.2/Issue/HasContexts/Inverse";
public static final String Issue_HasSeverity = "http://www.simantics.org/Issue-1.2/Issue/HasSeverity";
public static final String Issue_HasSeverity_Inverse = "http://www.simantics.org/Issue-1.2/Issue/HasSeverity/Inverse";
+ public static final String Issue_contexts = "http://www.simantics.org/Issue-1.2/Issue/contexts";
+ public static final String Issue_contexts_Inverse = "http://www.simantics.org/Issue-1.2/Issue/contexts/Inverse";
public static final String Issue_creationTime = "http://www.simantics.org/Issue-1.2/Issue/creationTime";
public static final String Issue_creationTime_Inverse = "http://www.simantics.org/Issue-1.2/Issue/creationTime/Inverse";
public static final String Issue_path = "http://www.simantics.org/Issue-1.2/Issue/path";
Functions = getResourceOrNull(graph, URIs.Functions);
Functions_defaultDescription = getResourceOrNull(graph, URIs.Functions_defaultDescription);
Functions_dependencyBaseRealizationFunction = getResourceOrNull(graph, URIs.Functions_dependencyBaseRealizationFunction);
+ Functions_standardIssueContexts = getResourceOrNull(graph, URIs.Functions_standardIssueContexts);
Functions_standardIssuePath = getResourceOrNull(graph, URIs.Functions_standardIssuePath);
Functions_standardIssueResource = getResourceOrNull(graph, URIs.Functions_standardIssueResource);
Functions_standardIssueSeverity = getResourceOrNull(graph, URIs.Functions_standardIssueSeverity);
Issue_HasContexts_Inverse = getResourceOrNull(graph, URIs.Issue_HasContexts_Inverse);
Issue_HasSeverity = getResourceOrNull(graph, URIs.Issue_HasSeverity);
Issue_HasSeverity_Inverse = getResourceOrNull(graph, URIs.Issue_HasSeverity_Inverse);
+ Issue_contexts = getResourceOrNull(graph, URIs.Issue_contexts);
+ Issue_contexts_Inverse = getResourceOrNull(graph, URIs.Issue_contexts_Inverse);
Issue_creationTime = getResourceOrNull(graph, URIs.Issue_creationTime);
Issue_creationTime_Inverse = getResourceOrNull(graph, URIs.Issue_creationTime_Inverse);
Issue_path = getResourceOrNull(graph, URIs.Issue_path);
L0.HasResourceClass "org.simantics.issues.ui.ontology.IssueUIResource"
//--------------------------------------------------------------------------
-// Functions
+// Libraries
UI.Functions : L0.Library
ACTIONS.SetSeverityAction <T ACT.Action
>-- ACTIONS.SetSeverityAction.HasSeverity --> ISSUE.Severity <R L0.DependsOn : L0.FunctionalRelation
+ACTIONS.Help : ACT.Action
//--------------------------------------------------------------------------
// Issue Browse context
ACTIONS.Hide : ACT.Action
@VP.actionContribution "Unhide" IBC.Issue SILK.shading VP.EditActionCategory
ACTIONS.Unhide : ACT.Action
-
+ @VP.actionContribution "Help" IBC.Issue SILK.help VP.EditActionCategory ACTIONS.Help
+ @VP.actionContribution "Help" IBC.DynamicIssueHierarchyNode SILK.help VP.EditActionCategory ACTIONS.Help
//--------------------------------------------------------------------------
// Batch Issue Source Browse context
public final Resource ActionContext;
public final Resource Actions;
+ public final Resource Actions_Help;
public final Resource Actions_Hide;
public final Resource Actions_Resolve;
public final Resource Actions_SetSeverityAction;
public static class URIs {
public static final String ActionContext = "http://www.simantics.org/IssueUI-1.1/ActionContext";
public static final String Actions = "http://www.simantics.org/IssueUI-1.1/Actions";
+ public static final String Actions_Help = "http://www.simantics.org/IssueUI-1.1/Actions/Help";
public static final String Actions_Hide = "http://www.simantics.org/IssueUI-1.1/Actions/Hide";
public static final String Actions_Resolve = "http://www.simantics.org/IssueUI-1.1/Actions/Resolve";
public static final String Actions_SetSeverityAction = "http://www.simantics.org/IssueUI-1.1/Actions/SetSeverityAction";
public IssueUIResource(ReadGraph graph) {
ActionContext = getResourceOrNull(graph, URIs.ActionContext);
Actions = getResourceOrNull(graph, URIs.Actions);
+ Actions_Help = getResourceOrNull(graph, URIs.Actions_Help);
Actions_Hide = getResourceOrNull(graph, URIs.Actions_Hide);
Actions_Resolve = getResourceOrNull(graph, URIs.Actions_Resolve);
Actions_SetSeverityAction = getResourceOrNull(graph, URIs.Actions_SetSeverityAction);
class="org.simantics.issues.ui.handler.Hide"/>
<resource uri="http://www.simantics.org/IssueUI-0.0/Actions/Unhide"
class="org.simantics.issues.ui.handler.Unhide"/>
-
+
+ <resource uri="http://www.simantics.org/IssueUI-0.0/Actions/Help"
+ class="org.simantics.issues.ui.handler.Help" />
</target>
id="org.simantics.issues.category"
name="Issues">
</category>
- <!--
- <view
- category="org.simantics.issues.category"
- class="org.simantics.issues.ui.IssueView"
- icon="platform:/plugin/com.famfamfam.silk/icons/error.png"
- id="org.simantics.issues.ui.issueview"
- name="Issues">
- </view>
- -->
<view
category="org.simantics.issues.category"
class="org.simantics.issues.ui.IssueView2"
*******************************************************************************/
package org.simantics.issues.ui;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.IWorkbenchPart;
import org.simantics.Simantics;
+import org.simantics.browsing.ui.GraphExplorer;
+import org.simantics.browsing.ui.model.browsecontexts.BrowseContext;
import org.simantics.db.ReadGraph;
import org.simantics.db.Resource;
import org.simantics.db.common.request.ResourceRead;
import org.simantics.issues.ui.ontology.IssueUIResource;
import org.simantics.modeling.ModelingResources;
import org.simantics.ui.workbench.IPropertyPage;
+import org.simantics.utils.ui.SWTUtils;
import org.simantics.views.swt.ModelledView;
/**
return null;
}
+ @SuppressWarnings({ "unchecked", "deprecation" })
+ @Override
+ public <T> T getAdapter(Class<T> adapter) {
+ if (GraphExplorer.class == adapter)
+ return (T) tryGetExplorer(container);
+ if (BrowseContext.class == adapter)
+ return (T) tryGetBrowseContext(container);
+ return super.getAdapter(adapter);
+ }
+
+ private BrowseContext tryGetBrowseContext(Control control) {
+ return SWTUtils.tryGetObject(control, c -> {
+ return c instanceof IAdaptable
+ ? (BrowseContext) ((IAdaptable) c).getAdapter(BrowseContext.class)
+ : null;
+ });
+ }
+
+ private GraphExplorer tryGetExplorer(Control control) {
+ return SWTUtils.tryGetObject(control, c -> {
+ return c.isDisposed() ? null
+ : (GraphExplorer) c.getData(GraphExplorer.KEY_GRAPH_EXPLORER);
+ });
+ }
+
}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2017 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.issues.ui.handler;
+
+import org.eclipse.ui.PlatformUI;
+import org.simantics.Simantics;
+import org.simantics.databoard.Bindings;
+import org.simantics.databoard.binding.Binding;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.common.request.TernaryRead;
+import org.simantics.db.common.utils.Logger;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.adapter.ActionFactory;
+import org.simantics.db.layer0.variable.Variable;
+
+/**
+ * @author Tuukka Lehtonen
+ * @since 1.27.0
+ */
+public class Help implements ActionFactory {
+
+ @Override
+ public Runnable create(Object target) {
+ if (target instanceof Variable) {
+ return () -> {
+ try {
+ String id = Simantics.sync(new PossibleVariablePropertyValue<String>((Variable) target, "contextualHelpId", Bindings.STRING));
+ if (id == null) {
+ PlatformUI.getWorkbench().getHelpSystem().displayDynamicHelp();
+ return;
+ }
+ PlatformUI.getWorkbench().getHelpSystem().displayHelp(id);
+ } catch (DatabaseException e) {
+ Logger.defaultLogError(e);
+ }
+ };
+ }
+
+ return null;
+ }
+
+ static class PossibleVariablePropertyValue<T> extends TernaryRead<Variable, String, Binding, T> {
+
+ public PossibleVariablePropertyValue(Variable variable, String property, Binding binding) {
+ super(variable, property, binding);
+ }
+
+ @Override
+ public T perform(ReadGraph graph) throws DatabaseException {
+ return parameter.getPossiblePropertyValue(graph, parameter2, parameter3);
+ }
+
+ }
+
+}
import org.simantics.issues.ontology.IssueResource;
import org.simantics.issues.ui.internal.Activator;
import org.simantics.ui.contribution.DynamicMenuContribution;
-import org.simantics.utils.datastructures.Callback;
import org.simantics.utils.ui.ErrorLogger;
import org.simantics.utils.ui.ISelectionUtils;
graph.deny(issue, ISSUE.Issue_HasSeverity);
}
}
- }, new Callback<DatabaseException>() {
- @Override
- public void run(DatabaseException e) {
- if (e != null)
- ErrorLogger.defaultLogError(e);
- }
+ }, e -> {
+ if (e != null)
+ ErrorLogger.defaultLogError(e);
});
}
import org.simantics.layer0.Layer0;
import org.simantics.modeling.ModelingResources;
import org.simantics.modeling.ui.Activator;
-import org.simantics.structural.stubs.StructuralResource2;
import org.simantics.ui.SimanticsUI;
import org.simantics.ui.workbench.editor.AbstractResourceEditorAdapter;
-import org.simantics.utils.datastructures.Pair;
/**
* @author Tuukka Lehtonen