Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the developer to specify that the ListSelectionView source and target lists should be sorted. #1446

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -47,6 +47,7 @@
import org.controlsfx.glyphfont.Glyph;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.function.Consumer;

Expand Down Expand Up @@ -474,6 +475,22 @@ protected final void setEventHandler(Consumer<ActionEvent> eventHandler) {
super.setEventHandler(eventHandler);
}
}

private Comparator<T> comparator;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please convert this into ObjectProperty<Comparator>. Have a look into other properties in the class.


/**
* Set a comparator to ensure that the source and target items list is sorted
* @param comparator the comparator to use to sort the source and target items.
*/
public void setComparator(Comparator<T> comparator) {
this.comparator = comparator;
}
private void sortItems(ListView<T> sourceListView, ListView<T> targetListView) {
if (comparator != null) {
sourceListView.getItems().sort(comparator);
targetListView.getItems().sort(comparator);
}
}

/**
* Action use to move the selected items from the
Expand All @@ -492,7 +509,10 @@ public MoveToTarget() {
@Override
public void initialize(ListView<T> sourceListView, ListView<T> targetListView) {
disabledProperty().bind(Bindings.isEmpty(sourceListView.getSelectionModel().getSelectedItems()));
setEventHandler(ae -> moveToTarget(sourceListView, targetListView));
setEventHandler(ae -> {
moveToTarget(sourceListView, targetListView);
sortItems(sourceListView, targetListView);
});
}
}

Expand All @@ -513,7 +533,10 @@ public MoveToTargetAll() {
@Override
public void initialize(ListView<T> sourceListView, ListView<T> targetListView) {
disabledProperty().bind(Bindings.isEmpty(sourceListView.getItems()));
setEventHandler(ae -> moveToTargetAll(sourceListView, targetListView));
setEventHandler(ae -> {
moveToTargetAll(sourceListView, targetListView);
sortItems(sourceListView, targetListView);
});
}
}

Expand All @@ -534,7 +557,10 @@ public MoveToSource() {
@Override
public void initialize(ListView<T> sourceListView, ListView<T> targetListView) {
disabledProperty().bind(Bindings.isEmpty(targetListView.getSelectionModel().getSelectedItems()));
setEventHandler(ae -> moveToSource(sourceListView, targetListView));
setEventHandler(ae -> {
moveToSource(sourceListView, targetListView);
sortItems(sourceListView, targetListView);
});
}
}

Expand All @@ -555,7 +581,10 @@ public MoveToSourceAll() {
@Override
public void initialize(ListView<T> sourceListView, ListView<T> targetListView) {
disabledProperty().bind(Bindings.isEmpty(targetListView.getItems()));
setEventHandler(ae -> moveToSourceAll(sourceListView, targetListView));
setEventHandler(ae -> {
moveToSourceAll(sourceListView, targetListView);
sortItems(sourceListView, targetListView);
});
}
}

Expand Down