add powerplay import to client
This commit is contained in:
@@ -13,6 +13,7 @@ import ru.trader.ServicesManager;
|
||||
import ru.trader.World;
|
||||
import ru.trader.model.*;
|
||||
import ru.trader.services.MaddavoParserTask;
|
||||
import ru.trader.services.PowerPlayParserTask;
|
||||
import ru.trader.view.support.Localization;
|
||||
import ru.trader.view.support.ViewUtils;
|
||||
|
||||
@@ -309,6 +310,24 @@ public class MainController {
|
||||
});
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void importPowerPlaySystems() {
|
||||
chooseFile(new FileChooser.ExtensionFilter("PowerPlay StarSystems file (StarSystems*.csv)","StarSystems*.csv"), file -> {
|
||||
PowerPlayParserTask task = new PowerPlayParserTask(file, PowerPlayParserTask.FILE_TYPE.SYSTEMS, World.getMarket());
|
||||
Screeners.showProgress(Localization.getString("message.import.systems"), task, () -> ViewUtils.doFX(this::reload));
|
||||
});
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void importPowerPlayPrediction() {
|
||||
chooseFile(new FileChooser.ExtensionFilter("PowerPlay Preparation file (Prediction*.csv)","Prediction*.csv"), file -> {
|
||||
PowerPlayParserTask task = new PowerPlayParserTask(file, PowerPlayParserTask.FILE_TYPE.PREDICTION, World.getMarket());
|
||||
Screeners.showProgress(Localization.getString("message.import.systems"), task, () -> ViewUtils.doFX(this::reload));
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void chooseFile(FileChooser.ExtensionFilter filter, Consumer<File> action) {
|
||||
FileChooser fileChooser = new FileChooser();
|
||||
fileChooser.getExtensionFilters().add(filter);
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package ru.trader.services;
|
||||
|
||||
import javafx.concurrent.Task;
|
||||
import ru.trader.core.Market;
|
||||
import ru.trader.powerplay.PPParser;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class PowerPlayParserTask extends Task<Void> {
|
||||
|
||||
private final File file;
|
||||
private final FILE_TYPE type;
|
||||
private final PPParser parser;
|
||||
|
||||
public PowerPlayParserTask(File file, FILE_TYPE type, Market market) {
|
||||
this.file = file;
|
||||
this.type = type;
|
||||
this.parser = new PPParser(market);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void cancelled() {
|
||||
parser.cancel();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void call() throws Exception {
|
||||
|
||||
switch (type){
|
||||
|
||||
case SYSTEMS: parser.parseSystems(file);
|
||||
break;
|
||||
case PREDICTION: parser.parsePrediction(file);
|
||||
break;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public enum FILE_TYPE {
|
||||
SYSTEMS, PREDICTION
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,10 @@
|
||||
<MenuItem text="%market.stations" onAction="#impMadStations"/>
|
||||
<MenuItem text="%market.offers" onAction="#impMadOffers"/>
|
||||
</Menu>
|
||||
<Menu text="PowerPlay">
|
||||
<MenuItem text="StarSystem" onAction="#importPowerPlaySystems"/>
|
||||
<MenuItem text="Prediction" onAction="#importPowerPlayPrediction"/>
|
||||
</Menu>
|
||||
<MenuItem text="XML" onAction="#importWorld"/>
|
||||
<MenuItem text="EDCE JSON" onAction="#importEDCE"/>
|
||||
</Menu>
|
||||
|
||||
Reference in New Issue
Block a user