Search in sources :

Example 6 with IArchiveManager

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());
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) IArchiveManager(com.archimatetool.editor.model.IArchiveManager) File(java.io.File) IArchimateModel(com.archimatetool.model.IArchimateModel) Test(org.junit.Test)

Example 7 with IArchiveManager

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());
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) IArchiveManager(com.archimatetool.editor.model.IArchiveManager) IArchimateModel(com.archimatetool.model.IArchimateModel) Test(org.junit.Test)

Example 8 with IArchiveManager

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);
            }
        }
    }
}
Also used : IDiagramModelImageProvider(com.archimatetool.model.IDiagramModelImageProvider) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) IArchiveManager(com.archimatetool.editor.model.IArchiveManager)

Example 9 with IArchiveManager

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;
}
Also used : IOException(java.io.IOException) IArchiveManager(com.archimatetool.editor.model.IArchiveManager) GraficoModelImporter(org.archicontribs.modelrepository.grafico.GraficoModelImporter) IArchimateModel(com.archimatetool.model.IArchimateModel)

Example 10 with IArchiveManager

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;
}
Also used : IArchiveManager(com.archimatetool.editor.model.IArchiveManager) File(java.io.File) IArchimateModel(com.archimatetool.model.IArchimateModel)

Aggregations

IArchiveManager (com.archimatetool.editor.model.IArchiveManager)23 IArchimateModel (com.archimatetool.model.IArchimateModel)11 CommandStack (org.eclipse.gef.commands.CommandStack)9 File (java.io.File)7 IOException (java.io.IOException)5 Image (org.eclipse.swt.graphics.Image)4 EObject (org.eclipse.emf.ecore.EObject)3 Test (org.junit.Test)3 ICanvasModel (com.archimatetool.canvas.model.ICanvasModel)2 CompatibilityHandlerException (com.archimatetool.editor.model.compatibility.CompatibilityHandlerException)2 ModelCompatibility (com.archimatetool.editor.model.compatibility.ModelCompatibility)2 IFolder (com.archimatetool.model.IFolder)2 Resource (org.eclipse.emf.ecore.resource.Resource)2 Command (org.eclipse.gef.commands.Command)2 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)2 ICanvasModelImage (com.archimatetool.canvas.model.ICanvasModelImage)1 IIconic (com.archimatetool.canvas.model.IIconic)1 AddDiagramObjectCommand (com.archimatetool.editor.diagram.commands.AddDiagramObjectCommand)1 ModelChecker (com.archimatetool.editor.model.ModelChecker)1 EObjectFeatureCommand (com.archimatetool.editor.model.commands.EObjectFeatureCommand)1