From ab77c98a361788f69c3adc72ff90b22a90977c07 Mon Sep 17 00:00:00 2001 From: DieGurke Date: Sat, 3 Oct 2020 15:08:02 +0200 Subject: [PATCH] Added functionality --- .../client/ui/control/QuickSelectControl.java | 5 +++ .../ui/controller/GroupCreationTab.java | 31 ++++++++++++------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/client/src/main/java/envoy/client/ui/control/QuickSelectControl.java b/client/src/main/java/envoy/client/ui/control/QuickSelectControl.java index 9097d1b..2019a5c 100644 --- a/client/src/main/java/envoy/client/ui/control/QuickSelectControl.java +++ b/client/src/main/java/envoy/client/ui/control/QuickSelectControl.java @@ -16,7 +16,10 @@ import envoy.data.User; */ public class QuickSelectControl extends VBox { + User user; + public QuickSelectControl(User user, GroupCreationTab tab) { + this.user = user; setPrefWidth(37); setMaxWidth(37); setMinWidth(37); @@ -70,4 +73,6 @@ public class QuickSelectControl extends VBox { getStyleClass().add("quick-select"); } + + public User getUser() { return user; } } 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 ca6a179..82a24af 100644 --- a/client/src/main/java/envoy/client/ui/controller/GroupCreationTab.java +++ b/client/src/main/java/envoy/client/ui/controller/GroupCreationTab.java @@ -70,7 +70,7 @@ public class GroupCreationTab implements EventListener { @FXML private void initialize() { userList.setCellFactory(new ListCellFactory<>(ContactControl::new)); - userList.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); + userList.getSelectionModel().setSelectionMode(SelectionMode.SINGLE); createButton.setDisable(true); eventBus.registerListener(this); userList.getItems() @@ -81,9 +81,7 @@ public class GroupCreationTab implements EventListener { .filter(not(localDB.getUser()::equals)) .map(User.class::cast) .collect(Collectors.toList())); - quickSelectList.setPrefHeight(0); - quickSelectList.setMaxHeight(0); - quickSelectList.setMinHeight(0); + resizeQuickSelectSpace(0); } /** @@ -95,9 +93,9 @@ public class GroupCreationTab implements EventListener { private void userListClicked() { createButton.setDisable(userList.getSelectionModel().isEmpty() || groupNameField.getText().isBlank()); quickSelectList.getItems().add(new QuickSelectControl(userList.getSelectionModel().getSelectedItem(), this)); - quickSelectList.setPrefHeight(60); - quickSelectList.setMaxHeight(60); - quickSelectList.setMinHeight(60); + resizeQuickSelectSpace(60); + userList.getItems().remove(userList.getSelectionModel().getSelectedItem()); + userList.getSelectionModel().clearSelection(); } /** @@ -107,7 +105,7 @@ public class GroupCreationTab implements EventListener { * @since Envoy Client v0.1-beta */ @FXML - private void textUpdated() { createButton.setDisable(userList.getSelectionModel().isEmpty() || groupNameField.getText().isBlank()); } + private void textUpdated() { createButton.setDisable(quickSelectList.getItems().size() == 0 || groupNameField.getText().isBlank()); } /** * Sends a {@link GroupCreation} to the server and closes this scene. @@ -135,6 +133,9 @@ public class GroupCreationTab implements EventListener { // Restoring the original design as tabs will always be reused setErrorMessageLabelSize(0); groupNameField.clear(); + quickSelectList.getItems().forEach(q -> userList.getItems().add(q.getUser())); + quickSelectList.getItems().clear(); + resizeQuickSelectSpace(0); } } @@ -148,7 +149,7 @@ public class GroupCreationTab implements EventListener { private void createGroup(String name) { Context.getInstance() .getClient() - .send(new GroupCreation(name, userList.getSelectionModel().getSelectedItems().stream().map(User::getID).collect(Collectors.toSet()))); + .send(new GroupCreation(name, quickSelectList.getItems().stream().map(q -> q.getUser().getID()).collect(Collectors.toSet()))); } /** @@ -165,13 +166,19 @@ public class GroupCreationTab implements EventListener { public void removeFromQuickSelection(QuickSelectControl element) { quickSelectList.getItems().remove(element); + userList.getItems().add(element.getUser()); if (quickSelectList.getItems().size() == 0) { - quickSelectList.setPrefHeight(0); - quickSelectList.setMaxHeight(0); - quickSelectList.setMinHeight(0); + resizeQuickSelectSpace(0); + createButton.setDisable(true); } } + private void resizeQuickSelectSpace(int value) { + quickSelectList.setPrefHeight(value); + quickSelectList.setMaxHeight(value); + quickSelectList.setMinHeight(value); + } + @FXML private void backButtonClicked() { eventBus.dispatch(new BackEvent());