From: jsimomaa Date: Tue, 4 Jun 2019 16:49:40 +0000 (+0300) Subject: Fix hide style X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F18%2F2918%2F1;p=simantics%2Fdistrict.git Fix hide style gitlab #46 Change-Id: I8b7ea75ec130938a143654a5caae6fd7cb8a79c3 --- diff --git a/org.simantics.district.network/src/org/simantics/district/network/profile/HideStyle.java b/org.simantics.district.network/src/org/simantics/district/network/profile/HideStyle.java index d5f2620f..e1d8bd04 100644 --- a/org.simantics.district.network/src/org/simantics/district/network/profile/HideStyle.java +++ b/org.simantics.district.network/src/org/simantics/district/network/profile/HideStyle.java @@ -3,9 +3,15 @@ package org.simantics.district.network.profile; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.exception.DatabaseException; +import org.simantics.diagram.profile.ProfileKeys; import org.simantics.diagram.profile.StyleBase; +import org.simantics.g2d.diagram.IDiagram; +import org.simantics.g2d.diagram.handler.DataElementMap; +import org.simantics.g2d.element.ElementUtils; +import org.simantics.g2d.element.IElement; import org.simantics.scenegraph.INode; import org.simantics.scenegraph.g2d.nodes.SingleElementNode; +import org.simantics.scenegraph.profile.DataNodeMap; import org.simantics.scenegraph.profile.EvaluationContext; /** @@ -19,17 +25,51 @@ public class HideStyle extends StyleBase { } @Override - public void applyStyleForNode(EvaluationContext observer, INode node, Boolean result) { - SingleElementNode n = (SingleElementNode) node; - n.setVisible(false); - n.setHidden(true); + public void applyStyleForItem(EvaluationContext evaluationContext, DataNodeMap map, Object item, Boolean value) { + INode node = map.getNode(item); + if (node == null) { + evaluationContext.update(); + return; + } + + IDiagram diagram = evaluationContext.getConstant(ProfileKeys.DIAGRAM); + DataElementMap emap = diagram.getDiagramClass().getSingleItem(DataElementMap.class); + IElement element = emap.getElement(diagram, item); + if (element == null) + return; + + hideElements(evaluationContext, diagram, element, node); } @Override - protected void cleanupStyleForNode(EvaluationContext evaluationContext, INode node) { - SingleElementNode n = (SingleElementNode) node; - n.setVisible(true); - n.setHidden(false); + protected void cleanupStyleForItem(EvaluationContext evaluationContext, DataNodeMap map, Object item) { + IDiagram diagram = evaluationContext.getConstant(ProfileKeys.DIAGRAM); + DataElementMap emap = diagram.getDiagramClass().getSingleItem(DataElementMap.class); + + INode node = map.getNode(item); + if (node == null) + return; + IElement element = emap.getElement(diagram, item); + if (element == null) + return; + + showElements(diagram, element, node); + } + + protected void hideElements(EvaluationContext evaluationContext, IDiagram diagram, IElement element, INode node) { + setVisibility(element, node, false); + } + + protected void showElements(IDiagram diagram, IElement element, INode node) { + setVisibility(element, node, true); + } + + protected void setVisibility(IElement element, INode node, boolean visible) { + if (element != null) + ElementUtils.setHidden(element, !visible); + if (node instanceof SingleElementNode) { + ((SingleElementNode) node).setHidden(!visible); + } } @Override