luksch
luksch

Reputation: 11712

Call JFace ComboViewer setComparator() upon open

I am stuck with a SWT problem. I want to postpone the creation of a ViewerComparator class to the point a user actually wants to select an item from the ComboViewer. In my use case the Comparator is a pretty complex beast that uses a lot of resources. The user usually does not need to actually open the CombiViewer, so I thought I could save computing time by deferring the creation of the Comparator to the moment when it is really needed.

Here is what I tried:

comboViewer1.addOpenListener(new IOpenListener(){

    @Override
    public void open(OpenEvent event) {

        if (comboViewer1.getComparator() == null){
            comboViewer1.setComparator(new ViewerComp(transientModelThing.getComRef()));
        }
    }
});

I am not very familiar with SWT and JFace. But in the debugger I see that this open method is NEVER called. I expected it to be called when the user tried to fold out the combo box.

No ideas to why the listener is not working? A postSelectionListener that I register much the same way functions flawlessly. comboViewer1 and transientModelThing are a public globals. ViewerComp is my private class that implements this complex Comparator.

Upvotes: 1

Views: 303

Answers (1)

luksch
luksch

Reputation: 11712

In the good tradition of answering own questions if they are solved, I put here my solution:

comboViewer1.getControl().addListener(SWT.MouseEnter, new Listener(){

    @Override
    public void handleEvent(Event event) {

        if (comboViewer1.getComparator() == null){
            comboViewer1.setComparator(new ViewerComp(transientModelThing.getComRef()));
        }
    }
});

I used the SWT.MouseEnter event for now. This is of course not exactly what I wanted, but it is close enough.

@greg-449 Thx for the input!

Upvotes: 0

Related Questions