Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » [SOLVED] How to delete references and without deleting elements?
[SOLVED] How to delete references and without deleting elements? [message #740504] Tue, 18 October 2011 15:28 Go to next message
Iban Ayestaran is currently offline Iban AyestaranFriend
Messages: 58
Registered: September 2011
Member
Hello everybody,

I have an ecore metamodel that has some objects called 'tasks' and some other objects called 'mode_abstracts', as you can see in the attached figure. 'mode_abstracts' have references to tasks, so many different 'mode_abstracts' may have a reference to one task. Everything works more or less ok, but the problem is that if I delete a reference to a task from the diagram, the 'task' element is deleted instead of just the reference, so all the other modes that reference the task get damaged (in the gmfmap file I have tasks inside mode_abstracts, as child references).

Looking for an answer in the forums, it seems that the solution is to customize the "getDestroyElementCommand(DestroyElementRequest req)" code in the "TaskItemSemanticEditPolicy.java" file. I customized as shown below, but the only thing I get with that code is that the element is correctly deleted in the diagram but it stands in the model, so when I close and reopen the diagram file, the task appears again as before.

Does anybody know what am I missing?

	protected Command getDestroyElementCommand(DestroyElementRequest req) {
		CompositeTransactionalCommand cmd = new CompositeTransactionalCommand(getEditingDomain(), null);
		DestroyReferenceRequest request = new DestroyReferenceRequest(
				getEditingDomain(),
				req.getContainer(),
				IbanPackage.eINSTANCE.getMode_abstract_Tasks(),
				req.getElementToDestroy(),
				false);
		cmd.add(new DestroyReferenceCommand(request));
		
		return getGEFWrapper(cmd.reduce());
	}


Thanks in advance!
  • Attachment: ecore.png
    (Size: 5.45KB, Downloaded 107 times)

[Updated on: Wed, 26 October 2011 12:36]

Report message to a moderator

Re: How to delete references and without deleting elements? [message #740692 is a reply to message #740504] Tue, 18 October 2011 19:45 Go to previous messageGo to next message
Svyatoslav Kovalsky is currently offline Svyatoslav KovalskyFriend
Messages: 12
Registered: October 2011
Junior Member
Hello,

To be able to have model elements without corresponding diagram elements, you should make diagram non-synchronized
- this is driven with GenDiagram#synchronized property.
Once you'll make your diagram non-synchronized, "Delete from Diagram" action will appear
(check org.eclipse.gmf.runtime.diagram.ui.actions.internal.DeleteFromDiagramAction).

Regards,
Svyatoslav Kovalsky
at Montages Think Tank, Prague, Czech Republic
Montages AG, Zurich, Switzerland
Re: How to delete references and without deleting elements? [message #741200 is a reply to message #740692] Wed, 19 October 2011 09:36 Go to previous messageGo to next message
Iban Ayestaran is currently offline Iban AyestaranFriend
Messages: 58
Registered: September 2011
Member
Hello,

maybe I didn't explain it very well, but that's not what I am looking for. My diagram must be synchronized with the model.

My problem is the following. Imagine that my example model looks like the following:

IbanProgram
|--ModeAbstract modename
___|--Task task1name
___|--Task task2name
___|--Task task3name
|--ModeAbstract mode2name
___|--Task task1name
___|--Task task3name
|--Task task1name
|--Task task2name
|--Task task3name

That is, I have defined 2 modes and 3 tasks, where one mode has references to the three tasks and the other has references to two of them.

My problem is that if I don't customize the code, when I delete (for example) the reference between mode1 and task1, task1 element is also deleted, and mode2 becomes erroneous because it has a reference to task1, which does not exist any more.

Customizing the code as I showed in the first message, my diagram deletes the reference between mode1 and task1 as I want, but the model remains unchanged, so when I close and reopen the diagram file, the reference appears again.

What I want is to delete only the reference between (for expample) mode1 and task1, without deleting the task1 element, so that the mode2 remains with a reference to task1, which keeps existing as before. The perfect solution would be to check whether another reference to the task already exists in the diagram, and if not, delete also the element (in the example, if I delete the reference between mode1 and task2, task2 element should also be deleted).

A similar question is treated in http://www.eclipse.org/forums/index.php/m/225928/ , but as I said, the code customization proposed there does not work for me. Does anybody know the solution??

Iban.

[Updated on: Wed, 19 October 2011 09:37]

Report message to a moderator

[SOLVED] How to delete references and without deleting elements? [message #752549 is a reply to message #741200] Wed, 26 October 2011 12:35 Go to previous message
Iban Ayestaran is currently offline Iban AyestaranFriend
Messages: 58
Registered: September 2011
Member
Hello,
I have fixed my problem by using the following code:

protected Command getDestroyElementCommand(DestroyElementRequest req) {
		CompositeTransactionalCommand cmd = new CompositeTransactionalCommand(
				getEditingDomain(), null);
		DestroyReferenceRequest request = new DestroyReferenceRequest(
				getEditingDomain(), 
				((View)getHost().getParent().getModel()).getElement(),
				GioLikePackage.eINSTANCE.getMode_abstract_Tasks(),
				req.getElementToDestroy(),
				false);
		cmd.add(new DestroyReferenceCommand(request));	
		return getGEFWrapper(cmd.reduce());
	}


I just post this in case someone finds it useful.

Bye!
Previous Topic:List of vertical labels in a container
Next Topic:Setting attribute by drag&drop
Goto Forum:
  


Current Time: Mon Dec 22 18:00:29 GMT 2014

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

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