Archived
0

implement illegal items indication on vendor editor screen

This commit is contained in:
iMoHax
2016-03-15 14:54:41 +03:00
parent 400f600b2c
commit be2dd6c95e
9 changed files with 53 additions and 6 deletions

View File

@@ -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<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);
}
}
}
}
}

View File

@@ -148,6 +148,10 @@ public class ItemModel implements Comparable<ItemModel> {
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();

View File

@@ -18,7 +18,7 @@ public abstract class DecoratedCellFactory<S, T> implements Callback<TableColumn
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
public final TableCell<S, T> call(TableColumn<S, T> param) {

View File

@@ -39,7 +39,7 @@ public abstract class DecoratedListCellFactory<T> implements Callback<ListView<T
this.decorated = decorated;
}
abstract void doStyle(ListCell<T> cell, T item);
protected abstract void doStyle(ListCell<T> cell, T item);
@Override
public final ListCell<T> call(ListView<T> param) {

View File

@@ -19,7 +19,7 @@ public abstract class DecoratedRowFactory<S> implements Callback<TableView<S>, T
this.decorated = decorated;
}
abstract void doStyle(TableRow<S> row, S entry);
protected abstract void doStyle(TableRow<S> row, S entry);
@Override
public final TableRow<S> call(TableView<S> param) {

View File

@@ -22,7 +22,7 @@ public class OfferDecoratedListCell extends DecoratedListCellFactory<OfferModel>
}
@Override
void doStyle(ListCell<OfferModel> cell, OfferModel item) {
protected void doStyle(ListCell<OfferModel> cell, OfferModel item) {
ObservableList<String> styles = cell.getStyleClass();
styles.remove(ViewUtils.ILLEGAL_ITEM_STYLE);
if (item != null && item.isIllegal()){

View File

@@ -9,6 +9,7 @@ import ru.trader.view.support.ViewUtils;
public class OfferDecoratedRow extends DecoratedRowFactory<OfferModel> {
public OfferDecoratedRow() {
super();
}
public OfferDecoratedRow(Callback<TableView<OfferModel>, TableRow<OfferModel>> decorated) {
@@ -16,7 +17,7 @@ public class OfferDecoratedRow extends DecoratedRowFactory<OfferModel> {
}
@Override
void doStyle(TableRow<OfferModel> row, OfferModel entry) {
protected void doStyle(TableRow<OfferModel> row, OfferModel entry) {
ObservableList<String> styles = row.getStyleClass();
styles.remove(ViewUtils.ILLEGAL_ITEM_STYLE);
if (entry != null && entry.isIllegal()){

View File

@@ -17,7 +17,7 @@ public class OrderDecoratedListCell extends DecoratedListCellFactory<OrderModel>
}
@Override
void doStyle(ListCell<OrderModel> cell, OrderModel item) {
protected void doStyle(ListCell<OrderModel> cell, OrderModel item) {
ObservableList<String> styles = cell.getStyleClass();
styles.remove(ViewUtils.ILLEGAL_ITEM_STYLE);
if (item != null && item.isIllegal()){

View File

@@ -12,6 +12,10 @@ public interface Item extends Comparable<Item> {
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) ||