From ff05c9c2511aa7118eb7ff5479f4aeb0f2297573 Mon Sep 17 00:00:00 2001 From: lantzelot-swe <75668734+lantzelot-swe@users.noreply.github.com> Date: Fri, 4 Nov 2022 21:05:38 +0100 Subject: [PATCH] fix: Trying to save a game view without any filters shows an error message instead of an exception. --- .../lantz/gui/gameview/GameViewManager.java | 36 ++++++++++++++----- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/src/main/java/se/lantz/gui/gameview/GameViewManager.java b/src/main/java/se/lantz/gui/gameview/GameViewManager.java index 827cb8b..197bbcb 100644 --- a/src/main/java/se/lantz/gui/gameview/GameViewManager.java +++ b/src/main/java/se/lantz/gui/gameview/GameViewManager.java @@ -69,25 +69,43 @@ public class GameViewManager } } } - + private boolean okToSave(GameView gameView) { - String title = "Invalid name"; + String title = "No filters"; + if (gameView.getViewFilters().isEmpty()) + { + JOptionPane.showMessageDialog(MainWindow.getInstance(), + "The gamelist view have no filters defined, add a filter and try again.", + title, + JOptionPane.ERROR_MESSAGE); + return false; + } + + title = "Invalid name"; //Check name towards all other available gameviews, no duplicates. Also minimum two characters if (gameView.getName().length() < 2) - { - JOptionPane.showMessageDialog(MainWindow.getInstance(), "The gamelist view name is too short, give it a different name.", title, JOptionPane.ERROR_MESSAGE); + { + JOptionPane.showMessageDialog(MainWindow.getInstance(), + "The gamelist view name is too short, give it a different name.", + title, + JOptionPane.ERROR_MESSAGE); return false; } for (int i = 0; i < uiModel.getGameViewModel().getSize(); i++) { GameView currentView = uiModel.getGameViewModel().getElementAt(i); - if (currentView.getGameViewId() != gameView.getGameViewId() && currentView.getName().equalsIgnoreCase(gameView.getName())) + if (currentView.getGameViewId() != gameView.getGameViewId() && + currentView.getName().equalsIgnoreCase(gameView.getName())) { - JOptionPane.showMessageDialog(MainWindow.getInstance(), "A gamelist view with the same name aleady exists, give it a different name.", title, JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(MainWindow.getInstance(), + "A gamelist view with the same name aleady exists, give it a different name.", + title, + JOptionPane.ERROR_MESSAGE); return false; } } + return true; } @@ -104,7 +122,7 @@ public class GameViewManager MainWindow.getInstance().selectViewAfterRestore(); } } - + public void renameFavoritesView(GameView gameView) { GameViewRenameFavoritesDialog dialog = new GameViewRenameFavoritesDialog(MainWindow.getInstance(), gameView); @@ -118,7 +136,7 @@ public class GameViewManager if (okToSave(gameView)) { saveFavNameInPreferences(gameView); - + //Refresh after renaming MainWindow.getInstance().refreshMenuAndUI(); //Trigger reload of game view after editing @@ -134,7 +152,7 @@ public class GameViewManager } } } - + private void saveFavNameInPreferences(GameView gameView) { Properties configuredProperties = FileManager.getConfiguredProperties();