Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Hooking into selections
Hooking into selections [message #956705] Wed, 24 October 2012 18:47 Go to next message
Hernan Gonzalez is currently offline Hernan GonzalezFriend
Messages: 188
Registered: October 2010
Location: Buenos Aires, Argentina
Senior Member
I wish to hook into the editor so that when a shape is selected the StatusLine is updated with my custom information.

Is this a known task?

I see that there is a DiagramEditorInternal.selectionChanged() method which is called when the selection changed (ok), and it tries located the related pictogramElement(s) and call selectPictogramElements()
I though that overriding selectPictogramElements() I could attain my goal but,
at least in my scenario, the method is not called when a figure is selected by the user.
Strangely this loop inside DiagramEditorInternal.selectionChanged() does not find any PE in the if() else(), the "object" is not a EObject but a org.eclipse.graphiti.ui.internal.parts.ShapeEditPart

    // Collect all Pictogram Elements for all selected domain
    // objects into one list
    for (Iterator<?> iterator = structuredSelection.iterator(); iterator.hasNext();) {
     Object object = iterator.next();
     if (object instanceof EObject) {
      // Find the Pictogram Elements for the given domain
      // object via the standard link service
      List<PictogramElement> referencingPes = Graphiti.getLinkService().getPictogramElements(
        getDiagramTypeProvider().getDiagram(), (EObject) object);
      if (referencingPes.size() > 0) {
       peList.addAll(referencingPes);
      }
     } else {
      // For non-EMF domain objects use the registered
      // notification service for finding
      PictogramElement[] relatedPictogramElements = getDiagramTypeProvider().getNotificationService()
        .calculateRelatedPictogramElements(new Object[] { object });
      for (int i = 0; i < relatedPictogramElements.length; i++) {
       peList.add(relatedPictogramElements[i]);
      }
     }
    }


Is this the correct expected behaviour?

[Updated on: Wed, 24 October 2012 19:07]

Report message to a moderator

Re: Hooking into selections [message #958224 is a reply to message #956705] Thu, 25 October 2012 21:25 Go to previous messageGo to next message
Hernan Gonzalez is currently offline Hernan GonzalezFriend
Messages: 188
Registered: October 2010
Location: Buenos Aires, Argentina
Senior Member
My current understanding:

1.
DiagramEditorInternal.selectionChanged(IWorkbenchPart part, ISelection selection)  

is not a Graphiti specific method, it's a listener method (overrides GraphicalEditor), that will be called from "below" (by the Eclipse UI) to notify us that a selection changed happened in the UI. The selected thing will be tipically (in Graphiti sceneario) a GEF EditPart.

2.
DiagramEditorInternal.selectPictogramElements(PictogramElement[] pictogramElements)

should be called when we want (from inside Graphiti) to programatically select some pictogram elements. This will tell the underlying UI (Eclipse's selection provider) to set the new selection, and will eventually cause Eclipse to call selectionChanged() method (when it perform in the UI the selection and notifies the registered listeners).
This method, typically, will NOT be executed when a user selects a shape in the Editor by clicking it.


Then, I guess that my task can be done by overriding selectionChanged() with something like:

MyEditor.selectionChanged() {
   super.selectionChanged();
    PictogramElement[] pes = PictogramElement[] getSelectedPictogramElements();
    // update the status line
}

I'll try that.

My main doubt are: in the typical scenario I described (is there any other?), the
DiagramEditorInternal.selectionChanged() receives an EditPart, and hence the if/else blocks in the body will not have effect. However, the body of the method (see the code in the previous post) seems to assume that we have a model object (an EObject in the "if", or a non-EMF domain object in the "else"). Doesn't this sound wrong?

[Updated on: Thu, 25 October 2012 21:26]

Report message to a moderator

Re: Hooking into selections [message #958923 is a reply to message #958224] Fri, 26 October 2012 10:16 Go to previous message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Hernan,

your understanding of the methods purposes is correct and adding your coding
to selectionChanged shold do it.

However, the coding there needs to be able to handle all kinds of
selections, this might be different kinds of objects in various selection
cases that depend on where the selection is done by the user.

Michael
Previous Topic:Couple Graphiti Editor with XText DSL
Next Topic:Change mouse pointer on hover over
Goto Forum:
  


Current Time: Fri Mar 29 14:31:18 GMT 2024

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

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

Back to the top