Search in sources :

Example 1 with ModelAction

use of net.parostroj.timetable.gui.actions.execution.ModelAction 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 ModelAction

use of net.parostroj.timetable.gui.actions.execution.ModelAction in project grafikon by jub77.

the class MainFrameWindowListener method windowClosing.

@Override
public void windowClosing(WindowEvent e) {
    super.windowClosing(e);
    ModelAction action = ExitAction.getExitAction(parent, model, false);
    ActionHandler.getInstance().execute(action);
}
Also used : ModelAction(net.parostroj.timetable.gui.actions.execution.ModelAction)

Example 3 with ModelAction

use of net.parostroj.timetable.gui.actions.execution.ModelAction in project grafikon by jub77.

the class ExportAction method getSaveModelAction.

public static ModelAction getSaveModelAction(ActionContext context, final File file, final Component parent, final Library library) {
    ModelAction action = new EventDispatchAfterModelAction(context) {

        private String errorMessage;

        @Override
        protected void backgroundAction() {
            setWaitMessage(ResourceLoader.getString("wait.message.savelibrary"));
            setWaitDialogVisible(true);
            long time = System.currentTimeMillis();
            try {
                ModelUtils.saveLibraryData(library, file);
            } catch (LSException e) {
                log.warn("Error saving library.", e);
                errorMessage = ResourceLoader.getString("dialog.error.saving");
            } catch (Exception e) {
                log.warn("Error saving library.", e);
                errorMessage = ResourceLoader.getString("dialog.error.saving");
            } finally {
                log.debug("Saved in {}ms", System.currentTimeMillis() - time);
                setWaitDialogVisible(false);
            }
        }

        @Override
        protected void eventDispatchActionAfter() {
            if (errorMessage != null) {
                GuiComponentUtils.showError(errorMessage + " " + file.getName(), parent);
            }
        }
    };
    return action;
}
Also used : EventDispatchAfterModelAction(net.parostroj.timetable.gui.actions.execution.EventDispatchAfterModelAction) ModelAction(net.parostroj.timetable.gui.actions.execution.ModelAction) EventDispatchAfterModelAction(net.parostroj.timetable.gui.actions.execution.EventDispatchAfterModelAction) LSException(net.parostroj.timetable.model.ls.LSException) LSException(net.parostroj.timetable.model.ls.LSException)

Aggregations

ModelAction (net.parostroj.timetable.gui.actions.execution.ModelAction)3 EventDispatchAfterModelAction (net.parostroj.timetable.gui.actions.execution.EventDispatchAfterModelAction)2 Component (java.awt.Component)1 ActionContext (net.parostroj.timetable.gui.actions.execution.ActionContext)1 CloseableFileChooser (net.parostroj.timetable.gui.actions.impl.CloseableFileChooser)1 ExportImportSelectionSource (net.parostroj.timetable.gui.components.ExportImportSelectionSource)1 LSException (net.parostroj.timetable.model.ls.LSException)1