Search in sources :

Example 1 with ApplicationModelEvent

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

the class SaveAction method getSaveModelAction.

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

        private String errorMessage;

        @Override
        protected void backgroundAction() {
            setWaitMessage(ResourceLoader.getString("wait.message.savemodel"));
            setWaitDialogVisible(true);
            long time = System.currentTimeMillis();
            try {
                ModelUtils.saveModelData(model, file);
            } catch (LSException e) {
                log.warn("Error saving model.", e);
                errorMessage = ResourceLoader.getString("dialog.error.saving");
            } catch (Exception e) {
                log.warn("Error saving model.", 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);
            } else {
                model.fireEvent(new ApplicationModelEvent(ApplicationModelEventType.MODEL_SAVED, model));
            }
        }
    };
    return action;
}
Also used : ApplicationModelEvent(net.parostroj.timetable.gui.ApplicationModelEvent) LSException(net.parostroj.timetable.model.ls.LSException) LSException(net.parostroj.timetable.model.ls.LSException)

Aggregations

ApplicationModelEvent (net.parostroj.timetable.gui.ApplicationModelEvent)1 LSException (net.parostroj.timetable.model.ls.LSException)1