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