From 3650d1eec752656e5cb1f3becd675021e7c35d49 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Wed, 2 Aug 2017 19:18:33 -0700 Subject: [PATCH] Refresh all settings on plugin load. --- .../org/nwapw/abacus/fx/AbacusController.java | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/nwapw/abacus/fx/AbacusController.java b/src/main/java/org/nwapw/abacus/fx/AbacusController.java index 5b7b4c5..a3dd793 100644 --- a/src/main/java/org/nwapw/abacus/fx/AbacusController.java +++ b/src/main/java/org/nwapw/abacus/fx/AbacusController.java @@ -11,6 +11,8 @@ import javafx.util.StringConverter; import org.nwapw.abacus.Abacus; import org.nwapw.abacus.config.Configuration; import org.nwapw.abacus.number.NumberInterface; +import org.nwapw.abacus.plugin.PluginListener; +import org.nwapw.abacus.plugin.PluginManager; import org.nwapw.abacus.tree.TreeNode; import java.util.Set; @@ -20,7 +22,7 @@ import java.util.Set; * The controller for the abacus FX UI, responsible * for all the user interaction. */ -public class AbacusController { +public class AbacusController implements PluginListener { /** * Constant string that is displayed if the text could not be lexed or parsed. @@ -109,16 +111,8 @@ public class AbacusController { outputColumn.setCellValueFactory(cell -> cell.getValue().outputProperty()); abacus = new Abacus(); - Configuration configuration = abacus.getConfiguration(); - Set disabledPlugins = configuration.getDisabledPlugins(); - numberImplementationOptions.addAll(abacus.getPluginManager().getAllNumbers()); - String actualImplementation = configuration.getNumberImplementation(); - String toSelect = (numberImplementationOptions.contains(actualImplementation)) ? actualImplementation : "naive"; - numberImplementationBox.getSelectionModel().select(toSelect); - for(Class pluginClass : abacus.getPluginManager().getLoadedPluginClasses()){ - String fullName = pluginClass.getName(); - enabledPlugins.add(new ToggleablePlugin(!disabledPlugins.contains(fullName), fullName)); - } + abacus.getPluginManager().addListener(this); + abacus.getPluginManager().reload(); } @FXML @@ -155,4 +149,23 @@ public class AbacusController { abacus.getConfiguration().saveTo(Abacus.CONFIG_FILE); } + @Override + public void onLoad(PluginManager manager) { + Configuration configuration = abacus.getConfiguration(); + Set disabledPlugins = configuration.getDisabledPlugins(); + numberImplementationOptions.addAll(abacus.getPluginManager().getAllNumbers()); + String actualImplementation = configuration.getNumberImplementation(); + String toSelect = (numberImplementationOptions.contains(actualImplementation)) ? actualImplementation : "naive"; + numberImplementationBox.getSelectionModel().select(toSelect); + for(Class pluginClass : abacus.getPluginManager().getLoadedPluginClasses()){ + String fullName = pluginClass.getName(); + enabledPlugins.add(new ToggleablePlugin(!disabledPlugins.contains(fullName), fullName)); + } + } + + @Override + public void onUnload(PluginManager manager) { + enabledPlugins.clear(); + numberImplementationOptions.clear(); + } }