Support for selection changes in views
steghoja opened this issue · 6 comments
I have a use case in which I want to regenerate the diagram when the selection in the project explorer changes. Since the project explorer is not an editor, changes in this view are not captured by PlantUmlView
out of the box.
I have managed to implement a very hacky way of achieving what I want by extending PlantUmlView
and overwriting updateDiagramText(boolean, IWorkbenchPart, ISelection)
and exposing the list of DiagramTextProvider
s via PlantUmlUtil
. However, this hardly feels like the best way to do it and I wonder if there is a more elegant solution.
I imagine other use cases such as creating a class diagram on selecting a package in the package explorer.
Any ideas for how to achieve this?
The current design allows diagramTextProviders to say they support a specific editor and optionally its selection. It sounds easy to extend this to also cover views (IWorkbenchPart in general), but I haven't looked at the details. The relevant code is in net.sourceforge.plantuml.eclipse.views.AbstractDiagramSourceView, where an IPartListener triggers updating the diagram text. There's several place where the code checks that the workbench part is an editor, it may just work removing the checks and changing some types from IEditorPart to IWorkbenchPart.
I'm not sure if parts contribute selection providers to the site, so the selection listener logic may need to be extended.
Thanks for the quick answer! I suspected as much. This would be a pretty deep change and will probably require extensive testing. I'll see what I can do and send a pull request if I come up with something.
https://www.eclipse.org/articles/Article-WorkbenchSelections/article.html suggests views also contribute selections through the site's selection service, so that part of the current design should just work.
I have made some progress on this and you can see my WIP here. When I activate a view (such as the Project Explorer or the Package Explorer), the generation of diagrams is now triggered. I have not yet managed to get changes in the selections to work. The listener is triggered, but the change is not reflected in the diagram. However, if I leave the view and return, the update happens. I suspect that this has to do with pinnedTo
, but I need to investigate further.
At this point, I'd be happy if you could have a look at the changes, maybe test them with your test rig, and let me know what you think.
We have also PlantUML output generated in views e.g. in console view from some tool. How can we help with testing? Do you have a plugin build for install and test? Thanks!
Close, should be fixed in release 1.1.23