Search in sources :

Example 1 with Library

use of net.parostroj.timetable.model.library.Library 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 Library

use of net.parostroj.timetable.model.library.Library in project grafikon by jub77.

the class ImportSelectionModelAction method eventDispatchAction.

@Override
protected void eventDispatchAction() {
    TrainDiagram diagram = (TrainDiagram) context.getAttribute("diagram");
    Library library = (Library) context.getAttribute("library");
    boolean trainImport = context.hasAttribute("trainImport");
    TrainGroupFilter filter = (TrainGroupFilter) context.getAttribute("trainFilter");
    if (diagram != null || library != null) {
        final ExportImportSelectionDialog importDialog = new ExportImportSelectionDialog(GuiComponentUtils.getWindow(context.getLocationComponent()), true);
        ExportImportSelectionSource source;
        if (trainImport) {
            source = ExportImportSelectionSource.fromDiagramSingleTypeWithFilter(diagram, ImportComponent.TRAINS, filter::apply);
        } else {
            source = diagram != null ? ExportImportSelectionSource.fromDiagramToDiagram(diagram) : ExportImportSelectionSource.fromLibraryToDiagram(library);
        }
        importDialog.setSelectionSource(source);
        importDialog.setLocationRelativeTo(context.getLocationComponent());
        importDialog.setVisible(true);
        context.setCancelled(importDialog.isCancelled());
        if (!context.isCancelled()) {
            context.setAttribute("selection", importDialog.getSelection());
        }
    }
}
Also used : ExportImportSelectionDialog(net.parostroj.timetable.gui.dialogs.ExportImportSelectionDialog) Library(net.parostroj.timetable.model.library.Library) ExportImportSelectionSource(net.parostroj.timetable.gui.components.ExportImportSelectionSource) TrainDiagram(net.parostroj.timetable.model.TrainDiagram)

Example 3 with Library

use of net.parostroj.timetable.model.library.Library 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

Library (net.parostroj.timetable.model.library.Library)3 ExportImportSelection (net.parostroj.timetable.gui.components.ExportImportSelection)2 ExportImportSelectionSource (net.parostroj.timetable.gui.components.ExportImportSelectionSource)2 TrainDiagram (net.parostroj.timetable.model.TrainDiagram)2 Component (java.awt.Component)1 Frame (java.awt.Frame)1 ActionEvent (java.awt.event.ActionEvent)1 File (java.io.File)1 AbstractAction (javax.swing.AbstractAction)1 JFileChooser (javax.swing.JFileChooser)1 ApplicationModel (net.parostroj.timetable.gui.ApplicationModel)1 ActionContext (net.parostroj.timetable.gui.actions.execution.ActionContext)1 ActionHandler (net.parostroj.timetable.gui.actions.execution.ActionHandler)1 EventDispatchAfterModelAction (net.parostroj.timetable.gui.actions.execution.EventDispatchAfterModelAction)1 ModelAction (net.parostroj.timetable.gui.actions.execution.ModelAction)1 CloseableFileChooser (net.parostroj.timetable.gui.actions.impl.CloseableFileChooser)1 FileChooserFactory (net.parostroj.timetable.gui.actions.impl.FileChooserFactory)1 ModelUtils (net.parostroj.timetable.gui.actions.impl.ModelUtils)1 ExportImportSelectionBaseDialog (net.parostroj.timetable.gui.dialogs.ExportImportSelectionBaseDialog)1 ExportImportSelectionDialog (net.parostroj.timetable.gui.dialogs.ExportImportSelectionDialog)1