Search in sources :

Example 1 with BootstrapAjaxLink

use of de.agilecoders.wicket.core.markup.html.bootstrap.button.BootstrapAjaxLink in project syncope by apache.

the class RealmChoicePanel method reloadRealmTree.

public final void reloadRealmTree() {
    final Label realmLabel = new Label("realmLabel", new Model<>());
    realmLabel.setOutputMarkupId(true);
    container.addOrReplace(realmLabel);
    if (model.getObject().getFullPath().startsWith(SyncopeConstants.ROOT_REALM)) {
        realmLabel.setDefaultModel(new ResourceModel("realmLabel", "Realm"));
    } else {
        realmLabel.setDefaultModel(new ResourceModel("dynRealmLabel", "Dynamic Realm"));
    }
    final Label label = new Label("realm", model.getObject().getFullPath());
    label.setOutputMarkupId(true);
    container.addOrReplace(label);
    final DropDownButton realms = new DropDownButton("realms", new ResourceModel("select", ""), new Model<IconType>(GlyphIconType.folderopen)) {

        private static final long serialVersionUID = -5560086780455361131L;

        @Override
        protected List<AbstractLink> newSubMenuButtons(final String buttonMarkupId) {
            RealmChoicePanel.this.links.clear();
            RealmChoicePanel.this.links.add(new BootstrapAjaxLink<RealmTO>(ButtonList.getButtonMarkupId(), new Model<RealmTO>(), Buttons.Type.Link, new ResourceModel("realms", "Realms")) {

                private static final long serialVersionUID = -7978723352517770744L;

                @Override
                public void onClick(final AjaxRequestTarget target) {
                }

                @Override
                public boolean isEnabled() {
                    return false;
                }

                @Override
                protected void onComponentTag(final ComponentTag tag) {
                    tag.put("class", "panel box box-primary box-header with-border");
                    tag.put("style", "margin: 20px 5px 0px 5px; width: 90%");
                }
            });
            for (Pair<String, RealmTO> link : realmTree.getObject()) {
                final RealmTO realmTO = link.getValue();
                RealmChoicePanel.this.links.add(new BootstrapAjaxLink<RealmTO>(ButtonList.getButtonMarkupId(), Model.of(realmTO), Buttons.Type.Link, new Model<>(link.getKey())) {

                    private static final long serialVersionUID = -7978723352517770644L;

                    @Override
                    public void onClick(final AjaxRequestTarget target) {
                        model.setObject(realmTO);
                        label.setDefaultModelObject(model.getObject().getFullPath());
                        realmLabel.setDefaultModel(new ResourceModel("realmLabel", "Realm"));
                        target.add(label);
                        send(pageRef.getPage(), Broadcast.EXACT, new ChosenRealm<>(realmTO, target));
                    }

                    @Override
                    public boolean isEnabled() {
                        return availableRealms.stream().anyMatch(availableRealm -> realmTO.getFullPath().startsWith(availableRealm));
                    }
                });
            }
            if (!dynRealmTree.getObject().isEmpty()) {
                RealmChoicePanel.this.links.add(new BootstrapAjaxLink<RealmTO>(ButtonList.getButtonMarkupId(), new Model<RealmTO>(), Buttons.Type.Link, new ResourceModel("dynrealms", "Dynamic Realms")) {

                    private static final long serialVersionUID = -7978723352517770744L;

                    @Override
                    public void onClick(final AjaxRequestTarget target) {
                    }

                    @Override
                    public boolean isEnabled() {
                        return false;
                    }

                    @Override
                    protected void onComponentTag(final ComponentTag tag) {
                        tag.put("class", "panel box box-primary box-header with-border");
                        tag.put("style", "margin: 20px 5px 0px 5px; width: 90%");
                    }
                });
                for (DynRealmTO dynRealmTO : dynRealmTree.getObject()) {
                    final RealmTO realmTO = new RealmTO();
                    realmTO.setKey(dynRealmTO.getKey());
                    realmTO.setName(dynRealmTO.getKey());
                    realmTO.setFullPath(dynRealmTO.getKey());
                    RealmChoicePanel.this.links.add(new BootstrapAjaxLink<RealmTO>(ButtonList.getButtonMarkupId(), new Model<RealmTO>(), Buttons.Type.Link, new Model<>(realmTO.getKey())) {

                        private static final long serialVersionUID = -7978723352517770644L;

                        @Override
                        public void onClick(final AjaxRequestTarget target) {
                            model.setObject(realmTO);
                            label.setDefaultModelObject(realmTO.getKey());
                            realmLabel.setDefaultModel(new ResourceModel("dynRealmLabel", "Dynamic Realm"));
                            target.add(label);
                            send(pageRef.getPage(), Broadcast.EXACT, new ChosenRealm<>(realmTO, target));
                        }

                        @Override
                        public boolean isEnabled() {
                            return availableRealms.stream().anyMatch(availableRealm -> {
                                return SyncopeConstants.ROOT_REALM.equals(availableRealm) || realmTO.getKey().equals(availableRealm);
                            });
                        }
                    });
                }
            }
            return RealmChoicePanel.this.links;
        }
    };
    realms.setOutputMarkupId(true);
    realms.setAlignment(AlignmentBehavior.Alignment.RIGHT);
    realms.setType(Buttons.Type.Menu);
    MetaDataRoleAuthorizationStrategy.authorize(realms, ENABLE, StandardEntitlement.REALM_LIST);
    container.addOrReplace(realms);
}
Also used : StandardEntitlement(org.apache.syncope.common.lib.types.StandardEntitlement) DynRealmTO(org.apache.syncope.common.lib.to.DynRealmTO) RealmTO(org.apache.syncope.common.lib.to.RealmTO) Buttons(de.agilecoders.wicket.core.markup.html.bootstrap.button.Buttons) HashMap(java.util.HashMap) SyncopeConsoleSession(org.apache.syncope.client.console.SyncopeConsoleSession) IconType(de.agilecoders.wicket.core.markup.html.bootstrap.image.IconType) StringUtils(org.apache.commons.lang3.StringUtils) GlyphIconType(de.agilecoders.wicket.core.markup.html.bootstrap.image.GlyphIconType) ArrayList(java.util.ArrayList) BootstrapAjaxLink(de.agilecoders.wicket.core.markup.html.bootstrap.button.BootstrapAjaxLink) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ComponentTag(org.apache.wicket.markup.ComponentTag) AbstractLink(org.apache.wicket.markup.html.link.AbstractLink) Label(org.apache.wicket.markup.html.basic.Label) AlignmentBehavior(de.agilecoders.wicket.core.markup.html.bootstrap.behavior.AlignmentBehavior) SyncopeConstants(org.apache.syncope.common.lib.SyncopeConstants) MetaDataRoleAuthorizationStrategy(org.apache.wicket.authroles.authorization.strategies.role.metadata.MetaDataRoleAuthorizationStrategy) ButtonList(de.agilecoders.wicket.core.markup.html.bootstrap.button.ButtonList) Collection(java.util.Collection) Model(org.apache.wicket.model.Model) LoadableDetachableModel(org.apache.wicket.model.LoadableDetachableModel) PageReference(org.apache.wicket.PageReference) Collectors(java.util.stream.Collectors) Panel(org.apache.wicket.markup.html.panel.Panel) List(java.util.List) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) DropDownButton(de.agilecoders.wicket.core.markup.html.bootstrap.button.dropdown.DropDownButton) Comparator(java.util.Comparator) RealmRestClient(org.apache.syncope.client.console.rest.RealmRestClient) ResourceModel(org.apache.wicket.model.ResourceModel) Collections(java.util.Collections) Broadcast(org.apache.wicket.event.Broadcast) DropDownButton(de.agilecoders.wicket.core.markup.html.bootstrap.button.dropdown.DropDownButton) Label(org.apache.wicket.markup.html.basic.Label) DynRealmTO(org.apache.syncope.common.lib.to.DynRealmTO) RealmTO(org.apache.syncope.common.lib.to.RealmTO) DynRealmTO(org.apache.syncope.common.lib.to.DynRealmTO) IconType(de.agilecoders.wicket.core.markup.html.bootstrap.image.IconType) GlyphIconType(de.agilecoders.wicket.core.markup.html.bootstrap.image.GlyphIconType) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ComponentTag(org.apache.wicket.markup.ComponentTag) Model(org.apache.wicket.model.Model) LoadableDetachableModel(org.apache.wicket.model.LoadableDetachableModel) ResourceModel(org.apache.wicket.model.ResourceModel) ResourceModel(org.apache.wicket.model.ResourceModel) AbstractLink(org.apache.wicket.markup.html.link.AbstractLink)

Aggregations

AlignmentBehavior (de.agilecoders.wicket.core.markup.html.bootstrap.behavior.AlignmentBehavior)1 BootstrapAjaxLink (de.agilecoders.wicket.core.markup.html.bootstrap.button.BootstrapAjaxLink)1 ButtonList (de.agilecoders.wicket.core.markup.html.bootstrap.button.ButtonList)1 Buttons (de.agilecoders.wicket.core.markup.html.bootstrap.button.Buttons)1 DropDownButton (de.agilecoders.wicket.core.markup.html.bootstrap.button.dropdown.DropDownButton)1 GlyphIconType (de.agilecoders.wicket.core.markup.html.bootstrap.image.GlyphIconType)1 IconType (de.agilecoders.wicket.core.markup.html.bootstrap.image.IconType)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Pair (org.apache.commons.lang3.tuple.Pair)1 SyncopeConsoleSession (org.apache.syncope.client.console.SyncopeConsoleSession)1 RealmRestClient (org.apache.syncope.client.console.rest.RealmRestClient)1 SyncopeConstants (org.apache.syncope.common.lib.SyncopeConstants)1