Search in sources :

Example 1 with ExportImportSelection

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);
}
Also used : ExportImportSelection(net.parostroj.timetable.gui.components.ExportImportSelection) Library(net.parostroj.timetable.model.library.Library) TrainDiagram(net.parostroj.timetable.model.TrainDiagram)

Example 2 with ExportImportSelection

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);
    }
}
Also used : CyclicBarrier(java.util.concurrent.CyclicBarrier) Iterables(com.google.common.collect.Iterables) Logger(org.slf4j.Logger) Collection(java.util.Collection) GuiComponentUtils(net.parostroj.timetable.gui.utils.GuiComponentUtils) LoggerFactory(org.slf4j.LoggerFactory) ImportError(net.parostroj.timetable.model.imports.Import.ImportError) ModelPredicates(net.parostroj.timetable.filters.ModelPredicates) ImportComponent(net.parostroj.timetable.model.imports.ImportComponent) JOptionPane(javax.swing.JOptionPane) Collectors(java.util.stream.Collectors) Node(net.parostroj.timetable.model.Node) Consumer(java.util.function.Consumer) ExportImportSelection(net.parostroj.timetable.gui.components.ExportImportSelection) List(java.util.List) ObjectWithId(net.parostroj.timetable.model.ObjectWithId) ResourceLoader(net.parostroj.timetable.gui.utils.ResourceLoader) TrainDiagramPartImport(net.parostroj.timetable.model.imports.TrainDiagramPartImport) Map(java.util.Map) LinkedList(java.util.LinkedList) TrainType(net.parostroj.timetable.model.TrainType) TrainDiagram(net.parostroj.timetable.model.TrainDiagram) Group(net.parostroj.timetable.model.Group) Train(net.parostroj.timetable.model.Train) ImportComponent(net.parostroj.timetable.model.imports.ImportComponent) ObjectWithId(net.parostroj.timetable.model.ObjectWithId) TrainDiagram(net.parostroj.timetable.model.TrainDiagram) ExportImportSelection(net.parostroj.timetable.gui.components.ExportImportSelection) Collection(java.util.Collection) Train(net.parostroj.timetable.model.Train) TrainDiagramPartImport(net.parostroj.timetable.model.imports.TrainDiagramPartImport)

Example 3 with ExportImportSelection

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;
}
Also used : ExportImportSelection(net.parostroj.timetable.gui.components.ExportImportSelection)

Example 4 with ExportImportSelection

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();
}
Also used : CloseableFileChooser(net.parostroj.timetable.gui.actions.impl.CloseableFileChooser) ApplicationModel(net.parostroj.timetable.gui.ApplicationModel) Frame(java.awt.Frame) Logger(org.slf4j.Logger) ActionHandler(net.parostroj.timetable.gui.actions.execution.ActionHandler) ActionContext(net.parostroj.timetable.gui.actions.execution.ActionContext) GuiComponentUtils(net.parostroj.timetable.gui.utils.GuiComponentUtils) LoggerFactory(org.slf4j.LoggerFactory) EventDispatchAfterModelAction(net.parostroj.timetable.gui.actions.execution.EventDispatchAfterModelAction) FileChooserFactory(net.parostroj.timetable.gui.actions.impl.FileChooserFactory) Component(java.awt.Component) ActionEvent(java.awt.event.ActionEvent) ExportImportSelectionSource(net.parostroj.timetable.gui.components.ExportImportSelectionSource) File(java.io.File) ExportImportSelection(net.parostroj.timetable.gui.components.ExportImportSelection) AbstractAction(javax.swing.AbstractAction) ModelUtils(net.parostroj.timetable.gui.actions.impl.ModelUtils) LibraryBuilder(net.parostroj.timetable.model.library.LibraryBuilder) ExportImportSelectionBaseDialog(net.parostroj.timetable.gui.dialogs.ExportImportSelectionBaseDialog) LSException(net.parostroj.timetable.model.ls.LSException) JFileChooser(javax.swing.JFileChooser) ModelAction(net.parostroj.timetable.gui.actions.execution.ModelAction) Library(net.parostroj.timetable.model.library.Library) ResourceLoader(net.parostroj.timetable.utils.ResourceLoader) LibraryBuilder(net.parostroj.timetable.model.library.LibraryBuilder)

Aggregations

ExportImportSelection (net.parostroj.timetable.gui.components.ExportImportSelection)4 GuiComponentUtils (net.parostroj.timetable.gui.utils.GuiComponentUtils)2 TrainDiagram (net.parostroj.timetable.model.TrainDiagram)2 Library (net.parostroj.timetable.model.library.Library)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Iterables (com.google.common.collect.Iterables)1 Component (java.awt.Component)1 Frame (java.awt.Frame)1 ActionEvent (java.awt.event.ActionEvent)1 File (java.io.File)1 Collection (java.util.Collection)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 CyclicBarrier (java.util.concurrent.CyclicBarrier)1 Consumer (java.util.function.Consumer)1 Collectors (java.util.stream.Collectors)1 AbstractAction (javax.swing.AbstractAction)1 JFileChooser (javax.swing.JFileChooser)1