@Test void closeModuleInvalid() { robot.interact(() -> { assertThrows(NullPointerException.class, () -> workbench.closeModule(null)); assertThrows(IllegalArgumentException.class, () -> workbench.closeModule(mock(WorkbenchModule.class))); assertThrows(IllegalArgumentException.class, () -> workbench.closeModule(mockModules[0])); }); }
public final boolean closeModule(WorkbenchModule module) { LOGGER.trace("closeModule - " + module); LOGGER.trace("closeModule - List of open modules: " + openModules); Objects.requireNonNull(module); int i = openModules.indexOf(module); if (i == -1) { throw new IllegalArgumentException("Module has not been opened yet."); } WorkbenchModule oldActive = getActiveModule(); WorkbenchModule newActive; if (oldActive != module) { newActive = oldActive; } else if (openModules.size() == 1) { newActive = null; LOGGER.trace("closeModule - Next active: Home Screen"); } else if (i == 0) { newActive = openModules.get(i + 1); LOGGER.trace("closeModule - Next active: Next Module - " + newActive); } else { newActive = openModules.get(i - 1); LOGGER.trace("closeModule - Next active: Previous Module - " + newActive); } if (oldActive == module) { LOGGER.trace("closeModule - " + module + " was deactivated"); module.deactivate(); } if (getModuleCloseable(module).getNow(false) || module.destroy()) { LOGGER.trace("closeModule - Destroy: Success - " + module); boolean removal = openModules.remove(module); moduleCloseableMap.remove(module); LOGGER.trace("closeModule - Destroy, Removal successful: " + removal + " - " + module); if (oldActive != newActive) { LOGGER.trace("closeModule - Set active module to: " + newActive); } activeModule.setValue(newActive); return removal; } else { resetModuleCloseable(module); LOGGER.trace("closeModule - Destroy: Fail - " + module); if (getActiveModule() == module) { module.activate(); } openModule(module); return false; } }
Workbench extends Control { public final boolean closeModule(WorkbenchModule module) { LOGGER.trace("closeModule - " + module); LOGGER.trace("closeModule - List of open modules: " + openModules); Objects.requireNonNull(module); int i = openModules.indexOf(module); if (i == -1) { throw new IllegalArgumentException("Module has not been opened yet."); } WorkbenchModule oldActive = getActiveModule(); WorkbenchModule newActive; if (oldActive != module) { newActive = oldActive; } else if (openModules.size() == 1) { newActive = null; LOGGER.trace("closeModule - Next active: Home Screen"); } else if (i == 0) { newActive = openModules.get(i + 1); LOGGER.trace("closeModule - Next active: Next Module - " + newActive); } else { newActive = openModules.get(i - 1); LOGGER.trace("closeModule - Next active: Previous Module - " + newActive); } if (oldActive == module) { LOGGER.trace("closeModule - " + module + " was deactivated"); module.deactivate(); } if (getModuleCloseable(module).getNow(false) || module.destroy()) { LOGGER.trace("closeModule - Destroy: Success - " + module); boolean removal = openModules.remove(module); moduleCloseableMap.remove(module); LOGGER.trace("closeModule - Destroy, Removal successful: " + removal + " - " + module); if (oldActive != newActive) { LOGGER.trace("closeModule - Set active module to: " + newActive); } activeModule.setValue(newActive); return removal; } else { resetModuleCloseable(module); LOGGER.trace("closeModule - Destroy: Fail - " + module); if (getActiveModule() == module) { module.activate(); } openModule(module); return false; } } }
Workbench extends Control { public final boolean closeModule(WorkbenchModule module) { LOGGER.trace("closeModule - " + module); LOGGER.trace("closeModule - List of open modules: " + openModules); Objects.requireNonNull(module); int i = openModules.indexOf(module); if (i == -1) { throw new IllegalArgumentException("Module has not been opened yet."); } WorkbenchModule oldActive = getActiveModule(); WorkbenchModule newActive; if (oldActive != module) { newActive = oldActive; } else if (openModules.size() == 1) { newActive = null; LOGGER.trace("closeModule - Next active: Home Screen"); } else if (i == 0) { newActive = openModules.get(i + 1); LOGGER.trace("closeModule - Next active: Next Module - " + newActive); } else { newActive = openModules.get(i - 1); LOGGER.trace("closeModule - Next active: Previous Module - " + newActive); } if (oldActive == module) { LOGGER.trace("closeModule - " + module + " was deactivated"); module.deactivate(); } if (getModuleCloseable(module).getNow(false) || module.destroy()) { LOGGER.trace("closeModule - Destroy: Success - " + module); boolean removal = openModules.remove(module); moduleCloseableMap.remove(module); LOGGER.trace("closeModule - Destroy, Removal successful: " + removal + " - " + module); if (oldActive != newActive) { LOGGER.trace("closeModule - Set active module to: " + newActive); } activeModule.setValue(newActive); return removal; } else { resetModuleCloseable(module); LOGGER.trace("closeModule - Destroy: Fail - " + module); if (getActiveModule() == module) { module.activate(); } openModule(module); return false; } } Workbench(); private  Workbench(WorkbenchBuilder builder); }
Workbench extends Control { public final boolean closeModule(WorkbenchModule module) { LOGGER.trace("closeModule - " + module); LOGGER.trace("closeModule - List of open modules: " + openModules); Objects.requireNonNull(module); int i = openModules.indexOf(module); if (i == -1) { throw new IllegalArgumentException("Module has not been opened yet."); } WorkbenchModule oldActive = getActiveModule(); WorkbenchModule newActive; if (oldActive != module) { newActive = oldActive; } else if (openModules.size() == 1) { newActive = null; LOGGER.trace("closeModule - Next active: Home Screen"); } else if (i == 0) { newActive = openModules.get(i + 1); LOGGER.trace("closeModule - Next active: Next Module - " + newActive); } else { newActive = openModules.get(i - 1); LOGGER.trace("closeModule - Next active: Previous Module - " + newActive); } if (oldActive == module) { LOGGER.trace("closeModule - " + module + " was deactivated"); module.deactivate(); } if (getModuleCloseable(module).getNow(false) || module.destroy()) { LOGGER.trace("closeModule - Destroy: Success - " + module); boolean removal = openModules.remove(module); moduleCloseableMap.remove(module); LOGGER.trace("closeModule - Destroy, Removal successful: " + removal + " - " + module); if (oldActive != newActive) { LOGGER.trace("closeModule - Set active module to: " + newActive); } activeModule.setValue(newActive); return removal; } else { resetModuleCloseable(module); LOGGER.trace("closeModule - Destroy: Fail - " + module); if (getActiveModule() == module) { module.activate(); } openModule(module); return false; } } Workbench(); private  Workbench(WorkbenchBuilder builder); static WorkbenchBuilder builder(WorkbenchModule... modules); final void openModule(WorkbenchModule module); final void openAddModulePage(); final boolean closeModule(WorkbenchModule module); final void completeModuleCloseable(WorkbenchModule module); final boolean showOverlay(Region overlay, boolean blocking); final boolean hideOverlay(Region overlay); final void clearOverlays(); final WorkbenchDialog showDialog(WorkbenchDialog dialog); final WorkbenchDialog showErrorDialog(String title,
                                               String message,
                                               Consumer<ButtonType> onResult); final WorkbenchDialog showErrorDialog(String title,
                                               String message,
                                               Exception exception,
                                               Consumer<ButtonType> onResult); final WorkbenchDialog showErrorDialog(String title,
                                               String message,
                                               String details,
                                               Consumer<ButtonType> onResult); final WorkbenchDialog showWarningDialog(String title,
                                                 String message,
                                                 Consumer<ButtonType> onResult); final WorkbenchDialog showConfirmationDialog(String title,
                                                      String message,
                                                      Consumer<ButtonType> onResult); final WorkbenchDialog showInformationDialog(String title,
                                                     String message,
                                                     Consumer<ButtonType> onResult); final void hideDialog(WorkbenchDialog dialog); final void showDrawer(Region drawer, Side side); final void showDrawer(Region drawer, Side side, int percentage); final void hideDrawer(); final void showNavigationDrawer(); final void hideNavigationDrawer(); final ObservableList<WorkbenchModule> getOpenModules(); final ObservableList<WorkbenchModule> getModules(); final WorkbenchModule getActiveModule(); final ReadOnlyObjectProperty<WorkbenchModule> activeModuleProperty(); final Node getActiveModuleView(); final ReadOnlyObjectProperty<Node> activeModuleViewProperty(); final boolean isSingleModuleLayout(); final ObservableList<ToolbarItem> getToolbarControlsLeft(); final ObservableList<ToolbarItem> getToolbarControlsRight(); final ObservableMap<Region, WorkbenchOverlay> getOverlays(); final NavigationDrawer getNavigationDrawer(); final void setNavigationDrawer(NavigationDrawer navigationDrawer); final ObjectProperty<NavigationDrawer> navigationDrawerProperty(); final ObservableList<MenuItem> getNavigationDrawerItems(); final ObservableList<Region> getNonBlockingOverlaysShown(); final ObservableList<Region> getBlockingOverlaysShown(); final int getModulesPerPage(); final void setModulesPerPage(int modulesPerPage); final IntegerProperty modulesPerPageProperty(); final Callback<Workbench, Tab> getTabFactory(); final void setTabFactory(Callback<Workbench, Tab> tabFactory); final ObjectProperty<Callback<Workbench, Tab>> tabFactoryProperty(); final Callback<Workbench, Tile> getTileFactory(); final void setTileFactory(Callback<Workbench, Tile> tileFactory); final ObjectProperty<Callback<Workbench, Tile>> tileFactoryProperty(); final Callback<Workbench, Page> getPageFactory(); final void setPageFactory(Callback<Workbench, Page> pageFactory); final ObjectProperty<Callback<Workbench, Page>> pageFactoryProperty(); final int getAmountOfPages(); final ReadOnlyIntegerProperty amountOfPagesProperty(); final Region getDrawerShown(); final ReadOnlyObjectProperty<Region> drawerShownProperty(); final Side getDrawerSideShown(); final ReadOnlyObjectProperty<Side> drawerSideShownProperty(); @Override final String getUserAgentStylesheet(); }
Workbench extends Control { public final boolean closeModule(WorkbenchModule module) { LOGGER.trace("closeModule - " + module); LOGGER.trace("closeModule - List of open modules: " + openModules); Objects.requireNonNull(module); int i = openModules.indexOf(module); if (i == -1) { throw new IllegalArgumentException("Module has not been opened yet."); } WorkbenchModule oldActive = getActiveModule(); WorkbenchModule newActive; if (oldActive != module) { newActive = oldActive; } else if (openModules.size() == 1) { newActive = null; LOGGER.trace("closeModule - Next active: Home Screen"); } else if (i == 0) { newActive = openModules.get(i + 1); LOGGER.trace("closeModule - Next active: Next Module - " + newActive); } else { newActive = openModules.get(i - 1); LOGGER.trace("closeModule - Next active: Previous Module - " + newActive); } if (oldActive == module) { LOGGER.trace("closeModule - " + module + " was deactivated"); module.deactivate(); } if (getModuleCloseable(module).getNow(false) || module.destroy()) { LOGGER.trace("closeModule - Destroy: Success - " + module); boolean removal = openModules.remove(module); moduleCloseableMap.remove(module); LOGGER.trace("closeModule - Destroy, Removal successful: " + removal + " - " + module); if (oldActive != newActive) { LOGGER.trace("closeModule - Set active module to: " + newActive); } activeModule.setValue(newActive); return removal; } else { resetModuleCloseable(module); LOGGER.trace("closeModule - Destroy: Fail - " + module); if (getActiveModule() == module) { module.activate(); } openModule(module); return false; } } Workbench(); private  Workbench(WorkbenchBuilder builder); static WorkbenchBuilder builder(WorkbenchModule... modules); final void openModule(WorkbenchModule module); final void openAddModulePage(); final boolean closeModule(WorkbenchModule module); final void completeModuleCloseable(WorkbenchModule module); final boolean showOverlay(Region overlay, boolean blocking); final boolean hideOverlay(Region overlay); final void clearOverlays(); final WorkbenchDialog showDialog(WorkbenchDialog dialog); final WorkbenchDialog showErrorDialog(String title,
                                               String message,
                                               Consumer<ButtonType> onResult); final WorkbenchDialog showErrorDialog(String title,
                                               String message,
                                               Exception exception,
                                               Consumer<ButtonType> onResult); final WorkbenchDialog showErrorDialog(String title,
                                               String message,
                                               String details,
                                               Consumer<ButtonType> onResult); final WorkbenchDialog showWarningDialog(String title,
                                                 String message,
                                                 Consumer<ButtonType> onResult); final WorkbenchDialog showConfirmationDialog(String title,
                                                      String message,
                                                      Consumer<ButtonType> onResult); final WorkbenchDialog showInformationDialog(String title,
                                                     String message,
                                                     Consumer<ButtonType> onResult); final void hideDialog(WorkbenchDialog dialog); final void showDrawer(Region drawer, Side side); final void showDrawer(Region drawer, Side side, int percentage); final void hideDrawer(); final void showNavigationDrawer(); final void hideNavigationDrawer(); final ObservableList<WorkbenchModule> getOpenModules(); final ObservableList<WorkbenchModule> getModules(); final WorkbenchModule getActiveModule(); final ReadOnlyObjectProperty<WorkbenchModule> activeModuleProperty(); final Node getActiveModuleView(); final ReadOnlyObjectProperty<Node> activeModuleViewProperty(); final boolean isSingleModuleLayout(); final ObservableList<ToolbarItem> getToolbarControlsLeft(); final ObservableList<ToolbarItem> getToolbarControlsRight(); final ObservableMap<Region, WorkbenchOverlay> getOverlays(); final NavigationDrawer getNavigationDrawer(); final void setNavigationDrawer(NavigationDrawer navigationDrawer); final ObjectProperty<NavigationDrawer> navigationDrawerProperty(); final ObservableList<MenuItem> getNavigationDrawerItems(); final ObservableList<Region> getNonBlockingOverlaysShown(); final ObservableList<Region> getBlockingOverlaysShown(); final int getModulesPerPage(); final void setModulesPerPage(int modulesPerPage); final IntegerProperty modulesPerPageProperty(); final Callback<Workbench, Tab> getTabFactory(); final void setTabFactory(Callback<Workbench, Tab> tabFactory); final ObjectProperty<Callback<Workbench, Tab>> tabFactoryProperty(); final Callback<Workbench, Tile> getTileFactory(); final void setTileFactory(Callback<Workbench, Tile> tileFactory); final ObjectProperty<Callback<Workbench, Tile>> tileFactoryProperty(); final Callback<Workbench, Page> getPageFactory(); final void setPageFactory(Callback<Workbench, Page> pageFactory); final ObjectProperty<Callback<Workbench, Page>> pageFactoryProperty(); final int getAmountOfPages(); final ReadOnlyIntegerProperty amountOfPagesProperty(); final Region getDrawerShown(); final ReadOnlyObjectProperty<Region> drawerShownProperty(); final Side getDrawerSideShown(); final ReadOnlyObjectProperty<Side> drawerSideShownProperty(); @Override final String getUserAgentStylesheet();  }