Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » copying / Cloning a Diagram object(copying / Cloning a Diagram object)
copying / Cloning a Diagram object [message #835486] Tue, 03 April 2012 09:31
ganesh ram is currently offline ganesh ramFriend
Messages: 26
Registered: January 2012
Junior Member
This is what am trying to do.

I create a GMF Model - (this serves as a template in my usecase).
Now i want to create an instance of this model.
I have added a new menu to the right click context-menu say "Create Instance".

In the corresponding action class, i want to create an instance of this model.
The instance would look similar to the model, but with a few attributes in the "Property View" enabled.


public static Resource createDiagram(URI diagramURI, URI modelURI, final Application application, final Diagram appModelDiagram, IProgressMonitor progressMonitor) {

		TransactionalEditingDomain editingDomain = GMFEditingDomainFactory.INSTANCE.createEditingDomain();
		progressMonitor.beginTask(Messages.ApplicationDiagramEditorUtil_CreateDiagramProgressTask,3);
		
		final Resource diagramResource = editingDomain.getResourceSet().createResource(diagramURI);
		final Resource modelResource = editingDomain.getResourceSet().createResource(modelURI);

		final String diagramName = diagramURI.lastSegment();
		
		AbstractTransactionalCommand command = new AbstractTransactionalCommand(editingDomain, Messages.ApplicationDiagramEditorUtil_CreateDiagramCommandLabel,	Collections.EMPTY_LIST) {
			protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info)
					throws ExecutionException {
				
//checkpoint A				[b]Application model = application;[/b]				
//checkpoint B				modelResource.getContents().add(model);


//checkpoint C                    [b]Diagram diagram = appModelDiagram;[/b]				
				if (diagram != null) {
//checkpoint D				diagramResource.getContents().add(diagram);
					diagram.setName(diagramName);
					diagram.setElement(model);
				}
				try {
					modelResource.save(ApplicationDiagramEditorUtil.getSaveOptions());
					diagramResource.save(ApplicationDiagramEditorUtil.getSaveOptions());
				} catch (IOException e) {
					ApplicationDiagramEditorPlugin.getInstance().logError("Unable to store model and diagram resources", e); 
				}
				return CommandResult.newOKCommandResult();
			}
		};
		try {
			OperationHistoryFactory.getOperationHistory().execute(command,	new SubProgressMonitor(progressMonitor, 1), null);
		} catch (ExecutionException e) {
			ApplicationDiagramEditorPlugin.getInstance().logError("Unable to create model and diagram", e); 
		}
		setCharset(WorkspaceSynchronizer.getFile(modelResource));
		setCharset(WorkspaceSynchronizer.getFile(diagramResource));
		return diagramResource;
	}


In the lines that i have made bold (checkpoint A & C), when i create an instance, i wanted to reuse the domain and diagram objects of the Model file.
But i get the following exception at lines checkpoint B &D- "IllegalStateException Cannot modify resource set without a write transaction".

At checkpoint A, I created a new Application object and set the values from the old object to the new object and this solved the first problem.

Now to create the Diagram object for the instance, should i create a new Diagram Object using "ViewService.createDiagram()", iterate through & set all the children from the old to the new Diagram object. This seems a little complicated.
Is there any way to clone the Diagram object or reuse the diagram object ?
How do i accomplish this ?

Previous Topic:Moving figures in layout
Next Topic:Put Figures/Nodes in a fixed location in the canvas when opening the Editor?
Goto Forum:
  


Current Time: Thu Apr 25 13:43:27 GMT 2024

Powered by FUDForum. Page generated in 0.02723 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top