Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Selecting a node after creation
Selecting a node after creation [message #1821415] Wed, 12 February 2020 17:50 Go to next message
Ken Keefe is currently offline Ken KeefeFriend
Messages: 41
Registered: April 2012
I'm trying to automatically select a node right after it is created. I have other behavior that is triggered in the UI when a node is selected (a node details composite appears).

Here is the code I have in my CreateNewNodeOnClickHandler class (it serves the same roll as the same class found in the MindMap example).

RBDPart rbdPart = (RBDPart)part;
ReliabilityBlockDiagram rbd = rbdPart.getContent();
Point2D mouseInLocal = part.getVisual().sceneToLocal(e.getSceneX(), e.getSceneY());

DiagramObject dObj = null;
switch (palette.getSelectedTool()) {
case RBDPaletteComposite.COMPONENT:
	dObj = RBDFactory.eINSTANCE.createComponent();
if(dObj != null) {
	dObj.setLocation(mouseInLocal.getX(), mouseInLocal.getY());
	// GEF provides the CreatePolicy and operations to add a new element
	// to the model
	IRootPart<? extends Node> root = getHost().getRoot();
	// get the policy bound to the IRootPart
	CreationPolicy creationPolicy = root.getAdapter(CreationPolicy.class);
	// initialize the policy
	// create a IContentPart for our new model. 
	IContentPart<? extends Node> newNodePart = creationPolicy.create(dObj, rbdPart, HashMultimap.<IContentPart<? extends Node>, String>create());
	// execute the creation
	//Select new part

As you can see, I added a line after the creation was committed that used the SelectionModel to select the new part. However, this doesn't seem to have any effect. Is there a better way to do what I want?
Re: Selecting a node after creation [message #1821419 is a reply to message #1821415] Wed, 12 February 2020 19:17 Go to previous messageGo to next message
Ken Keefe is currently offline Ken KeefeFriend
Messages: 41
Registered: April 2012
So, I think the node is being selected by the code above, because the details composite is showing. However, there is no visual feedback around the node on the canvas like when you click it with the selection tool. How do I get it to paint that dark shadow around the node to indicate that it is the selected node?
Re: Selecting a node after creation [message #1822394 is a reply to message #1821419] Thu, 05 March 2020 15:54 Go to previous message
Matthias Wienand is currently offline Matthias WienandFriend
Messages: 230
Registered: March 2015
Senior Member
Hi Ken,

the new part should be selected by default (so no need for manually setting the selection):

- CreationPolicy#create(content, parent, anchoreds) delegates to create(content, parent, anchoreds, doFocus=true, doSelect=true).
- A SelectOperation is constructed to perform changing the selection (so that it will be undoable).

You can test that this is the case by observing the state of SelectionModel (i.e. register ListChangeListener on getSelection()). It might seem like the selection is not changed if the selection is cleared shortly after. This could happen, for example, if another handler is executed after the CreateOnClickHandler.

Selection feedback construction works as follows:
- SelectionModel is changed (it is observable)
- SelectionBehavior observes that change
(- Feedback and Handles are destroyed or created, depending on the change)
- DefaultSelectionFeedbackPartFactory is used to create selection feedback parts (by default, only the primary selection will have feedback)
!!! - Selection Feedback Geometry Provider is queried from the part !!! this could be missing for the newly created part -> look into the module and compare part bindings with another part where selection works fine
- SelectionFeedbackPart is created to show the feedback geometry
(- Primary Selection Feedback Color Provider can be used to change the selection color for different parts)

All of these are exchangeable, i.e. you can, for example, subclass DefaultSelectionFeedbackPartFactory and change the binding in your module, in order to adjust selection feedback part creation.

Best regards,

[Updated on: Thu, 05 March 2020 15:55]

Report message to a moderator

Previous Topic:Is GEF 5.1.0 compatible with efxclipse 3.5.0
Next Topic:how to complete "group/ungroup"
Goto Forum:

Current Time: Sun Feb 25 10:44:57 GMT 2024

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

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

Back to the top