How to catch first time displaying of the WizardPage
Asked Answered
O

5

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?

Oxymoron answered 24/4, 2012 at 17:40 Comment(0)
K
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);
}
Kingwood answered 30/4, 2012 at 18:12 Comment(1)
Thank you, I used another wayOxymoron
A
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.

Alcoran answered 24/4, 2012 at 17:51 Comment(2)
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.Oxymoron
@user433689 use Wizard.getContainer() to retrieve the WizardDialogAlcoran
K
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);
    }
});
Kev answered 8/12, 2014 at 9:53 Comment(0)
O
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.

Oxymoron answered 3/5, 2012 at 13:42 Comment(0)
G
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
            }
        }
    });
}
Gandhiism answered 24/3, 2016 at 11:32 Comment(3)
Please explain your solution!Arlinda
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 progressGandhiism
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.Arlinda

© 2022 - 2024 — McMap. All rights reserved.