]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Allow overriding issue hidden-ness/hiding logic in inheriting ontologies 85/1185/3
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 2 Nov 2017 14:52:34 +0000 (16:52 +0200)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 2 Nov 2017 15:16:51 +0000 (17:16 +0200)
Changed the way issues are modelled by adding two new
function-properties: hider & hidden. hider is used to change the
hidden-state of issues and hidden is used to query the state. This
allows e.g. fully variable-based dynamic issue hierarchies to support
hiding as well.

refs #7594

Change-Id: Ieba88fb4ffd3142dc4371fa941fd5f31d6eaf93f

bundles/org.simantics.db.common/src/org/simantics/db/common/utils/TagUtil.java
bundles/org.simantics.issues.common/src/org/simantics/issues/common/All.java
bundles/org.simantics.issues.common/src/org/simantics/issues/common/HideFunction.java [new file with mode: 0644]
bundles/org.simantics.issues.ontology/graph/Issue.pgraph
bundles/org.simantics.issues.ui.ontology/graph/IssueUI.pgraph
bundles/org.simantics.issues.ui/src/org/simantics/issues/ui/contribution/IssueLabelDecorationRule.java
bundles/org.simantics.issues.ui/src/org/simantics/issues/ui/handler/FunctionHandler.java [new file with mode: 0644]
bundles/org.simantics.issues.ui/src/org/simantics/issues/ui/handler/Hide.java
bundles/org.simantics.issues.ui/src/org/simantics/issues/ui/handler/PreferenceHandler.java
bundles/org.simantics.issues.ui/src/org/simantics/issues/ui/handler/Unhide.java

index 81457b4086e68874536aa63d76691b0d33412188..5cdeebc9f2ac4a23886d592e1710572c8a9e47ba 100644 (file)
@@ -23,7 +23,6 @@ import org.simantics.db.common.CommentMetadata;
 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
@@ -62,12 +61,9 @@ public class TagUtil {
                 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);
         });
     }
 
index 6eccb1755f22c746f9f91666e57b097a543467a8..d39ee983745bed698ffa35c49342d3228999252b 100644 (file)
@@ -14,6 +14,7 @@ import org.simantics.db.layer0.variable.Variables;
 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 {
        
@@ -96,4 +97,30 @@ 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;
+    }
+
 }
diff --git a/bundles/org.simantics.issues.common/src/org/simantics/issues/common/HideFunction.java b/bundles/org.simantics.issues.common/src/org/simantics/issues/common/HideFunction.java
new file mode 100644 (file)
index 0000000..d72c363
--- /dev/null
@@ -0,0 +1,76 @@
+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
index c68e561f43abd47687828347037378d3366de08f..a819028de94dc38b3a860edb753059b42235c0f9 100644 (file)
@@ -42,6 +42,8 @@ ISSUE.Issue <T L0.Entity
     >-- 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"
@@ -57,6 +59,12 @@ ISSUE.Issue <T L0.Entity
     @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."
index 281bec912b3b2e8295d299f76fde093401f5f36d..fa2099b9a9dd5822a0735bdd6a6957ff97143a26 100644 (file)
@@ -44,6 +44,8 @@ ACTIONS.SetSeverityAction <T ACT.Action
     >-- 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
@@ -154,7 +156,8 @@ IBC
     @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
@@ -191,10 +194,10 @@ IAC = UI.ActionContext : VP.BrowseContext
         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
 
index 7f77719678fec7bb07e20f23a770b70a460379f0..cee7c8aefbb123b7ea8b0326cf0a5de7bd57e423 100644 (file)
@@ -15,9 +15,11 @@ import org.eclipse.jface.resource.FontDescriptor;
 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;
 
 /**
@@ -33,42 +35,75 @@ public enum IssueLabelDecorationRule implements LabelDecorationRule {
 
     @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;
+        }
+    };
+
 }
diff --git a/bundles/org.simantics.issues.ui/src/org/simantics/issues/ui/handler/FunctionHandler.java b/bundles/org.simantics.issues.ui/src/org/simantics/issues/ui/handler/FunctionHandler.java
new file mode 100644 (file)
index 0000000..38b2c93
--- /dev/null
@@ -0,0 +1,78 @@
+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
index c6886c1704c4a17c3f51cbca439ef6a8a8910dbd..299b71346609bcc74f7f1fd3dfbd094736f24852 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * 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
@@ -8,19 +8,17 @@
  *
  * 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);
     }
 
 }
index 7a82395982868b3332197603b6b16ce5fb7adc8c..20a343938b804c23691e7c80386c1521584a1080 100644 (file)
@@ -39,7 +39,6 @@ import org.simantics.db.layer0.adapter.ActionFactory2;
 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;
 
@@ -96,7 +95,7 @@ class PreferenceHandler extends AbstractHandler implements IElementUpdater, Acti
         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;
index 72a9fb4c05aa5f3f2795ff89e6bdd39428bce9ef..24918c1fb1787c30b850b4ca94e7846d1268e9fa 100644 (file)
@@ -8,19 +8,17 @@
  *
  * 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);
     }
 
 }