implement clear, export, import market
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package ru.trader;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.xml.sax.SAXException;
|
||||
import ru.trader.core.Market;
|
||||
import ru.trader.core.MarketAnalyzer;
|
||||
@@ -17,6 +19,7 @@ import java.io.UnsupportedEncodingException;
|
||||
public class World {
|
||||
private static Market world;
|
||||
private static final String STORE_FILE="world.xml";
|
||||
private final static Logger LOG = LoggerFactory.getLogger(World.class);
|
||||
|
||||
static {
|
||||
try {
|
||||
@@ -33,11 +36,24 @@ public class World {
|
||||
world.commit();
|
||||
}
|
||||
|
||||
public static void saveTo(File file) throws FileNotFoundException, UnsupportedEncodingException, XMLStreamException {
|
||||
Store.saveToFile(world, file);
|
||||
world.commit();
|
||||
}
|
||||
|
||||
public static void imp(File file) throws IOException, SAXException {
|
||||
LOG.info("Import from {}", file.getName());
|
||||
XSSFImporter xssfImporter = new XSSFImporter(file);
|
||||
world = xssfImporter.doImport();
|
||||
}
|
||||
|
||||
public static void impXml(File file) throws ParserConfigurationException, SAXException, IOException {
|
||||
LOG.info("Import from {}", file.getName());
|
||||
Market market = Store.loadFromFile(file);
|
||||
world.add(market);
|
||||
}
|
||||
|
||||
|
||||
public static Market getMarket() {
|
||||
return world;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import ru.trader.World;
|
||||
import ru.trader.model.*;
|
||||
import ru.trader.view.support.Localization;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
@@ -111,19 +112,83 @@ public class MainController {
|
||||
public void importWorld(ActionEvent actionEvent) {
|
||||
try {
|
||||
FileChooser fileChooser = new FileChooser();
|
||||
FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("Excel files (*.xlsx)", "*.xlsx");
|
||||
FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("XML bd files (*.xml)", "*.xml");
|
||||
fileChooser.getExtensionFilters().add(extFilter);
|
||||
fileChooser.setInitialDirectory(new File("."));
|
||||
File file = fileChooser.showOpenDialog(null);
|
||||
if (file !=null) {
|
||||
World.imp(file);
|
||||
World.impXml(file);
|
||||
reload();
|
||||
}
|
||||
} catch (SAXException | IOException e) {
|
||||
} catch (ParserConfigurationException | SAXException | IOException e) {
|
||||
LOG.error("Error on import file", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void exportWorld(ActionEvent actionEvent) {
|
||||
try {
|
||||
FileChooser fileChooser = new FileChooser();
|
||||
FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("XML bd files (*.xml)", "*.xml");
|
||||
fileChooser.getExtensionFilters().add(extFilter);
|
||||
fileChooser.setInitialDirectory(new File("."));
|
||||
File file = fileChooser.showSaveDialog(null);
|
||||
if (file !=null) {
|
||||
World.saveTo(file);
|
||||
reload();
|
||||
}
|
||||
} catch (FileNotFoundException | UnsupportedEncodingException | XMLStreamException e) {
|
||||
LOG.error("Error on save as file", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void clear(ActionEvent actionEvent){
|
||||
Action res = Screeners.showConfirm(String.format(Localization.getString("dialog.confirm.remove"), Localization.getString("market.all")));
|
||||
if (res == Dialog.ACTION_YES) {
|
||||
market.clear();
|
||||
reload();
|
||||
}
|
||||
}
|
||||
|
||||
public void clearOffers(ActionEvent actionEvent){
|
||||
Action res = Screeners.showConfirm(String.format(Localization.getString("dialog.confirm.remove"), Localization.getString("market.offers")));
|
||||
if (res == Dialog.ACTION_YES) {
|
||||
market.clearOffers();
|
||||
reload();
|
||||
}
|
||||
}
|
||||
|
||||
public void clearStations(ActionEvent actionEvent){
|
||||
Action res = Screeners.showConfirm(String.format(Localization.getString("dialog.confirm.remove"), Localization.getString("market.stations")));
|
||||
if (res == Dialog.ACTION_YES) {
|
||||
market.clearStations();
|
||||
reload();
|
||||
}
|
||||
}
|
||||
|
||||
public void clearSystems(ActionEvent actionEvent){
|
||||
Action res = Screeners.showConfirm(String.format(Localization.getString("dialog.confirm.remove"), Localization.getString("market.systems")));
|
||||
if (res == Dialog.ACTION_YES) {
|
||||
market.clearSystems();
|
||||
reload();
|
||||
}
|
||||
}
|
||||
|
||||
public void clearItems(ActionEvent actionEvent){
|
||||
Action res = Screeners.showConfirm(String.format(Localization.getString("dialog.confirm.remove"), Localization.getString("market.items")));
|
||||
if (res == Dialog.ACTION_YES) {
|
||||
market.clearItems();
|
||||
reload();
|
||||
}
|
||||
}
|
||||
|
||||
public void clearGroups(ActionEvent actionEvent){
|
||||
Action res = Screeners.showConfirm(String.format(Localization.getString("dialog.confirm.remove"), Localization.getString("market.groups")));
|
||||
if (res == Dialog.ACTION_YES) {
|
||||
market.clearGroups();
|
||||
reload();
|
||||
}
|
||||
}
|
||||
|
||||
public Optional<GroupModel> addGroup(){
|
||||
GroupModel group = Screeners.showAddGroup(market);
|
||||
return Optional.ofNullable(group);
|
||||
@@ -189,6 +254,7 @@ public class MainController {
|
||||
}
|
||||
|
||||
private void reload(){
|
||||
if (world != null) world.getModeler().clear();
|
||||
world = new MarketModel(World.getMarket());
|
||||
market = world;
|
||||
Screeners.reinitAll();
|
||||
|
||||
@@ -101,6 +101,8 @@ public class OffersController {
|
||||
}
|
||||
|
||||
void init(){
|
||||
station = null;
|
||||
system = null;
|
||||
MarketModel market = MainController.getMarket();
|
||||
market.getNotificator().add(new OffersChangeListener());
|
||||
systems.setItems(market.systemsProperty());
|
||||
|
||||
@@ -248,6 +248,8 @@ public class Screeners {
|
||||
|
||||
public static void reinitAll() {
|
||||
mainController.init();
|
||||
systemsEditorController.init();
|
||||
vEditorController.init();
|
||||
filterController.init();
|
||||
EMDNUpdater.setMarket(MainController.getMarket());
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ public class StationEditorController {
|
||||
init();
|
||||
}
|
||||
|
||||
private void init(){
|
||||
void init(){
|
||||
if (updater != null){
|
||||
name.textProperty().unbindBidirectional(updater.nameProperty());
|
||||
distance.numberProperty().unbindBidirectional(updater.distanceProperty());
|
||||
|
||||
@@ -94,7 +94,7 @@ public class SystemsEditorController {
|
||||
init();
|
||||
}
|
||||
|
||||
private void init(){
|
||||
void init(){
|
||||
market = MainController.getMarket();
|
||||
system1.setItems(market.systemsProperty());
|
||||
system2.setItems(market.systemsProperty());
|
||||
|
||||
@@ -203,4 +203,33 @@ public class MarketModel {
|
||||
return modeler.get(p);
|
||||
}
|
||||
|
||||
public void clear(){
|
||||
LOG.info("Clear market");
|
||||
market.clear();
|
||||
}
|
||||
|
||||
public void clearOffers(){
|
||||
LOG.info("Clear offers");
|
||||
market.clearOffers();
|
||||
}
|
||||
|
||||
public void clearStations(){
|
||||
LOG.info("Clear stations");
|
||||
market.clearVendors();
|
||||
}
|
||||
|
||||
public void clearSystems(){
|
||||
LOG.info("Clear systems");
|
||||
market.clearPlaces();
|
||||
}
|
||||
|
||||
public void clearItems(){
|
||||
LOG.info("Clear items");
|
||||
market.clearItems();
|
||||
}
|
||||
|
||||
public void clearGroups(){
|
||||
LOG.info("Clear groups");
|
||||
market.clearGroups();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user