dildik
dildik

Reputation: 405

Java get changed title of a dialog

I am trying to catch SWT events, like SWT.activate, SWT.deactivate and SWT.dispose in Eclipse. So, I can see which dialog was opened or activated, which was closed and which was deactivated. If the event was caught, I extract the Shell object and extracts its title with shell.getText(). To listen to events, I used an untyped listener (edited):

PlatformUI.getWorkbench().getDisplay().addFilter(SWT.Activate, shellListener);
Listener shellListener = new Listener(){
    @Override public void handleEvent(Event e) {
        if (event.widget.getClass() == org.eclipse.swt.widgets.Shell.class){
            Shell shell = (Shell) e.widget;
            String shellTitle = shell.getText();
            if (event.type == Activate) {
                String message = "The following dialog was activated: " + shellTitle;
                // do other stuff with 'message'
            }
        }
    }
};

If in Eclipse I open 'New' and the listener above correctly displays 'New' as activated dialog. But if I select 'Java Interface' within the 'New' dialog, then I am landing in a dialog, called 'New Java Interface'. But my handleEvent method is not fired and therefore I cannot extract the new dialog title. My question is: What kind of event is called or what happens, when I am in an Eclipse dialog and clicking on something in it which leads me to another dialog (with a new title)?

Upvotes: 0

Views: 331

Answers (1)

Anton Sarov
Anton Sarov

Reputation: 3748

I think the problem here comes from the fact that the New 'dialog' in Eclipse is actually a Wizard. When you select 'Java Interface' (in the 'New' dialog) you are actually then landing not in another dialog but on a page within the same wizard. Every page in this wizard can have it's own title but behind the scene it is the same underlying shell object, that is why you don't receive further events.

By the way: when working with the SWT.Activate, SWT.Deactivate and other similar shell events, it might be helpflul / easier to the a ShellAdapter

Upvotes: 1

Related Questions