Quick Select Support for the GroupCreationTab #77

Merged
mpk merged 9 commits from f/quick-group-select into develop 2020-10-04 21:28:57 +02:00
2 changed files with 17 additions and 13 deletions
Showing only changes of commit 51b189e8f5 - Show all commits

View File

@ -11,17 +11,18 @@ import envoy.client.util.IconUtil;
import envoy.data.User; import envoy.data.User;
/** /**
* Displays a user as a quickSelectControl which is used in the quickSelectList. * Displays an {@link User} as a quickSelectControl which is used in the
mpk marked this conversation as resolved Outdated
Outdated
Review
... a {@link User} as ...
``` ... a {@link User} as ... ```
Outdated
Review

We don't use camelCase is Javadoc.

We don't use camelCase is Javadoc.
* quickSelectList.
* *
* @author Maximilian Käfer * @author Maximilian Käfer
* @since Envoy Client v0.3-beta * @since Envoy Client v0.3-beta
*/ */
public class QuickSelectControl extends VBox { public class QuickSelectControl extends VBox {
mpk marked this conversation as resolved Outdated
Outdated
Review

Please make this private.

Please make this `private`.
User user; private User user;
/** /**
mpk marked this conversation as resolved Outdated
Outdated
Review

As I've already been conditioned by a certain member of the Envoy team (the coffee machine guy) to not use @link in constructors for the own component, I've since swapped to using @code, so maybe you should too.

It might be beneficial to create a convention for such cases from here on.

As I've already been conditioned by a certain member of the Envoy team (the coffee machine guy) to not use `@link` in constructors for the own component, I've since swapped to using `@code`, so maybe you should too. It might be beneficial to create a convention for such cases from here on.
* Creates an instance of the {@link QuickSelectControl}. * Creates an instance of the {@code QuickSelectControl}.
* *
* @param user the user whose data is used to create this instance. * @param user the user whose data is used to create this instance.
* @param tab the parent tab ({@link GroupCreationTab}). * @param tab the parent tab ({@link GroupCreationTab}).
@ -49,7 +50,6 @@ public class QuickSelectControl extends VBox {
clip.setArcHeight(32); clip.setArcHeight(32);
clip.setArcWidth(32); clip.setArcWidth(32);
contactProfilePic.setClip(clip); contactProfilePic.setClip(clip);
mpk marked this conversation as resolved
Review

This is, as far as I can see, unnecessary.
Have tested it, it is.

This is, as far as I can see, unnecessary. Have tested it, it is.
setAlignment(Pos.TOP_CENTER);
picHold.getChildren().add(contactProfilePic); picHold.getChildren().add(contactProfilePic);
stackPane.getChildren().add(picHold); stackPane.getChildren().add(picHold);
@ -59,7 +59,7 @@ public class QuickSelectControl extends VBox {
hBox.setMinHeight(12); hBox.setMinHeight(12);
var region = new Region(); var region = new Region();
hBox.getChildren().add(region); hBox.getChildren().add(region);
hBox.setHgrow(region, Priority.ALWAYS); HBox.setHgrow(region, Priority.ALWAYS);
mpk marked this conversation as resolved Outdated
Outdated
Review

This line should be

HBox.setHgrow(region, Priority.ALWAYS);

(setHgrow is a static method)

This line should be ``` HBox.setHgrow(region, Priority.ALWAYS); ``` (`setHgrow` is a static method)
var removeBtn = new Button(); var removeBtn = new Button();
removeBtn.setPrefSize(12, 12); removeBtn.setPrefSize(12, 12);
@ -85,7 +85,7 @@ public class QuickSelectControl extends VBox {
} }
/** /**
* @return the user whose data is used in this instance. * @return the user whose data is used in this instance
mpk marked this conversation as resolved Outdated
Outdated
Review

The dot at the end is unnecessary.

The dot at the end is unnecessary.
* @since Envoy Client v0.3-beta * @since Envoy Client v0.3-beta
*/ */
public User getUser() { return user; } public User getUser() { return user; }

View File

@ -7,6 +7,7 @@ import java.util.stream.Collectors;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.*; import javafx.scene.control.*;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.HBox; import javafx.scene.layout.HBox;
import envoy.client.data.*; import envoy.client.data.*;
@ -82,6 +83,7 @@ public class GroupCreationTab implements EventListener {
.map(User.class::cast) .map(User.class::cast)
.collect(Collectors.toList())); .collect(Collectors.toList()));
resizeQuickSelectSpace(0); resizeQuickSelectSpace(0);
quickSelectList.addEventFilter(MouseEvent.MOUSE_PRESSED, evt -> evt.consume());
} }
/** /**
@ -91,12 +93,14 @@ public class GroupCreationTab implements EventListener {
*/ */
@FXML @FXML
delvh marked this conversation as resolved Outdated
Outdated
Review

Isn't that the wrong check here? Shouldn't it be

setDisable(quickSelectList.getItems().isEmpty() && userList.getSelectionModel().isEmpty() || ...);
Isn't that the wrong check here? Shouldn't it be ``` setDisable(quickSelectList.getItems().isEmpty() && userList.getSelectionModel().isEmpty() || ...); ```
Outdated
Review

Yes there was an issue but it was not the one you suggested.

Yes there was an issue but it was not the one you suggested.
private void userListClicked() { private void userListClicked() {
mpk marked this conversation as resolved Outdated
Outdated
Review

You need to insert a null check for userList.getSelectionModel().getSelectedItem() as it can also happen that no element has been selected. This is especially the case if you click on the userList after every user has been removed from it.

You need to insert a null check for `userList.getSelectionModel().getSelectedItem()` as it can also happen that no element has been selected. This is especially the case if you click on the userList after every user has been removed from it.
createButton.setDisable(userList.getSelectionModel().isEmpty() || groupNameField.getText().isBlank()); if (userList.getSelectionModel().getSelectedItem() != null) {
quickSelectList.getItems().add(new QuickSelectControl(userList.getSelectionModel().getSelectedItem(), this)); quickSelectList.getItems().add(new QuickSelectControl(userList.getSelectionModel().getSelectedItem(), this));
createButton.setDisable(quickSelectList.getItems().isEmpty() || groupNameField.getText().isBlank());
resizeQuickSelectSpace(60); resizeQuickSelectSpace(60);
userList.getItems().remove(userList.getSelectionModel().getSelectedItem()); userList.getItems().remove(userList.getSelectionModel().getSelectedItem());
userList.getSelectionModel().clearSelection(); userList.getSelectionModel().clearSelection();
} }
}
/** /**
* Checks, whether the {@code createButton} can be enabled because text is * Checks, whether the {@code createButton} can be enabled because text is
@ -105,7 +109,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(quickSelectList.getItems().size() == 0 || groupNameField.getText().isBlank()); } private void textUpdated() { createButton.setDisable(quickSelectList.getItems().isEmpty() || 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.
@ -173,7 +177,7 @@ 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()); userList.getItems().add(element.getUser());
if (quickSelectList.getItems().size() == 0) { if (quickSelectList.getItems().isEmpty()) {
resizeQuickSelectSpace(0); resizeQuickSelectSpace(0);
createButton.setDisable(true); createButton.setDisable(true);
mpk marked this conversation as resolved Outdated
Outdated
Review

You really do like it if no one except you can ever resize components, right?

You really do like it if no one except you can ever resize components, right?
Outdated
Review

I have absolutely no clue what you mean but as I see it this is just a usefull little method.

I have absolutely no clue what you mean but as I see it this is just a usefull little method.
} }