Quick Select Support for the GroupCreationTab #77
@ -16,7 +16,10 @@ import envoy.data.User;
|
|||||||
*/
|
*/
|
||||||
public class QuickSelectControl extends VBox {
|
public class QuickSelectControl extends VBox {
|
||||||
|
|
||||||
|
User user;
|
||||||
|
|
||||||
public QuickSelectControl(User user, GroupCreationTab tab) {
|
public QuickSelectControl(User user, GroupCreationTab tab) {
|
||||||
|
this.user = user;
|
||||||
setPrefWidth(37);
|
setPrefWidth(37);
|
||||||
setMaxWidth(37);
|
setMaxWidth(37);
|
||||||
setMinWidth(37);
|
setMinWidth(37);
|
||||||
@ -70,4 +73,6 @@ public class QuickSelectControl extends VBox {
|
|||||||
|
|
||||||
getStyleClass().add("quick-select");
|
getStyleClass().add("quick-select");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public User getUser() { return user; }
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ public class GroupCreationTab implements EventListener {
|
|||||||
@FXML
|
@FXML
|
||||||
private void initialize() {
|
private void initialize() {
|
||||||
userList.setCellFactory(new ListCellFactory<>(ContactControl::new));
|
userList.setCellFactory(new ListCellFactory<>(ContactControl::new));
|
||||||
userList.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
|
userList.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
|
||||||
createButton.setDisable(true);
|
createButton.setDisable(true);
|
||||||
eventBus.registerListener(this);
|
eventBus.registerListener(this);
|
||||||
userList.getItems()
|
userList.getItems()
|
||||||
@ -81,9 +81,7 @@ public class GroupCreationTab implements EventListener {
|
|||||||
.filter(not(localDB.getUser()::equals))
|
.filter(not(localDB.getUser()::equals))
|
||||||
.map(User.class::cast)
|
.map(User.class::cast)
|
||||||
.collect(Collectors.toList()));
|
.collect(Collectors.toList()));
|
||||||
quickSelectList.setPrefHeight(0);
|
resizeQuickSelectSpace(0);
|
||||||
quickSelectList.setMaxHeight(0);
|
|
||||||
quickSelectList.setMinHeight(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -95,9 +93,9 @@ public class GroupCreationTab implements EventListener {
|
|||||||
private void userListClicked() {
|
private void userListClicked() {
|
||||||
createButton.setDisable(userList.getSelectionModel().isEmpty() || groupNameField.getText().isBlank());
|
createButton.setDisable(userList.getSelectionModel().isEmpty() || groupNameField.getText().isBlank());
|
||||||
quickSelectList.getItems().add(new QuickSelectControl(userList.getSelectionModel().getSelectedItem(), this));
|
quickSelectList.getItems().add(new QuickSelectControl(userList.getSelectionModel().getSelectedItem(), this));
|
||||||
quickSelectList.setPrefHeight(60);
|
resizeQuickSelectSpace(60);
|
||||||
quickSelectList.setMaxHeight(60);
|
userList.getItems().remove(userList.getSelectionModel().getSelectedItem());
|
||||||
quickSelectList.setMinHeight(60);
|
userList.getSelectionModel().clearSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -107,7 +105,7 @@ public class GroupCreationTab implements EventListener {
|
|||||||
* @since Envoy Client v0.1-beta
|
* @since Envoy Client v0.1-beta
|
||||||
*/
|
*/
|
||||||
@FXML
|
@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.
|
* 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
|
// Restoring the original design as tabs will always be reused
|
||||||
setErrorMessageLabelSize(0);
|
setErrorMessageLabelSize(0);
|
||||||
groupNameField.clear();
|
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) {
|
private void createGroup(String name) {
|
||||||
Context.getInstance()
|
Context.getInstance()
|
||||||
.getClient()
|
.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) {
|
public void removeFromQuickSelection(QuickSelectControl element) {
|
||||||
quickSelectList.getItems().remove(element);
|
quickSelectList.getItems().remove(element);
|
||||||
|
userList.getItems().add(element.getUser());
|
||||||
if (quickSelectList.getItems().size() == 0) {
|
if (quickSelectList.getItems().size() == 0) {
|
||||||
quickSelectList.setPrefHeight(0);
|
resizeQuickSelectSpace(0);
|
||||||
quickSelectList.setMaxHeight(0);
|
createButton.setDisable(true);
|
||||||
quickSelectList.setMinHeight(0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void resizeQuickSelectSpace(int value) {
|
||||||
|
quickSelectList.setPrefHeight(value);
|
||||||
|
quickSelectList.setMaxHeight(value);
|
||||||
|
quickSelectList.setMinHeight(value);
|
||||||
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void backButtonClicked() {
|
private void backButtonClicked() {
|
||||||
eventBus.dispatch(new BackEvent());
|
eventBus.dispatch(new BackEvent());
|
||||||
|
Reference in New Issue
Block a user