Quick Select Support for the GroupCreationTab #77

Merged
DieGurke merged 9 commits from f/quick-group-select into develop 2 years ago
Owner

This PR provides a more refined and user friendly mechanism to select members for a group when creating it.
Fixes #60

This PR provides a more refined and user friendly mechanism to select members for a group when creating it. Fixes #60
DieGurke added this to the v0.3-beta milestone 2 years ago
DieGurke added the
client
M
labels 2 years ago
DieGurke self-assigned this 2 years ago
DieGurke requested review from delvh 2 years ago
DieGurke requested review from kske 2 years ago
kske requested changes 2 years ago
kske left a comment
Owner

Could you disable the selection of users already displayed inside the quick selector? At the moment selection is possible and serves no purpose.

Could you disable the selection of users already displayed inside the quick selector? At the moment selection is possible and serves no purpose.
*/
public class QuickSelectControl extends VBox {
User user;
Owner

Please make this private.

Please make this `private`.
DieGurke marked this conversation as resolved
}
/**
* @return the user whose data is used in this instance.
Owner

The dot at the end is unnecessary.

The dot at the end is unnecessary.
DieGurke marked this conversation as resolved
Owner

This is the unnecessary selection I mentioned in my review.

grafik

This is the unnecessary selection I mentioned in my review. ![grafik](/attachments/96b16504-ae9f-41eb-bab9-c501a5925bc0)
7.0 KiB
delvh approved these changes 2 years ago
delvh left a comment
Owner

Noticed some fixes are possible.
Otherwise good job 👍.

Noticed some fixes are possible. Otherwise good job 👍.
import envoy.data.User;
/**
* Displays a user as a quickSelectControl which is used in the quickSelectList.
Owner
... a {@link User} as ...
``` ... a {@link User} as ... ```
DieGurke marked this conversation as resolved
User user;
/**
* Creates an instance of the {@link QuickSelectControl}.
Owner

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.
DieGurke marked this conversation as resolved
*/
public QuickSelectControl(User user, GroupCreationTab tab) {
this.user = user;
setPadding(new Insets(1, 0, 0, 0));
Owner

?

?
Poster
Owner

This centers the component (it is just 1 pixel but very noticable)

This centers the component (it is just 1 pixel but very noticable)
DieGurke marked this conversation as resolved
stackPane.setAlignment(Pos.TOP_CENTER);
// Profile picture
var picHold = new VBox();
Owner

Why exactly are you declaring a VBox inside a VBox?

Why exactly are you declaring a `VBox` inside a `VBox`?
Poster
Owner

It is more about the image view which this inner vBox is holding. An image view doesn't give me the option to add padding, so I had to do it with its parent: the vBox.

It is more about the image view which this inner vBox is holding. An image view doesn't give me the option to add padding, so I had to do it with its parent: the vBox.
DieGurke marked this conversation as resolved
clip.setArcHeight(32);
clip.setArcWidth(32);
contactProfilePic.setClip(clip);
setAlignment(Pos.TOP_CENTER);
Owner

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.
DieGurke marked this conversation as resolved
hBox.setMinHeight(12);
var region = new Region();
hBox.getChildren().add(region);
hBox.setHgrow(region, Priority.ALWAYS);
Owner

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)
DieGurke marked this conversation as resolved
removeBtn.setPrefSize(12, 12);
removeBtn.setMaxSize(12, 12);
removeBtn.setMinSize(12, 12);
removeBtn.setOnMouseClicked(evt -> tab.removeFromQuickSelection(this));
Owner

As far as I can see, this is the only reason, why you're limiting this component to be used only in the GroupCreationTab.

The OOP approach would be to define a setter that delegates what action to perform on the mouse click of the remove button. This would look something like this:

public void onRemoveButtonClicked(BiConsumer<? super MouseEvent, User> action){
	removeBtn.setOnMouseClicked(evt->action.accept(evt, user));
}

This additionally brings the advantage of reusability.

When this is implemented, the GroupCreationTab can be removed from the declaration of this component.

As far as I can see, this is the only reason, why you're limiting this component to be used only in the GroupCreationTab. The OOP approach would be to define a setter that delegates what action to perform on the mouse click of the remove button. This would look something like this: ``` public void onRemoveButtonClicked(BiConsumer<? super MouseEvent, User> action){ removeBtn.setOnMouseClicked(evt->action.accept(evt, user)); } ``` This additionally brings the advantage of reusability. When this is implemented, the `GroupCreationTab` can be removed from the declaration of this component.
DieGurke marked this conversation as resolved
removeBtn.setMinSize(12, 12);
removeBtn.setOnMouseClicked(evt -> tab.removeFromQuickSelection(this));
removeBtn.setId("remove-button");
hBox.getChildren().add(removeBtn);
Owner

If I understand you correctly, the only purpose of the HBox is to position the remove button to the far right of the component.

I've experimented a bit and found out that I can achieve the same result using two components (and a few lines) less:

  1. Remove lines 56-63 + 71 (stackPane.getChildren(...))
  2. Change hBox in line 70 to picHold
  3. Make picHold from a VBox to an HBox
  4. Done.
If I understand you correctly, the only purpose of the `HBox` is to position the remove button to the far right of the component. I've experimented a bit and found out that I can achieve the same result using two components (and a few lines) less: 1. Remove lines 56-63 + 71 (`stackPane.getChildren(...)`) 2. Change `hBox` in line 70 to `picHold` 3. Make `picHold` from a `VBox` to an `HBox` 4. Done.
Poster
Owner

Just paste your modified code an a comment because it is very hard to understand what you want if you just give a description. (Because the lines have changed)

Just paste your modified code an a comment because it is very hard to understand what you want if you just give a description. (Because the lines have changed)
Owner

Funny thing. They haven't. But still:

  1. Remove the variables hBox and region
  2. the picHold variable should be an HBox, not a VBox
  3. the line hBox.getChildren().add(removeBtn); should be
picHold.getChildren().add(removeBtn);
  1. The line below where you are adding hBox to stackPane can be deleted
Funny thing. They haven't. But still: 1. Remove the variables `hBox` and `region` 2. the `picHold` variable should be an `HBox`, not a `VBox` 3. the line `hBox.getChildren().add(removeBtn);` should be ``` picHold.getChildren().add(removeBtn); ``` 4. The line below where you are adding `hBox` to `stackPane` can be deleted
Poster
Owner

I won't do this as it has no necessarity here. Btw I have the feeling that you did not understand the whole mechanism behind the component definition and usage.

Alternatively phrased, I won't do it because no. Sincerely @kske aka Jesus, das Massiv

I won't do this as it has no necessarity here. Btw I have the feeling that you did not understand the whole mechanism behind the component definition and usage. Alternatively phrased, I won't do it because no. Sincerely @kske aka Jesus, das Massiv
Owner

So why exactly are we now allowing unnecessary overhead? I've shown you in detail that I can reproduce the same result using two components less. What's the deal with that?

So why exactly are we now allowing unnecessary overhead? I've shown you in detail that I can reproduce the same result using two components less. What's the deal with that?
Owner

Oh, and by the way, if you have to resort to ' I won't do it because no' as the reasoning for something, then something is wrong with that thing.

Oh, and by the way, if you have to resort to ' I won't do it because no' as the reasoning for something, then something is wrong with that thing.
nameLabel.setMaxSize(35, 20);
nameLabel.setMinSize(35, 20);
nameLabel.setText(user.getName());
nameLabel.setAlignment(Pos.TOP_CENTER);
Owner

Unnecessary. Delete the line.

Unnecessary. Delete the line.
Poster
Owner

No it is defenitly not as this is centering the label!

No it is defenitly not as this is centering the label!
DieGurke marked this conversation as resolved
@FXML
private void userListClicked() { createButton.setDisable(userList.getSelectionModel().isEmpty() || groupNameField.getText().isBlank()); }
private void userListClicked() {
createButton.setDisable(userList.getSelectionModel().isEmpty() || groupNameField.getText().isBlank());
Owner

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() || ...); ```
Poster
Owner

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.
delvh marked this conversation as resolved
private void userListClicked() { createButton.setDisable(userList.getSelectionModel().isEmpty() || groupNameField.getText().isBlank()); }
private void userListClicked() {
createButton.setDisable(userList.getSelectionModel().isEmpty() || groupNameField.getText().isBlank());
quickSelectList.getItems().add(new QuickSelectControl(userList.getSelectionModel().getSelectedItem(), this));
Owner

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.
DieGurke marked this conversation as resolved
*/
@FXML
private void textUpdated() { createButton.setDisable(userList.getSelectionModel().isEmpty() || groupNameField.getText().isBlank()); }
private void textUpdated() { createButton.setDisable(quickSelectList.getItems().size() == 0 || groupNameField.getText().isBlank()); }
Owner

Use

setDisable(quickSelectList.getItems().isEmpty()||...);
Use ``` setDisable(quickSelectList.getItems().isEmpty()||...); ```
DieGurke marked this conversation as resolved
public void removeFromQuickSelection(QuickSelectControl element) {
quickSelectList.getItems().remove(element);
userList.getItems().add(element.getUser());
if (quickSelectList.getItems().size() == 0) {
Owner

Use

if(quickSelectList.getItems().isEmpty()){
Use ``` if(quickSelectList.getItems().isEmpty()){ ```
DieGurke marked this conversation as resolved
}
}
private void resizeQuickSelectSpace(int value) {
Owner

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?
Poster
Owner

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.
DieGurke marked this conversation as resolved
#quick-select-list .scroll-bar:horizontal{
-fx-pref-height: 0;
-fx-max-height: 0;
-fx-min-height: 0;
Owner

Is that even needed in this case?

Is that even needed in this case?
Owner

Meant is only the last line...

Meant is only the last line...
Poster
Owner

Yes it is absolutly necessary.

Yes it is absolutly necessary.
Owner

Why? If the max height is already at 0, the pref height won't be larger than that, same for the min height...

Why? If the max height is already at 0, the pref height won't be larger than that, same for the min height...
Poster
Owner

No thats the thing I tried it and the scroll bars appear. I wondered to.

No thats the thing I tried it and the scroll bars appear. I wondered to.
DieGurke marked this conversation as resolved
#quick-select-list .scroll-bar:vertical{
-fx-pref-width: 0;
-fx-max-width: 0;
-fx-min-width: 0;
Owner

Is that even needed in this case?

Is that even needed in this case?
Owner

Meant is only the last line...

Meant is only the last line...
Poster
Owner

Yes it is absolutly necessary.

Yes it is absolutly necessary.
Owner

Why? If the max width is already 0, not even the pref width should matter, especially not the min width.

Why? If the max width is already 0, not even the pref width should matter, especially not the min width.
Poster
Owner

No thats the thing I tried it and the scroll bars appear. I wondered to.

No thats the thing I tried it and the scroll bars appear. I wondered to.
DieGurke marked this conversation as resolved
delvh approved these changes 2 years ago
delvh left a comment
Owner

👍

👍
stackPane.getChildren().add(hBox);
getChildren().add(stackPane);
Owner

Delete this blank line.

Delete this blank line.
DieGurke marked this conversation as resolved
delvh reviewed 2 years ago
private void initialize() {
userList.setCellFactory(new ListCellFactory<>(ContactControl::new));
userList.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
userList.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
Owner

Wait... Isn't that already default behavior?

Wait... Isn't that already default behavior?
DieGurke marked this conversation as resolved
kske approved these changes 2 years ago
delvh requested changes 2 years ago
import envoy.data.User;
/**
* Displays an {@link User} as a quickSelectControl which is used in the
Owner

We don't use camelCase is Javadoc.

We don't use camelCase is Javadoc.
DieGurke marked this conversation as resolved
DieGurke requested review from delvh 2 years ago
DieGurke merged commit 99867eb23a into develop 2 years ago
DieGurke deleted branch f/quick-group-select 2 years ago
This repo is archived. You cannot comment on pull requests.
Loading…
There is no content yet.