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