From ab1a5e9c612b505a051e9ff2ac572a0833277fba Mon Sep 17 00:00:00 2001 From: DieGurke Date: Mon, 24 Aug 2020 21:08:48 +0200 Subject: [PATCH] Shortened code --- .../ui/controller/GroupCreationTab.java | 74 ++++++++----------- 1 file changed, 31 insertions(+), 43 deletions(-) diff --git a/client/src/main/java/envoy/client/ui/controller/GroupCreationTab.java b/client/src/main/java/envoy/client/ui/controller/GroupCreationTab.java index f4ae707..900742a 100644 --- a/client/src/main/java/envoy/client/ui/controller/GroupCreationTab.java +++ b/client/src/main/java/envoy/client/ui/controller/GroupCreationTab.java @@ -122,33 +122,19 @@ public class GroupCreationTab { private void createButtonClicked() { name = groupNameField.getText(); if (!Bounds.isValidContactName(name)) { - errorMessageLabel.setPrefHeight(30); - errorMessageLabel.setMinHeight(30); - errorMessageLabel.setMaxHeight(30); + setErrorMessageLabelSize(30); errorMessageLabel.setText("The group name is not valid!"); groupNameField.clear(); } else if (groupNameAlreadyPresent(name)) { - errorMessageLabel.setPrefHeight(30); - errorMessageLabel.setMinHeight(30); - errorMessageLabel.setMaxHeight(30); + setErrorMessageLabelSize(30); errorMessageLabel.setText("Name does already exist! Proceed anyways?"); - proceedDupButton.setPrefHeight(30); - proceedDupButton.setMinHeight(30); - proceedDupButton.setMaxHeight(30); - cancelDupButton.setPrefHeight(30); - cancelDupButton.setMinHeight(30); - cancelDupButton.setMaxHeight(30); - errorProceedBox.setPrefHeight(30); - errorProceedBox.setMinHeight(30); - errorProceedBox.setMaxHeight(30); + setProcessPaneSize(30); createButton.setDisable(true); cancelButton.setDisable(true); } else { createGroup(name); eventBus.dispatch(new BackEvent()); - errorMessageLabel.setPrefHeight(0); - errorMessageLabel.setMinHeight(0); - errorMessageLabel.setMaxHeight(0); + setErrorMessageLabelSize(0); groupNameField.clear(); } } @@ -183,7 +169,11 @@ public class GroupCreationTab { } @FXML - private void backButtonClicked() { eventBus.dispatch(new BackEvent()); } + private void backButtonClicked() { + eventBus.dispatch(new BackEvent()); + setErrorMessageLabelSize(0); + setProcessPaneSize(0); + } @FXML private void proceedOnNameDuplication() { @@ -191,18 +181,8 @@ public class GroupCreationTab { cancelButton.setDisable(false); createGroup(name); eventBus.dispatch(new BackEvent()); - errorMessageLabel.setPrefHeight(0); - errorMessageLabel.setMinHeight(0); - errorMessageLabel.setMaxHeight(0); - proceedDupButton.setPrefHeight(0); - proceedDupButton.setMinHeight(0); - proceedDupButton.setMaxHeight(0); - cancelDupButton.setPrefHeight(0); - cancelDupButton.setMinHeight(0); - cancelDupButton.setMaxHeight(0); - errorProceedBox.setPrefHeight(0); - errorProceedBox.setMinHeight(0); - errorProceedBox.setMaxHeight(0); + setErrorMessageLabelSize(0); + setProcessPaneSize(0); groupNameField.clear(); } @@ -210,18 +190,26 @@ public class GroupCreationTab { private void cancelOnNameDuplication() { createButton.setDisable(false); cancelButton.setDisable(false); - errorMessageLabel.setPrefHeight(0); - errorMessageLabel.setMinHeight(0); - errorMessageLabel.setMaxHeight(0); - proceedDupButton.setPrefHeight(0); - proceedDupButton.setMinHeight(0); - proceedDupButton.setMaxHeight(0); - cancelDupButton.setPrefHeight(0); - cancelDupButton.setMinHeight(0); - cancelDupButton.setMaxHeight(0); - errorProceedBox.setPrefHeight(0); - errorProceedBox.setMinHeight(0); - errorProceedBox.setMaxHeight(0); + setErrorMessageLabelSize(0); + setProcessPaneSize(0); groupNameField.clear(); } + + private void setErrorMessageLabelSize(int value) { + errorMessageLabel.setPrefHeight(value); + errorMessageLabel.setMinHeight(value); + errorMessageLabel.setMaxHeight(value); + } + + private void setProcessPaneSize(int value) { + proceedDupButton.setPrefHeight(value); + proceedDupButton.setMinHeight(value); + proceedDupButton.setMaxHeight(value); + cancelDupButton.setPrefHeight(value); + cancelDupButton.setMinHeight(value); + cancelDupButton.setMaxHeight(value); + errorProceedBox.setPrefHeight(value); + errorProceedBox.setMinHeight(value); + errorProceedBox.setMaxHeight(value); + } }