Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Moving child part from one parent part to other
Moving child part from one parent part to other [message #1734838] Mon, 13 June 2016 12:13 Go to next message
Nebojsa Rajic is currently offline Nebojsa RajicFriend
Messages: 5
Registered: June 2016
Junior Member
Hi everyone, I'm working with GEF4 and I'm new to it.
I have a good experience with gef3. Scenario that I'm trying to produce is:

There are two container parts (hosts for JavaFX stack panes) in the viewers root part and they suppose to be a parent components as well, which are capable to lay other basic JavaFX nodes. What would be a proper way in terms of ITools and IPolices to achieve handling a single/multiple selected nodes from one parent container into another parent container or into the viewers root part without braking MCV pattern and with ability for undo/redo support.

Currently I'm using custom FXRelocateOnDragPolicy but there is no getTargetParts like it was in gef3. Not sure am I on correct path.

  • Attachment: GEF4.jpg
    (Size: 63.53KB, Downloaded 210 times)

[Updated on: Wed, 15 June 2016 10:03]

Report message to a moderator

Re: Moving child part from one parent part to other [message #1735144 is a reply to message #1734838] Wed, 15 June 2016 19:35 Go to previous message
Colin Sharples is currently offline Colin SharplesFriend
Messages: 90
Registered: July 2009
Location: Wellington, New Zealand

First of all, there's two basic types of policy, interaction policies and transaction policies. An interaction policy handles the user interaction by mouse (click and/or drag) or keyboard (type), and so implements one of more of the IFXOnXxxPolicy interfaces. A transaction policy is responsible for creating and invoking operations which will update the model and/or visual parts. The general pattern is that the interaction policy will work out what is happening (i.e. what is the new parent node), and update the transaction policy with the details, invoking the transaction policy when the user completes the action.

So for example, you would have two policies called, say RelocateChildOnDragPolicy and RelocateChildTxPolicy, and in your module you would install both those policies on your child part.

RelocateChildOnDragPolicy would extend AbstractFXInteractionPolicy and implement IFXOnDragPolicy. This will give it three methods to handle the user interaction, press(), drag() and release(). In press(), as the user clicks on the child part, you would lookup and initialize the transaction policy from the host, like this:
RelocateChildTxPolicy txPolicy = getHost().getAdapter(RelocateChildTxPolicy.class);

This would create an operation, say RelocateChildOperation - at this stage, the transaction policy only knows the host, which is the child that you are moving. That's okay, we'll tell it later about the new parent.

The drag() method is called as you move the child node around. Use the corrdinates in the mouse event to determine the new parent for the node. I generally do this in model code, as all my model objects keep track of their location and dimensions within the overall scene, but you can also do this through the visual parts as well. When you have identified the new parent for the child, you update the transaction policy with that information:
  public void drag(MouseEvent e, Dimension delta) {
    ParentPart newParent = ... // look up using the mouse location
    RelocateChildTxPolicy txPolicy = getHost().getAdapter(RelocateChildTxPolicy.class);

The setNewParent method on your transaction policy would update the operation with the new parent.

The release() method is where you commit the changes:
    RelocateChildTxPolicy txPolicy = getHost().getAdapter(RelocateChildTxPolicy.class);

This will invoke your operation, which will up date the model to change the child's parent, and then refresh the visuals of the old parent, new parent and child. The operation will be in the undo history, so make sure that the undo() method puts everything back to the way it was before, and refreshed the visuals again.

Colin Sharples
CTG Games Ltd
Wellington, New Zealand
Previous Topic:Custom Property Sheet listener and events
Next Topic:[GEF4] DotEXport/DotImport subgraph
Goto Forum:

Current Time: Sat Sep 22 16:29:06 GMT 2018

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

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

Back to the top