Search in sources :

Example 1 with ExportImportSelectionSource

use of net.parostroj.timetable.gui.components.ExportImportSelectionSource in project grafikon by jub77.

the class ExportAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent event) {
    final Component parent = GuiComponentUtils.getTopLevelComponent(event.getSource());
    ExportImportSelectionSource source = ExportImportSelectionSource.fromDiagramToLibrary(model.getDiagram());
    exportDialog.setSelectionSource(source);
    exportDialog.setLocationRelativeTo(parent);
    exportDialog.setVisible(true);
    boolean cancelled = exportDialog.isCancelled();
    if (!cancelled) {
        // saving library
        try (CloseableFileChooser gtmlFileChooser = FileChooserFactory.getInstance().getFileChooser(FileChooserFactory.Type.GTML)) {
            int retVal = gtmlFileChooser.showSaveDialog(parent);
            if (retVal == JFileChooser.APPROVE_OPTION) {
                ActionContext c = new ActionContext(parent);
                ModelAction action = getSaveModelAction(c, gtmlFileChooser.getSelectedFile(), parent, this.createLibrary(exportDialog.getSelection()));
                ActionHandler.getInstance().execute(action);
            }
        }
    }
}
Also used : EventDispatchAfterModelAction(net.parostroj.timetable.gui.actions.execution.EventDispatchAfterModelAction) ModelAction(net.parostroj.timetable.gui.actions.execution.ModelAction) CloseableFileChooser(net.parostroj.timetable.gui.actions.impl.CloseableFileChooser) ExportImportSelectionSource(net.parostroj.timetable.gui.components.ExportImportSelectionSource) Component(java.awt.Component) ActionContext(net.parostroj.timetable.gui.actions.execution.ActionContext)

Example 2 with ExportImportSelectionSource

use of net.parostroj.timetable.gui.components.ExportImportSelectionSource 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)

Aggregations

ExportImportSelectionSource (net.parostroj.timetable.gui.components.ExportImportSelectionSource)2 Component (java.awt.Component)1 ActionContext (net.parostroj.timetable.gui.actions.execution.ActionContext)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 ExportImportSelectionDialog (net.parostroj.timetable.gui.dialogs.ExportImportSelectionDialog)1 TrainDiagram (net.parostroj.timetable.model.TrainDiagram)1 Library (net.parostroj.timetable.model.library.Library)1