Search in sources :

Example 16 with Panel

use of org.apache.wicket.markup.html.panel.Panel 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)

Example 17 with Panel

use of org.apache.wicket.markup.html.panel.Panel in project syncope by apache.

the class Realm method buildTabList.

private List<ITab> buildTabList(final PageReference pageRef) {
    List<ITab> tabs = new ArrayList<>();
    tabs.add(new ITabComponent(new Model<>("DETAILS"), StandardEntitlement.REALM_CREATE, StandardEntitlement.REALM_UPDATE, StandardEntitlement.REALM_DELETE) {

        private static final long serialVersionUID = -5861786415855103549L;

        @Override
        public Panel getPanel(final String panelId) {
            final ActionsPanel<RealmTO> actionPanel = new ActionsPanel<>("actions", null);
            if (realmTO.getFullPath().startsWith(SyncopeConstants.ROOT_REALM)) {
                actionPanel.add(new ActionLink<RealmTO>(realmTO) {

                    private static final long serialVersionUID = 2802988981431379827L;

                    @Override
                    public void onClick(final AjaxRequestTarget target, final RealmTO ignore) {
                        onClickCreate(target);
                    }
                }, ActionLink.ActionType.CREATE, StandardEntitlement.REALM_CREATE).hideLabel();
                actionPanel.add(new ActionLink<RealmTO>(realmTO) {

                    private static final long serialVersionUID = 2802988981431379828L;

                    @Override
                    public void onClick(final AjaxRequestTarget target, final RealmTO ignore) {
                        onClickEdit(target, realmTO);
                    }
                }, ActionLink.ActionType.EDIT, StandardEntitlement.REALM_UPDATE).hideLabel();
                actionPanel.add(new ActionLink<RealmTO>(realmTO) {

                    private static final long serialVersionUID = 2802988981431379827L;

                    @Override
                    public void onClick(final AjaxRequestTarget target, final RealmTO ignore) {
                        onClickTemplate(target);
                    }
                }, ActionLink.ActionType.TEMPLATE, StandardEntitlement.REALM_UPDATE).hideLabel();
                actionPanel.add(new ActionLink<RealmTO>(realmTO) {

                    private static final long serialVersionUID = 2802988981431379829L;

                    @Override
                    public void onClick(final AjaxRequestTarget target, final RealmTO ignore) {
                        onClickDelete(target, realmTO);
                    }
                }, ActionLink.ActionType.DELETE, StandardEntitlement.REALM_DELETE, true).hideLabel();
            }
            RealmDetails panel = new RealmDetails(panelId, realmTO, actionPanel, false);
            panel.setContentEnabled(false);
            actionPanel.setEnabled(true);
            return panel;
        }

        @Override
        public boolean isVisible() {
            return SyncopeConsoleApplication.get().getSecuritySettings().getAuthorizationStrategy().isActionAuthorized(this, RENDER);
        }
    });
    final Triple<UserFormLayoutInfo, GroupFormLayoutInfo, Map<String, AnyObjectFormLayoutInfo>> formLayoutInfo = FormLayoutInfoUtils.fetch(anyTypes.stream().map(EntityTO::getKey).collect(Collectors.toList()));
    for (final AnyTypeTO anyType : anyTypes) {
        tabs.add(new ITabComponent(new Model<>(anyType.getKey()), String.format("%s_SEARCH", anyType.getKey())) {

            private static final long serialVersionUID = 1169585538404171118L;

            @Override
            public WebMarkupContainer getPanel(final String panelId) {
                return new AnyPanel(panelId, anyType, realmTO, formLayoutInfo, true, pageRef);
            }

            @Override
            public boolean isVisible() {
                return SyncopeConsoleApplication.get().getSecuritySettings().getAuthorizationStrategy().isActionAuthorized(this, RENDER);
            }
        });
    }
    return tabs;
}
Also used : ActionsPanel(org.apache.syncope.client.console.wicket.markup.html.form.ActionsPanel) ArrayList(java.util.ArrayList) RealmTO(org.apache.syncope.common.lib.to.RealmTO) AnyTypeTO(org.apache.syncope.common.lib.to.AnyTypeTO) ITab(org.apache.wicket.extensions.markup.html.tabs.ITab) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) EntityTO(org.apache.syncope.common.lib.to.EntityTO) ActionsPanel(org.apache.syncope.client.console.wicket.markup.html.form.ActionsPanel) ConnObjectPanel(org.apache.syncope.client.console.wizards.any.ConnObjectPanel) AjaxBootstrapTabbedPanel(de.agilecoders.wicket.core.markup.html.bootstrap.tabs.AjaxBootstrapTabbedPanel) Panel(org.apache.wicket.markup.html.panel.Panel) WizardMgtPanel(org.apache.syncope.client.console.wizards.WizardMgtPanel) Model(org.apache.wicket.model.Model) GroupFormLayoutInfo(org.apache.syncope.client.console.layout.GroupFormLayoutInfo) ITabComponent(org.apache.syncope.client.console.commons.ITabComponent) UserFormLayoutInfo(org.apache.syncope.client.console.layout.UserFormLayoutInfo) Map(java.util.Map)

Example 18 with Panel

use of org.apache.wicket.markup.html.panel.Panel in project wicket by apache.

the class ComponentMarkupIdTest method idGeneratedWhenPanelNotAddedToPage.

/**
 */
@Test
public void idGeneratedWhenPanelNotAddedToPage() {
    // In wicket 1.4 the following sequence would not cause an exception
    Panel panel = new EmptyPanel("bla");
    // however in 1.5 the following statement generated a WicketRuntimeException
    // that the markup type could not be determined
    String markupId = panel.getMarkupId();
    // instead 1.4 would just generate the missing markup identifier
    Assert.assertEquals("bla1", markupId);
}
Also used : Panel(org.apache.wicket.markup.html.panel.Panel) EmptyPanel(org.apache.wicket.markup.html.panel.EmptyPanel) EmptyPanel(org.apache.wicket.markup.html.panel.EmptyPanel) Test(org.junit.Test)

Example 19 with Panel

use of org.apache.wicket.markup.html.panel.Panel in project wicket by apache.

the class SimplePageTest method renderHomePage_2.

/**
 * @throws Exception
 */
@Test
public void renderHomePage_2() throws Exception {
    executeTest(SimplePage.class, "SimplePageExpectedResult.html");
    String document = tester.getLastResponseAsString();
    Label label = (Label) tester.getLastRenderedPage().get("myLabel");
    assertNotNull(label);
    assertTrue(document.contains("<span wicket:id=\"myLabel\">Test Label</span>"));
    Panel panel = (Panel) tester.getLastRenderedPage().get("myPanel");
    assertNotNull(panel);
    assertTrue(document.contains("<wicket:panel>Inside the panel<span wicket:id=\"label\">mein Label</span></wicket:panel>"));
    label = (Label) tester.getLastRenderedPage().get("myPanel:label");
    assertNotNull(label);
    assertFalse("".equals(document));
    assertTrue(document.contains("<span wicket:id=\"label\">mein Label</span>"));
    Border border = (Border) tester.getLastRenderedPage().get("myBorder");
    assertNotNull(border);
    assertFalse("".equals(document));
    assertTrue(document.contains("<wicket:border>before body - <wicket:body>border</wicket:body> - after body</wicket:border>"));
    border = (Border) tester.getLastRenderedPage().get("myBorder2");
    assertNotNull(border);
    assertFalse("".equals(document));
    assertTrue(document.contains("<span wicket:id=\"myBorder2\" testAttr=\"myValue\"><wicket:border>before body - <wicket:body>border</wicket:body> - after body</wicket:border></span>"));
    // do the same test twice. Igor reported a problem with that, so we have to test it.
    border = (Border) tester.getLastRenderedPage().get("myBorder2");
    assertNotNull(border);
    assertFalse("".equals(document));
    assertTrue(document.contains("<span wicket:id=\"myBorder2\" testAttr=\"myValue\"><wicket:border>before body - <wicket:body>border</wicket:body> - after body</wicket:border></span>"));
    WebMarkupContainer container = (WebMarkupContainer) tester.getLastRenderedPage().get("test");
    assertNotNull(container);
    assertFalse("".equals(document));
    assertTrue(document.contains("body<span wicket:id=\"myLabel2\">Test Label2</span>"));
    label = (Label) tester.getLastRenderedPage().get("test:myLabel2");
    assertNotNull(label);
    assertFalse("".equals(document));
    assertTrue(document.contains("<span wicket:id=\"myLabel2\">Test Label2</span>"));
}
Also used : Panel(org.apache.wicket.markup.html.panel.Panel) Border(org.apache.wicket.markup.html.border.Border) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) Test(org.junit.Test)

Example 20 with Panel

use of org.apache.wicket.markup.html.panel.Panel in project wicket by apache.

the class SimplePageTest method renderHomePage_2b.

/**
 * @throws Exception
 */
@Test
public void renderHomePage_2b() throws Exception {
    // Render the component without having rendered the page previously
    SimplePage page = new SimplePage();
    Label label = (Label) page.get("myLabel");
    assertNotNull(label);
    ValueMap attr = label.getMarkupAttributes();
    assertNotNull(attr);
    assertEquals("myLabel", attr.getString("wicket:id"));
    Panel panel = (Panel) page.get("myPanel");
    assertNotNull(panel);
    attr = panel.getMarkupAttributes();
    assertNotNull(attr);
    assertEquals("myPanel", attr.getString("wicket:id"));
    label = (Label) page.get("myPanel:label");
    assertNotNull(label);
    attr = label.getMarkupAttributes();
    assertNotNull(attr);
    assertEquals("label", attr.getString("wicket:id"));
    Border border = (Border) page.get("myBorder");
    assertNotNull(border);
    attr = border.getMarkupAttributes();
    assertNotNull(attr);
    assertEquals("myBorder", attr.getString("wicket:id"));
    border = (Border) page.get("myBorder2");
    assertNotNull(border);
    attr = border.getMarkupAttributes();
    assertNotNull(attr);
    assertEquals("myBorder2", attr.getString("wicket:id"));
    // do the same test twice. Igor reported a problem with that, so we have to test it.
    border = (Border) page.get("myBorder2");
    assertNotNull(border);
    attr = border.getMarkupAttributes();
    assertNotNull(attr);
    assertEquals("myBorder2", attr.getString("wicket:id"));
    WebMarkupContainer container = (WebMarkupContainer) page.get("test");
    assertNotNull(container);
    attr = container.getMarkupAttributes();
    assertNotNull(attr);
    assertEquals("test", attr.getString("wicket:id"));
    label = (Label) page.get("test:myLabel2");
    assertNotNull(label);
    attr = label.getMarkupAttributes();
    assertNotNull(attr);
    assertEquals("myLabel2", attr.getString("wicket:id"));
}
Also used : Panel(org.apache.wicket.markup.html.panel.Panel) ValueMap(org.apache.wicket.util.value.ValueMap) Border(org.apache.wicket.markup.html.border.Border) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) Test(org.junit.Test)

Aggregations

Panel (org.apache.wicket.markup.html.panel.Panel)76 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)27 ArrayList (java.util.ArrayList)21 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)18 BasePanel (com.evolveum.midpoint.gui.api.component.BasePanel)16 ITab (org.apache.wicket.extensions.markup.html.tabs.ITab)16 Before (org.junit.Before)16 AbstractTab (org.apache.wicket.extensions.markup.html.tabs.AbstractTab)15 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)13 AjaxBootstrapTabbedPanel (de.agilecoders.wicket.core.markup.html.bootstrap.tabs.AjaxBootstrapTabbedPanel)12 ResourceModel (org.apache.wicket.model.ResourceModel)11 DivTestPanel (org.odlabs.wiquery.ui.DivTestPanel)11 ItemPanelSettingsBuilder (com.evolveum.midpoint.gui.impl.prism.panel.ItemPanelSettingsBuilder)10 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)10 List (java.util.List)9 Test (org.junit.Test)9 IModel (org.apache.wicket.model.IModel)8 Model (org.apache.wicket.model.Model)6 ActionsPanel (org.apache.syncope.client.console.wicket.markup.html.form.ActionsPanel)5 Label (org.apache.wicket.markup.html.basic.Label)5