Skip to content
This repository has been archived by the owner on Oct 13, 2021. It is now read-only.

Commit

Permalink
Fix updating UI bug
Browse files Browse the repository at this point in the history
Signed-off-by: Nassirou NAMBIEMA <[email protected]>
  • Loading branch information
Nassirou NAMBIEMA committed Jan 30, 2020
1 parent ec7db3a commit b050b59
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -109,6 +110,8 @@ public class ModificationScriptEditor extends BorderPane

private Service<String> scriptUpdateService;

private AppStorageListener appStorageListener;

public ModificationScriptEditor(AbstractScript abstractScript, Scene scene, GseContext context) {
this.abstractScript = abstractScript;
this.context = context;
Expand All @@ -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<String> suggestions = new ArrayList<>();
List<AutoCompletionWordsProvider> completionWordsProviderExtensions = findCompletionWordsProviderExtensions(abstractScript);
Expand Down Expand Up @@ -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<ButtonType, Boolean> resultConverter = buttonType -> buttonType == ButtonType.OK ? Boolean.TRUE : Boolean.FALSE;
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
<slf4j.version>1.7.22</slf4j.version>
<tiwulfx.version>2.0</tiwulfx.version>

<powsyblafs.version>3.1.0</powsyblafs.version>
<powsyblafs.version>3.2.0-SNAPSHOT</powsyblafs.version>
<powsyblcore.version>3.1.0</powsyblcore.version>

</properties>
Expand Down

0 comments on commit b050b59

Please sign in to comment.