Skip to content

Commit

Permalink
Merged in GuillaumeJ/gjourdaincontrolsfx (pull request controlsfx#707)
Browse files Browse the repository at this point in the history
controlsfx#858 Enables custom Category sort for PropertySheet

Approved-by: Eugene Ryzhikov <eryzhikov@gmail.com>
Approved-by: Jonathan Giles <jonathan@jonathangiles.net>
  • Loading branch information
JonathanGiles committed Aug 30, 2018
2 parents b617763 + 6763765 commit 69c99ef
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
Expand Up @@ -136,6 +136,7 @@ public PropertySheetSkin(final PropertySheet control) {
registerChangeListener(searchField.textProperty(), "FILTER-UI"); //$NON-NLS-1$
registerChangeListener(control.modeSwitcherVisibleProperty(), "TOOLBAR-MODE"); //$NON-NLS-1$
registerChangeListener(control.searchBoxVisibleProperty(), "TOOLBAR-SEARCH"); //$NON-NLS-1$
registerChangeListener(control.categoryComparatorProperty(), "CATEGORY-COMPARATOR"); //$NON-NLS-1$

control.getItems().addListener((ListChangeListener<Item>) change -> refreshProperties());

Expand All @@ -154,7 +155,7 @@ public PropertySheetSkin(final PropertySheet control) {
@Override protected void handleControlPropertyChanged(String p) {
super.handleControlPropertyChanged(p);

if (p == "MODE" || p == "EDITOR-FACTORY" || p == "FILTER") { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
if (p == "MODE" || p == "EDITOR-FACTORY" || p == "FILTER" || p == "CATEGORY-COMPARATOR") { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
refreshProperties();
} else if (p == "FILTER-UI") { //$NON-NLS-1$
getSkinnable().setTitleFilter(searchField.getText());
Expand Down Expand Up @@ -192,7 +193,7 @@ private Node buildPropertySheetContainer() {
switch( getSkinnable().modeProperty().get() ) {
case CATEGORY: {
// group by category
Map<String, List<Item>> categoryMap = new TreeMap<>();
Map<String, List<Item>> categoryMap = new TreeMap(getSkinnable().getCategoryComparator());
for( Item p: getSkinnable().getItems()) {
String category = p.getCategory();
List<Item> list = categoryMap.get(category);
Expand Down
Expand Up @@ -28,6 +28,7 @@

import impl.org.controlsfx.skin.PropertySheetSkin;

import java.util.Comparator;
import java.util.Optional;

import javafx.beans.property.SimpleBooleanProperty;
Expand Down Expand Up @@ -204,7 +205,6 @@ default public boolean isEditable() {
private final ObservableList<Item> items;



/**************************************************************************
*
* Constructors
Expand Down Expand Up @@ -439,6 +439,38 @@ public final void setTitleFilter( String filter ) {
titleFilterProperty.set(filter);
}

// --- categoryComparatorProperty
private final SimpleObjectProperty<Comparator<String>> categoryComparatorProperty =
new SimpleObjectProperty<>(this, "categoryComparator", null); //$NON-NLS-1$

/**
* Used to represent how the categories should be laid out in
* the PropertySheet when using the Category mode (see {@link Mode}).
* Thus allowing user to sort categories by other ways than alphabetical
* or numerical order.
* @return A SimpleObjectproperty.
*/
public final SimpleObjectProperty<Comparator<String>> categoryComparatorProperty() {
return categoryComparatorProperty;
}

/**
* @see Mode
* @return how the categories should be laid out in
* the PropertySheet.
*/
public final Comparator<String> getCategoryComparator() {
return categoryComparatorProperty.get();
}

/**
* Set how the categories should be laid out in
* the PropertySheet.
* @param mode
*/
public final void setCategoryComparator(Comparator<String> categoryComparator) {
categoryComparatorProperty.set(categoryComparator);
}


/***************************************************************************
Expand Down

0 comments on commit 69c99ef

Please sign in to comment.