Search in sources :

Example 21 with IArchiveManager

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

the class LoadModelFromFileProvider method loadModel.

static IArchimateModel loadModel(File file) throws IOException {
    if (file == null || !file.exists()) {
        return null;
    }
    // Ascertain if this is an archive file
    boolean useArchiveFormat = IArchiveManager.FACTORY.isArchiveFile(file);
    // Create the Resource
    Resource resource = ArchimateResourceFactory.createNewResource(useArchiveFormat ? IArchiveManager.FACTORY.createArchiveModelURI(file) : URI.createFileURI(file.getAbsolutePath()));
    // Check model compatibility
    ModelCompatibility modelCompatibility = new ModelCompatibility(resource);
    // Load model
    resource.load(null);
    IArchimateModel model = (IArchimateModel) resource.getContents().get(0);
    // And then fix any backward compatibility issues
    try {
        modelCompatibility.fixCompatibility();
    } catch (CompatibilityHandlerException ex) {
    }
    model.setFile(file);
    model.setDefaults();
    // Add an Archive Manager and load images
    IArchiveManager archiveManager = IArchiveManager.FACTORY.createArchiveManager(model);
    model.setAdapter(IArchiveManager.class, archiveManager);
    archiveManager.loadImages();
    // Add a Command Stack
    CommandStack cmdStack = new CommandStack();
    model.setAdapter(CommandStack.class, cmdStack);
    return model;
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) ModelCompatibility(com.archimatetool.editor.model.compatibility.ModelCompatibility) Resource(org.eclipse.emf.ecore.resource.Resource) CompatibilityHandlerException(com.archimatetool.editor.model.compatibility.CompatibilityHandlerException) IArchiveManager(com.archimatetool.editor.model.IArchiveManager) IArchimateModel(com.archimatetool.model.IArchimateModel)

Example 22 with IArchiveManager

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

the class IconicDelegate method updateImage.

public void updateImage() {
    disposeImage();
    if (fIconic.getImagePath() != null) {
        IArchiveManager archiveManager = (IArchiveManager) fIconic.getAdapter(IArchiveManager.class);
        Image image = null;
        try {
            image = archiveManager.createImage(fIconic.getImagePath());
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        if (image != null) {
            // If the image bounds is bigger than the maximum displayed image here then create a scaled image
            if (image.getBounds().width > IIconic.MAX_IMAGE_SIZE || image.getBounds().height > IIconic.MAX_IMAGE_SIZE) {
                fImage = ImageFactory.getScaledImage(image, IIconic.MAX_IMAGE_SIZE);
                image.dispose();
            } else // Else use original
            {
                fImage = image;
            }
        }
    }
}
Also used : IArchiveManager(com.archimatetool.editor.model.IArchiveManager) Image(org.eclipse.swt.graphics.Image)

Example 23 with IArchiveManager

use of com.archimatetool.editor.model.IArchiveManager in project archi-modelrepository-plugin by archi-contribs.

the class GraficoModelImporter method loadImages.

/**
 * Read images from images subfolder and load them into the model
 *
 * @param model
 * @param folder
 * @throws IOException
 */
private void loadImages(File folder) throws IOException {
    IArchiveManager archiveManager = IArchiveManager.FACTORY.createArchiveManager(fModel);
    byte[] bytes;
    // Add all images files
    for (File imageFile : folder.listFiles()) {
        if (imageFile.isFile()) {
            bytes = Files.readAllBytes(imageFile.toPath());
            // /!\ This must match the prefix used in
            // ArchiveManager.createArchiveImagePathname
            // $NON-NLS-1$
            archiveManager.addByteContentEntry("images/" + imageFile.getName(), bytes);
        }
    }
}
Also used : IArchiveManager(com.archimatetool.editor.model.IArchiveManager) File(java.io.File)

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