1

I'm using a TreeViewer with a list of customers. I added a DoubleClickListener to the TreeViewer.

this.treeViewer.addDoubleClickListener(new IDoubleClickListener() {
        @Override
        public void doubleClick(DoubleClickEvent event) {
            IStructuredSelection thisSelection = (IStructuredSelection) event
                    .getSelection();
            Object selectedNode = thisSelection.getFirstElement();

            if (selectedNode instanceof ICustomer) {
                ICustomer customer = (ICustomer) selectedNode;
                selectionService.setSelection(customer);

                perspective = (MPerspective) modelService
                        .find("de.checkpoint.rinteln.carlofon.perspective.customer",
                                app);
            }

            if (perspective != null) {
                partService.switchPerspective(perspective);
            }
        }
    });

In the Customer-Perspective, I've got 2 Views, which use the selected customer to load his data(orders and reminders) from the DB.

In the Customer-View, everything works just fine. But once i move on the next view(Reminder or Order) the selection list Null, which I don't get.

@Inject
void setSelection(
        @Optional @Named(IServiceConstants.ACTIVE_SELECTION) ICustomer customer) {

    if (customer != null) {
        idText.setText("" + customer.getCustomerId());
        customerNameText
                .setText(customer.getFirstname() + " " + customer.getLastname());
        steetText.setText(customer.getStreet());
        cityText.setText(customer.getCity());
        steetCodeText.setText("" + customer.getCityCode());

    } else {
        // TODO Clear View!
    }
}

And in the Reminder-View (in the same perspective as the Customer-View), the selected Customer is Null

@Inject
void setSelection(
        @Optional @Named(IServiceConstants.ACTIVE_SELECTION) ICustomer customer) {

    if (customer != null) {
        super.treeViewer.setInput(service.loadAll());
    } else {
        // TODO Clear View!
    }
}

Which lead to my question, do i miss something? Am I not supposed to use the same selection in different views?

I must add, that both views extend an AbstractView in which the IDoubleClickListener is implemented.

P Varga
  • 19,174
  • 12
  • 70
  • 108
Lycone
  • 650
  • 9
  • 18
  • If you only want an event on double click it might be better to use IEventBroker with a specific event rather than the selection event which can fire for all sorts of reasons. – greg-449 Jan 27 '19 at 17:35
  • It still doesn't explain, why the next view gets customer with a null-value. I'll give the IEventBroker a try. I must admit, I'm pretty new in this e4 world. – Lycone Feb 06 '19 at 06:29
  • I tried with the IEventBroker and I still have the same problem. I guess, the reason why, it doesn't work it because at the moment i operate the perspective switch, the View isn't there already, so the event get lost. – Lycone Mar 16 '19 at 08:48

0 Answers0