From: Antti Villberg Date: Fri, 29 Nov 2019 07:57:07 +0000 (+0200) Subject: Maintain info about changed resources in virtual graph X-Git-Tag: v1.43.0~136^2~26^2 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F41%2F3641%2F2;p=simantics%2Fplatform.git Maintain info about changed resources in virtual graph gitlab #428 Change-Id: Ia697012400c7a0a4bd07462eafbf08ffa082890d --- diff --git a/bundles/org.simantics.modeling.ontology/graph/Modeling.pgraph b/bundles/org.simantics.modeling.ontology/graph/Modeling.pgraph index a45e7419c..e566026b1 100644 --- a/bundles/org.simantics.modeling.ontology/graph/Modeling.pgraph +++ b/bundles/org.simantics.modeling.ontology/graph/Modeling.pgraph @@ -411,6 +411,10 @@ MOD.changeInformation + diff --git a/bundles/org.simantics.modeling.ui/icons/changed_decorator.png b/bundles/org.simantics.modeling.ui/icons/changed_decorator.png new file mode 100644 index 000000000..f0476a43d Binary files /dev/null and b/bundles/org.simantics.modeling.ui/icons/changed_decorator.png differ diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/Activator.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/Activator.java index 565c30895..dfce14c6b 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/Activator.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/Activator.java @@ -41,6 +41,8 @@ public class Activator extends AbstractUIPlugin { public static String INFO_SVG_TEXT; public static String NOTE_SVG_TEXT; + public static ImageDescriptor CHANGED_DECORATOR_ICON; + public static ImageDescriptor BULLET_GREEN_ICON; public static ImageDescriptor BULLET_YELLOW_ICON; @@ -109,6 +111,8 @@ public class Activator extends AbstractUIPlugin { INFO_SVG_TEXT = FileUtils.getContents(bundle.getResource("icons/info.svg")); //$NON-NLS-1$ NOTE_SVG_TEXT = FileUtils.getContents(bundle.getResource("icons/note4.svg")); //$NON-NLS-1$ + CHANGED_DECORATOR_ICON = ImageDescriptor.createFromURL(bundle.getResource("icons/changed_decorator.png")); //$NON-NLS-1$ + BULLET_GREEN_ICON = ImageDescriptor.createFromURL(bundle.getResource("icons/bullet_green.png")); //$NON-NLS-1$ BULLET_YELLOW_ICON = ImageDescriptor.createFromURL(bundle.getResource("icons/bullet_yellow.png")); //$NON-NLS-1$ diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser2/image/ChangedResourceImageDecorationRule.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser2/image/ChangedResourceImageDecorationRule.java new file mode 100644 index 000000000..586387b67 --- /dev/null +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser2/image/ChangedResourceImageDecorationRule.java @@ -0,0 +1,43 @@ +package org.simantics.modeling.ui.modelBrowser2.image; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.IDecoration; +import org.simantics.browsing.ui.content.ImageDecorator; +import org.simantics.browsing.ui.model.imagedecorators.ImageDecorationRule; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.modeling.ModelingResources; +import org.simantics.modeling.ui.Activator; +import org.simantics.utils.ui.gfx.DecorationOverlayIcon; + +public class ChangedResourceImageDecorationRule implements ImageDecorationRule { + + private ImageDecorator CHANGED_DECORATOR = new ImageDecorator() { + @Override + public Image decorateImage(Image image, String column, int itemIndex) { + ImageDescriptor original = (ImageDescriptor)image; + ImageDescriptor decorated = (original == null || original.getImageData() == null) ? Activator.CHANGED_DECORATOR_ICON + : new DecorationOverlayIcon(original, Activator.CHANGED_DECORATOR_ICON, IDecoration.BOTTOM_RIGHT); + return (Image)decorated; + } + }; + + @Override + public boolean isCompatible(Class contentType) { + return Resource.class.isAssignableFrom(contentType); + } + + @Override + public ImageDecorator getImageDecorator(ReadGraph graph, Object content) + throws DatabaseException + { + Resource resource = (Resource) content; + ModelingResources MOD = ModelingResources.getInstance(graph); + if (!graph.hasStatement(resource, MOD.changed)) + return null; + + return CHANGED_DECORATOR; + } + +} diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/ModelingUtils.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/ModelingUtils.java index ea960c1d0..4a4d97a18 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/ModelingUtils.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/ModelingUtils.java @@ -67,6 +67,7 @@ import org.simantics.db.RequestProcessor; import org.simantics.db.Resource; import org.simantics.db.Session; import org.simantics.db.Statement; +import org.simantics.db.VirtualGraph; import org.simantics.db.WriteGraph; import org.simantics.db.common.Indexing; import org.simantics.db.common.NamedResource; @@ -2464,4 +2465,16 @@ public class ModelingUtils { return DiagramGraphUtil.getModelingRules(graph, diagramResource, null); } + public static void markChanged(WriteGraph graph, Resource r) throws DatabaseException { + VirtualGraphSupport support = Simantics.getSession().getService(VirtualGraphSupport.class); + VirtualGraph vg = support.getWorkspacePersistent("changeInformation"); + graph.syncRequest(new WriteRequest(vg) { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + ModelingResources MOD = ModelingResources.getInstance(graph); + graph.claim(r, MOD.changed, MOD.changed, r); + } + }); + } + } diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/utils/OntologicalRequirementEnforceRequest.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/utils/OntologicalRequirementEnforceRequest.java index dd547ffe3..3f8ffb15b 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/utils/OntologicalRequirementEnforceRequest.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/utils/OntologicalRequirementEnforceRequest.java @@ -11,6 +11,7 @@ import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.layer0.Layer0; import org.simantics.modeling.ModelingResources; +import org.simantics.modeling.ModelingUtils; import org.simantics.modeling.adapters.ChangeHistoryUpdated; import org.simantics.modeling.adapters.ChangeInformation; @@ -92,6 +93,7 @@ public class OntologicalRequirementEnforceRequest extends WriteRequest { for (Resource c : creates) { CommonDBUtils.selectClusterSet(graph, c); graph.claimLiteral(c, MOD.changeInformation, MOD.changeInformation_Inverse, MOD.ChangeInformation, info, ChangeInformation.BINDING); + ModelingUtils.markChanged(graph, c); } } @@ -107,6 +109,7 @@ public class OntologicalRequirementEnforceRequest extends WriteRequest { info.modifiedBy = author; CommonDBUtils.selectClusterSet(graph, m); graph.claimLiteral(m, MOD.changeInformation, MOD.changeInformation_Inverse, MOD.ChangeInformation, info, ChangeInformation.BINDING); + ModelingUtils.markChanged(graph, m); } for (Resource r : ids) {