use of com.archimatetool.editor.model.IArchiveManager in project archi by archimatetool.
the class SaveModelProvider method saveModel.
private void saveModel(IArchimateModel model, File file) throws IOException {
// Set model version
model.setVersion(ModelVersion.VERSION);
// File
model.setFile(file);
// 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();
}
use of com.archimatetool.editor.model.IArchiveManager 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;
}
use of com.archimatetool.editor.model.IArchiveManager in project archi by archimatetool.
the class EditorModelManager method createNewArchiveManager.
/**
* Create a new ArchiveManager for the model
*/
private IArchiveManager createNewArchiveManager(IArchimateModel model) {
IArchiveManager archiveManager = IArchiveManager.FACTORY.createArchiveManager(model);
model.setAdapter(IArchiveManager.class, archiveManager);
// Load images now
try {
archiveManager.loadImages();
} catch (IOException ex) {
// $NON-NLS-1$
Logger.logError("Could not load images", ex);
ex.printStackTrace();
}
return archiveManager;
}
use of com.archimatetool.editor.model.IArchiveManager in project archi by archimatetool.
the class DiagramModelImageSection method setImage.
protected void setImage(Object selected) {
String path = null;
try {
// User selected a file
if (selected instanceof File) {
File file = (File) selected;
if (!file.exists() || !file.canRead()) {
return;
}
IArchiveManager archiveManager = (IArchiveManager) ((IAdapter) getFirstSelectedObject()).getAdapter(IArchiveManager.class);
path = archiveManager.addImageFromFile(file);
} else // User selected a Gallery image path
if (selected instanceof String) {
path = (String) selected;
} else // User selected nothing
{
return;
}
} catch (IOException ex) {
ex.printStackTrace();
MessageDialog.openError(getPart().getSite().getShell(), Messages.DiagramModelImageSection_5, Messages.DiagramModelImageSection_6);
return;
}
CompoundCommand result = new CompoundCommand();
for (EObject dmo : getEObjects()) {
if (isAlive(dmo)) {
Command cmd = new EObjectFeatureCommand(Messages.DiagramModelImageSection_7, dmo, IArchimatePackage.Literals.DIAGRAM_MODEL_IMAGE_PROVIDER__IMAGE_PATH, path);
if (cmd.canExecute()) {
result.add(cmd);
}
}
}
executeCommand(result.unwrap());
}
use of com.archimatetool.editor.model.IArchiveManager in project archi by archimatetool.
the class EditorModelManagerTests method createNewModel_IsValid.
@Test
public void createNewModel_IsValid() {
IArchimateModel model = editorModelManager.createNewModel();
assertNotNull(model);
// Has default folders
assertFalse(model.getFolders().isEmpty());
// Has One Default View
// $NON-NLS-1$
assertTrue(model.getFolder(FolderType.DIAGRAMS).getElements().get(0) instanceof IArchimateDiagramModel);
// Has a Command Stack
assertTrue(model.getAdapter(CommandStack.class) instanceof CommandStack);
// Has an Archive Manager
assertTrue(model.getAdapter(IArchiveManager.class) instanceof IArchiveManager);
// Has an ECore Adapter
assertTrue(hasECoreAdapter(model));
}
Aggregations