Search in sources :

Example 1 with ChangesTracker

use of net.parostroj.timetable.model.changes.ChangesTracker in project grafikon by jub77.

the class ModelUtils method saveModelData.

public static void saveModelData(final ApplicationModel model, File file) throws LSException {
    // update author and date before save
    TrainDiagram diagram = model.getDiagram();
    boolean originalSkip = diagram.getAttributes().isSkipListeners();
    diagram.getAttributes().setSkipListeners(true);
    String user = model.getProgramSettings().getUserNameOrSystemUser();
    diagram.setSaveUser(user);
    final ChangesTracker tracker = diagram.getChangesTracker();
    final DiagramChangeSet set = tracker.getCurrentChangeSet();
    if (set != null && tracker.isTrackingEnabled()) {
        try {
            // do the update in event dispatch thread (because of events)
            SwingUtilities.invokeAndWait(() -> {
                tracker.updateCurrentChangeSet(set.getVersion(), user, Calendar.getInstance());
            });
        } catch (Exception e) {
            log.warn("Error updating values for current diagram change set.", e);
        }
    }
    log.info("Saving: {}", file);
    LSFile ls = LSFileFactory.getInstance().createForSave();
    ls.save(diagram, file);
    diagram.getAttributes().setSkipListeners(originalSkip);
}
Also used : LSFile(net.parostroj.timetable.model.ls.LSFile) ChangesTracker(net.parostroj.timetable.model.changes.ChangesTracker) DiagramChangeSet(net.parostroj.timetable.model.changes.DiagramChangeSet) IOException(java.io.IOException) LSException(net.parostroj.timetable.model.ls.LSException)

Aggregations

IOException (java.io.IOException)1 ChangesTracker (net.parostroj.timetable.model.changes.ChangesTracker)1 DiagramChangeSet (net.parostroj.timetable.model.changes.DiagramChangeSet)1 LSException (net.parostroj.timetable.model.ls.LSException)1 LSFile (net.parostroj.timetable.model.ls.LSFile)1