Search code examples
eclipsepluginseclipse-plugineclipse-rcp

How to add raido button and implementation to BasicNewFileResourceWizard


I have a file wizard that cretes css file programatically. I would like to add aditional component at the bottom like raio button or checkbox. Is there a way to add it here and its basic implementation. Or should I go with custom wizard creation?

public class MyNewFileWizard extends BasicNewFileResourceWizard
{
  WizardNewFileCreationPage mainPage;

  public static final String WIZARD_ID = "ui.wizard.MyNewFileWizard";

  public MyNewFileWizard()
  {
    super();
  }

  @Override
  public void addPages()
  {

    mainPage = new WizardNewFileCreationPage("New File Page", getSelection())
    {
      @Override
      protected InputStream getInitialContents()
      {
        StringBuilder sb = new StringBuilder();
        sb.append("SAMPLE_README_FILE");

        return new ByteArrayInputStream(sb.toString().getBytes());
      }
    };

    mainPage.setFileExtension("css");
    addPage(mainPage);
  }

  @Override
  public boolean performFinish()
  {
    IFile file = mainPage.createNewFile();
    if (file == null) {
      return false;
    }

    selectAndReveal(file);

    // Open editor on new file.
    IWorkbenchWindow dw = getWorkbench().getActiveWorkbenchWindow();
    try {
      if (dw != null) {
        IWorkbenchPage page = dw.getActivePage();
        if (page != null) {
          IDE.openEditor(page, file, true);
        }
      }
    }
    catch (PartInitException e) {
      //openError(dw.getShell(), "Problems opening editor", e.getMessage(), e);
    }

    return true;
  }
}

Solution

  • You could try overriding the WizardNewFileCreationPage createAdvancedControls method:

    @Override
    protected void createAdvancedControls(Composite parent)
    {
      super.createAdvancedControls(parent);
    
      ... add your controls here
    }