implemented groupCreationTab

This commit is contained in:
2020-08-23 20:15:52 +02:00
parent f77795edb1
commit bd75da1ab9
8 changed files with 85 additions and 112 deletions

View File

@ -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.
*

View File

@ -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.<ContactSearchScene>getController().initializeData(sceneContext, localDB);
tabPane.getSelectionModel().select(1);
}
@FXML
private void groupCreationButtonClicked() {
//TODO: initialize Data
tabPane.getSelectionModel().select(2);
}
@FXML
private void voiceButtonClicked() {

View File

@ -32,7 +32,7 @@ import envoy.util.EnvoyLog;
* <i>The actual search algorithm is implemented on the server.
* <p>
* To create a group, a button is available that loads the
* {@link GroupCreationScene}.
* {@link GroupCreationTab}.
* <p>
* Project: <strong>envoy-client</strong><br>
* File: <strong>ContactSearchScene.java</strong><br>
@ -50,10 +50,6 @@ public class ContactSearchTab {
@FXML
private ListView<User> 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));

View File

@ -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&auml;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<User> 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()); }
}