Reputation: 11
My application contains three views: On the left side view "A" and view "B" each with a list of table entries and on the right side the view "Details" that shows the details for the selected entries of view "A" or view "B" depending on which view was activated as last on the left side.
It works with rcp3 but I can't find an equivalent solution for rcp e4.
In rcp3 it is implemented with the workbench site selection provider like this:
ViewA:
public void createPartControl(Composite parent) {
viewer = new TableViewer(parent, SWT.MULTI);
viewer.setContentProvider(ArrayContentProvider.getInstance());
viewer.setInput(Arrays.asList("A1", "A2", "A3"));
getSite().setSelectionProvider(viewer);
}
ViewB:
public void createPartControl(Composite parent) {
viewer = new TableViewer(parent, SWT.MULTI);
viewer.setContentProvider(ArrayContentProvider.getInstance());
viewer.setInput(Arrays.asList("B1", "B2", "B3"));
getSite().setSelectionProvider(viewer);
}
DetailsView:
public void createPartControl(Composite parent) {
composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout(1, true));
detailsLabel = new Label(composite, SWT.NONE);
detailsLabel.setText("");
getSite().getPage().addSelectionListener(ViewA.ID, this);
getSite().getPage().addSelectionListener(ViewB.ID, this);
}
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
if (part instanceof ViewA || part instanceof ViewB){
showDetailsOfEntries(
selection instanceof IStructuredSelection structuredSelection ?
structuredSelection.toList() : Collections.emptyList() );
}
}
private void showDetailsOfEntries( List<?> entries) {
String details = entries.stream().map(Object::toString).collect(Collectors.joining(", "));
detailsLabel.setText(details);
composite.layout(true);
}
I can switch back and forth between "A" and "B", and the "Details" view show the details of the selected entries of "A" or "B".
I tried to migrate this to rcp e4:
ViewA und ViewB:
@Inject
private ESelectionService selectionService
@PostConstruct
public void createPartControl(Composite parent) {
...
viewer.addSelectionChangedListener(event -> {
selectionService.setSelection(event.getSelection());
});
DetailsView:
@Inject
private ESelectionService selectionService
@PostConstruct
public void createPartControl(Composite parent) {
...
selectionService.addSelectionListener(ViewA.ID, this);
selectionService.addSelectionListener(ViewB.ID, this);
}
public void selectionChanged(MPart part, Object selection) {
if (part.getElementId().equals(ViewA.ID) || part.getElementId().equals(ViewB.ID)) {
...
}
}
But now the behavior is different. Switching between the views "A" and "B" don't change the selection and so there is no update in the "Details" view. The "selectionChanged" method in "Details" view is now only be called if there is a new selection in view "A" or "B" and not when switching between view "A" and "B" as it was in rcp3.
How can I achieve the old behavior?
Upvotes: 0
Views: 34