Search in sources :

Example 1 with ICanvasModel

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());
}
Also used : DiagramImageEditPart(com.archimatetool.editor.diagram.editparts.diagram.DiagramImageEditPart) DiagramConnectionEditPart(com.archimatetool.editor.diagram.editparts.DiagramConnectionEditPart) EditPart(org.eclipse.gef.EditPart) EmptyEditPart(com.archimatetool.editor.diagram.editparts.diagram.EmptyEditPart) ICanvasModel(com.archimatetool.canvas.model.ICanvasModel) Test(org.junit.Test)

Example 2 with ICanvasModel

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);
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) Resource(org.eclipse.emf.ecore.resource.Resource) CompatibilityHandlerException(com.archimatetool.editor.model.compatibility.CompatibilityHandlerException) IOException(java.io.IOException) IArchiveManager(com.archimatetool.editor.model.IArchiveManager) IncompatibleModelException(com.archimatetool.editor.model.compatibility.IncompatibleModelException) NewDiagramCommand(com.archimatetool.editor.views.tree.commands.NewDiagramCommand) NewDiagramCommand(com.archimatetool.editor.views.tree.commands.NewDiagramCommand) Command(org.eclipse.gef.commands.Command) ModelCompatibility(com.archimatetool.editor.model.compatibility.ModelCompatibility) ICanvasModel(com.archimatetool.canvas.model.ICanvasModel) IArchimateModel(com.archimatetool.model.IArchimateModel) IFolder(com.archimatetool.model.IFolder)

Example 3 with ICanvasModel

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;
}
Also used : IDiagramModelReference(com.archimatetool.model.IDiagramModelReference) EObject(org.eclipse.emf.ecore.EObject) ICanvasModel(com.archimatetool.canvas.model.ICanvasModel) IArchiveManager(com.archimatetool.editor.model.IArchiveManager) File(java.io.File) IArchimateModel(com.archimatetool.model.IArchimateModel) IFolder(com.archimatetool.model.IFolder)

Aggregations

ICanvasModel (com.archimatetool.canvas.model.ICanvasModel)3 IArchiveManager (com.archimatetool.editor.model.IArchiveManager)2 IArchimateModel (com.archimatetool.model.IArchimateModel)2 IFolder (com.archimatetool.model.IFolder)2 DiagramConnectionEditPart (com.archimatetool.editor.diagram.editparts.DiagramConnectionEditPart)1 DiagramImageEditPart (com.archimatetool.editor.diagram.editparts.diagram.DiagramImageEditPart)1 EmptyEditPart (com.archimatetool.editor.diagram.editparts.diagram.EmptyEditPart)1 CompatibilityHandlerException (com.archimatetool.editor.model.compatibility.CompatibilityHandlerException)1 IncompatibleModelException (com.archimatetool.editor.model.compatibility.IncompatibleModelException)1 ModelCompatibility (com.archimatetool.editor.model.compatibility.ModelCompatibility)1 NewDiagramCommand (com.archimatetool.editor.views.tree.commands.NewDiagramCommand)1 IDiagramModelReference (com.archimatetool.model.IDiagramModelReference)1 File (java.io.File)1 IOException (java.io.IOException)1 EObject (org.eclipse.emf.ecore.EObject)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 EditPart (org.eclipse.gef.EditPart)1 Command (org.eclipse.gef.commands.Command)1 CommandStack (org.eclipse.gef.commands.CommandStack)1 Test (org.junit.Test)1