Archived
0

add update from EMDN button

This commit is contained in:
iMoHax
2014-08-28 17:21:37 +04:00
parent f426a2d34e
commit 98c6df4546
12 changed files with 396 additions and 109 deletions

View File

@@ -69,6 +69,7 @@ public class Main extends Application {
if (res == Dialog.Actions.YES) World.save();
else if (res == Dialog.Actions.CANCEL) we.consume();
}
World.shutdown();
Screeners.closeAll();
} catch (FileNotFoundException | UnsupportedEncodingException | XMLStreamException e) {
LOG.error("Ошибка при сохранении",e);

View File

@@ -3,6 +3,8 @@ package ru.trader;
import org.xml.sax.SAXException;
import ru.trader.core.Market;
import ru.trader.core.SimpleMarket;
import ru.trader.emdn.EMDN;
import ru.trader.emdn.Station;
import ru.trader.model.ModelFabrica;
import ru.trader.store.Store;
import ru.trader.store.XSSFImporter;
@@ -17,12 +19,14 @@ import java.io.UnsupportedEncodingException;
public class World {
private static Market world;
private static final String STORE_FILE="world.xml";
private final static EMDN emdn = new EMDN("tcp://firehose.elite-market-data.net:9050", true);
static {
try {
File file = new File(STORE_FILE);
if (file.exists()) world = Store.loadFromFile(file);
else world = new SimpleMarket();
emdn.start();
} catch (ParserConfigurationException | SAXException | IOException e) {
throw new RuntimeException(e);
}
@@ -44,4 +48,11 @@ public class World {
return world;
}
public static Station getEMDN(String name){
return emdn.getVendor(name);
}
public static void shutdown(){
emdn.shutdown();
}
}

View File

@@ -15,7 +15,10 @@ import org.controlsfx.control.action.Action;
import org.controlsfx.dialog.Dialog;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.trader.World;
import ru.trader.core.OFFER_TYPE;
import ru.trader.emdn.ItemData;
import ru.trader.emdn.Station;
import ru.trader.model.*;
import ru.trader.model.support.BindingsHelper;
import ru.trader.view.support.Localization;
@@ -221,6 +224,21 @@ public class VendorEditorController {
}
}
public void updateFromEMDN(){
Station emdnData = World.getEMDN(vendor.getName());
LOG.debug("Update from EMDN");
if (emdnData == null) return;
for (FakeOffer offer : items.getItems()) {
ItemData data = emdnData.getData(offer.item.getId());
LOG.debug("Update item {} to {}", offer.item.getName(), data);
if (data != null){
offer.setBprice(data.getBuy());
offer.setSprice(data.getSell());
}
}
}
public class FakeOffer {
private final ItemModel item;
private DoubleProperty sprice;

View File

@@ -20,6 +20,8 @@ public class ItemModel{
public String getName() {return name != null ? name.get() : item.getName();}
public String getId() {return item.getName();}
public void setName(String value) {
LOG.info("Change name of item {} to {}", item, name);
market.updateName(this, value);

View File

@@ -26,6 +26,7 @@
<Button prefWidth="30" onAction="#up"><graphic><Glyph text="FontAwesome|ARROW_UP"/></graphic></Button>
<Button prefWidth="30" onAction="#down"><graphic><Glyph text="FontAwesome|ARROW_DOWN"/></graphic></Button>
<Button prefWidth="30" onAction="#add"><graphic><Glyph text="FontAwesome|PLUS"/></graphic></Button>
<Button prefWidth="30" onAction="#updateFromEMDN"><graphic><Glyph text="FontAwesome|REFRESH"/></graphic></Button>
</VBox>
<TableView fx:id="items" prefWidth="375.0" editable="true" GridPane.columnIndex="1" GridPane.rowIndex="2">
<columns>