Skip to main content



      Home
Home » Modeling » GMF (Graphical Modeling Framework) » User selection in diagram(Find out which element the user clicked on)
User selection in diagram [message #660260] Thu, 17 March 2011 11:20 Go to next message
Eclipse UserFriend
Hello,

is there a way to find out on *which* element the user clicked on in the diagram? Something like an action on the left click of the mouse - if the user clicks on an element, I want to display in the console the name and type of the selected element. Any clues?

Thank you.
Re: User selection in diagram [message #660268 is a reply to message #660260] Thu, 17 March 2011 11:39 Go to previous messageGo to next message
Eclipse UserFriend
On 17-03-11 16:20, Darie wrote:
> Hello,
>
> is there a way to find out on *which* element the user clicked on in the
> diagram? Something like an action on the left click of the mouse - if
> the user clicks on an element, I want to display in the console the name
> and type of the selected element. Any clues?
>
> Thank you.


in your xxxDiagramEditor do the following:


/**
* Hook into the synchronizer, we want to know what is going on with
* selections, so we can modify the diagram model.
*
*/
private SelectionSynchronizer synchronizer;

@Override
protected SelectionSynchronizer getSelectionSynchronizer() {
if (synchronizer == null)
synchronizer = new CustomSelectionSynchronizer();
return synchronizer;
}

/**
* A custom synchronizer, which by parameter can either sync.
viewers, or
* replace the Graphical viewer input.
*
* @author dzonekl
*
*/
class CustomSelectionSynchronizer extends SelectionSynchronizer {

@Override
public void addViewer(EditPartViewer viewer) {
super.addViewer(viewer);
}

@Override
public void selectionChanged(SelectionChangedEvent event) {
// We turn off the default synchronization.
// super.selectionChanged(event);

### PRrocess the selection here.


}
}
Re: User selection in diagram [message #660287 is a reply to message #660268] Thu, 17 March 2011 12:33 Go to previous messageGo to next message
Eclipse UserFriend
Hello Christophe,

thank you very much, it does work indeed as I want!

Cheers!
Re: User selection in diagram [message #660578 is a reply to message #660287] Sat, 19 March 2011 11:41 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

I use the following in xxxDiagramEditor:

/**
* @generated
*/
private ISelectionListener selectionListener = new ISelectionListener() {
  @Override
  public void selectionChanged(IWorkbenchPart part, ISelection selection) {
    //place your code here
  }
};

/**
* @generated
*/
@Override
protected void startListening() {
  super.startListening();

  PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().addPostSelectionListener(selectionListener);
}

/**
* @generated
*/
@Override
protected void stopListening() {
  super.stopListening();

  PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().removePostSelectionListener(selectionListener);
}


You can extend the xpt/editor/Editor.xpt template for this.

Ralph
Re: User selection in diagram [message #780759 is a reply to message #660268] Thu, 19 January 2012 05:11 Go to previous message
Eclipse UserFriend
Please can anyone tell me how to get the name of selected node of gmf diagram and where to write...


Thanks in Advance
Previous Topic:GMF - Mix Images and Text
Next Topic:Grouping Nodes on the canvas
Goto Forum:
  


Current Time: Sun Nov 09 21:27:44 EST 2025

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

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

Back to the top