Search in sources :

Example 16 with IDiagramModelReference

use of com.archimatetool.model.IDiagramModelReference 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)

Example 17 with IDiagramModelReference

use of com.archimatetool.model.IDiagramModelReference in project archi by archimatetool.

the class CanvasModelEditPartFactory method createEditPart.

public EditPart createEditPart(EditPart context, Object model) {
    if (model == null) {
        return null;
    }
    EditPart child = null;
    IObjectUIProvider provider = null;
    // Diagram Model Reference is an exception to the rule
    if (model instanceof IDiagramModelReference) {
        child = new CanvasDiagramModelReferenceEditPart();
    } else if (model instanceof EObject) {
        provider = ObjectUIFactory.INSTANCE.getProviderForClass(((EObject) model).eClass());
        if (provider != null) {
            child = provider.createEditPart();
        }
    }
    /*
         * It's better to return an Empty Edit Part in case of a corrupt model.
         * Returning null is disastrous and means the Diagram View won't open.
         */
    if (child == null) {
        // $NON-NLS-1$
        Logger.logError("Could not create EditPart for: " + model);
        child = new EmptyEditPart();
    }
    // Set the Model in the Edit part
    child.setModel(model);
    return child;
}
Also used : IDiagramModelReference(com.archimatetool.model.IDiagramModelReference) EObject(org.eclipse.emf.ecore.EObject) EditPart(org.eclipse.gef.EditPart) EmptyEditPart(com.archimatetool.editor.diagram.editparts.diagram.EmptyEditPart) EmptyEditPart(com.archimatetool.editor.diagram.editparts.diagram.EmptyEditPart) IObjectUIProvider(com.archimatetool.editor.ui.factory.IObjectUIProvider)

Aggregations

IDiagramModelReference (com.archimatetool.model.IDiagramModelReference)17 IDiagramModel (com.archimatetool.model.IDiagramModel)7 Test (org.junit.Test)7 EObject (org.eclipse.emf.ecore.EObject)5 EmptyEditPart (com.archimatetool.editor.diagram.editparts.diagram.EmptyEditPart)4 EditPart (org.eclipse.gef.EditPart)4 IArchimateModel (com.archimatetool.model.IArchimateModel)3 IDiagramModelGroup (com.archimatetool.model.IDiagramModelGroup)3 DiagramConnectionEditPart (com.archimatetool.editor.diagram.editparts.DiagramConnectionEditPart)2 IObjectUIProvider (com.archimatetool.editor.ui.factory.IObjectUIProvider)2 IArchimateConcept (com.archimatetool.model.IArchimateConcept)2 IDiagramModelArchimateConnection (com.archimatetool.model.IDiagramModelArchimateConnection)2 IDiagramModelArchimateObject (com.archimatetool.model.IDiagramModelArchimateObject)2 IDiagramModelComponent (com.archimatetool.model.IDiagramModelComponent)2 IDiagramModelNote (com.archimatetool.model.IDiagramModelNote)2 IDiagramModelObject (com.archimatetool.model.IDiagramModelObject)2 ArrayList (java.util.ArrayList)2 ICanvasModel (com.archimatetool.canvas.model.ICanvasModel)1 DiagramImageEditPart (com.archimatetool.editor.diagram.editparts.diagram.DiagramImageEditPart)1 IArchiveManager (com.archimatetool.editor.model.IArchiveManager)1