implement illegal items indication on vendor editor screen
This commit is contained in:
@@ -1,9 +1,12 @@
|
|||||||
package ru.trader.controllers;
|
package ru.trader.controllers;
|
||||||
|
|
||||||
|
import javafx.beans.InvalidationListener;
|
||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
|
import javafx.collections.ObservableList;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.Parent;
|
import javafx.scene.Parent;
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
|
import javafx.util.Callback;
|
||||||
import javafx.util.converter.LongStringConverter;
|
import javafx.util.converter.LongStringConverter;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -14,6 +17,7 @@ import ru.trader.model.StationModel;
|
|||||||
import ru.trader.model.SystemModel;
|
import ru.trader.model.SystemModel;
|
||||||
import ru.trader.model.support.StationUpdater;
|
import ru.trader.model.support.StationUpdater;
|
||||||
import ru.trader.view.support.*;
|
import ru.trader.view.support.*;
|
||||||
|
import ru.trader.view.support.cells.DecoratedRowFactory;
|
||||||
import ru.trader.view.support.cells.EditOfferCell;
|
import ru.trader.view.support.cells.EditOfferCell;
|
||||||
import ru.trader.view.support.cells.TextFieldCell;
|
import ru.trader.view.support.cells.TextFieldCell;
|
||||||
|
|
||||||
@@ -78,13 +82,16 @@ public class StationEditorController {
|
|||||||
type.setConverter(new StationTypeStringConverter());
|
type.setConverter(new StationTypeStringConverter());
|
||||||
faction.setItems(FXCollections.observableArrayList(FACTION.values()));
|
faction.setItems(FXCollections.observableArrayList(FACTION.values()));
|
||||||
faction.setConverter(new FactionStringConverter());
|
faction.setConverter(new FactionStringConverter());
|
||||||
|
faction.valueProperty().addListener(e -> updateItems());
|
||||||
government.setItems(FXCollections.observableArrayList(GOVERNMENT.values()));
|
government.setItems(FXCollections.observableArrayList(GOVERNMENT.values()));
|
||||||
government.setConverter(new GovernmentStringConverter());
|
government.setConverter(new GovernmentStringConverter());
|
||||||
|
government.valueProperty().addListener(e -> updateItems());
|
||||||
economic.setItems(FXCollections.observableArrayList(ECONOMIC_TYPE.values()));
|
economic.setItems(FXCollections.observableArrayList(ECONOMIC_TYPE.values()));
|
||||||
economic.setConverter(new EconomicTypeStringConverter());
|
economic.setConverter(new EconomicTypeStringConverter());
|
||||||
subEconomic.setItems(FXCollections.observableArrayList(ECONOMIC_TYPE.values()));
|
subEconomic.setItems(FXCollections.observableArrayList(ECONOMIC_TYPE.values()));
|
||||||
subEconomic.setConverter(new EconomicTypeStringConverter());
|
subEconomic.setConverter(new EconomicTypeStringConverter());
|
||||||
items.getSelectionModel().setCellSelectionEnabled(true);
|
items.getSelectionModel().setCellSelectionEnabled(true);
|
||||||
|
items.setRowFactory(new FakeOfferDecoratedRow());
|
||||||
buy.setCellFactory(EditOfferCell.forTable(new PriceStringConverter(), false));
|
buy.setCellFactory(EditOfferCell.forTable(new PriceStringConverter(), false));
|
||||||
sell.setCellFactory(EditOfferCell.forTable(new PriceStringConverter(), true));
|
sell.setCellFactory(EditOfferCell.forTable(new PriceStringConverter(), true));
|
||||||
demand.setCellFactory(TextFieldCell.forTableColumn(new LongStringConverter()));
|
demand.setCellFactory(TextFieldCell.forTableColumn(new LongStringConverter()));
|
||||||
@@ -127,6 +134,13 @@ public class StationEditorController {
|
|||||||
items.setItems(updater.getOffers());
|
items.setItems(updater.getOffers());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateItems(){
|
||||||
|
items.setItems(null);
|
||||||
|
items.layout();
|
||||||
|
if (updater != null){
|
||||||
|
items.setItems(updater.getOffers());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void createDialog(Parent owner, Parent content){
|
private void createDialog(Parent owner, Parent content){
|
||||||
dlg = new Dialog<>();
|
dlg = new Dialog<>();
|
||||||
@@ -221,4 +235,28 @@ public class StationEditorController {
|
|||||||
public void updateFromEMDN(){
|
public void updateFromEMDN(){
|
||||||
EMDNUpdater.updateFromEMDN(updater);
|
EMDNUpdater.updateFromEMDN(updater);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class FakeOfferDecoratedRow extends DecoratedRowFactory<StationUpdater.FakeOffer> {
|
||||||
|
|
||||||
|
public FakeOfferDecoratedRow() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public FakeOfferDecoratedRow(Callback<TableView<StationUpdater.FakeOffer>, TableRow<StationUpdater.FakeOffer>> decorated) {
|
||||||
|
super(decorated);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doStyle(TableRow<StationUpdater.FakeOffer> row, StationUpdater.FakeOffer entry) {
|
||||||
|
ObservableList<String> styles = row.getStyleClass();
|
||||||
|
styles.remove(ViewUtils.ILLEGAL_ITEM_STYLE);
|
||||||
|
if (entry != null){
|
||||||
|
GOVERNMENT g = government.getValue();
|
||||||
|
FACTION f = faction.getValue();
|
||||||
|
if (entry.getItem().isIllegal(f, g)){
|
||||||
|
styles.add(ViewUtils.ILLEGAL_ITEM_STYLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -148,6 +148,10 @@ public class ItemModel implements Comparable<ItemModel> {
|
|||||||
item.setLegal(government, legal);
|
item.setLegal(government, legal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isIllegal(FACTION faction, GOVERNMENT government){
|
||||||
|
return item.isIllegal(faction, government);
|
||||||
|
}
|
||||||
|
|
||||||
public void refresh(){
|
public void refresh(){
|
||||||
LOG.trace("Refresh stats of itemDesc {}", this);
|
LOG.trace("Refresh stats of itemDesc {}", this);
|
||||||
statBuy.refresh();
|
statBuy.refresh();
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ public abstract class DecoratedCellFactory<S, T> implements Callback<TableColumn
|
|||||||
this.decorated = decorated;
|
this.decorated = decorated;
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract void doStyle(TableCell<S, T> cell, S entry, T item);
|
protected abstract void doStyle(TableCell<S, T> cell, S entry, T item);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final TableCell<S, T> call(TableColumn<S, T> param) {
|
public final TableCell<S, T> call(TableColumn<S, T> param) {
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ public abstract class DecoratedListCellFactory<T> implements Callback<ListView<T
|
|||||||
this.decorated = decorated;
|
this.decorated = decorated;
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract void doStyle(ListCell<T> cell, T item);
|
protected abstract void doStyle(ListCell<T> cell, T item);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final ListCell<T> call(ListView<T> param) {
|
public final ListCell<T> call(ListView<T> param) {
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ public abstract class DecoratedRowFactory<S> implements Callback<TableView<S>, T
|
|||||||
this.decorated = decorated;
|
this.decorated = decorated;
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract void doStyle(TableRow<S> row, S entry);
|
protected abstract void doStyle(TableRow<S> row, S entry);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final TableRow<S> call(TableView<S> param) {
|
public final TableRow<S> call(TableView<S> param) {
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ public class OfferDecoratedListCell extends DecoratedListCellFactory<OfferModel>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void doStyle(ListCell<OfferModel> cell, OfferModel item) {
|
protected void doStyle(ListCell<OfferModel> cell, OfferModel item) {
|
||||||
ObservableList<String> styles = cell.getStyleClass();
|
ObservableList<String> styles = cell.getStyleClass();
|
||||||
styles.remove(ViewUtils.ILLEGAL_ITEM_STYLE);
|
styles.remove(ViewUtils.ILLEGAL_ITEM_STYLE);
|
||||||
if (item != null && item.isIllegal()){
|
if (item != null && item.isIllegal()){
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import ru.trader.view.support.ViewUtils;
|
|||||||
|
|
||||||
public class OfferDecoratedRow extends DecoratedRowFactory<OfferModel> {
|
public class OfferDecoratedRow extends DecoratedRowFactory<OfferModel> {
|
||||||
public OfferDecoratedRow() {
|
public OfferDecoratedRow() {
|
||||||
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
public OfferDecoratedRow(Callback<TableView<OfferModel>, TableRow<OfferModel>> decorated) {
|
public OfferDecoratedRow(Callback<TableView<OfferModel>, TableRow<OfferModel>> decorated) {
|
||||||
@@ -16,7 +17,7 @@ public class OfferDecoratedRow extends DecoratedRowFactory<OfferModel> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void doStyle(TableRow<OfferModel> row, OfferModel entry) {
|
protected void doStyle(TableRow<OfferModel> row, OfferModel entry) {
|
||||||
ObservableList<String> styles = row.getStyleClass();
|
ObservableList<String> styles = row.getStyleClass();
|
||||||
styles.remove(ViewUtils.ILLEGAL_ITEM_STYLE);
|
styles.remove(ViewUtils.ILLEGAL_ITEM_STYLE);
|
||||||
if (entry != null && entry.isIllegal()){
|
if (entry != null && entry.isIllegal()){
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ public class OrderDecoratedListCell extends DecoratedListCellFactory<OrderModel>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void doStyle(ListCell<OrderModel> cell, OrderModel item) {
|
protected void doStyle(ListCell<OrderModel> cell, OrderModel item) {
|
||||||
ObservableList<String> styles = cell.getStyleClass();
|
ObservableList<String> styles = cell.getStyleClass();
|
||||||
styles.remove(ViewUtils.ILLEGAL_ITEM_STYLE);
|
styles.remove(ViewUtils.ILLEGAL_ITEM_STYLE);
|
||||||
if (item != null && item.isIllegal()){
|
if (item != null && item.isIllegal()){
|
||||||
|
|||||||
@@ -12,6 +12,10 @@ public interface Item extends Comparable<Item> {
|
|||||||
default boolean isIllegal(Vendor vendor){
|
default boolean isIllegal(Vendor vendor){
|
||||||
FACTION faction = vendor.getFaction();
|
FACTION faction = vendor.getFaction();
|
||||||
GOVERNMENT government = vendor.getGovernment();
|
GOVERNMENT government = vendor.getGovernment();
|
||||||
|
return isIllegal(faction, government);
|
||||||
|
}
|
||||||
|
|
||||||
|
default boolean isIllegal(FACTION faction, GOVERNMENT government){
|
||||||
if (faction != null && getLegalFactions().contains(faction)) return false;
|
if (faction != null && getLegalFactions().contains(faction)) return false;
|
||||||
if (government != null && getLegalGovernments().contains(government)) return false;
|
if (government != null && getLegalGovernments().contains(government)) return false;
|
||||||
return faction != null && getIllegalFactions().contains(faction) ||
|
return faction != null && getIllegalFactions().contains(faction) ||
|
||||||
|
|||||||
Reference in New Issue
Block a user