5

I'm writing a little wizard for Eclipse with some pages and I need to catch the moment of the first time page displaying.

I checked constructor and createControl but they are called in the creation moment in the Wizard object (addPages).

Is there a way to get what I need? Maybe somebody knows some trick?

Lii
  • 11,553
  • 8
  • 64
  • 88
morbilli
  • 99
  • 8

5 Answers5

4

You can override setVisible(boolean) method in your WizardPage. So for example use something like:

private boolean initialized = false;

@Override
public void setVisible(boolean visible) {
    if (!initialized && visible) {
        //do something
        initialized = true;
    }
    control.setVisible(visible);
}
2

You can use a IPageChangedListener or a IpageChangingListener, registered on the WizardDialog. They will be notified when the current page of the wizard changes.

Baldrick
  • 23,882
  • 6
  • 74
  • 79
  • I don't use `WizardDialog`, I use `org.eclipse.jface.wizard.Wizard` and `org.eclipse.ui.INewWizard`. And I don't know how to use `IPageChangedListener` or `IpageChangingListener` in this case. – morbilli Apr 25 '12 at 08:43
  • @user433689 use `Wizard.getContainer()` to retrieve the `WizardDialog` – Baldrick Apr 25 '12 at 09:58
1

I prefer to remove the listener after first painting. That way you don't need an additional boolean field and you avoid unnecessary calling paintControl and checking that boolean every time.

container.addPaintListener(new PaintListener()
{
    @Override
    public void paintControl(PaintEvent e)
    {
        doUsefulStuff();
        container.removePaintListener(this);
    }
});
Danny Lo
  • 1,553
  • 4
  • 26
  • 48
0

Ok, I created a listener for a paint event and used a flag m_isFirsTime, which controlled from Wizard class:

public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);

    setControl(container);
    container.addPaintListener(new PaintListener() {
        @Override
        public void paintControl(PaintEvent arg0) {
            if (m_isFirstTime) {
                m_isFirstTime = false;
                StartXMLParsing();
            }
        }
    });
...
}

It is ok for me.

morbilli
  • 99
  • 8
0

After controls created the async UI task executed where a long init operation can be performed. UI already created and shown when Runnable starts therefore wizard appears immediately and user can see initialization progress:

public void createControl(Composite parent) {
    // create controls
    getContainer().getShell().getDisplay().asyncExec(new Runnable() {
        @Override
        public void run() {
            try {
                getContainer().run(false, false, new IRunnableWithProgress() {
                    @Override
                    public void run(IProgressMonitor arg0) throws InvocationTargetException, InterruptedException {
                        // init and validate controls here
                    }
                });
            } catch (InvocationTargetException e) {
                // handle e.getCause();
            } catch (InterruptedException e) {
                // nothing
            }
        }
    });
}
  • 2
    Please explain your solution! – gaRos Mar 24 '16 at 11:35
  • After controls created the async UI task executed where a long init operation can be performed. UI already created and shown when Runnable starts therefore wizard appears immediatly and user can see initialization progress – Alexey Markevich Mar 28 '16 at 06:17
  • I mean not for me, put this explanation into your answer to make it complete, if somebody check it he will see why your solution is working. – gaRos Mar 29 '16 at 07:59