Quick Select Support for the GroupCreationTab #77
@ -1,18 +1,19 @@
|
|||||||
package envoy.client.ui.control;
|
package envoy.client.ui.control;
|
||||||
|
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import javafx.geometry.*;
|
import javafx.geometry.*;
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
import javafx.scene.image.ImageView;
|
import javafx.scene.image.ImageView;
|
||||||
import javafx.scene.layout.*;
|
import javafx.scene.layout.*;
|
||||||
import javafx.scene.shape.Rectangle;
|
import javafx.scene.shape.Rectangle;
|
||||||
|
|
||||||
import envoy.client.ui.controller.GroupCreationTab;
|
|
||||||
import envoy.client.util.IconUtil;
|
import envoy.client.util.IconUtil;
|
||||||
import envoy.data.User;
|
import envoy.data.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
mpk marked this conversation as resolved
Outdated
|
|||||||
* Displays an {@link User} as a quickSelectControl which is used in the
|
* Displays an {@link User} as a quick select control which is used in the
|
||||||
* quickSelectList.
|
* quick select list.
|
||||||
*
|
*
|
||||||
* @author Maximilian Käfer
|
* @author Maximilian Käfer
|
||||||
* @since Envoy Client v0.3-beta
|
* @since Envoy Client v0.3-beta
|
||||||
@ -24,11 +25,11 @@ public class QuickSelectControl extends VBox {
|
|||||||
/**
|
/**
|
||||||
* Creates an instance of the {@code QuickSelectControl}.
|
* Creates an instance of the {@code QuickSelectControl}.
|
||||||
*
|
*
|
||||||
* @param user the user whose data is used to create this instance.
|
* @param user the contact whose data is used to create this instance.
|
||||||
* @param tab the parent tab ({@link GroupCreationTab}).
|
* @param action the action to perform when a contact is removed with this control as a parameter
|
||||||
* @since Envoy Client v0.3-beta
|
* @since Envoy Client v0.3-beta
|
||||||
*/
|
*/
|
||||||
public QuickSelectControl(User user, GroupCreationTab tab) {
|
public QuickSelectControl(User user, Consumer<QuickSelectControl> action) {
|
||||||
mpk marked this conversation as resolved
Outdated
delvh
commented
? ?
mpk
commented
This centers the component (it is just 1 pixel but very noticable) This centers the component (it is just 1 pixel but very noticable)
|
|||||||
this.user = user;
|
this.user = user;
|
||||||
setPadding(new Insets(1, 0, 0, 0));
|
setPadding(new Insets(1, 0, 0, 0));
|
||||||
setPrefWidth(37);
|
setPrefWidth(37);
|
||||||
@ -65,13 +66,12 @@ public class QuickSelectControl extends VBox {
|
|||||||
removeBtn.setPrefSize(12, 12);
|
removeBtn.setPrefSize(12, 12);
|
||||||
removeBtn.setMaxSize(12, 12);
|
removeBtn.setMaxSize(12, 12);
|
||||||
removeBtn.setMinSize(12, 12);
|
removeBtn.setMinSize(12, 12);
|
||||||
mpk marked this conversation as resolved
delvh
commented
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:
This additionally brings the advantage of reusability. When this is implemented, the 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.
|
|||||||
removeBtn.setOnMouseClicked(evt -> tab.removeFromQuickSelection(this));
|
removeBtn.setOnMouseClicked(evt -> action.accept(this));
|
||||||
removeBtn.setId("remove-button");
|
removeBtn.setId("remove-button");
|
||||||
delvh
commented
If I understand you correctly, the only purpose of the I've experimented a bit and found out that I can achieve the same result using two components (and a few lines) less:
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.
mpk
commented
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)
delvh
commented
Funny thing. They haven't. But still:
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
mpk
commented
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
delvh
commented
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?
delvh
commented
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.
|
|||||||
hBox.getChildren().add(removeBtn);
|
hBox.getChildren().add(removeBtn);
|
||||||
stackPane.getChildren().add(hBox);
|
stackPane.getChildren().add(hBox);
|
||||||
getChildren().add(stackPane);
|
getChildren().add(stackPane);
|
||||||
|
|
||||||
mpk marked this conversation as resolved
Outdated
delvh
commented
Delete this blank line. Delete this blank line.
|
|||||||
|
|
||||||
var nameLabel = new Label();
|
var nameLabel = new Label();
|
||||||
nameLabel.setPrefSize(35, 20);
|
nameLabel.setPrefSize(35, 20);
|
||||||
nameLabel.setMaxSize(35, 20);
|
nameLabel.setMaxSize(35, 20);
|
||||||
|
@ -71,7 +71,6 @@ 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.SINGLE);
|
|
||||||
createButton.setDisable(true);
|
createButton.setDisable(true);
|
||||||
mpk marked this conversation as resolved
Outdated
delvh
commented
Wait... Isn't that already default behavior? Wait... Isn't that already default behavior?
|
|||||||
eventBus.registerListener(this);
|
eventBus.registerListener(this);
|
||||||
userList.getItems()
|
userList.getItems()
|
||||||
@ -94,7 +93,7 @@ public class GroupCreationTab implements EventListener {
|
|||||||
@FXML
|
@FXML
|
||||||
private void userListClicked() {
|
private void userListClicked() {
|
||||||
delvh marked this conversation as resolved
Outdated
delvh
commented
Isn't that the wrong check here? Shouldn't it be
Isn't that the wrong check here? Shouldn't it be
```
setDisable(quickSelectList.getItems().isEmpty() && userList.getSelectionModel().isEmpty() || ...);
```
mpk
commented
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.
|
|||||||
if (userList.getSelectionModel().getSelectedItem() != null) {
|
if (userList.getSelectionModel().getSelectedItem() != null) {
|
||||||
mpk marked this conversation as resolved
Outdated
delvh
commented
You need to insert a null check for 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.
|
|||||||
quickSelectList.getItems().add(new QuickSelectControl(userList.getSelectionModel().getSelectedItem(), this));
|
quickSelectList.getItems().add(new QuickSelectControl(userList.getSelectionModel().getSelectedItem(), this::removeFromQuickSelection));
|
||||||
createButton.setDisable(quickSelectList.getItems().isEmpty() || groupNameField.getText().isBlank());
|
createButton.setDisable(quickSelectList.getItems().isEmpty() || groupNameField.getText().isBlank());
|
||||||
resizeQuickSelectSpace(60);
|
resizeQuickSelectSpace(60);
|
||||||
userList.getItems().remove(userList.getSelectionModel().getSelectedItem());
|
userList.getItems().remove(userList.getSelectionModel().getSelectedItem());
|
||||||
|
We don't use camelCase is Javadoc.