Archived
0

update item's model name on change lang

This commit is contained in:
iMoHax
2015-02-22 11:53:37 +03:00
parent c7d2b6bad2
commit 5c2655f5fa
4 changed files with 27 additions and 3 deletions

View File

@@ -65,8 +65,10 @@ public class MainController {
}
toggleGroup.selectedToggleProperty().addListener((cb, o, n) -> {
try {
if (n!=null)
if (n != null) {
Main.changeLocale((Locale) n.getUserData());
world.refresh();
}
} catch (IOException e) {
LOG.error("Error on change locale to {}", n.getUserData());
LOG.error("",e);

View File

@@ -39,6 +39,12 @@ public class GroupModel implements Comparable<GroupModel> {
return Localization.getString("item.group." + group.getName(), group.getName());
}
void updateName(){
if (name != null){
name.setValue(buildName());
}
}
@Override
public int compareTo(GroupModel other) {
int cmp = group.getType().compareTo(other.group.getType());

View File

@@ -39,7 +39,7 @@ public class ItemModel implements Comparable<ItemModel> {
public String getId() {return item.getName();}
public String getName() {return name != null ? name.get() : Localization.getString("item." + item.getName(), item.getName());}
public String getName() {return name != null ? name.get() : buildName();}
public void setName(String value) {
LOG.info("Change name of item {} to {}", item, value);
@@ -49,12 +49,22 @@ public class ItemModel implements Comparable<ItemModel> {
public ReadOnlyStringProperty nameProperty() {
if (name == null) {
String lName = Localization.getString("item." + item.getName(), item.getName());
String lName = buildName();
name = new SimpleStringProperty(lName);
}
return name;
}
private String buildName(){
return Localization.getString("item." + item.getName(), item.getName());
}
void updateName(){
if (name != null){
name.setValue(buildName());
}
}
public ReadOnlyDoubleProperty avgBuyProperty() {
return statBuy.avgProperty();
}

View File

@@ -252,4 +252,10 @@ public class MarketModel {
LOG.info("Clear groups");
market.clearGroups();
}
public void refresh(){
LOG.debug("Refresh names");
groups.get().forEach(GroupModel::updateName);
items.get().forEach(ItemModel::updateName);
}
}