Example usage for org.apache.wicket Component getPage

List of usage examples for org.apache.wicket Component getPage

Introduction

In this page you can find the example usage for org.apache.wicket Component getPage.

Prototype

@Override
public final Page getPage() 

Source Link

Document

Gets the page holding this component.

Usage

From source file:org.apache.syncope.fit.console.AbstractConsoleITCase.java

License:Apache License

protected <V extends Serializable> Component findComponentByProp(final String property, final String searchPath,
        final V key) {

    Component component = TESTER.getComponentFromLastRenderedPage(searchPath);
    return (component instanceof MarkupContainer ? MarkupContainer.class.cast(component) : component.getPage())
            .visitChildren(ListItem.class, new IVisitor<ListItem<?>, Component>() {

                @Override//from   w  ww . j  a  v  a  2  s .c  om
                public void component(final ListItem<?> object, final IVisit<Component> visit) {
                    try {
                        Method getter = PropertyResolver.getPropertyGetter(property, object.getModelObject());
                        if (getter != null && getter.invoke(object.getModelObject()).equals(key)) {
                            visit.stop(object);
                        }
                    } catch (Exception e) {
                        LOG.error("Error invoke method", e);
                    }
                }
            });
}

From source file:org.apache.syncope.fit.console.AbstractConsoleITCase.java

License:Apache License

protected Component findComponentById(final String searchPath, final String id) {
    Component component = TESTER.getComponentFromLastRenderedPage(searchPath);
    return (component instanceof MarkupContainer ? MarkupContainer.class.cast(component) : component.getPage())
            .visitChildren(Component.class, new IVisitor<Component, Component>() {

                @Override//  ww  w.j a  va  2s .  c o  m
                public void component(final Component object, final IVisit<Component> visit) {
                    if (object.getId().equals(id)) {
                        visit.stop(object);
                    }
                }
            });
}

From source file:org.apache.syncope.fit.console.LogsITCase.java

License:Apache License

private Component searchLog(final String property, final String searchPath, final String key) {
    Component component = TESTER.getComponentFromLastRenderedPage(searchPath);

    Component result = component.getPage().visitChildren(ListItem.class,
            new IVisitor<ListItem<LoggerTO>, Component>() {

                @Override/*  w  ww.  j  a  v a  2s.c  om*/
                public void component(final ListItem<LoggerTO> object, final IVisit<Component> visit) {
                    try {
                        if (object.getModelObject() instanceof LoggerTO
                                && PropertyResolver.getPropertyGetter(property, object.getModelObject())
                                        .invoke(object.getModelObject()).equals(key)) {
                            visit.stop(object);
                        }
                    } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
                        LOG.error("Error invoke method", ex);
                    }
                }
            });
    return result;
}

From source file:org.artifactory.webapp.wicket.page.browse.home.RememberPageBehavior.java

License:Open Source License

@Override
public void beforeRender(Component component) {
    Page page = component.getPage();
    String pageUrl = getPageUrl(page);
    Cookie cookie = new Cookie(COOKIE_NAME, pageUrl);
    String contextPath = WicketUtils.getHttpServletRequest().getContextPath();
    cookie.setPath(contextPath);/* ww  w . j  ava 2  s .c om*/
    WicketUtils.getWebResponse().addCookie(cookie);
}

From source file:org.cdlflex.ui.markup.html.button.ButtonList.java

License:Apache License

/**
 * checks whether there is a button that is active or not.
 *
 * @param activeButton the current active button
 * @return true, if at least one button of button list is active
 *//*from   w w w  .  j ava 2 s. co  m*/
public final boolean hasActiveButton(final Component activeButton) {
    final Class<? extends Page> pageClass = activeButton.getPage().getPageClass();

    for (final AbstractLink link : getList()) {
        if (link instanceof IActivatable) {
            if (((IActivatable) link).isActive(activeButton)) {
                return true;
            }
        } else if (link instanceof BookmarkablePageLink) {
            if (((BookmarkablePageLink<?>) link).getPageClass().equals(pageClass)) {
                return true;
            }
        }
    }

    return false;
}

From source file:org.dcm4chee.web.common.secure.ExtendedSwarmStrategy.java

License:LGPL

private MarkupContainer findLowestSecureContainer(Component component) {

    final MarkupContainer[] lowestSecureParent = new MarkupContainer[1];

    component.visitParents(MarkupContainer.class, new IVisitor<Component>() {
        public Object component(Component component) {
            if (component instanceof ISecureComponent) {
                lowestSecureParent[0] = (MarkupContainer) component;
                return IVisitor.STOP_TRAVERSAL;
            }/*from w ww.  j  a va2  s  .co m*/
            return null;
        }
    });

    if (null == lowestSecureParent[0]) {
        try {
            lowestSecureParent[0] = component.getPage();
        } catch (IllegalStateException e) {
            throw new SecurityException(
                    this.getClass() + ": Unable to create alias for component: " + component, e);
        }
    }

    MarkupContainer markupContainer = lowestSecureParent[0];
    return markupContainer;
}

From source file:org.dcm4chee.wizard.common.login.secure.ExtendedSwarmStrategy.java

License:LGPL

private MarkupContainer findLowestSecureContainer(Component component) {

    final MarkupContainer[] lowestSecureParent = new MarkupContainer[1];

    component.visitParents(MarkupContainer.class, new IVisitor<MarkupContainer, Void>() {
        public void component(MarkupContainer component, IVisit<Void> visit) {
            if (component instanceof ISecureComponent) {
                lowestSecureParent[0] = component;
                visit.stop();//  w  w w. j  av  a 2  s.c o m
            }
        }
    });

    if (null == lowestSecureParent[0]) {
        try {
            lowestSecureParent[0] = component.getPage();
        } catch (IllegalStateException e) {
            throw new SecurityException(
                    this.getClass() + ": Unable to create alias for component: " + component, e);
        }
    }

    MarkupContainer markupContainer = lowestSecureParent[0];
    return markupContainer;
}

From source file:org.devgateway.eudevfin.ui.common.permissions.PermissionAuthorizationStrategy.java

License:Open Source License

/**
 * {@inheritDoc IAuthorizationStrategy#isActionAuthorized}
 *///  w  ww .  j ava2 s. c om
@Override
public boolean isActionAuthorized(Component component, Action action) {
    if (action == Component.ENABLE)
        return true; // we don't have permissions for enable, yet
    if (!(component instanceof PermissionAwareComponent))
        return true;
    if (action != Component.RENDER)
        throw new AssertionError("was assuming that action is render from this step forward");
    PermissionAwareComponent pwc = (PermissionAwareComponent) component;
    Page page = component.getPage();
    if (page == null || !(page instanceof PermissionAwarePage))
        return true; //not a permission aware page => other strategies decide

    ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder
            .getRequestAttributes();
    HttpServletRequest httpServletRequest = requestAttributes.getRequest();
    String transactionType = httpServletRequest.getParameter(Constants.PARAM_TRANSACTION_TYPE);
    if (transactionType == null || transactionType.isEmpty())
        return true; //not a transaction aware scope => others decide

    HashMap<String, RoleActionMapping> permissions = ((PermissionAwarePage) page).getPermissions();
    return checkPermissions(pwc, transactionType, permissions);
}

From source file:org.devproof.portal.core.app.PortalSession.java

License:Apache License

/**
 * Whether an user has the right for this component
 *
 * @param component component/*  w w w .  ja v a  2 s .  c om*/
 * @param action
 * @return true if the user has the right
 */
public boolean hasRight(Component component, Action action) {
    List<Right> allRights = rightService.getAllRights();
    if (component instanceof BookmarkablePageLink<?>) {
        /*
        * This will remove the links for pages where the user hasn't got
        * rights. If there exists a right starting with page.PageClassName,
        * the user must have the right to access the page!
        */
        BookmarkablePageLink<?> l = (BookmarkablePageLink<?>) component;
        Class<? extends Page> pageClass = l.getPageClass();
        return hasRight(pageClass, action);
    } else if (hasSecuredAnnotation(component.getClass())) {
        return evaluateSecuredAnnotation(component.getClass(), action);
    }
    // problem with tree table, i dont know why
    else if (!(component instanceof TreeTable)) {
        String rightName = RightConstants.COMPONENT_RIGHT_PREFIX
                + component.getPage().getClass().getSimpleName() + "." + component.getId();
        Right right = rightService.newRightEntity(rightName);
        if (allRights.contains(right)) {
            return hasRight(right);
        }

        rightName = RightConstants.GENERAL_RIGHT_PREFIX + component.getClass().getSimpleName();
        right = rightService.newRightEntity(rightName);
        if (allRights.contains(right)) {
            return hasRight(right);
        }
    }
    return true;
}

From source file:org.efaps.ui.wicket.components.menu.LinkItem.java

License:Apache License

/**
 * {@inheritDoc}/* ww w .j a v a  2s .co  m*/
 */
@Override
public void open(final Component _openComponent) throws EFapsException {
    final UIMenuItem model = super.getModelObject();

    final AbstractCommand command = model.getCommand();
    _openComponent.getPage();
    if (command.getTargetTable() != null) {
        if (command.getTargetStructurBrowserField() != null) {
            final StructurBrowserPage page = new StructurBrowserPage(model.getCommandUUID(),
                    model.getInstanceKey());
            setResponsePage(page);
        } else {
            if ("GridX".equals(Configuration.getAttribute(ConfigAttribute.TABLEDEFAULTTYPE))) {
                final GridPage page = new GridPage(Model.of(UIGrid.get(command.getUUID())));
                setResponsePage(page);
            } else {
                final TablePage page = new TablePage(model.getCommandUUID(), model.getInstanceKey());
                setResponsePage(page);
            }
        }
    } else if (command.getTargetForm() != null) {
        final FormPage page = new FormPage(model.getCommandUUID(), model.getInstanceKey());
        setResponsePage(page);
    }
}