import org.simantics.db.common.request.WriteRequest;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.service.VirtualGraphSupport;
-import org.simantics.utils.datastructures.Callback;
/**
* @author Tuukka Lehtonen
graph.markUndoPoint();
processSelection(graph, resources);
}
- }, new Callback<DatabaseException>() {
- @Override
- public void run(DatabaseException e) {
- if (e != null)
- handleError(e);
- }
+ }, e -> {
+ if (e != null)
+ handleError(e);
});
}
import org.simantics.issues.ontology.IssueResource;
import org.simantics.layer0.Layer0;
import org.simantics.scl.reflection.annotations.SCLValue;
+import org.simantics.scl.runtime.function.Function1;
public class All {
throw new IllegalArgumentException("Unsupported property type: " + property);
}
+ @SCLValue(type = "ReadGraph -> Resource -> a -> b")
+ public static Function1<Boolean, Boolean> standardIssueHider(ReadGraph graph, Resource converter, Object property) throws DatabaseException {
+ if (property instanceof Variable) {
+ Variable hider = (Variable) property;
+ Variable issue = hider.getParent(graph);
+ Resource r = issue.getPossibleRepresents(graph);
+ if (r != null)
+ return new HideFunction(r);
+ }
+ return null;
+ }
+
+ @SCLValue(type = "ReadGraph -> Resource -> a -> Boolean")
+ public static Boolean standardIssueHidden(ReadGraph graph, Resource converter, Object property) throws DatabaseException {
+ if (property instanceof Variable) {
+ Variable hidden = (Variable) property;
+ Variable issue = hidden.getParent(graph);
+ Resource r = issue.getPossibleRepresents(graph);
+ if (r != null) {
+ IssueResource ISSUE = IssueResource.getInstance(graph);
+ return graph.hasStatement(r, ISSUE.Hidden);
+ }
+ }
+ return false;
+ }
+
}
--- /dev/null
+package org.simantics.issues.common;
+
+import java.util.Objects;
+
+import org.simantics.databoard.util.ObjectUtils;
+import org.simantics.db.Resource;
+import org.simantics.db.VirtualGraph;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.CommentMetadata;
+import org.simantics.db.common.request.WriteRequest;
+import org.simantics.db.common.utils.NameUtils;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.exception.RuntimeDatabaseException;
+import org.simantics.db.service.VirtualGraphSupport;
+import org.simantics.issues.ontology.IssueResource;
+import org.simantics.scl.runtime.SCLContext;
+import org.simantics.scl.runtime.function.FunctionImpl1;
+
+/**
+ * @author Tuukka Lehtonen
+ * @since 1.31.0
+ */
+class HideFunction extends FunctionImpl1<Boolean, Boolean> {
+
+ private Resource[] issues;
+
+ public HideFunction(Resource... issues) {
+ this.issues = issues;
+ }
+
+ @Override
+ public Boolean apply(Boolean hide) {
+ try {
+ WriteGraph graph = Objects.requireNonNull((WriteGraph) SCLContext.getCurrent().get("graph"));
+ IssueResource ISSUE = IssueResource.getInstance(graph);
+ boolean changed = false;
+ for (Resource issue : issues)
+ changed |= tag(graph, issue, ISSUE.Hidden, hide);
+ return changed;
+ } catch (DatabaseException e) {
+ throw new RuntimeDatabaseException(e);
+ }
+ }
+
+ private static boolean tag(WriteGraph graph, Resource r, Resource tagRel, boolean tag) throws DatabaseException {
+ boolean isTagged = graph.hasStatement(r, tagRel);
+ if (tag && !isTagged) {
+ // If r is virtual, we perform tagging in the same vg
+ VirtualGraphSupport vgs = graph.getService(VirtualGraphSupport.class);
+ VirtualGraph vg = vgs.getGraph(graph, r);
+ if (vg != null) {
+ graph.sync(new WriteRequest(vg) {
+ @Override
+ public void perform(WriteGraph graph) throws DatabaseException {
+ graph.claim(r, tagRel, tagRel, r);
+ CommentMetadata cm = graph.getMetadata(CommentMetadata.class);
+ graph.addMetadata(cm.add(ObjectUtils.toString("Marking " + NameUtils.getSafeLabel(graph, r) + " to " + NameUtils.getSafeName(graph, tagRel))));
+ }
+ });
+ } else {
+ graph.claim(r, tagRel, tagRel, r);
+ CommentMetadata cm = graph.getMetadata(CommentMetadata.class);
+ graph.addMetadata(cm.add(ObjectUtils.toString("Marking " + NameUtils.getSafeLabel(graph, r) + " to " + NameUtils.getSafeName(graph, tagRel))));
+ }
+ return true;
+ } else if (!tag && isTagged) {
+ graph.deny(r, tagRel, tagRel, r);
+ CommentMetadata cm = graph.getMetadata(CommentMetadata.class);
+ graph.addMetadata(cm.add(ObjectUtils.toString("Denying " + NameUtils.getSafeLabel(graph, r) + " to " + NameUtils.getSafeName(graph, tagRel))));
+ return true;
+ }
+
+ return false;
+ }
+
+}
\ No newline at end of file
>-- ISSUE.Issue.resource ==> "String" <R L0.HasProperty : L0.FunctionalRelation
>-- ISSUE.Issue.path ==> "String" <R L0.HasProperty : L0.FunctionalRelation
>-- ISSUE.Issue.creationTime --> L0.String <R L0.HasProperty : L0.FunctionalRelation
+ >-- ISSUE.Issue.hider ==> "Maybe (Boolean -> <WriteGraph> Boolean)" <R L0.HasProperty : L0.FunctionalRelation
+ >-- ISSUE.Issue.hidden ==> "Boolean" <R L0.HasProperty : L0.FunctionalRelation
@L0.assert L0.HasDescription
ISSUE.Functions.defaultDescription : L0.Function
L0.HasValueType "String"
@L0.assert ISSUE.Issue.contexts
ISSUE.Functions.standardIssueContexts : L0.Function
L0.HasValueType "[Resource]"
+ @L0.assert ISSUE.Issue.hider
+ ISSUE.Functions.standardIssueHider : L0.Function
+ L0.HasValueType "Maybe (Boolean -> <WriteGraph> Boolean)"
+ @L0.assert ISSUE.Issue.hidden
+ ISSUE.Functions.standardIssueHidden : L0.Function
+ L0.HasValueType "Boolean"
ISSUE.UserIssue
L0.HasDescription "A tag for marking issues as manually added, i.e. so called user issues."
>-- ACTIONS.SetSeverityAction.HasSeverity --> ISSUE.Severity <R L0.DependsOn : L0.FunctionalRelation
ACTIONS.Help : ACT.Action
+ACTIONS.Hide : ACT.Action
+ACTIONS.Unhide : ACT.Action
//--------------------------------------------------------------------------
// Issue Browse context
@VP.customLabelRule IBC.Issue IBC.IssueLabelRule
@VP.customLabelRule IBC.DynamicIssueHierarchyNode IBC.IssueLabelRule
@VP.customVisualsRuleWithPriorityAndTest IBC.Issue VP.VariableLabelModifierRule 1.0 IBC.UserIssueTest
- @VP.customLabelDecorationRule ISSUE.Issue IBC.IssueLabelDecorationRule
+ @VP.customLabelDecorationRule IBC.Issue IBC.IssueLabelDecorationRule
+ @VP.customLabelDecorationRule IBC.DynamicIssueHierarchyNode IBC.IssueLabelDecorationRule
// Images
@VP.constantImageRule IBC.FatalFolder SILK.bomb
ACTIONS.Resolve : ACT.Action
@VP.actionContribution "Unresolve" IBC.Issue SILK.lightbulb_off VP.EditActionCategory
ACTIONS.Unresolve : ACT.Action
- @VP.actionContribution "Hide" IBC.Issue SILK.shading VP.EditActionCategory
- ACTIONS.Hide : ACT.Action
- @VP.actionContribution "Unhide" IBC.Issue SILK.shading VP.EditActionCategory
- ACTIONS.Unhide : ACT.Action
+ @VP.actionContribution "Hide" IBC.Issue SILK.shading VP.EditActionCategory ACTIONS.Hide
+ @VP.actionContribution "Hide" IBC.DynamicIssueHierarchyNode SILK.shading VP.EditActionCategory ACTIONS.Hide
+ @VP.actionContribution "Unhide" IBC.Issue SILK.shading VP.EditActionCategory ACTIONS.Unhide
+ @VP.actionContribution "Unhide" IBC.DynamicIssueHierarchyNode SILK.shading VP.EditActionCategory ACTIONS.Unhide
@VP.actionContribution "Help" IBC.Issue SILK.help VP.EditActionCategory ACTIONS.Help
@VP.actionContribution "Help" IBC.DynamicIssueHierarchyNode SILK.help VP.EditActionCategory ACTIONS.Help
import org.eclipse.swt.SWT;
import org.simantics.browsing.ui.content.LabelDecorator;
import org.simantics.browsing.ui.model.labeldecorators.LabelDecorationRule;
+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.issues.ontology.IssueResource;
/**
@Override
public boolean isCompatible(Class<?> contentType) {
- return contentType.equals(Resource.class);
+ return contentType.equals(Variable.class);
}
@Override
public LabelDecorator getLabelDecorator(ReadGraph graph, Object content) throws DatabaseException {
- Resource issue = (Resource) content;
+ Variable issue = (Variable) content;
- final boolean hidden = graph.hasStatement(issue, IssueResource.getInstance(graph).Hidden);
- final boolean user = graph.hasStatement(issue, IssueResource.getInstance(graph).UserIssue);
- final boolean resolved = graph.hasStatement(issue, IssueResource.getInstance(graph).Resolved);
- if (!hidden && !user && !resolved)
- return null;
+ boolean hidden = false;
+ boolean user = false;
+ boolean resolved = false;
- return new LabelDecorator.Stub() {
- @SuppressWarnings("unchecked")
- @Override
- public <F> F decorateFont(F font, String column, int itemIndex) {
- int style = 0;
- style |= resolved ? SWT.ITALIC : 0;
- return style != 0 ? (F) ((FontDescriptor) font).setStyle(style) : font;
- }
- @SuppressWarnings("unchecked")
- @Override
- public <C> C decorateForeground(C color, String column, int itemIndex) {
- if (hidden)
- return (C) Constants.HIDDEN_FG;
- return color;
- }
- @SuppressWarnings("unchecked")
- @Override
- public <C> C decorateBackground(C color, String column, int itemIndex) {
- if (user)
- return (C) Constants.USER_BG;
- return color;
- }
- };
+ Resource issueR = issue.getPossibleRepresents(graph);
+ if (issueR != null) {
+ IssueResource ISSUE = IssueResource.getInstance(graph);
+ hidden = graph.hasStatement(issueR, ISSUE.Hidden);
+ user = graph.hasStatement(issueR, ISSUE.UserIssue);
+ resolved = graph.hasStatement(issueR, ISSUE.Resolved);
+ } else {
+ hidden = Boolean.TRUE.equals(issue.getPossiblePropertyValue(graph, "hidden", Bindings.BOOLEAN));
+ }
+
+ int index = (hidden ? 1 : 0) + (user ? 2 : 0) + (resolved ? 4 : 0);
+ return DECORATORS[index];
}
+ private static final Decorator[] DECORATORS = {
+ null,
+ new Decorator(true, false, false),
+ new Decorator(false, true, false),
+ new Decorator(true, true, false),
+ new Decorator(false, false, true),
+ new Decorator(true, false, true),
+ new Decorator(false, true, true),
+ new Decorator(true, true, true),
+ };
+
+ private static class Decorator extends LabelDecorator.Stub {
+ private boolean hidden;
+ private boolean user;
+ private boolean resolved;
+
+ public Decorator(boolean hidden, boolean user, boolean resolved) {
+ this.hidden = hidden;
+ this.user = user;
+ this.resolved = resolved;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <F> F decorateFont(F font, String column, int itemIndex) {
+ int style = 0;
+ style |= resolved ? SWT.ITALIC : 0;
+ //style |= hidden ? SWT.BOLD : 0;
+ return style != 0 ? (F) ((FontDescriptor) font).setStyle(style) : font;
+ }
+ @SuppressWarnings("unchecked")
+ @Override
+ public <C> C decorateForeground(C color, String column, int itemIndex) {
+ if (hidden)
+ return (C) Constants.HIDDEN_FG;
+ return color;
+ }
+ @SuppressWarnings("unchecked")
+ @Override
+ public <C> C decorateBackground(C color, String column, int itemIndex) {
+ if (user)
+ return (C) Constants.USER_BG;
+ return color;
+ }
+ };
+
}
--- /dev/null
+package org.simantics.issues.ui.handler;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.simantics.Simantics;
+import org.simantics.db.Resource;
+import org.simantics.db.Session;
+import org.simantics.db.VirtualGraph;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.request.WriteRequest;
+import org.simantics.db.common.utils.Logger;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.variable.Variable;
+import org.simantics.db.service.VirtualGraphSupport;
+import org.simantics.scl.runtime.SCLContext;
+import org.simantics.scl.runtime.function.Function;
+
+/**
+ * @author Tuukka Lehtonen
+ * @since 1.31.0
+ */
+class FunctionHandler extends PreferenceHandler {
+
+ private String functionPropertyName;
+ private Object argument;
+
+ public FunctionHandler(String virtualGraphId, String functionPropertyName, Object argument) {
+ super(virtualGraphId, null, false);
+ this.functionPropertyName = functionPropertyName;
+ this.argument = argument;
+ }
+
+ public void execute(List<Variable> vars, List<Resource> resources) {
+ if (vars.isEmpty())
+ return;
+ Session session = Simantics.peekSession();
+ if (session == null)
+ return;
+
+ VirtualGraph vg = virtualGraphId == null ? null :
+ session.getService(VirtualGraphSupport.class).getWorkspacePersistent(virtualGraphId);
+
+ session.asyncRequest(new WriteRequest(vg) {
+ @Override
+ public void perform(WriteGraph graph) throws DatabaseException {
+ graph.markUndoPoint();
+ execute(graph, vars, functionPropertyName);
+ }
+ }, e -> {
+ if (e != null)
+ Logger.defaultLogError(e);
+ });
+ }
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ protected void execute(WriteGraph graph, List<Variable> vars, String functionPropertyName) throws DatabaseException {
+ List<Function> hiders = new ArrayList<>(vars.size());
+ for (Variable v : vars) {
+ Function f = v.getPossiblePropertyValue(graph, functionPropertyName);
+ if (f != null)
+ hiders.add(f);
+ }
+ if (!hiders.isEmpty()) {
+ SCLContext ctx = SCLContext.getCurrent();
+ Object oldGraph = ctx.put("graph", graph);
+ try {
+ for (Function f : hiders)
+ f.apply(argument);
+ } catch (Throwable t) {
+ throw new DatabaseException(t);
+ } finally {
+ ctx.put("graph", oldGraph);
+ }
+ }
+ }
+
+}
\ No newline at end of file
/*******************************************************************************
- * Copyright (c) 2007, 2011 Association for Decentralized Information Management
+ * Copyright (c) 2007, 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
*
* Contributors:
* VTT Technical Research Centre of Finland - initial API and implementation
+ * Semantum Oy - #7594 introduced FunctionHandler
*******************************************************************************/
package org.simantics.issues.ui.handler;
-import org.simantics.issues.ontology.IssueResource;
-
-
/**
* @author Tuukka Lehtonen
*/
-public class Hide extends PreferenceHandler {
+public class Hide extends FunctionHandler {
public Hide() {
- super(null, IssueResource.URIs.Hidden, true);
+ super(null, "hider", Boolean.TRUE);
}
}
import org.simantics.db.layer0.variable.Variable;
import org.simantics.db.request.Read;
import org.simantics.issues.ontology.IssueResource;
-import org.simantics.utils.datastructures.SelectionUtils;
import org.simantics.utils.ui.ErrorLogger;
import org.simantics.utils.ui.ISelectionUtils;
return null;
}
- public void execute(final List<Variable> vars, List<Resource> resources) {
+ public void execute(List<Variable> vars, List<Resource> resources) {
Session session = Simantics.peekSession();
if (session == null)
return;
*
* Contributors:
* VTT Technical Research Centre of Finland - initial API and implementation
+ * Semantum Oy - #7594 introduced FunctionHandler
*******************************************************************************/
package org.simantics.issues.ui.handler;
-import org.simantics.issues.ontology.IssueResource;
-
-
/**
* @author Tuukka Lehtonen
*/
-public class Unhide extends PreferenceHandler {
+public class Unhide extends FunctionHandler {
public Unhide() {
- super(null, IssueResource.URIs.Hidden, false);
+ super(null, "hider", Boolean.FALSE);
}
}