X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=org.simantics.district.network%2Fsrc%2Forg%2Fsimantics%2Fdistrict%2Fnetwork%2Fprofile%2FThrottledStyleBase.java;h=8e5421a84b3693b8362778266206a61916f3302d;hb=ded33522a93462a69f30ecb258df42b8d7127b22;hp=67ca25952522f41caa0b7a59a163131fa2a7b878;hpb=8364294edf86a6915ae3fe7eade555d95fd7e435;p=simantics%2Fdistrict.git diff --git a/org.simantics.district.network/src/org/simantics/district/network/profile/ThrottledStyleBase.java b/org.simantics.district.network/src/org/simantics/district/network/profile/ThrottledStyleBase.java index 67ca2595..8e5421a8 100644 --- a/org.simantics.district.network/src/org/simantics/district/network/profile/ThrottledStyleBase.java +++ b/org.simantics.district.network/src/org/simantics/district/network/profile/ThrottledStyleBase.java @@ -14,7 +14,6 @@ package org.simantics.district.network.profile; import java.util.Optional; import java.util.concurrent.atomic.AtomicLong; -import org.simantics.Simantics; import org.simantics.databoard.Bindings; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; @@ -38,29 +37,13 @@ public abstract class ThrottledStyleBase extends StyleBase> resultListener; @Override protected Read> getStyleCalculationRequest(Resource runtimeDiagram, Resource entry, Resource item) { - Simantics.getSession().asyncRequest(new ProfileUpdateIntervalRead(runtimeDiagram), new Listener() { - - @Override - public void execute(Long result) { - interval.set(result); - } - - @Override - public void exception(Throwable t) { - LOGGER.error("Could not listen interval from runtime diagram {}", runtimeDiagram, t); - } - - @Override - public boolean isDisposed() { - return resultListener.isDisposed(); - } - }); + //Simantics.getSession().asyncRequest(new ProfileUpdateIntervalRead(runtimeDiagram), new ProfileUpdateIntervalListener(runtimeDiagram, entry, item)); return super.getStyleCalculationRequest(runtimeDiagram, entry, item); } @@ -89,10 +72,12 @@ public abstract class ThrottledStyleBase extends StyleBase result) { - if (!result.equals(Optional.empty())) { + if (!Optional.empty().equals(result) && result != null) { applyThrottledStyleForNode(evaluationContext, node, result.get()); } else { LOGGER.debug("Do not apply as results are unchanged for {} {} {}", evaluationContext, node, result); + // TODO: fix this duplicate method invocation with null + applyThrottledStyleForNode(evaluationContext, node, null); } } @@ -110,9 +95,83 @@ public abstract class ThrottledStyleBase extends StyleBase { + + private Resource runtimeDiagram; + private Resource entry; + private Resource item; + + public ProfileUpdateIntervalListener(Resource runtimeDiagram, Resource entry, Resource item) { + this.runtimeDiagram = runtimeDiagram; + this.entry = entry; + this.item = item; + } + + @Override + public void execute(Long result) { + interval.set(result); + } + + @Override + public void exception(Throwable t) { + LOGGER.error("Could not listen interval from runtime diagram {}", runtimeDiagram, t); + } + + @Override + public boolean isDisposed() { + return resultListener.isDisposed(); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + getEnclosingInstance().hashCode(); + result = prime * result + ((entry == null) ? 0 : entry.hashCode()); + result = prime * result + ((item == null) ? 0 : item.hashCode()); + result = prime * result + ((runtimeDiagram == null) ? 0 : runtimeDiagram.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ProfileUpdateIntervalListener other = (ProfileUpdateIntervalListener) obj; + if (!getEnclosingInstance().equals(other.getEnclosingInstance())) + return false; + if (entry == null) { + if (other.entry != null) + return false; + } else if (!entry.equals(other.entry)) + return false; + if (item == null) { + if (other.item != null) + return false; + } else if (!item.equals(other.item)) + return false; + if (runtimeDiagram == null) { + if (other.runtimeDiagram != null) + return false; + } else if (!runtimeDiagram.equals(other.runtimeDiagram)) + return false; + return true; + } + + private ThrottledStyleBase getEnclosingInstance() { + return ThrottledStyleBase.this; + } + } + }