From b050b5946efa128b0e667d1ada4745cc1e8204c7 Mon Sep 17 00:00:00 2001 From: Nassirou NAMBIEMA Date: Wed, 29 Jan 2020 17:46:23 +0100 Subject: [PATCH] Fix updating UI bug Signed-off-by: Nassirou NAMBIEMA --- .../ext/base/ModificationScriptEditor.java | 41 ++++++++++--------- pom.xml | 2 +- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/gse-afs-ext-base/src/main/java/com/powsybl/gse/afs/ext/base/ModificationScriptEditor.java b/gse-afs-ext-base/src/main/java/com/powsybl/gse/afs/ext/base/ModificationScriptEditor.java index 619ec852..a932cd39 100644 --- a/gse-afs-ext-base/src/main/java/com/powsybl/gse/afs/ext/base/ModificationScriptEditor.java +++ b/gse-afs-ext-base/src/main/java/com/powsybl/gse/afs/ext/base/ModificationScriptEditor.java @@ -12,6 +12,7 @@ import com.powsybl.afs.storage.events.AppStorageListener; import com.powsybl.afs.storage.events.DependencyAdded; import com.powsybl.afs.storage.events.DependencyRemoved; +import com.powsybl.afs.storage.events.NodeEvent; import com.powsybl.commons.util.ServiceLoaderCache; import com.powsybl.gse.spi.AutoCompletionWordsProvider; import com.powsybl.gse.spi.GseContext; @@ -109,6 +110,8 @@ public class ModificationScriptEditor extends BorderPane private Service scriptUpdateService; + private AppStorageListener appStorageListener; + public ModificationScriptEditor(AbstractScript abstractScript, Scene scene, GseContext context) { this.abstractScript = abstractScript; this.context = context; @@ -119,25 +122,9 @@ public ModificationScriptEditor(AbstractScript abstractScript, Scene scene, GseC codeEditor = getCodeEditor(); - AppStorageListener l = eventList -> - eventList.getEvents().forEach(nodeEvent -> - Platform.runLater(() -> { - boolean nodeEventEqualsAbstractScript = nodeEvent.getId().equals(abstractScript.getId()); - boolean oneOrMoreDependenciesHaveChanged = this.abstractScript.getIncludedScripts().stream().anyMatch(includeScript -> includeScript.getId().equals(nodeEvent.getId())); - if (oneOrMoreDependenciesHaveChanged || nodeEventEqualsAbstractScript) { - boolean isDependencyAddedType = DependencyAdded.TYPENAME.equals(nodeEvent.getType()); - boolean isDependencyRemovedType = DependencyRemoved.TYPENAME.equals(nodeEvent.getType()); - - boolean dependenciesAreAddedOrRemoved = nodeEventEqualsAbstractScript && (isDependencyAddedType || isDependencyRemovedType); - - if (dependenciesAreAddedOrRemoved || oneOrMoreDependenciesHaveChanged) { - abstractScript.clearDependenciesCache(); - updateIncludePane(); - } - } - })); - - abstractScript.getFileSystem().getEventBus().addListener(l); + appStorageListener = eventList -> eventList.getEvents().forEach(nodeEvent -> Platform.runLater(() -> updateDependenciesView(abstractScript, nodeEvent))); + + abstractScript.getFileSystem().getEventBus().addListener(appStorageListener); //Adding autocompletion keywords suggestions depending the context List suggestions = new ArrayList<>(); List completionWordsProviderExtensions = findCompletionWordsProviderExtensions(abstractScript); @@ -197,6 +184,22 @@ public ModificationScriptEditor(AbstractScript abstractScript, Scene scene, GseC abstractScript.addListener(this); } + private void updateDependenciesView(AbstractScript abstractScript, NodeEvent nodeEvent) { + boolean nodeEventEqualsAbstractScript = nodeEvent.getId().equals(abstractScript.getId()); + boolean oneOrMoreDependenciesHaveChanged = this.abstractScript.getIncludedScripts().stream().anyMatch(includeScript -> includeScript.getId().equals(nodeEvent.getId())); + if (oneOrMoreDependenciesHaveChanged || nodeEventEqualsAbstractScript) { + boolean isDependencyAddedType = DependencyAdded.TYPENAME.equals(nodeEvent.getType()); + boolean isDependencyRemovedType = DependencyRemoved.TYPENAME.equals(nodeEvent.getType()); + + boolean dependenciesAreAddedOrRemoved = nodeEventEqualsAbstractScript && (isDependencyAddedType || isDependencyRemovedType); + + if (dependenciesAreAddedOrRemoved || oneOrMoreDependenciesHaveChanged) { + abstractScript.clearDependenciesCache(); + updateIncludePane(); + } + } + } + private void addIncludedScript(Scene scene, GseContext context) { VirtualScriptCreator virtualScriptCreator = new VirtualScriptCreator(abstractScript, scene, context); Callback resultConverter = buttonType -> buttonType == ButtonType.OK ? Boolean.TRUE : Boolean.FALSE; diff --git a/pom.xml b/pom.xml index 74915376..2e67a7a7 100755 --- a/pom.xml +++ b/pom.xml @@ -107,7 +107,7 @@ 1.7.22 2.0 - 3.1.0 + 3.2.0-SNAPSHOT 3.1.0