Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » automatically add parent node when child added
automatically add parent node when child added [message #539124] Wed, 09 June 2010 17:23 Go to next message
emil salageanu is currently offline emil salageanuFriend
Messages: 94
Registered: June 2010
Location: Nice, France
Member
Hello everybody,

Lets consider a GMF editor for an xml file like:

      <a> 
         <b> 
           <c/> 
          <b>
      <a> 



I would like to let the user add a "c" figure directly to an "a" parent (select a "c" creation tool from the palette and put it on an "a" figure ) and the "b" intermediate node (and, of course Edit part and figure) to be automatically generated so, at the end, the model to look like the xml above.

I think it should be done in the CreateCommand class for c (CCreateCommand) but an instance of this class is not created unless trying to create a "c" inside a "b" parent, which, of course, does not exist. I tried to debug in order to find the condition for the creation of the command but I did not find it.

Thanks for any clues,
Emil






Re: automatically add parent node when child added [message #539579 is a reply to message #539124] Fri, 11 June 2010 12:17 Go to previous messageGo to next message
emil salageanu is currently offline emil salageanuFriend
Messages: 94
Registered: June 2010
Location: Nice, France
Member
I have performed some tests on the subject, I still did not find a way to do what I need.

Just for Test:
Lets automatically create a "C" child when a "B" element is created.

This works fine, and it is done by modifying the BCreateCommand#doExecuteWithResult() method and creating the c emf element as child of b. Works fine, we can see a "B" with a "C" child on the diagram.



Now, what I actually need, is to create a "B" parent when a "C" is created.
What I have done 'till now:

- first of al, we need to allow the creation of "C" when the user mouse goes over an "A" element. In order to do so we need to modify the ATypeItemSemanticEditPolicy#getCreateCommand() method and return a Create Command for the case of a "C" element. So, I added a condition like this:


protected Command getCreateCommand(CreateElementRequest req) {
...............................
............................

if (MyModelElementTypes.CType_3006 == req.getElementType()) {
			return getGEFWrapper(new CWithParentCreateCommand(req));
		}

}


Now I need to write a class CWithParentCreateCommand.
This class is identical to the BCreateCommand (the one where a C child is added).

Well. Everything goes fine: We can select the "C" creation tool now, we can trigger the create command on an "A" object, and indeed a "B" parent is automatically created for the "C" element, like we needed:

<a>
     <b> 
        <c/>
    </b>
  </a> 


Only one thing goes wrong: the "A" figure is not updated so we cannot see the "b" and the "c" on the diagram. If we resize the "a" figure, then "b" and "c" becomes visible.

Finally, we have 2 cases:

1. We automatically add a "c" child when a "b" element is added. Everything works fine.
2. We automatically add a "b" parent when a "c" element is added: works for the model, the view is not updated.

Note: in both cases the same XXXCreateCommand class is used. In both of the cases an "A" parent will receive a "B" child. The difference is that, in the first case the request points to a "B" object while in the second case the request points to a "C".


Any clues are welcomed.

Emil.



[Updated on: Fri, 11 June 2010 12:26]

Report message to a moderator

Re: automatically add parent node when child added [message #539624 is a reply to message #539579] Fri, 11 June 2010 14:26 Go to previous messageGo to next message
emil salageanu is currently offline emil salageanuFriend
Messages: 94
Registered: June 2010
Location: Nice, France
Member
The bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=281014 (after a workbench restart the programatically-created figures are no longer visible) applies for the first case (when programatically adding a "C" child when a "b" element is created). The workaround (removing the semantic hints) works just fine.

In the case of the creation of a "B" parent programatically, I still have the same problem (the created figure is not visible). Note: the created figure will appear if closing and reopening the editor, with coordinates 0,0 relative to its parent.

Still need some help Smile



Re: automatically add parent node when child added [message #540551 is a reply to message #539624] Wed, 16 June 2010 13:57 Go to previous messageGo to next message
Olivier Marot is currently offline Olivier MarotFriend
Messages: 14
Registered: September 2009
Junior Member
Your figure is not refreshed because it has no reason to.
You should make a canonical refresh programatically by calling the xxxCanonicalEditPolicy.refresh()

Either get it from the edit part :
xxxEditPart.getEditPolicy(EditPolicyRoles.CANONICAL_ROLE);
or from the semantic element :
CanonicalEditPolicy.getRegisteredEditPolicies(modelElement);

This should create the view for B.
Re: automatically add parent node when child added [message #540800 is a reply to message #540551] Thu, 17 June 2010 12:17 Go to previous message
emil salageanu is currently offline emil salageanuFriend
Messages: 94
Registered: June 2010
Location: Nice, France
Member
Thanks Olivier for your answer.

I tried your solution with no success. But the problem was not there ..

The problem was that a visual ID could not be found for a C child added for an A parent (I recall that we wanted to automatically create the intermediate B element).

The solution is a little bit tricky:



Step1: implement a BwithCCreateCommand class for the Type B which creates a a "B" with a child "C". The "doExecuteWithResult" method looks like:

protected CommandResult doExecuteWithResult(IProgressMonitor monitor,
			IAdaptable info) throws ExecutionException {

		B newElement = DevFactory.eINSTANCE.createB();
		AAAType owner = (AAAType) getElementToEdit();
		owner.setB(newElement);

		// --->  C creation
		CType c = DevFactory.eINSTANCE.createCType();
		newElement.setC(c);
		// <--- CTypecreation		

		doConfigure(newElement, monitor, info);
		((CreateElementRequest) getRequest()).setNewElement(newElement);
		return CommandResult.newOKCommandResult(newElement);
	}


Step 2: modify the ATypeItemSemanticEditPolicy#getCreateCommand() as explained before.

Step3.

Modify the method XXXViewProvider#createNode method.
Add a condition to the case corresponding to C.VisualID :



case CTypeEditPart.VISUAL_ID:
			if (containerView.getType().equals(new Integer(ATypeEditPart.VISUAL_ID).toString()))
			{
				return createB_NNNN(domainElement, containerView, index,
						persisted, preferencesHint);
			}else
			return createC_NNNN(domainElement, containerView, index,
					persisted, preferencesHint);




That's it, it works now.

[Updated on: Thu, 17 June 2010 12:32]

Report message to a moderator

Previous Topic:Memory leak - Graphical shapes
Next Topic:Wrapping Label Vertical Orientation
Goto Forum:
  


Current Time: Sat Jul 27 05:28:08 GMT 2024

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

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

Back to the top