From be2dd6c95e2685fdf6533c3d09a3462561abca89 Mon Sep 17 00:00:00 2001 From: iMoHax Date: Tue, 15 Mar 2016 14:54:41 +0300 Subject: [PATCH] implement illegal items indication on vendor editor screen --- .../controllers/StationEditorController.java | 38 +++++++++++++++++++ .../main/java/ru/trader/model/ItemModel.java | 4 ++ .../support/cells/DecoratedCellFactory.java | 2 +- .../cells/DecoratedListCellFactory.java | 2 +- .../support/cells/DecoratedRowFactory.java | 2 +- .../support/cells/OfferDecoratedListCell.java | 2 +- .../view/support/cells/OfferDecoratedRow.java | 3 +- .../support/cells/OrderDecoratedListCell.java | 2 +- core/src/main/java/ru/trader/core/Item.java | 4 ++ 9 files changed, 53 insertions(+), 6 deletions(-) diff --git a/client/src/main/java/ru/trader/controllers/StationEditorController.java b/client/src/main/java/ru/trader/controllers/StationEditorController.java index 00169d0..7bba312 100644 --- a/client/src/main/java/ru/trader/controllers/StationEditorController.java +++ b/client/src/main/java/ru/trader/controllers/StationEditorController.java @@ -1,9 +1,12 @@ package ru.trader.controllers; +import javafx.beans.InvalidationListener; import javafx.collections.FXCollections; +import javafx.collections.ObservableList; import javafx.fxml.FXML; import javafx.scene.Parent; import javafx.scene.control.*; +import javafx.util.Callback; import javafx.util.converter.LongStringConverter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -14,6 +17,7 @@ import ru.trader.model.StationModel; import ru.trader.model.SystemModel; import ru.trader.model.support.StationUpdater; 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.TextFieldCell; @@ -78,13 +82,16 @@ public class StationEditorController { type.setConverter(new StationTypeStringConverter()); faction.setItems(FXCollections.observableArrayList(FACTION.values())); faction.setConverter(new FactionStringConverter()); + faction.valueProperty().addListener(e -> updateItems()); government.setItems(FXCollections.observableArrayList(GOVERNMENT.values())); government.setConverter(new GovernmentStringConverter()); + government.valueProperty().addListener(e -> updateItems()); economic.setItems(FXCollections.observableArrayList(ECONOMIC_TYPE.values())); economic.setConverter(new EconomicTypeStringConverter()); subEconomic.setItems(FXCollections.observableArrayList(ECONOMIC_TYPE.values())); subEconomic.setConverter(new EconomicTypeStringConverter()); items.getSelectionModel().setCellSelectionEnabled(true); + items.setRowFactory(new FakeOfferDecoratedRow()); buy.setCellFactory(EditOfferCell.forTable(new PriceStringConverter(), false)); sell.setCellFactory(EditOfferCell.forTable(new PriceStringConverter(), true)); demand.setCellFactory(TextFieldCell.forTableColumn(new LongStringConverter())); @@ -127,6 +134,13 @@ public class StationEditorController { 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){ dlg = new Dialog<>(); @@ -221,4 +235,28 @@ public class StationEditorController { public void updateFromEMDN(){ EMDNUpdater.updateFromEMDN(updater); } + + private class FakeOfferDecoratedRow extends DecoratedRowFactory { + + public FakeOfferDecoratedRow() { + super(); + } + + public FakeOfferDecoratedRow(Callback, TableRow> decorated) { + super(decorated); + } + + @Override + protected void doStyle(TableRow row, StationUpdater.FakeOffer entry) { + ObservableList 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); + } + } + } + } } diff --git a/client/src/main/java/ru/trader/model/ItemModel.java b/client/src/main/java/ru/trader/model/ItemModel.java index 5479928..bd4780b 100644 --- a/client/src/main/java/ru/trader/model/ItemModel.java +++ b/client/src/main/java/ru/trader/model/ItemModel.java @@ -148,6 +148,10 @@ public class ItemModel implements Comparable { item.setLegal(government, legal); } + public boolean isIllegal(FACTION faction, GOVERNMENT government){ + return item.isIllegal(faction, government); + } + public void refresh(){ LOG.trace("Refresh stats of itemDesc {}", this); statBuy.refresh(); diff --git a/client/src/main/java/ru/trader/view/support/cells/DecoratedCellFactory.java b/client/src/main/java/ru/trader/view/support/cells/DecoratedCellFactory.java index 8eddf72..8460414 100644 --- a/client/src/main/java/ru/trader/view/support/cells/DecoratedCellFactory.java +++ b/client/src/main/java/ru/trader/view/support/cells/DecoratedCellFactory.java @@ -18,7 +18,7 @@ public abstract class DecoratedCellFactory implements Callback cell, S entry, T item); + protected abstract void doStyle(TableCell cell, S entry, T item); @Override public final TableCell call(TableColumn param) { diff --git a/client/src/main/java/ru/trader/view/support/cells/DecoratedListCellFactory.java b/client/src/main/java/ru/trader/view/support/cells/DecoratedListCellFactory.java index 0f85cbd..5ebe9d9 100644 --- a/client/src/main/java/ru/trader/view/support/cells/DecoratedListCellFactory.java +++ b/client/src/main/java/ru/trader/view/support/cells/DecoratedListCellFactory.java @@ -39,7 +39,7 @@ public abstract class DecoratedListCellFactory implements Callback cell, T item); + protected abstract void doStyle(ListCell cell, T item); @Override public final ListCell call(ListView param) { diff --git a/client/src/main/java/ru/trader/view/support/cells/DecoratedRowFactory.java b/client/src/main/java/ru/trader/view/support/cells/DecoratedRowFactory.java index 33b0704..c5e7e8a 100644 --- a/client/src/main/java/ru/trader/view/support/cells/DecoratedRowFactory.java +++ b/client/src/main/java/ru/trader/view/support/cells/DecoratedRowFactory.java @@ -19,7 +19,7 @@ public abstract class DecoratedRowFactory implements Callback, T this.decorated = decorated; } - abstract void doStyle(TableRow row, S entry); + protected abstract void doStyle(TableRow row, S entry); @Override public final TableRow call(TableView param) { diff --git a/client/src/main/java/ru/trader/view/support/cells/OfferDecoratedListCell.java b/client/src/main/java/ru/trader/view/support/cells/OfferDecoratedListCell.java index 895ccdd..af61a09 100644 --- a/client/src/main/java/ru/trader/view/support/cells/OfferDecoratedListCell.java +++ b/client/src/main/java/ru/trader/view/support/cells/OfferDecoratedListCell.java @@ -22,7 +22,7 @@ public class OfferDecoratedListCell extends DecoratedListCellFactory } @Override - void doStyle(ListCell cell, OfferModel item) { + protected void doStyle(ListCell cell, OfferModel item) { ObservableList styles = cell.getStyleClass(); styles.remove(ViewUtils.ILLEGAL_ITEM_STYLE); if (item != null && item.isIllegal()){ diff --git a/client/src/main/java/ru/trader/view/support/cells/OfferDecoratedRow.java b/client/src/main/java/ru/trader/view/support/cells/OfferDecoratedRow.java index 90b656e..5447cc0 100644 --- a/client/src/main/java/ru/trader/view/support/cells/OfferDecoratedRow.java +++ b/client/src/main/java/ru/trader/view/support/cells/OfferDecoratedRow.java @@ -9,6 +9,7 @@ import ru.trader.view.support.ViewUtils; public class OfferDecoratedRow extends DecoratedRowFactory { public OfferDecoratedRow() { + super(); } public OfferDecoratedRow(Callback, TableRow> decorated) { @@ -16,7 +17,7 @@ public class OfferDecoratedRow extends DecoratedRowFactory { } @Override - void doStyle(TableRow row, OfferModel entry) { + protected void doStyle(TableRow row, OfferModel entry) { ObservableList styles = row.getStyleClass(); styles.remove(ViewUtils.ILLEGAL_ITEM_STYLE); if (entry != null && entry.isIllegal()){ diff --git a/client/src/main/java/ru/trader/view/support/cells/OrderDecoratedListCell.java b/client/src/main/java/ru/trader/view/support/cells/OrderDecoratedListCell.java index 01eed4d..3a3c7f7 100644 --- a/client/src/main/java/ru/trader/view/support/cells/OrderDecoratedListCell.java +++ b/client/src/main/java/ru/trader/view/support/cells/OrderDecoratedListCell.java @@ -17,7 +17,7 @@ public class OrderDecoratedListCell extends DecoratedListCellFactory } @Override - void doStyle(ListCell cell, OrderModel item) { + protected void doStyle(ListCell cell, OrderModel item) { ObservableList styles = cell.getStyleClass(); styles.remove(ViewUtils.ILLEGAL_ITEM_STYLE); if (item != null && item.isIllegal()){ diff --git a/core/src/main/java/ru/trader/core/Item.java b/core/src/main/java/ru/trader/core/Item.java index 4c2bbf1..d881b12 100644 --- a/core/src/main/java/ru/trader/core/Item.java +++ b/core/src/main/java/ru/trader/core/Item.java @@ -12,6 +12,10 @@ public interface Item extends Comparable { default boolean isIllegal(Vendor vendor){ FACTION faction = vendor.getFaction(); GOVERNMENT government = vendor.getGovernment(); + return isIllegal(faction, government); + } + + default boolean isIllegal(FACTION faction, GOVERNMENT government){ if (faction != null && getLegalFactions().contains(faction)) return false; if (government != null && getLegalGovernments().contains(government)) return false; return faction != null && getIllegalFactions().contains(faction) ||