use of com.archimatetool.canvas.model.ICanvasModel in project archi by archimatetool.
the class CanvasModelEditPartFactoryTests method testCanvasDiagramPart.
@Test
public void testCanvasDiagramPart() {
ICanvasModel cm = ICanvasFactory.eINSTANCE.createCanvasModel();
EditPart editPart = editPartFactory.createEditPart(null, cm);
assertTrue(editPart instanceof CanvasDiagramPart);
assertEquals(cm, editPart.getModel());
}
use of com.archimatetool.canvas.model.ICanvasModel in project archi by archimatetool.
the class NewCanvasFromTemplateWizard method createNewCanvasFromTemplate.
private void createNewCanvasFromTemplate(File file) throws IncompatibleModelException, IOException {
// Ascertain if this is a zip file
boolean isArchiveFormat = IArchiveManager.FACTORY.isArchiveFile(file);
Resource resource = ArchimateResourceFactory.createNewResource(isArchiveFormat ? IArchiveManager.FACTORY.createArchiveModelURI(file) : URI.createFileURI(file.getAbsolutePath()));
// Check model compatibility
ModelCompatibility modelCompatibility = new ModelCompatibility(resource);
// Wrap in try/catch to load as much as possible
try {
resource.load(null);
} catch (IOException ex) {
// Error occured loading model. Was it a disaster?
try {
modelCompatibility.checkErrors();
}// Incompatible
catch (IncompatibleModelException ex1) {
fErrorMessage = NLS.bind(Messages.NewCanvasFromTemplateWizard_4, file) + "\n" + // $NON-NLS-1$
ex1.getMessage();
throw ex1;
}
}
// And then fix any backward compatibility issues
try {
modelCompatibility.fixCompatibility();
} catch (CompatibilityHandlerException ex) {
}
// Pull out the Canvas model
IArchimateModel templateModel = (IArchimateModel) resource.getContents().get(0);
IFolder folderViews = templateModel.getFolder(FolderType.DIAGRAMS);
ICanvasModel canvasModel = (ICanvasModel) folderViews.getElements().get(0);
// Create New UUIDs for elements...
TemplateUtils.generateNewUUIDs(canvasModel);
// Load the images from the template model's file now
if (isArchiveFormat) {
IArchiveManager archiveManager = (IArchiveManager) fFolder.getAdapter(IArchiveManager.class);
archiveManager.loadImagesFromModelFile(file);
}
Command cmd = new NewDiagramCommand(fFolder, canvasModel, Messages.NewCanvasFromTemplateWizard_5);
CommandStack commandStack = (CommandStack) fFolder.getAdapter(CommandStack.class);
commandStack.execute(cmd);
}
use of com.archimatetool.canvas.model.ICanvasModel in project archi by archimatetool.
the class SaveCanvasAsTemplateWizard method saveModelToTempFile.
private File saveModelToTempFile() throws IOException {
// $NON-NLS-1$
File tmpFile = File.createTempFile("architemplate", null);
tmpFile.deleteOnExit();
// Create a new container Archimate model
IArchimateModel tempModel = IArchimateFactory.eINSTANCE.createArchimateModel();
tempModel.setDefaults();
// Remove this after default folders have been added, as we'll generate our own IDs
tempModel.eAdapters().clear();
tempModel.setId(EcoreUtil.generateUUID());
tempModel.setFile(tmpFile);
tempModel.setVersion(ModelVersion.VERSION);
tempModel.setName(Messages.SaveCanvasAsTemplateWizard_4);
// Get the Canvas copy
ICanvasModel copyCanvas = EcoreUtil.copy(fCanvasModel);
// Remove any unsupported elements
for (Iterator<EObject> iter = copyCanvas.eAllContents(); iter.hasNext(); ) {
EObject eObject = iter.next();
if (eObject instanceof IDiagramModelReference) {
EcoreUtil.delete(eObject);
}
}
// Generate new IDs
TemplateUtils.generateNewUUIDs(copyCanvas);
// Add the canvas copy to a new Views folder
IFolder folder = tempModel.getDefaultFolderForObject(copyCanvas);
folder.getElements().add(copyCanvas);
// Use an Archive Manager to save it
IArchiveManager archiveManager = IArchiveManager.FACTORY.createArchiveManager(tempModel);
archiveManager.saveModel();
archiveManager.dispose();
return tmpFile;
}
Aggregations