Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » GEF5 Add multiple parts to Group
GEF5 Add multiple parts to Group [message #1802331] Wed, 06 February 2019 15:07 Go to next message
João Pedro is currently offline João PedroFriend
Messages: 52
Registered: December 2014
Member
My solution to have different outputs/inputs was to add smaller Nodes (Let's call them IO parts) close to the main center Node (let's call it Main Model part). These IO parts will then be selectable to connect amongst each other:

index.php/fa/34822/0/

Now I'm having several issues since I'm trying to group several IO parts and 1 Main Model part and have the following behaviors:

-Drag the whole group together
-Be able to select individually each IO part
- Be able to double click on the Main Model part to open some settings (it can be as well a double click on the whole Group)

I can already drag the Group but not select each individual part... When I try to select, it gives a "Not yet initialized!" error:

!STACK 0
java.lang.IllegalStateException: Not yet initialized!
	at org.eclipse.gef.mvc.fx.policies.AbstractPolicy.checkInitialized(AbstractPolicy.java:38)
	at org.eclipse.gef.mvc.fx.policies.AbstractPolicy.commit(AbstractPolicy.java:59)
	at org.eclipse.gef.mvc.fx.policies.TransformPolicy.commit(TransformPolicy.java:123)
	at org.eclipse.gef.mvc.fx.handlers.AbstractHandler.commit(AbstractHandler.java:129)
	at org.eclipse.gef.mvc.fx.handlers.TranslateSelectedOnDragHandler.endDrag(TranslateSelectedOnDragHandler.java:140)
	at org.eclipse.gef.mvc.fx.gestures.ClickDragGesture.release(ClickDragGesture.java:471)



Can you guys give me some hints? I've been at this for days now and I feel that I'm close to achieving what I want but there's something missing... I also couldn't find any example that could help me.

Thanks.

[Updated on: Wed, 06 February 2019 16:16]

Report message to a moderator

Re: GEF5 Add multiple parts to Group [message #1802406 is a reply to message #1802331] Fri, 08 February 2019 10:46 Go to previous messageGo to next message
João Pedro is currently offline João PedroFriend
Messages: 52
Registered: December 2014
Member
Ok, so I've been trying a LOT of approaches and I think I got it right but there's still something missing:

index.php/fa/34843/0/

As you can see in the image, I can still just select the ModelPart and not the IOParts. The strange behavior I can observe is that when the mouse enters the IOPart width area, it automatically highlights the ModelPart with the ShapeOutlineProvider.

So, for some reason my group is bounded to the ModelPart bounds and I can't understand why.

Some help please :D

[Updated on: Fri, 08 February 2019 10:47]

Report message to a moderator

Re: GEF5 Add multiple parts to Group [message #1802906 is a reply to message #1802406] Mon, 18 February 2019 19:06 Go to previous messageGo to next message
Matthias Wienand is currently offline Matthias WienandFriend
Messages: 230
Registered: March 2015
Senior Member
Hi Joao,

that looks pretty good already!

The IllegalStateException indicates that a policy is used (to perform some manipulation) that was already committed (Policy.commit()) or not yet initialized (Policy.init()).

Processing of inputs depends on the organisation of your part hierarchy (flat or nested), the visuals used (and their registration at visual-part-map), the gestures in-use (probably defaults), and the handlers used.

Note that handlers that both react to the same inputs might need to mutually exclude each other to work properly (i.e. you drag an input but it belongs to the whole group => "TranslateGroupOnDragHandler" needs to exclude that interaction explicitly).

Best regards,
Matthias

[Updated on: Mon, 18 February 2019 19:08]

Report message to a moderator

Re: GEF5 Add multiple parts to Group [message #1803099 is a reply to message #1802906] Fri, 22 February 2019 11:07 Go to previous messageGo to next message
João Pedro is currently offline João PedroFriend
Messages: 52
Registered: December 2014
Member
Thanks for the answer Matthias!

I'm still facing problems with the Translation of my Group and wanted some feedback if possible.

So, currently I need to select my whole group parts, and if I do I can correctly move them (and the connections associated to the group - see image):
index.php/fa/34944/0/

However, I don't want to force the user to select all the Parts in order to move the Group. If the user selects the ChildPart he should also be able to move the whole GroupPart. In order to achieve this I added the following code to the bindChildPartAdapters:

// support moving nodes via mouse drag
adapterMapBinder.addBinding(AdapterKey.defaultRole()).to(TransformPolicy.class);
		adapterMapBinder.addBinding(AdapterKey.defaultRole()).to(TranslateSelectedOnDragHandler.class);


and then I tried to call the setContentTransform of the GroupPart within the getContentTransform of the ChildPart and setting the setContentTransform of the ChildPart by first calling the getContentTransform of the GroupPart . Now, if I move the ChildPart, the GruopPart moves but I'm getting erratic behaviors (I guess it's because one Affine is going into another Affine, etc) and can't figure out if this strategy is the best approach.

What do you think Matthias?
Re: GEF5 Add multiple parts to Group [message #1803197 is a reply to message #1803099] Mon, 25 February 2019 09:15 Go to previous messageGo to next message
Matthias Wienand is currently offline Matthias WienandFriend
Messages: 230
Registered: March 2015
Senior Member
Hi Joao,

the individual transforms of the parts should not be shared. If the child parts are inserted into the visual of their parent part, they will move along with their parent automatically.

TranslateSelectedOnDragHandler will translate all parts in SelectionModel that have a TransformPolicy. Since you do not want this behaviour, you could subclass TranslateSelectedOnDragHandler, for example TranslateGroupOnChildDragHandler that will translate the GroupPart but is registered for a ChildPart.

Best regards,
Matthias
Re: GEF5 Add multiple parts to Group [message #1803280 is a reply to message #1803197] Tue, 26 February 2019 09:19 Go to previous messageGo to next message
Patrick Muscat is currently offline Patrick MuscatFriend
Messages: 14
Registered: May 2018
Junior Member
Hello,

The parent/child relation between boxes and ports should do what you want. In our diagram we have three levels of parts: boxes/groups/ports where our boxes are your Group and our ports are your IO (in our model, groups are drawn to show synchronization between input ports streams).
- when selecting a box, all children (groups and ports) follow the move
- when selecting a group, all ports inside the group of ports follow the move (and with coordinate constraint stay inside the box
- and finally, ports can be moved inside their parent group of ports

Children follow mouse drag of their parent even if they are not selected. Another solution would be to use anchored/anchorage mechanism.

In the configure method of the module we call bind methods for each level:
bindNodePartAdapters(AdapterMaps.getAdapterMapBinder(binder(), NodePart.class);
bindPortGroupPartAdapters(AdapterMaps.getAdapterMapBinder(binder(), PortGroupPart.class));
bindPortPartAdapters(AdapterMaps.getAdapterMapBinder(binder(), PortPart.class));


then, in these methods we decide to add or not bindings to Policies, for example, Nodes (the boxes) are deletable (DeletionPolicy), moveable (TransformPolicy), resizeable (ResizePolicy) when groups of ports are not moveable nor resizeable (they follow the parent box) and ports are only moveable inside their parent group of ports.

https://www.eclipse.org/forums/index.php?t=getfile&id=34960&

[Updated on: Tue, 26 February 2019 09:37]

Report message to a moderator

Re: GEF5 Add multiple parts to Group [message #1803323 is a reply to message #1803280] Tue, 26 February 2019 19:05 Go to previous messageGo to next message
João Pedro is currently offline João PedroFriend
Messages: 52
Registered: December 2014
Member
Thanks for the answers guys!

However, I still can't move the whole GroupPart when I move the ChildPart.

What I did:
1-Added to the ChildPartAdapters:
		adapterMapBinder.addBinding(AdapterKey.defaultRole()).to(TransformPolicy.class);
		adapterMapBinder.addBinding(AdapterKey.defaultRole()).to([b][color=orange]TranslateGroupOnChildDragHandler[/color][/b].class);


and of course this to the GroupPartAdapters:
		adapterMapBinder.addBinding(AdapterKey.defaultRole()).to(TransformPolicy.class);
		adapterMapBinder.addBinding(AdapterKey.defaultRole()).to(TranslateSelectedOnDragHandler.class);


2-Made a TranslateGroupOnChildDragHandler. I guess I need to change only the returned parts, to have the parent and its child parts returned when the ChildPart is selected. Am I right?
public class TranslateGroupOnChildDragHandler extends TranslateSelectedOnDragHandler {
	
	@Override
	protected List<IContentPart<? extends Node>> getTargetParts() {
		
		GroupPart parent = (GroupPart) getHost().getParent();
		List<IContentPart<? extends Node>> list2 = new ArrayList<>();
		for (IVisualPart<? extends Node> iContentPart : parent.getChildrenUnmodifiable()) {
			list2.add((IContentPart<? extends Node>) iContentPart);
		}
		list2.add(parent); //add the parent as well
		return list2;
	}

}


3-Then in the ChildPart I added implementations for the methods from ITransformableContentPart

	@Override
	public Affine getContentTransform() {
		Rectangle bounds = getContent().getBounds();
		System.out.println("In ChildPart");
        return new Affine(new Translate(bounds.getX(), bounds.getY()));
	}

	@Override
	public void setContentTransform(Affine totalTransform) {
		// storing the new position
        Rectangle bounds = getContent().getBounds().getCopy();
        bounds.setX(totalTransform.getTx());
        bounds.setY(totalTransform.getTy());
        getContent().setBounds(bounds);
		
	}


and of course, a similar implementation of those methods in GroupPart.

When I move the ChildPart, it already moves everything but with erratic behavior. It looks, again, like it's making two moves at once.
What am I doing wrong??
Re: GEF5 Add multiple parts to Group [message #1803346 is a reply to message #1803323] Wed, 27 February 2019 08:20 Go to previous messageGo to next message
Patrick Muscat is currently offline Patrick MuscatFriend
Messages: 14
Registered: May 2018
Junior Member
Erratic behaviour ? If one of them is moving twice faster it is because two TransformPolicy are applied on the same Part by two different handlers in the same "drag" event. I did not understand that you wanted to move the parent when moving the child, It is something we are not doing in our diagram.

If two handlers are activated for the drag, one for the groupPart and one for the childPart then their targets should respectively return the groupPart and the childPart only. Another solution would be to activate only one handler which acts on the groupPart and the childPart simultaneously by customizing the getTargetParts method.
Re: GEF5 Add multiple parts to Group [message #1803356 is a reply to message #1803346] Wed, 27 February 2019 10:26 Go to previous messageGo to next message
João Pedro is currently offline João PedroFriend
Messages: 52
Registered: December 2014
Member
Quote:

If one of them is moving twice faster it is because two TransformPolicy are applied on the same Part by two different handlers in the same "drag" event.


Yep, that's what's happening.

Quote:

Another solution would be to activate only one handler which acts on the groupPart and the childPart simultaneously by customizing the getTargetParts method.

Exactly Patrick! I followed the second suggestion as shown in my previous post and changed getTargetParts. Still, I'm missing something. Maybe it's because I'm using 2 different handlers, one for the GroupPart and other for the ChildPart....

[Updated on: Wed, 27 February 2019 10:26]

Report message to a moderator

Re: GEF5 Add multiple parts to Group [message #1803358 is a reply to message #1803356] Wed, 27 February 2019 10:41 Go to previous messageGo to next message
João Pedro is currently offline João PedroFriend
Messages: 52
Registered: December 2014
Member
Ok, found out the solution. I also had to change something in the TransformPolicy class.

I created a TransformPolicyChildDrag class, extending the aforementioned one:
public class TransformPolicyChildDrag extends TransformPolicy {
	
	@Override
	public ITransformableContentPart<? extends Node> getHost() {
		return (ITransformableContentPart<? extends Node>) getAdaptable().getParent();
	}
}



You guys sent me in the right direction! Thank you both for that.
Re: GEF5 Add multiple parts to Group [message #1803390 is a reply to message #1803358] Wed, 27 February 2019 19:10 Go to previous message
Matthias Wienand is currently offline Matthias WienandFriend
Messages: 230
Registered: March 2015
Senior Member
Hi Joao,

it might be working already, but by returning the parent as the host, you basically take out the child's transform policy. If you would not bind it in the first place, you would (most probably) get the same behavior.

I have to say I really like the explanations given by Patrick, so I encourage you to try a simpler setup inspired by those, e.g. have the ports immoveable by omitting TransformPolicy from ChildPart.

However, maybe it does make sense to revisit this later-on after working more with different handlers.

Best regards,
Matthias
Previous Topic:How to make dashed and customized Connection
Next Topic:Increase selectable Connection Part
Goto Forum:
  


Current Time: Sat Nov 09 00:16:48 GMT 2024

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

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

Back to the top