Example usage for org.eclipse.jface.wizard WizardDialog updateButtons

List of usage examples for org.eclipse.jface.wizard WizardDialog updateButtons

Introduction

In this page you can find the example usage for org.eclipse.jface.wizard WizardDialog updateButtons.

Prototype

@Override
    public void updateButtons() 

Source Link

Usage

From source file:org.eclipse.reddeer.codegen.handlers.CodeGenHandler.java

License:Open Source License

/**
 * Method for open RedDeer CodeGen wizard and runs all necessary listeners
 * //from w ww .  j ava 2s.c  o m
 * @param window
 */
private void openCodeGen(IWorkbenchWindow window) {

    log.info("Trying to open CodeGen wizard.");
    Shell[] shell = ShellLookup.getInstance().getShells();
    for (Shell sh : shell) {
        if (sh.getText() == CodeGenWizard.WIZZARD_NAME)
            return;
    }
    INewWizard wizard = new CodeGenWizard();
    WizardDialog dialog = new WizardDialog(window.getShell(), wizard);
    dialog.setMinimumPageSize(150, 350);

    dialog.addPageChangedListener(new IPageChangedListener() {

        @Override
        public void pageChanged(PageChangedEvent event) {
            log.info("Page changed listener was started.");
            Object selected = event.getSelectedPage();
            if (selected instanceof PreviewPage) {
                PreviewPage prev = ((PreviewPage) selected);
                log.debug("Active page -> 'PreviewPage'.");
                dialog.updateButtons();
            } else if (selected instanceof MethodsPage) {
                log.debug("Active page -> 'MethodsPage'.");
            } else if (selected instanceof FirstPage) {
                log.debug("Active page -> 'FirstPage'.");
                ((FirstPage) selected).dialogChanged();
                dialog.updateButtons();
            }
        }
    });

    dialog.addPageChangingListener(new IPageChangingListener() {

        @Override
        public void handlePageChanging(PageChangingEvent event) {
            log.info("Page changing listener was started.");
            Object current = event.getCurrentPage();
            Object target = event.getTargetPage();
            if (current instanceof MethodsPage && target instanceof PreviewPage) {
                log.debug("Switching between 'MethodsPage' -> 'PreviewPage'.");
                MethodsPage meth = ((MethodsPage) current);
                PreviewPage prev = ((PreviewPage) target);
                log.info("Trying to generate code.");
                CodeGenerator g = new CodeGenerator(meth.getClassBuilder().getClassName(),
                        meth.getClassBuilder().getPackageName(), meth.getSelectedOptional());
                log.info("Trying to update text area in 'PreviewPage'.");
                g.setLastActiveShell(lastActiveShell);
                prev.updateAreaContent(g.generateCode());
            }

        }
    });

    log.info("Opening WizardDialog -> " + wizard.getWindowTitle() + "...");
    dialog.open();
}

From source file:org.jboss.tools.forge.ui.ext.dialog.WizardDialogHelper.java

License:Open Source License

public void openWizard(String windowTitle, UICommand selectedCommand) {
    ForgeWizard wizard = new ForgeWizard(selectedCommand, context);
    wizard.setWindowTitle(windowTitle);//ww  w .  j  av  a  2s  . c o  m
    final WizardDialog wizardDialog = new WizardDialog(parentShell, wizard);
    // TODO: Show help button when it's possible to display the docs for
    // each UICommand
    wizardDialog.setHelpAvailable(false);
    wizardDialog.addPageChangingListener(new IPageChangingListener() {

        @Override
        public void handlePageChanging(PageChangingEvent event) {
            // Mark as unchanged
            ForgeWizardPage currentPage = (ForgeWizardPage) event.getCurrentPage();
            if (currentPage != null) {
                currentPage.setChanged(false);
            }
        }
    });
    wizardDialog.addPageChangedListener(new IPageChangedListener() {
        @Override
        public void pageChanged(PageChangedEvent event) {
            // BEHAVIOR: Finish button is enabled by default and then
            // disabled when any field is selected/changed in the first page

            // WHY: Wizard.canFinish() is called before getNextPage is
            // called, therefore not checking if the second page is complete

            // SOLUTION: Calling updateButtons will call canFinish() once
            // again and set the button to the correct state
            wizardDialog.updateButtons();
        }
    });
    wizardDialog.open();
}

From source file:org.jboss.tools.forge.ui.internal.ext.dialog.WizardDialogHelper.java

License:Open Source License

public void openWizard(String windowTitle, UICommand selectedCommand, Map<String, ?> values) {
    Assert.isNotNull(selectedCommand, "No command was selected for execution");
    CommandControllerFactory controllerFactory = FurnaceService.INSTANCE.lookup(CommandControllerFactory.class);
    CommandFactory commandFactory = FurnaceService.INSTANCE.lookup(CommandFactory.class);
    Assert.isNotNull(controllerFactory, CommandControllerFactory.class.getSimpleName() + " service not found");
    Assert.isNotNull(commandFactory, CommandFactory.class.getSimpleName() + " service not found");
    UICommandMetadata metadata = selectedCommand.getMetadata(context);
    Assert.isNotNull(metadata, "No metadata found for " + selectedCommand);
    String commandName = metadata.getName();
    UICommand newCommand = commandFactory.getNewCommandByName(context, commandName);
    if (windowTitle == null) {
        windowTitle = commandName;//from   w  ww  .j  ava2  s  .  co  m
    }
    ForgeUIRuntime runtime = new ForgeUIRuntime();
    CommandController controller = controllerFactory.createController(context, runtime, newCommand);
    try {
        controller.initialize();
    } catch (Exception e) {
        ForgeUIPlugin.displayMessage(windowTitle, "Error while initializing controller. Check logs",
                NotificationType.ERROR);
        ForgeUIPlugin.log(e);
        return;
    }
    ForgeWizard wizard = new ForgeWizard(windowTitle, controller, context);
    final WizardDialog wizardDialog;
    if (controller instanceof WizardCommandController) {
        WizardCommandController wizardController = (WizardCommandController) controller;
        if (values != null) {
            Map<String, InputComponent<?, ?>> inputs = wizardController.getInputs();
            for (String key : inputs.keySet()) {
                Object value = values.get(key);
                if (value != null)
                    wizardController.setValueFor(key, value);
            }
            while (wizardController.canMoveToNextStep()) {
                try {
                    wizardController.next().initialize();
                } catch (Exception e) {
                    ForgeUIPlugin.log(e);
                    break;
                }
                inputs = wizardController.getInputs();
                for (String key : inputs.keySet()) {
                    Object value = values.get(key);
                    if (value != null)
                        wizardController.setValueFor(key, value);
                }
            }
            // Rewind
            while (wizardController.canMoveToPreviousStep()) {
                try {
                    wizardController.previous();
                } catch (Exception e) {
                    ForgeUIPlugin.log(e);
                }
            }
        }
        wizardDialog = new ForgeWizardDialog(parentShell, wizard, wizardController);
    } else {
        if (values != null) {
            for (Entry<String, ?> entry : values.entrySet()) {
                controller.setValueFor(entry.getKey(), entry.getValue());
            }
        }
        wizardDialog = new ForgeCommandDialog(parentShell, wizard);
    }
    // TODO: Show help button when it's possible to display the docs for
    // each UICommand
    wizardDialog.setHelpAvailable(false);
    wizardDialog.addPageChangingListener(new IPageChangingListener() {

        @Override
        public void handlePageChanging(PageChangingEvent event) {
            // Mark as unchanged
            ForgeWizardPage currentPage = (ForgeWizardPage) event.getCurrentPage();
            if (currentPage != null) {
                currentPage.setChanged(false);
            }
        }
    });
    wizardDialog.addPageChangedListener(new IPageChangedListener() {
        @Override
        public void pageChanged(PageChangedEvent event) {
            // BEHAVIOR: Finish button is enabled by default and then
            // disabled when any field is selected/changed in the first page

            // WHY: Wizard.canFinish() is called before getNextPage is
            // called, therefore not checking if the second page is complete

            // SOLUTION: Calling updateButtons will call canFinish() once
            // again and set the button to the correct state
            wizardDialog.updateButtons();
        }
    });

    if (controller.getInputs().isEmpty() && controller.canExecute()) {
        try {
            ApplicationWindow window = new ApplicationWindow(parentShell);
            wizard.performFinish(window, parentShell);
        } catch (InvocationTargetException | InterruptedException e) {
            ForgeUIPlugin.log(e);
        }
    } else {
        try {
            wizardDialog.open();
        } catch (Exception e) {
            ForgeUIPlugin.displayMessage("Error", "Error while opening wizard. See Error log",
                    NotificationType.ERROR);
            ForgeUIPlugin.log(e);
        }
    }
}