I have simple requirement : My application contain 2 MParts. One MPart contains list of IDs displayed in TreeView from Database. By clicking on any ID, another MPart should populate/display data related to slected ID (from DB) in TableView.
I written, 1st MPart and it is displaying IDs in TreeView. On click capturing user selected ID and retrieved data related to that ID from DB. Using EPartService, i got reference of 2nd MPart. But not able to modify its TableView. (initially, i populated this TableView with empty rows. default). Basically I am trying to modify 2nd Mpart from 1st Mpart.
I am beginner, tried all related posts available in the net. Please point me right direction
In the following answer I will asume that you are talking about JFace
TreeViewer
andTableViewer
. If you are talking about JavaFXTreeView
andTableView
you will need to use a different way of capturing the selection event, but the usage of theESelectionService
remains the same.Setting the Selection
In the part with the tree you can use dependency injection to get the
ESelectionService
You can then add a
ISelectionChangedListener
to theTreeViewer
and forward the selection to the selection service.Instead of pushing the
IStructuredSelection
to the context you could also use your ID directly, i.e. by usingselection.getFirstElement()
.Observing the Selection
In the part with the table showing the details you can have the current selection injected. This method will be called everytime the selection changes.
Note the use of
@Optional
here. This will ensure that the method is also called when the active selection isnull
.More Information
For more information on the
ESelectionService
please refer to this tutorial: http://eclipsesource.com/blogs/tutorials/eclipse-4-e4-tutorial-part-7-services/