Added Group Creation Functionality
* Implemented new group creation scene (fxml) * Added group creation controller * Adjusted contact search scene (fxml)
This commit is contained in:
		@@ -58,6 +58,13 @@ public final class SceneContext {
 | 
			
		||||
		 */
 | 
			
		||||
		CONTACT_SEARCH_SCENE("/fxml/ContactSearchScene.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.
 | 
			
		||||
		 * 
 | 
			
		||||
 
 | 
			
		||||
@@ -19,9 +19,9 @@ import envoy.client.data.Settings;
 | 
			
		||||
import envoy.client.event.MessageCreationEvent;
 | 
			
		||||
import envoy.client.net.Client;
 | 
			
		||||
import envoy.client.net.WriteProxy;
 | 
			
		||||
import envoy.client.ui.ContactListCell;
 | 
			
		||||
import envoy.client.ui.MessageListCell;
 | 
			
		||||
import envoy.client.ui.SceneContext;
 | 
			
		||||
import envoy.client.ui.ContactListCell;
 | 
			
		||||
import envoy.data.Contact;
 | 
			
		||||
import envoy.data.Message;
 | 
			
		||||
import envoy.data.MessageBuilder;
 | 
			
		||||
@@ -173,7 +173,7 @@ public final class ChatScene {
 | 
			
		||||
	@FXML
 | 
			
		||||
	private void addContactButtonClicked() {
 | 
			
		||||
		sceneContext.load(SceneContext.SceneInfo.CONTACT_SEARCH_SCENE);
 | 
			
		||||
		sceneContext.<ContactSearchScene>getController().initializeData(sceneContext);
 | 
			
		||||
		sceneContext.<ContactSearchScene>getController().initializeData(sceneContext, localDB);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@FXML
 | 
			
		||||
 
 | 
			
		||||
@@ -8,9 +8,10 @@ import javafx.fxml.FXML;
 | 
			
		||||
import javafx.scene.control.*;
 | 
			
		||||
import javafx.scene.control.Alert.AlertType;
 | 
			
		||||
 | 
			
		||||
import envoy.client.data.LocalDB;
 | 
			
		||||
import envoy.client.event.SendEvent;
 | 
			
		||||
import envoy.client.ui.SceneContext;
 | 
			
		||||
import envoy.client.ui.ContactListCell;
 | 
			
		||||
import envoy.client.ui.SceneContext;
 | 
			
		||||
import envoy.data.Contact;
 | 
			
		||||
import envoy.event.ElementOperation;
 | 
			
		||||
import envoy.event.EventBus;
 | 
			
		||||
@@ -38,6 +39,9 @@ public class ContactSearchScene {
 | 
			
		||||
	@FXML
 | 
			
		||||
	private Button searchButton;
 | 
			
		||||
 | 
			
		||||
	@FXML
 | 
			
		||||
	private Button newGroupButton;
 | 
			
		||||
 | 
			
		||||
	@FXML
 | 
			
		||||
	private TextField searchBar;
 | 
			
		||||
 | 
			
		||||
@@ -46,6 +50,8 @@ public class ContactSearchScene {
 | 
			
		||||
 | 
			
		||||
	private SceneContext sceneContext;
 | 
			
		||||
 | 
			
		||||
	private LocalDB localDB;
 | 
			
		||||
 | 
			
		||||
	private static EventBus		eventBus	= EventBus.getInstance();
 | 
			
		||||
	private static final Logger	logger		= EnvoyLog.getLogger(ChatScene.class);
 | 
			
		||||
 | 
			
		||||
@@ -53,7 +59,10 @@ public class ContactSearchScene {
 | 
			
		||||
	 * @param sceneContext enables the user to return to the chat scene
 | 
			
		||||
	 * @since Envoy Client v0.1-beta
 | 
			
		||||
	 */
 | 
			
		||||
	public void initializeData(SceneContext sceneContext) { this.sceneContext = sceneContext; }
 | 
			
		||||
	public void initializeData(SceneContext sceneContext, LocalDB localDB) {
 | 
			
		||||
		this.sceneContext	= sceneContext;
 | 
			
		||||
		this.localDB		= localDB;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@FXML
 | 
			
		||||
	private void initialize() {
 | 
			
		||||
@@ -122,6 +131,12 @@ public class ContactSearchScene {
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@FXML
 | 
			
		||||
	private void newGroupButtonClicked() {
 | 
			
		||||
		sceneContext.load(SceneContext.SceneInfo.GROUP_CREATION_SCENE);
 | 
			
		||||
		sceneContext.<GroupCreationScene>getController().initializeData(sceneContext, localDB);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@FXML
 | 
			
		||||
	private void backButtonClicked() { sceneContext.pop(); }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,78 @@
 | 
			
		||||
package envoy.client.ui.controller;
 | 
			
		||||
 | 
			
		||||
import java.util.stream.Collectors;
 | 
			
		||||
 | 
			
		||||
import javafx.application.Platform;
 | 
			
		||||
import javafx.fxml.FXML;
 | 
			
		||||
import javafx.scene.control.*;
 | 
			
		||||
 | 
			
		||||
import envoy.client.data.LocalDB;
 | 
			
		||||
import envoy.client.event.SendEvent;
 | 
			
		||||
import envoy.client.ui.ContactListCell;
 | 
			
		||||
import envoy.client.ui.SceneContext;
 | 
			
		||||
import envoy.data.Contact;
 | 
			
		||||
import envoy.data.User;
 | 
			
		||||
import envoy.event.EventBus;
 | 
			
		||||
import envoy.event.GroupCreationEvent;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Project: <strong>envoy-client</strong><br>
 | 
			
		||||
 * File: <strong>ContactSearchSceneController.java</strong><br>
 | 
			
		||||
 * Created: <strong>07.06.2020</strong><br>
 | 
			
		||||
 *
 | 
			
		||||
 * @author Maximilian Käfer
 | 
			
		||||
 * @since Envoy Client v0.1-beta
 | 
			
		||||
 */
 | 
			
		||||
public class GroupCreationScene {
 | 
			
		||||
 | 
			
		||||
	@FXML
 | 
			
		||||
	private Button backButton;
 | 
			
		||||
 | 
			
		||||
	@FXML
 | 
			
		||||
	private Button createButton;
 | 
			
		||||
 | 
			
		||||
	@FXML
 | 
			
		||||
	private TextField groupNameBar;
 | 
			
		||||
 | 
			
		||||
	@FXML
 | 
			
		||||
	private ListView<Contact> contactList;
 | 
			
		||||
 | 
			
		||||
	private SceneContext sceneContext;
 | 
			
		||||
 | 
			
		||||
	private static EventBus		eventBus	= EventBus.getInstance();
 | 
			
		||||
	// private static final Logger logger = EnvoyLog.getLogger(ChatScene.class);
 | 
			
		||||
 | 
			
		||||
	@FXML
 | 
			
		||||
	private void initialize() {
 | 
			
		||||
		contactList.setCellFactory(e -> new ContactListCell());
 | 
			
		||||
		contactList.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * @param sceneContext enables the user to return to the chat scene
 | 
			
		||||
	 * @since Envoy Client v0.1-beta
 | 
			
		||||
	 */
 | 
			
		||||
	public void initializeData(SceneContext sceneContext, LocalDB localDB) {
 | 
			
		||||
		this.sceneContext	= sceneContext;
 | 
			
		||||
		Platform.runLater(() -> contactList.getItems()
 | 
			
		||||
			.addAll(localDB.getUsers()
 | 
			
		||||
				.values()
 | 
			
		||||
				.stream()
 | 
			
		||||
				.filter(c -> c instanceof User && c.getID() != localDB.getUser().getID())
 | 
			
		||||
				.collect(Collectors.toList())));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Sends a {@link GroupCreationEvent} to the server.
 | 
			
		||||
	 *
 | 
			
		||||
	 * @since Envoy Client v0.1-beta
 | 
			
		||||
	 */
 | 
			
		||||
	@FXML
 | 
			
		||||
	private void sendGroupObject() {
 | 
			
		||||
		eventBus.dispatch(new SendEvent(new GroupCreationEvent(groupNameBar.getText(),
 | 
			
		||||
				contactList.getSelectionModel().getSelectedItems().stream().map(Contact::getID).collect(Collectors.toSet()))));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@FXML
 | 
			
		||||
	private void backButtonClicked() { sceneContext.pop(); }
 | 
			
		||||
}
 | 
			
		||||
@@ -6,10 +6,8 @@
 | 
			
		||||
<?import javafx.scene.control.TextField?>
 | 
			
		||||
<?import javafx.scene.control.Tooltip?>
 | 
			
		||||
<?import javafx.scene.layout.HBox?>
 | 
			
		||||
<?import javafx.scene.layout.Pane?>
 | 
			
		||||
<?import javafx.scene.layout.VBox?>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
<VBox maxHeight="-Infinity" maxWidth="-Infinity" 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.ContactSearchScene">
 | 
			
		||||
   <children>
 | 
			
		||||
      <HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0">
 | 
			
		||||
@@ -30,15 +28,7 @@
 | 
			
		||||
                  <Tooltip autoHide="true" text="Clears the text to the left and the elements below" wrapText="true" />
 | 
			
		||||
               </tooltip>
 | 
			
		||||
            </Button>
 | 
			
		||||
            <Pane disable="true" maxWidth="20.0" prefWidth="20.0" visible="false">
 | 
			
		||||
               <HBox.margin>
 | 
			
		||||
                  <Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
 | 
			
		||||
               </HBox.margin>
 | 
			
		||||
               <padding>
 | 
			
		||||
                  <Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
 | 
			
		||||
               </padding>
 | 
			
		||||
            </Pane>
 | 
			
		||||
            <Button fx:id="searchButton" disable="true" defaultButton="true" mnemonicParsing="true" onAction="#suggestContacts" prefHeight="26.0" prefWidth="71.0" text="_Search" textOverrun="LEADING_WORD_ELLIPSIS">
 | 
			
		||||
            <Button fx:id="searchButton" defaultButton="true" disable="true" mnemonicParsing="true" onAction="#suggestContacts" prefHeight="26.0" prefWidth="71.0" text="_Search" textOverrun="LEADING_WORD_ELLIPSIS">
 | 
			
		||||
               <padding>
 | 
			
		||||
                  <Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
 | 
			
		||||
               </padding>
 | 
			
		||||
@@ -49,6 +39,11 @@
 | 
			
		||||
                  <Tooltip autoHide="true" text="Search for accounts with the name entered to the left" wrapText="true" />
 | 
			
		||||
               </tooltip>
 | 
			
		||||
            </Button>
 | 
			
		||||
            <Button mnemonicParsing="false" onAction="#newGroupButtonClicked" text="New Group">
 | 
			
		||||
               <HBox.margin>
 | 
			
		||||
                  <Insets left="100.0" />
 | 
			
		||||
               </HBox.margin>
 | 
			
		||||
            </Button>
 | 
			
		||||
         </children>
 | 
			
		||||
      </HBox>
 | 
			
		||||
      <ListView fx:id="contactList" onMouseClicked="#contactListClicked" prefHeight="314.0" prefWidth="600.0" />
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										49
									
								
								src/main/resources/fxml/GroupCreationScene.fxml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								src/main/resources/fxml/GroupCreationScene.fxml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,49 @@
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
 | 
			
		||||
<?import javafx.geometry.Insets?>
 | 
			
		||||
<?import javafx.scene.control.Button?>
 | 
			
		||||
<?import javafx.scene.control.Label?>
 | 
			
		||||
<?import javafx.scene.control.ListView?>
 | 
			
		||||
<?import javafx.scene.control.TextField?>
 | 
			
		||||
<?import javafx.scene.control.Tooltip?>
 | 
			
		||||
<?import javafx.scene.layout.HBox?>
 | 
			
		||||
<?import javafx.scene.layout.VBox?>
 | 
			
		||||
<?import javafx.scene.text.Font?>
 | 
			
		||||
 | 
			
		||||
<VBox maxHeight="-Infinity" maxWidth="-Infinity" 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">
 | 
			
		||||
   <children>
 | 
			
		||||
      <HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0">
 | 
			
		||||
         <children>
 | 
			
		||||
            <TextField fx:id="groupNameBar" prefColumnCount="22" promptText="Enter Group Name">
 | 
			
		||||
               <HBox.margin>
 | 
			
		||||
                  <Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
 | 
			
		||||
               </HBox.margin>
 | 
			
		||||
               <padding>
 | 
			
		||||
                  <Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
 | 
			
		||||
               </padding>
 | 
			
		||||
               <tooltip>
 | 
			
		||||
                  <Tooltip text="Enter a name. If an account by that name exists, it will be displayed below." wrapText="true" />
 | 
			
		||||
               </tooltip>
 | 
			
		||||
            </TextField>
 | 
			
		||||
         </children>
 | 
			
		||||
      </HBox>
 | 
			
		||||
      <Label text="Choose Members:">
 | 
			
		||||
         <font>
 | 
			
		||||
            <Font size="16.0" />
 | 
			
		||||
         </font>
 | 
			
		||||
      </Label>
 | 
			
		||||
      <ListView fx:id="contactList" prefHeight="314.0" prefWidth="600.0" />
 | 
			
		||||
      <Button mnemonicParsing="false" onAction="#sendGroupObject" text="Create" />
 | 
			
		||||
      <Button fx:id="backButton" cancelButton="true" mnemonicParsing="true" onAction="#backButtonClicked" text="_Back">
 | 
			
		||||
         <VBox.margin>
 | 
			
		||||
            <Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
 | 
			
		||||
         </VBox.margin>
 | 
			
		||||
         <padding>
 | 
			
		||||
            <Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
 | 
			
		||||
         </padding>
 | 
			
		||||
         <tooltip>
 | 
			
		||||
            <Tooltip autoHide="true" text="Takes you back to the screen where you can chat with others" wrapText="true" />
 | 
			
		||||
         </tooltip>
 | 
			
		||||
      </Button>
 | 
			
		||||
   </children>
 | 
			
		||||
</VBox>
 | 
			
		||||
		Reference in New Issue
	
	Block a user