Archived
0

add property list with none system and none station

This commit is contained in:
iMoHax
2015-01-07 14:33:29 +03:00
parent af06ab0914
commit 00d8f6e084
4 changed files with 41 additions and 27 deletions

View File

@@ -89,22 +89,10 @@ public class RouterController {
Main.SETTINGS.setJumps(n.intValue()); Main.SETTINGS.setJumps(n.intValue());
}); });
source.valueProperty().addListener((ov, o, n) -> { source.valueProperty().addListener((ov, o, n) -> {
if (n != ModelFabric.NONE_SYSTEM){ sStation.setItems(n.getStationsList());
ObservableList<StationModel> stations = FXCollections.observableArrayList(ModelFabric.NONE_STATION);
stations.addAll(n.getStations());
sStation.setItems(stations);
} else {
sStation.setItems(FXCollections.observableArrayList(ModelFabric.NONE_STATION));
}
}); });
target.valueProperty().addListener((ov, o, n) -> { target.valueProperty().addListener((ov, o, n) -> {
if (n != ModelFabric.NONE_SYSTEM){ tStation.setItems(n.getStationsList());
ObservableList<StationModel> stations = FXCollections.observableArrayList(ModelFabric.NONE_STATION);
stations.addAll(n.getStations());
tStation.setItems(stations);
} else {
tStation.setItems(FXCollections.observableArrayList(ModelFabric.NONE_STATION));
}
}); });
@@ -145,8 +133,7 @@ public class RouterController {
market.getNotificator().add(new RouterChangeListener()); market.getNotificator().add(new RouterChangeListener());
source.setItems(market.systemsProperty()); source.setItems(market.systemsProperty());
source.getSelectionModel().selectFirst(); source.getSelectionModel().selectFirst();
target.setItems(FXCollections.observableArrayList(market.systemsProperty())); target.setItems(market.systemsListProperty());
target.getItems().add(0, ModelFabric.NONE_SYSTEM);
target.getSelectionModel().selectFirst(); target.getSelectionModel().selectFirst();
orders.clear(); orders.clear();
totalBalance.setValue(balance.getValue()); totalBalance.setValue(balance.getValue());
@@ -274,15 +261,6 @@ public class RouterController {
} }
private class RouterChangeListener extends ChangeMarketListener { 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 @Override
public void add(StationModel station) { public void add(StationModel station) {

View File

@@ -3,6 +3,8 @@ package ru.trader.model;
import javafx.beans.property.ListProperty; import javafx.beans.property.ListProperty;
import javafx.beans.property.ReadOnlyListProperty; import javafx.beans.property.ReadOnlyListProperty;
import javafx.beans.property.SimpleListProperty; import javafx.beans.property.SimpleListProperty;
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -24,6 +26,8 @@ public class MarketModel {
private final Notificator notificator; private final Notificator notificator;
private final ListProperty<SystemModel> systems; private final ListProperty<SystemModel> systems;
// with NONE_SYSTEM
private ListProperty<SystemModel> systemsList;
private final ListProperty<ItemModel> items; private final ListProperty<ItemModel> items;
public MarketModel(Market market) { public MarketModel(Market market) {
@@ -33,8 +37,22 @@ public class MarketModel {
notificator = new Notificator(); notificator = new Notificator();
items = new SimpleListProperty<>(BindingsHelper.observableList(market.getItems(), modeler::get)); items = new SimpleListProperty<>(BindingsHelper.observableList(market.getItems(), modeler::get));
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.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() { public MarketAnalyzer getAnalyzer() {
return analyzer; return analyzer;
} }
@@ -50,6 +68,9 @@ public class MarketModel {
public ReadOnlyListProperty<SystemModel> systemsProperty() { public ReadOnlyListProperty<SystemModel> systemsProperty() {
return systems; return systems;
} }
public ReadOnlyListProperty<SystemModel> systemsListProperty() {
return systemsList;
}
public SystemModel add(String name, double x, double y, double z) { public SystemModel add(String name, double x, double y, double z) {
SystemModel system = modeler.get(market.addPlace(name, x, y, z)); SystemModel system = modeler.get(market.addPlace(name, x, y, z));

View File

@@ -1,6 +1,8 @@
package ru.trader.model; package ru.trader.model;
import javafx.beans.property.ReadOnlyStringProperty; import javafx.beans.property.ReadOnlyStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import ru.trader.core.*; import ru.trader.core.*;
import ru.trader.graph.PathRoute; import ru.trader.graph.PathRoute;
@@ -30,7 +32,7 @@ public class ModelFabric {
} }
public SystemModel get(Place system){ public SystemModel get(Place system){
if (system == null) return null; if (system == null) return NONE_SYSTEM;
SystemModel res=null; SystemModel res=null;
WeakReference<SystemModel> ref = systems.get(system); WeakReference<SystemModel> ref = systems.get(system);
if (ref != null){ if (ref != null){
@@ -45,7 +47,7 @@ public class ModelFabric {
public StationModel get(Vendor station){ public StationModel get(Vendor station){
if (station == null) return null; if (station == null) return NONE_STATION;
StationModel res=null; StationModel res=null;
WeakReference<StationModel> ref = stations.get(station); WeakReference<StationModel> ref = stations.get(station);
if (ref != null){ if (ref != null){
@@ -160,6 +162,11 @@ public class ModelFabric {
throw new UnsupportedOperationException("Is fake system, change unsupported"); throw new UnsupportedOperationException("Is fake system, change unsupported");
} }
@Override
public ObservableList<StationModel> getStationsList() {
return FXCollections.observableArrayList(ModelFabric.NONE_STATION);
}
@Override @Override
public List<StationModel> getStations(SERVICE_TYPE service) { public List<StationModel> getStations(SERVICE_TYPE service) {
throw new UnsupportedOperationException("Is fake system, change unsupported"); throw new UnsupportedOperationException("Is fake system, change unsupported");

View File

@@ -1,6 +1,8 @@
package ru.trader.model; package ru.trader.model;
import javafx.beans.property.*; import javafx.beans.property.*;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import ru.trader.core.Place; import ru.trader.core.Place;
@@ -80,6 +82,12 @@ public class SystemModel {
return system.get().stream().map(this::asModel).collect(Collectors.toList()); 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) { public List<StationModel> getStations(final SERVICE_TYPE service) {
return system.get().stream().filter(v -> v.has(service)).map(this::asModel).collect(Collectors.toList()); return system.get().stream().filter(v -> v.has(service)).map(this::asModel).collect(Collectors.toList());
} }