add property list with none system and none station
This commit is contained in:
@@ -89,22 +89,10 @@ public class RouterController {
|
||||
Main.SETTINGS.setJumps(n.intValue());
|
||||
});
|
||||
source.valueProperty().addListener((ov, o, n) -> {
|
||||
if (n != ModelFabric.NONE_SYSTEM){
|
||||
ObservableList<StationModel> stations = FXCollections.observableArrayList(ModelFabric.NONE_STATION);
|
||||
stations.addAll(n.getStations());
|
||||
sStation.setItems(stations);
|
||||
} else {
|
||||
sStation.setItems(FXCollections.observableArrayList(ModelFabric.NONE_STATION));
|
||||
}
|
||||
sStation.setItems(n.getStationsList());
|
||||
});
|
||||
target.valueProperty().addListener((ov, o, n) -> {
|
||||
if (n != ModelFabric.NONE_SYSTEM){
|
||||
ObservableList<StationModel> stations = FXCollections.observableArrayList(ModelFabric.NONE_STATION);
|
||||
stations.addAll(n.getStations());
|
||||
tStation.setItems(stations);
|
||||
} else {
|
||||
tStation.setItems(FXCollections.observableArrayList(ModelFabric.NONE_STATION));
|
||||
}
|
||||
tStation.setItems(n.getStationsList());
|
||||
});
|
||||
|
||||
|
||||
@@ -145,8 +133,7 @@ public class RouterController {
|
||||
market.getNotificator().add(new RouterChangeListener());
|
||||
source.setItems(market.systemsProperty());
|
||||
source.getSelectionModel().selectFirst();
|
||||
target.setItems(FXCollections.observableArrayList(market.systemsProperty()));
|
||||
target.getItems().add(0, ModelFabric.NONE_SYSTEM);
|
||||
target.setItems(market.systemsListProperty());
|
||||
target.getSelectionModel().selectFirst();
|
||||
orders.clear();
|
||||
totalBalance.setValue(balance.getValue());
|
||||
@@ -274,15 +261,6 @@ public class RouterController {
|
||||
}
|
||||
|
||||
private class RouterChangeListener extends ChangeMarketListener {
|
||||
@Override
|
||||
public void add(SystemModel system) {
|
||||
target.getItems().add(system);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(SystemModel system) {
|
||||
target.getItems().remove(system);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(StationModel station) {
|
||||
|
||||
@@ -3,6 +3,8 @@ package ru.trader.model;
|
||||
import javafx.beans.property.ListProperty;
|
||||
import javafx.beans.property.ReadOnlyListProperty;
|
||||
import javafx.beans.property.SimpleListProperty;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ListChangeListener;
|
||||
import javafx.collections.ObservableList;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -24,6 +26,8 @@ public class MarketModel {
|
||||
private final Notificator notificator;
|
||||
|
||||
private final ListProperty<SystemModel> systems;
|
||||
// with NONE_SYSTEM
|
||||
private ListProperty<SystemModel> systemsList;
|
||||
private final ListProperty<ItemModel> items;
|
||||
|
||||
public MarketModel(Market market) {
|
||||
@@ -33,8 +37,22 @@ public class MarketModel {
|
||||
notificator = new Notificator();
|
||||
items = new SimpleListProperty<>(BindingsHelper.observableList(market.getItems(), modeler::get));
|
||||
systems = new SimpleListProperty<>(BindingsHelper.observableList(market.get(), modeler::get));
|
||||
systemsList = new SimpleListProperty<>(FXCollections.observableArrayList(ModelFabric.NONE_SYSTEM));
|
||||
systemsList.addAll(systems);
|
||||
systems.addListener(SYSTEMS_CHANGE_LISTENER);
|
||||
}
|
||||
|
||||
private ListChangeListener<SystemModel> SYSTEMS_CHANGE_LISTENER = l -> {
|
||||
while (l.next()) {
|
||||
if (l.wasRemoved()) {
|
||||
systemsList.removeAll(l.getRemoved());
|
||||
}
|
||||
if (l.wasAdded()) {
|
||||
systemsList.addAll(l.getAddedSubList());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public MarketAnalyzer getAnalyzer() {
|
||||
return analyzer;
|
||||
}
|
||||
@@ -50,6 +68,9 @@ public class MarketModel {
|
||||
public ReadOnlyListProperty<SystemModel> systemsProperty() {
|
||||
return systems;
|
||||
}
|
||||
public ReadOnlyListProperty<SystemModel> systemsListProperty() {
|
||||
return systemsList;
|
||||
}
|
||||
|
||||
public SystemModel add(String name, double x, double y, double z) {
|
||||
SystemModel system = modeler.get(market.addPlace(name, x, y, z));
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package ru.trader.model;
|
||||
|
||||
import javafx.beans.property.ReadOnlyStringProperty;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import ru.trader.core.*;
|
||||
import ru.trader.graph.PathRoute;
|
||||
|
||||
@@ -30,7 +32,7 @@ public class ModelFabric {
|
||||
}
|
||||
|
||||
public SystemModel get(Place system){
|
||||
if (system == null) return null;
|
||||
if (system == null) return NONE_SYSTEM;
|
||||
SystemModel res=null;
|
||||
WeakReference<SystemModel> ref = systems.get(system);
|
||||
if (ref != null){
|
||||
@@ -45,7 +47,7 @@ public class ModelFabric {
|
||||
|
||||
|
||||
public StationModel get(Vendor station){
|
||||
if (station == null) return null;
|
||||
if (station == null) return NONE_STATION;
|
||||
StationModel res=null;
|
||||
WeakReference<StationModel> ref = stations.get(station);
|
||||
if (ref != null){
|
||||
@@ -160,6 +162,11 @@ public class ModelFabric {
|
||||
throw new UnsupportedOperationException("Is fake system, change unsupported");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObservableList<StationModel> getStationsList() {
|
||||
return FXCollections.observableArrayList(ModelFabric.NONE_STATION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<StationModel> getStations(SERVICE_TYPE service) {
|
||||
throw new UnsupportedOperationException("Is fake system, change unsupported");
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package ru.trader.model;
|
||||
|
||||
import javafx.beans.property.*;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import ru.trader.core.Place;
|
||||
@@ -80,6 +82,12 @@ public class SystemModel {
|
||||
return system.get().stream().map(this::asModel).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public ObservableList<StationModel> getStationsList() {
|
||||
ObservableList<StationModel> res = FXCollections.observableArrayList(ModelFabric.NONE_STATION);
|
||||
res.addAll(getStations());
|
||||
return res;
|
||||
}
|
||||
|
||||
public List<StationModel> getStations(final SERVICE_TYPE service) {
|
||||
return system.get().stream().filter(v -> v.has(service)).map(this::asModel).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user