X

Geertjan's Blog

  • March 29, 2014

Cause a Wizard to Appear Automatically

Geertjan Wielenga
Product Manager

Sometimes you may want a wizard to automatically appear, as a result of logic, rather than a user action. Normally, the user goes to the New File dialog or the New Project dialog or clicks an Action, such as provided by a menu item or toolbar button, and then a wizard starts up.

However, here's something slightly different. The module depends on the Window System API and hence the @OnShowing annotation is available.

import java.io.File;
import org.openide.awt.Actions;
import org.openide.windows.OnShowing;
@OnShowing
public class Startable implements Runnable {
    @Override
    public void run() {
        if (!new File("/path/to/some/folder").exists()) {
            Actions.forID("File", "org.something.core.CreateFolderWizardAction").actionPerformed(null);
        }
    }   
}

In the "run" method, use "Actions.forID" and pass in the category and the ID of the Action that starts up the wizard. Since when you use the Wizard wizard to create a wizard skeleton, you also get an Action, you should have an Action somewhere in your module structure. Instead of registering the wizard in the Action such that it appears as a toolbar button or menu item, just remove those annotations. The only annotations your Action needs are @ActionID and @ActionRegistration, not @ActionReference.

And with that, the wizard starts up after the application is initialized, automatically.

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.