sort items by localization name
This commit is contained in:
@@ -6,7 +6,7 @@ import javafx.beans.property.StringProperty;
|
|||||||
import ru.trader.core.Group;
|
import ru.trader.core.Group;
|
||||||
import ru.trader.view.support.Localization;
|
import ru.trader.view.support.Localization;
|
||||||
|
|
||||||
public class GroupModel {
|
public class GroupModel implements Comparable<GroupModel> {
|
||||||
|
|
||||||
private final Group group;
|
private final Group group;
|
||||||
private StringProperty name;
|
private StringProperty name;
|
||||||
@@ -39,6 +39,13 @@ public class GroupModel {
|
|||||||
return Localization.getString("item.group." + group.getName(), group.getName());
|
return Localization.getString("item.group." + group.getName(), group.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(GroupModel other) {
|
||||||
|
int cmp = group.getType().compareTo(other.group.getType());
|
||||||
|
if (cmp != 0) return cmp;
|
||||||
|
return getName().compareTo(other.getName());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return getName();
|
return getName();
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import ru.trader.view.support.Localization;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ItemModel {
|
public class ItemModel implements Comparable<ItemModel> {
|
||||||
private final static Logger LOG = LoggerFactory.getLogger(ItemModel.class);
|
private final static Logger LOG = LoggerFactory.getLogger(ItemModel.class);
|
||||||
|
|
||||||
private final Item item;
|
private final Item item;
|
||||||
@@ -17,17 +17,20 @@ public class ItemModel {
|
|||||||
|
|
||||||
private final ItemStatModel statSell;
|
private final ItemStatModel statSell;
|
||||||
private final ItemStatModel statBuy;
|
private final ItemStatModel statBuy;
|
||||||
|
private final GroupModel group;
|
||||||
|
|
||||||
ItemModel() {
|
ItemModel() {
|
||||||
this.item = null;
|
this.item = null;
|
||||||
this.statSell = null;
|
this.statSell = null;
|
||||||
this.statBuy = null;
|
this.statBuy = null;
|
||||||
|
this.group = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemModel(Item item, MarketModel market) {
|
ItemModel(Item item, MarketModel market) {
|
||||||
this.item = item;
|
this.item = item;
|
||||||
this.statSell = new ItemStatModel(market.getStat(OFFER_TYPE.SELL, item), market);
|
this.statSell = new ItemStatModel(market.getStat(OFFER_TYPE.SELL, item), market);
|
||||||
this.statBuy = new ItemStatModel(market.getStat(OFFER_TYPE.BUY, item), market);
|
this.statBuy = new ItemStatModel(market.getStat(OFFER_TYPE.BUY, item), market);
|
||||||
|
this.group = market.getModeler().get(item.getGroup());
|
||||||
}
|
}
|
||||||
|
|
||||||
Item getItem(){
|
Item getItem(){
|
||||||
@@ -112,6 +115,13 @@ public class ItemModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(ItemModel other) {
|
||||||
|
int cmp = group != null ? other.group != null ? group.compareTo(other.group) : 1 : 0;
|
||||||
|
if (cmp != 0) return cmp;
|
||||||
|
return getName().compareTo(other.getName());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
if (LOG.isTraceEnabled()){
|
if (LOG.isTraceEnabled()){
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ public class MarketModel {
|
|||||||
notificator = new Notificator();
|
notificator = new Notificator();
|
||||||
groups = new SimpleListProperty<>(BindingsHelper.observableList(market.getGroups(), modeler::get));
|
groups = new SimpleListProperty<>(BindingsHelper.observableList(market.getGroups(), modeler::get));
|
||||||
items = new SimpleListProperty<>(BindingsHelper.observableList(market.getItems(), modeler::get));
|
items = new SimpleListProperty<>(BindingsHelper.observableList(market.getItems(), modeler::get));
|
||||||
|
items.sort((i1, i2) -> i1.compareTo(i2));
|
||||||
systems = new SimpleListProperty<>(BindingsHelper.observableList(market.get(), modeler::get));
|
systems = new SimpleListProperty<>(BindingsHelper.observableList(market.get(), modeler::get));
|
||||||
systemsList = new SimpleListProperty<>(FXCollections.observableArrayList(ModelFabric.NONE_SYSTEM));
|
systemsList = new SimpleListProperty<>(FXCollections.observableArrayList(ModelFabric.NONE_SYSTEM));
|
||||||
systemsList.addAll(systems);
|
systemsList.addAll(systems);
|
||||||
|
|||||||
Reference in New Issue
Block a user