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;
}
Aggregations