Hooking into selections [message #956705] |
Wed, 24 October 2012 18:47 |
Hernan Gonzalez 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 |
Hernan Gonzalez 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
|
|
|
|
Powered by
FUDForum. Page generated in 0.03176 seconds