Search in sources :

Example 1 with ModelChecker

use of com.archimatetool.editor.model.ModelChecker in project archi by archimatetool.

the class EditorModelManager method saveModel.

@Override
public boolean saveModel(IArchimateModel model) throws IOException {
    // Check integrity
    ModelChecker checker = new ModelChecker(model);
    if (!checker.checkAll()) {
        if (PlatformUI.isWorkbenchRunning()) {
            checker.showErrorDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
        }
        return false;
    }
    // First time to save...
    if (model.getFile() == null) {
        File file = askSaveModel();
        if (file == null) {
            // cancelled
            return false;
        }
        model.setFile(file);
    }
    File file = model.getFile();
    // Save backup (if set in Preferences)
    if (Preferences.STORE.getBoolean(IPreferenceConstants.BACKUP_ON_SAVE) && file.exists()) {
        // $NON-NLS-1$
        FileUtils.copyFile(file, new File(model.getFile().getAbsolutePath() + ".bak"), false);
    }
    // Set model version
    model.setVersion(ModelVersion.VERSION);
    // Use Archive Manager to save contents
    IArchiveManager archiveManager = (IArchiveManager) model.getAdapter(IArchiveManager.class);
    archiveManager.saveModel();
    // Set CommandStack Save point
    CommandStack stack = (CommandStack) model.getAdapter(CommandStack.class);
    stack.markSaveLocation();
    // Send notification to Tree
    firePropertyChange(model, COMMAND_STACK_CHANGED, true, false);
    // Set all diagram models to be marked as "saved" - this is for the editor view persistence
    markDiagramModelsAsSaved(model);
    firePropertyChange(this, PROPERTY_MODEL_SAVED, null, model);
    return true;
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) ModelChecker(com.archimatetool.editor.model.ModelChecker) IArchiveManager(com.archimatetool.editor.model.IArchiveManager) File(java.io.File)

Aggregations

IArchiveManager (com.archimatetool.editor.model.IArchiveManager)1 ModelChecker (com.archimatetool.editor.model.ModelChecker)1 File (java.io.File)1 CommandStack (org.eclipse.gef.commands.CommandStack)1