use of com.archimatetool.editor.model.IArchiveManager in project archi by archimatetool.
the class EditorModelManagerTests method loadModel_File.
@Test
public void loadModel_File() {
File file = TestData.TEST_MODEL_FILE_ARCHISURANCE;
IArchimateModel model = editorModelManager.loadModel(file);
assertNotNull(model);
// File
assertEquals(file, model.getFile());
// 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));
// Is registered
assertEquals(1, editorModelManager.getModels().size());
assertTrue(editorModelManager.getModels().contains(model));
// Do it again, should be the same
IArchimateModel model2 = editorModelManager.loadModel(file);
assertEquals(model2, model);
// Is not registered twice
editorModelManager.openModel(model);
assertEquals(1, editorModelManager.getModels().size());
}
use of com.archimatetool.editor.model.IArchiveManager in project archi by archimatetool.
the class EditorModelManagerTests method openModel_Model.
@Test
public void openModel_Model() {
IArchimateModel model = IArchimateFactory.eINSTANCE.createArchimateModel();
model.setDefaults();
model.setName("Test");
editorModelManager.openModel(model);
// 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));
// Is registered
assertEquals(1, editorModelManager.getModels().size());
assertTrue(editorModelManager.getModels().contains(model));
// Is not registered twice
editorModelManager.openModel(model);
assertEquals(1, editorModelManager.getModels().size());
}
use of com.archimatetool.editor.model.IArchiveManager in project archi-modelrepository-plugin by archi-contribs.
the class GraficoModelExporter method saveImages.
/**
* Extract and save images used inside a model
*
* @param model
* @param folder
* @throws IOException
*/
private void saveImages() throws IOException {
List<String> added = new ArrayList<String>();
IArchiveManager archiveManager = (IArchiveManager) fModel.getAdapter(IArchiveManager.class);
if (archiveManager == null) {
archiveManager = IArchiveManager.FACTORY.createArchiveManager(fModel);
}
byte[] bytes;
for (Iterator<EObject> iter = fModel.eAllContents(); iter.hasNext(); ) {
EObject eObject = iter.next();
if (eObject instanceof IDiagramModelImageProvider) {
IDiagramModelImageProvider imageProvider = (IDiagramModelImageProvider) eObject;
String imagePath = imageProvider.getImagePath();
if (imagePath != null && !added.contains(imagePath)) {
bytes = archiveManager.getBytesFromEntry(imagePath);
Files.write(Paths.get(fLocalRepoFolder.getAbsolutePath() + File.separator + imagePath), bytes, StandardOpenOption.CREATE);
added.add(imagePath);
}
}
}
}
use of com.archimatetool.editor.model.IArchiveManager in project archi-modelrepository-plugin by archi-contribs.
the class LoadModelFromRepositoryProvider method loadModel.
private IArchimateModel loadModel(File folder) throws IOException {
GraficoModelImporter importer = new GraficoModelImporter(folder);
IArchimateModel model = importer.importAsModel();
if (importer.getUnresolvedObjects() != null) {
throw new IOException(Messages.LoadModelFromRepositoryProvider_8);
}
// Add an Archive Manager and load images
IArchiveManager archiveManager = IArchiveManager.FACTORY.createArchiveManager(model);
model.setAdapter(IArchiveManager.class, archiveManager);
archiveManager.loadImages();
CommandLineState.setModel(model);
return model;
}
use of com.archimatetool.editor.model.IArchiveManager in project archi by archimatetool.
the class SaveArchimateModelAsTemplateWizard method saveModelToTempFile.
private File saveModelToTempFile() throws IOException {
// $NON-NLS-1$
File tmpFile = File.createTempFile("architemplate", null);
tmpFile.deleteOnExit();
// Copy the model
IArchimateModel tempModel = EcoreUtil.copy(fModel);
tempModel.eAdapters().clear();
tempModel.setFile(tmpFile);
// Create a temp Archive Manager to save the temp model
IArchiveManager archiveManager = IArchiveManager.FACTORY.createArchiveManager(tempModel);
archiveManager.saveModel();
archiveManager.dispose();
return tmpFile;
}
Aggregations