From bd75da1ab96ae606730c658b4732cb0593e02e91 Mon Sep 17 00:00:00 2001 From: DieGurke Date: Sun, 23 Aug 2020 20:15:52 +0200 Subject: [PATCH] implemented groupCreationTab --- .../java/envoy/client/ui/SceneContext.java | 7 -- .../envoy/client/ui/controller/ChatScene.java | 10 +++ .../ui/controller/ContactSearchTab.java | 16 +--- ...eationScene.java => GroupCreationTab.java} | 24 +++--- client/src/main/resources/fxml/ChatScene.fxml | 3 +- .../resources/fxml/ContactSearchScene.fxml | 73 ------------------- .../resources/fxml/GroupCreationScene.fxml | 2 +- .../main/resources/fxml/GroupCreationTab.fxml | 62 ++++++++++++++++ 8 files changed, 85 insertions(+), 112 deletions(-) rename client/src/main/java/envoy/client/ui/controller/{GroupCreationScene.java => GroupCreationTab.java} (85%) delete mode 100644 client/src/main/resources/fxml/ContactSearchScene.fxml create mode 100644 client/src/main/resources/fxml/GroupCreationTab.fxml diff --git a/client/src/main/java/envoy/client/ui/SceneContext.java b/client/src/main/java/envoy/client/ui/SceneContext.java index c221d36..4db9bf9 100644 --- a/client/src/main/java/envoy/client/ui/SceneContext.java +++ b/client/src/main/java/envoy/client/ui/SceneContext.java @@ -55,13 +55,6 @@ public final class SceneContext { */ SETTINGS_SCENE("/fxml/SettingsScene.fxml"), - /** - * The scene in which the group creation screen is displayed. - * - * @since Envoy Client v0.1-beta - */ - GROUP_CREATION_SCENE("/fxml/GroupCreationScene.fxml"), - /** * The scene in which the login screen is displayed. * diff --git a/client/src/main/java/envoy/client/ui/controller/ChatScene.java b/client/src/main/java/envoy/client/ui/controller/ChatScene.java index 251dec7..4beb30a 100644 --- a/client/src/main/java/envoy/client/ui/controller/ChatScene.java +++ b/client/src/main/java/envoy/client/ui/controller/ChatScene.java @@ -133,6 +133,9 @@ public final class ChatScene implements Restorable { @FXML private Tab contactSearchTab; + + @FXML + private Tab groupCreationTab; private LocalDB localDB; private Client client; @@ -184,6 +187,7 @@ public final class ChatScene implements Restorable { try { contactSearchTab.setContent(FXMLLoader.load(new File("src/main/resources/fxml/ContactSearchTab.fxml").toURI().toURL())); + groupCreationTab.setContent(FXMLLoader.load(new File("src/main/resources/fxml/GroupCreationTab.fxml").toURI().toURL())); } catch (Exception e2) { e2.printStackTrace(); } @@ -400,6 +404,12 @@ public final class ChatScene implements Restorable { // sceneContext.getController().initializeData(sceneContext, localDB); tabPane.getSelectionModel().select(1); } + + @FXML + private void groupCreationButtonClicked() { + //TODO: initialize Data + tabPane.getSelectionModel().select(2); + } @FXML private void voiceButtonClicked() { diff --git a/client/src/main/java/envoy/client/ui/controller/ContactSearchTab.java b/client/src/main/java/envoy/client/ui/controller/ContactSearchTab.java index 1ffb842..067cfee 100644 --- a/client/src/main/java/envoy/client/ui/controller/ContactSearchTab.java +++ b/client/src/main/java/envoy/client/ui/controller/ContactSearchTab.java @@ -32,7 +32,7 @@ import envoy.util.EnvoyLog; * The actual search algorithm is implemented on the server. *

* To create a group, a button is available that loads the - * {@link GroupCreationScene}. + * {@link GroupCreationTab}. *

* Project: envoy-client
* File: ContactSearchScene.java
@@ -50,10 +50,6 @@ public class ContactSearchTab { @FXML private ListView userList; - private SceneContext sceneContext; - - private LocalDB localDB; - private Alert alert = new Alert(AlertType.CONFIRMATION); private User currentlySelectedUser; @@ -69,16 +65,6 @@ public class ContactSearchTab { private static final EventBus eventBus = EventBus.getInstance(); private static final Logger logger = EnvoyLog.getLogger(ChatScene.class); - /** - * @param sceneContext enables the user to return to the chat scene - * @param localDB the local database to which new contacts are added - * @since Envoy Client v0.1-beta - */ - public void initializeData(SceneContext sceneContext, LocalDB localDB) { - this.sceneContext = sceneContext; - this.localDB = localDB; - } - @FXML private void initialize() { userList.setCellFactory(new ListCellFactory<>(ContactControl::new)); diff --git a/client/src/main/java/envoy/client/ui/controller/GroupCreationScene.java b/client/src/main/java/envoy/client/ui/controller/GroupCreationTab.java similarity index 85% rename from client/src/main/java/envoy/client/ui/controller/GroupCreationScene.java rename to client/src/main/java/envoy/client/ui/controller/GroupCreationTab.java index 71c7dd4..47dc5af 100644 --- a/client/src/main/java/envoy/client/ui/controller/GroupCreationScene.java +++ b/client/src/main/java/envoy/client/ui/controller/GroupCreationTab.java @@ -11,8 +11,8 @@ import javafx.scene.control.Alert.AlertType; import envoy.client.data.Chat; import envoy.client.data.LocalDB; +import envoy.client.event.BackEvent; import envoy.client.event.SendEvent; -import envoy.client.ui.ClearableTextField; import envoy.client.ui.SceneContext; import envoy.client.ui.listcell.ContactControl; import envoy.client.ui.listcell.ListCellFactory; @@ -39,19 +39,17 @@ import envoy.util.Bounds; * @author Maximilian Käfer * @since Envoy Client v0.1-beta */ -public class GroupCreationScene { +public class GroupCreationTab { @FXML private Button createButton; @FXML - private ClearableTextField groupNameField; + private TextArea groupNameField; @FXML private ListView userList; - private SceneContext sceneContext; - private LocalDB localDB; private static final EventBus eventBus = EventBus.getInstance(); @@ -60,17 +58,14 @@ public class GroupCreationScene { private void initialize() { userList.setCellFactory(new ListCellFactory<>(ContactControl::new)); userList.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); - groupNameField.setClearButtonListener(e -> { groupNameField.getTextField().clear(); createButton.setDisable(true); }); } /** - * @param sceneContext enables the user to return to the chat scene * @param localDB the local database from which potential group members can * be selected * @since Envoy Client v0.1-beta */ - public void initializeData(SceneContext sceneContext, LocalDB localDB) { - this.sceneContext = sceneContext; + public void initializeData(LocalDB localDB) { this.localDB = localDB; Platform.runLater(() -> userList.getItems() .addAll(localDB.getChats() @@ -89,7 +84,7 @@ public class GroupCreationScene { */ @FXML private void userListClicked() { - createButton.setDisable(userList.getSelectionModel().isEmpty() || groupNameField.getTextField().getText().isBlank()); + createButton.setDisable(userList.getSelectionModel().isEmpty() || groupNameField.getText().isBlank()); } /** @@ -99,7 +94,7 @@ public class GroupCreationScene { * @since Envoy Client v0.1-beta */ @FXML - private void textUpdated() { createButton.setDisable(groupNameField.getTextField().getText().isBlank()); } + private void textUpdated() { createButton.setDisable(groupNameField.getText().isBlank()); } /** * Sends a {@link GroupCreation} to the server and closes this scene. @@ -110,10 +105,10 @@ public class GroupCreationScene { */ @FXML private void createButtonClicked() { - final var name = groupNameField.getTextField().getText(); + final var name = groupNameField.getText(); if (!Bounds.isValidContactName(name)) { new Alert(AlertType.ERROR, "The entered group name is not valid (" + Bounds.CONTACT_NAME_PATTERN + ")").showAndWait(); - groupNameField.getTextField().clear(); + groupNameField.clear(); } else if (groupNameAlreadyPresent(name)) { final var alert = new Alert(AlertType.WARNING, "You already have a group with that name.", ButtonType.OK, ButtonType.CANCEL); alert.setTitle("Create Group?"); @@ -135,7 +130,6 @@ public class GroupCreationScene { private void createGroup(String name) { eventBus.dispatch(new SendEvent( new GroupCreation(name, userList.getSelectionModel().getSelectedItems().stream().map(User::getID).collect(Collectors.toSet())))); - sceneContext.pop(); } /** @@ -156,5 +150,5 @@ public class GroupCreationScene { } @FXML - private void backButtonClicked() { sceneContext.pop(); } + private void backButtonClicked() { eventBus.dispatch(new BackEvent()); } } diff --git a/client/src/main/resources/fxml/ChatScene.fxml b/client/src/main/resources/fxml/ChatScene.fxml index eb4e80e..bc8f7c1 100644 --- a/client/src/main/resources/fxml/ChatScene.fxml +++ b/client/src/main/resources/fxml/ChatScene.fxml @@ -68,7 +68,7 @@ - - - - - - - - - - - - - - diff --git a/client/src/main/resources/fxml/GroupCreationScene.fxml b/client/src/main/resources/fxml/GroupCreationScene.fxml index a8c7472..8b2f286 100644 --- a/client/src/main/resources/fxml/GroupCreationScene.fxml +++ b/client/src/main/resources/fxml/GroupCreationScene.fxml @@ -15,7 +15,7 @@ minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" - fx:controller="envoy.client.ui.controller.GroupCreationScene"> + fx:controller="envoy.client.ui.controller.GroupCreationTab diff --git a/client/src/main/resources/fxml/GroupCreationTab.fxml b/client/src/main/resources/fxml/GroupCreationTab.fxml new file mode 100644 index 0000000..5b56bee --- /dev/null +++ b/client/src/main/resources/fxml/GroupCreationTab.fxml @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + +