UI: added custom sorting in choice dialog

This commit is contained in:
Oleg Agafonov 2017-12-29 06:11:10 +04:00
parent 35a950dc80
commit af0c77a409
3 changed files with 37 additions and 6 deletions

View file

@ -68,4 +68,9 @@ public interface Choice {
void setSearchEnabled(boolean isEnabled);
void setSearchText(String searchText);
String getSearchText();
// sorting
boolean isSortEnabled();
void setSortData(Map<String, Integer> sortData);
Map<String, Integer> getSortData();
}

View file

@ -47,6 +47,7 @@ public class ChoiceImpl implements Choice, Serializable {
protected String choiceKey;
protected Set<String> choices = new LinkedHashSet<>();
protected Map<String, String> keyChoices = new LinkedHashMap<>();
protected Map<String, Integer> sortData = new LinkedHashMap<>();
protected String message;
protected String subMessage;
protected boolean searchEnabled = true; // enable for all windows by default
@ -70,7 +71,8 @@ public class ChoiceImpl implements Choice, Serializable {
this.searchText = choice.searchText;
this.choices.addAll(choice.choices);
this.choiceKey = choice.choiceKey;
this.keyChoices = choice.keyChoices; // list should never change for the same object so copy by reference
this.keyChoices = choice.keyChoices; // list should never change for the same object so copy by reference TODO: check errors with that, it that ok? Color list is static
this.sortData = choice.sortData;
}
@Override
@ -193,4 +195,19 @@ public class ChoiceImpl implements Choice, Serializable {
return this.searchText;
};
@Override
public boolean isSortEnabled(){
return (this.sortData != null) && !this.sortData.isEmpty();
};
@Override
public void setSortData(Map<String, Integer> sortData){
this.sortData = sortData;
};
@Override
public Map<String, Integer> getSortData(){
return this.sortData;
};
}