use of net.parostroj.timetable.gui.components.ExportImportSelection in project grafikon by jub77.
the class OutputTemplateSelectionModelAction method action.
@Override
protected void action() {
ExportImportSelection selection = new ExportImportSelection();
selection.setImportOverwrite(true);
selection.setImportMatch(ImportMatch.NAME);
if (context.hasAttribute("library")) {
Library library = (Library) context.getAttribute("library");
selection.addItems(ImportComponent.OUTPUT_TEMPLATES, library.getItems().get(LibraryItemType.OUTPUT_TEMPLATE).stream().map(item -> item.getObject()).collect(Collectors.toList()));
} else {
TrainDiagram diagram = (TrainDiagram) context.getAttribute("diagram");
selection.addItems(ImportComponent.OUTPUT_TEMPLATES, diagram.getOutputTemplates());
}
context.setAttribute("selection", selection);
}
use of net.parostroj.timetable.gui.components.ExportImportSelection in project grafikon by jub77.
the class ImportModelAction method backgroundAction.
@Override
protected void backgroundAction() {
setWaitMessage(ResourceLoader.getString("wait.message.import"));
setWaitDialogVisible(true);
long time = System.currentTimeMillis();
try {
ExportImportSelection selection = context.getAttribute("selection", ExportImportSelection.class);
TrainDiagram diagram = context.getAttribute("diagramImport", TrainDiagram.class);
TrainImportConfig trainImportConfig = context.getAttribute("trainImport", TrainImportConfig.class);
Map<ImportComponent, Collection<ObjectWithId>> map = selection.getObjectMap();
imports = new TrainDiagramPartImport(diagram, selection.getImportMatch(), selection.isImportOverwrite());
List<ObjectWithId> list = map.values().stream().sequential().flatMap(item -> item.stream().sequential()).collect(Collectors.toList());
if (list.isEmpty()) {
return;
}
if (trainImportConfig != null && trainImportConfig.isRemoveExisting()) {
// remove existing trains in group
Consumer<ObjectWithId> deleteProcess = item -> diagram.getTrains().remove(item);
Iterable<Train> filteredTrains = Iterables.filter(diagram.getTrains(), ModelPredicates.inGroup(trainImportConfig.getToGroup()));
processItems(filteredTrains, deleteProcess);
}
// import new objects
Consumer<ObjectWithId> importProcess = item -> {
ImportComponent i = ImportComponent.getByComponentClass(item.getClass());
if (i != null) {
ObjectWithId imported = imports.importPart(item);
processImportedObject(imported, trainImportConfig);
} else {
log.warn("No import for class {}", item.getClass().getName());
}
};
processItems(list, importProcess);
} finally {
log.debug("Import finished in {}ms", System.currentTimeMillis() - time);
setWaitDialogVisible(false);
}
}
use of net.parostroj.timetable.gui.components.ExportImportSelection in project grafikon by jub77.
the class ExportImportSelectionDialog method getSelection.
@Override
public ExportImportSelection getSelection() {
ExportImportSelection selection = super.getSelection();
selection.setImportMatch(getImportMatch());
selection.setImportOverwrite(isImportOverwrite());
return selection;
}
use of net.parostroj.timetable.gui.components.ExportImportSelection in project grafikon by jub77.
the class ExportAction method createLibrary.
private Library createLibrary(ExportImportSelection selection) {
LibraryBuilder libBuilder = new LibraryBuilder(new LibraryBuilder.Config().setAddMissing(true));
selection.getObjectMap().values().stream().flatMap(item -> item.stream()).forEach(object -> libBuilder.importObject(object));
return libBuilder.build();
}
Aggregations