Search in sources :

Example 1 with ResultPage

use of org.apache.syncope.client.console.wizards.any.ResultPage in project syncope by apache.

the class WizardMgtPanel method onEvent.

@Override
@SuppressWarnings("unchecked")
public void onEvent(final IEvent<?> event) {
    if (event.getPayload() instanceof ExitEvent && modal != null) {
        final AjaxRequestTarget target = ExitEvent.class.cast(event.getPayload()).getTarget();
        // default behaviour: change it catching the event if needed
        modal.close(target);
    } else if (event.getPayload() instanceof AjaxWizard.NewItemEvent) {
        final AjaxWizard.NewItemEvent<T> newItemEvent = AjaxWizard.NewItemEvent.class.cast(event.getPayload());
        final AjaxRequestTarget target = newItemEvent.getTarget();
        final T item = newItemEvent.getItem();
        final boolean modalPanelAvailable = newItemEvent.getModalPanel() != null || newItemPanelBuilder != null;
        if (event.getPayload() instanceof AjaxWizard.NewItemActionEvent && modalPanelAvailable) {
            final WizardModalPanel<?> modalPanel;
            if (newItemEvent.getModalPanel() == null) {
                newItemPanelBuilder.setItem(item);
                modalPanel = newItemPanelBuilder.build(actualId, ((AjaxWizard.NewItemActionEvent<T>) newItemEvent).getIndex(), item != null ? isReadOnly() ? AjaxWizard.Mode.READONLY : AjaxWizard.Mode.EDIT : AjaxWizard.Mode.CREATE);
            } else {
                modalPanel = newItemEvent.getModalPanel();
            }
            if (wizardInModal) {
                final IModel<T> model = new CompoundPropertyModel<>(item);
                modal.setFormModel(model);
                target.add(modal.setContent(modalPanel));
                modal.header(new StringResourceModel(String.format("any.%s", newItemEvent.getEventDescription()), this, new Model<>(modalPanel.getItem())));
                modal.show(true);
            } else {
                final Fragment fragment = new Fragment("content", "wizard", WizardMgtPanel.this);
                fragment.add(new Label("title", newItemEvent.getResourceModel() == null ? Model.of(StringUtils.EMPTY) : newItemEvent.getResourceModel()));
                fragment.add(Component.class.cast(modalPanel));
                container.addOrReplace(fragment);
            }
            customActionCallback(target);
        } else if (event.getPayload() instanceof AjaxWizard.NewItemCancelEvent) {
            if (wizardInModal) {
                modal.close(target);
            } else {
                container.addOrReplace(initialFragment);
            }
            customActionOnCancelCallback(target);
        } else if (event.getPayload() instanceof AjaxWizard.NewItemFinishEvent) {
            SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
            ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
            if (wizardInModal && showResultPage) {
                modal.setContent(new ResultPage<T>(item, AjaxWizard.NewItemFinishEvent.class.cast(newItemEvent).getResult()) {

                    private static final long serialVersionUID = -2630573849050255233L;

                    @Override
                    protected void closeAction(final AjaxRequestTarget target) {
                        modal.close(target);
                    }

                    @Override
                    protected Panel customResultBody(final String id, final T item, final Serializable result) {
                        return WizardMgtPanel.this.customResultBody(id, item, result);
                    }
                });
                target.add(modal.getForm());
            } else if (wizardInModal) {
                modal.close(target);
            } else {
                container.addOrReplace(initialFragment);
            }
            customActionOnFinishCallback(target);
        }
        if (containerAutoRefresh) {
            target.add(container);
        }
    }
    super.onEvent(event);
}
Also used : IModel(org.apache.wicket.model.IModel) Serializable(java.io.Serializable) Label(org.apache.wicket.markup.html.basic.Label) WizardModalPanel(org.apache.syncope.client.console.panels.WizardModalPanel) Fragment(org.apache.wicket.markup.html.panel.Fragment) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ResultPage(org.apache.syncope.client.console.wizards.any.ResultPage) BasePage(org.apache.syncope.client.console.pages.BasePage) StringResourceModel(org.apache.wicket.model.StringResourceModel)

Example 2 with ResultPage

use of org.apache.syncope.client.console.wizards.any.ResultPage in project syncope by apache.

the class Realms method updateRealmContent.

private WebMarkupContainer updateRealmContent(final RealmTO realmTO, final int selectedIndex) {
    if (realmTO == null) {
        return content;
    }
    content.addOrReplace(new Realm("body", realmTO, Realms.this.getPageReference(), selectedIndex) {

        private static final long serialVersionUID = 8221398624379357183L;

        @Override
        protected void onClickTemplate(final AjaxRequestTarget target) {
            templates.setTargetObject(realmTO);
            templates.toggle(target, true);
        }

        @Override
        protected void setWindowClosedReloadCallback(final BaseModal<?> modal) {
            modal.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() {

                private static final long serialVersionUID = 8804221891699487139L;

                @Override
                public void onClose(final AjaxRequestTarget target) {
                    if (modal.getContent() instanceof ResultPage) {
                        Serializable result = ResultPage.class.cast(modal.getContent()).getResult();
                        RealmTO newRealmTO = RealmTO.class.cast(ProvisioningResult.class.cast(result).getEntity());
                        // reload realmChoicePanel label too - SYNCOPE-1151
                        target.add(realmChoicePanel.reloadRealmTree(target, Model.of(newRealmTO)));
                        realmChoicePanel.setCurrentRealm(newRealmTO);
                        send(Realms.this, Broadcast.DEPTH, new ChosenRealm<>(newRealmTO, target));
                    } else {
                        target.add(realmChoicePanel.reloadRealmTree(target));
                    }
                    target.add(content);
                    modal.show(false);
                }
            });
        }

        @Override
        protected void onClickCreate(final AjaxRequestTarget target) {
            this.wizardBuilder.setParentPath(realmChoicePanel.getCurrentRealm().getFullPath());
            send(this, Broadcast.EXACT, new AjaxWizard.NewItemActionEvent<RealmTO>(new RealmTO(), target) {

                @Override
                public String getEventDescription() {
                    return "realm.new";
                }
            });
        }

        @Override
        protected void onClickEdit(final AjaxRequestTarget target, final RealmTO realmTO) {
            this.wizardBuilder.setParentPath(realmTO.getFullPath());
            send(this, Broadcast.EXACT, new AjaxWizard.EditItemActionEvent<RealmTO>(realmTO, target) {

                @Override
                public String getEventDescription() {
                    return "realm.edit";
                }
            });
        }

        @Override
        protected void onClickDelete(final AjaxRequestTarget target, final RealmTO realmTO) {
            try {
                if (realmTO.getKey() == null) {
                    throw new Exception("Root realm cannot be deleted");
                }
                realmRestClient.delete(realmTO.getFullPath());
                RealmTO parent = realmChoicePanel.moveToParentRealm(realmTO.getKey());
                target.add(realmChoicePanel.reloadRealmTree(target));
                SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
                updateRealmContent(parent, selectedIndex);
                target.add(content);
            } catch (Exception e) {
                LOG.error("While deleting realm", e);
                // Escape line breaks
                SyncopeConsoleSession.get().error(e.getMessage().replace("\n", " "));
            }
            ((BasePage) Realms.this.getPage()).getNotificationPanel().refresh(target);
        }
    });
    return content;
}
Also used : Serializable(java.io.Serializable) RealmTO(org.apache.syncope.common.lib.to.RealmTO) WindowClosedCallback(org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow.WindowClosedCallback) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ResultPage(org.apache.syncope.client.console.wizards.any.ResultPage) Realm(org.apache.syncope.client.console.panels.Realm) ChosenRealm(org.apache.syncope.client.console.panels.RealmChoicePanel.ChosenRealm)

Aggregations

Serializable (java.io.Serializable)2 ResultPage (org.apache.syncope.client.console.wizards.any.ResultPage)2 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)2 BasePage (org.apache.syncope.client.console.pages.BasePage)1 Realm (org.apache.syncope.client.console.panels.Realm)1 ChosenRealm (org.apache.syncope.client.console.panels.RealmChoicePanel.ChosenRealm)1 WizardModalPanel (org.apache.syncope.client.console.panels.WizardModalPanel)1 RealmTO (org.apache.syncope.common.lib.to.RealmTO)1 WindowClosedCallback (org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow.WindowClosedCallback)1 Label (org.apache.wicket.markup.html.basic.Label)1 Fragment (org.apache.wicket.markup.html.panel.Fragment)1 IModel (org.apache.wicket.model.IModel)1 StringResourceModel (org.apache.wicket.model.StringResourceModel)1