Example usage for org.apache.wicket Component getDefaultModel

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

Introduction

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

Prototype

public final IModel<?> getDefaultModel() 

Source Link

Document

Gets the model.

Usage

From source file:org.brixcms.web.tile.pagetile.PageTileViewerPanel.java

License:Apache License

private boolean checkLoop(final IModel<BrixNode> model) {
    final boolean loop[] = { false };

    visitParents(PageTileViewerPanel.class, new IVisitor<Component, BrixNode>() {
        public void component(Component component, IVisit iVisit) {
            // found parent with same model, this indicates a loop
            if (component != PageTileViewerPanel.this && component.getDefaultModel().equals(model)) {
                loop[0] = true;//w ww .  j  a v  a 2s  . c o  m
            }
        }
    });

    return loop[0];
}

From source file:org.devgateway.eudevfin.ui.common.events.CurrencyUpdateBehavior.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*  w  ww  .  j a  va 2s .  c o m*/
protected void onEventExtra(Component component, IEvent<?> event) {
    //force the model to update
    IModel<Object> model = (IModel<Object>) component.getDefaultModel();
    model.setObject(model.getObject());
}

From source file:org.obiba.onyx.quartz.core.wicket.layout.impl.behavior.QuestionnaireStyleBehavior.java

License:Open Source License

@Override
public void onComponentTag(Component component, ComponentTag tag) {
    IModel model = component.getDefaultModel();

    if (QuestionnaireModel.class.isInstance(model)) {
        QuestionnaireModel qModel = (QuestionnaireModel) model;
        String cssClass = qModel.getQuestionnaireName() + "-" + qModel.getElementClass().getSimpleName() + "-"
                + qModel.getElementName().replace('.', '-');

        if (tag.getAttributes().containsKey("class")) {
            cssClass += " " + tag.getAttributes().getString("class");
        }/*from ww  w.  j  a  va2 s . c o  m*/
        tag.getAttributes().put("class", cssClass);
    }
}

From source file:org.obiba.onyx.quartz.test.ComponentTesterUtils.java

License:Open Source License

/**
 * Find the first child of given class, and with model equals to the given model.
 * @param parent//w ww.j  av  a 2  s  .c  om
 * @param clazz
 * @param model
 * @return
 */
public static Component findChild(WebMarkupContainer parent, final Class clazz, final IModel model) {
    if (parent == null) {
        throw new IllegalArgumentException("parent cannot be null.");
    }

    return (Component) parent.visitChildren(new Component.IVisitor() {

        public Object component(Component component) {
            if (clazz.isAssignableFrom(component.getClass()) && component.getDefaultModel().equals(model)) {
                log.debug("child.path: {}", component.getPath());
                return component;
            }
            return CONTINUE_TRAVERSAL;
        }

    });

}

From source file:org.opensingular.form.wicket.behavior.ConfigureByMInstanciaAttributesBehavior.java

License:Apache License

private static SInstance resolveInstance(Component component) {
    if (component != null) {
        IModel<?> model = component.getDefaultModel();
        if (model != null && ISInstanceAwareModel.class.isAssignableFrom(model.getClass())) {
            return ((ISInstanceAwareModel<?>) model).getSInstance();
        }/*from   www .  j  ava  2  s. c o m*/
    }
    return null;
}

From source file:org.opensingular.form.wicket.model.ISInstanceAwareModel.java

License:Apache License

/**
 * Recupera o {@link SInstance} associado ao componente, se o componente tiver um model do tipo {@link
 * ISInstanceAwareModel}.//from  www. j a va 2 s . com
 */
@Nonnull
static Optional<SInstance> optionalSInstance(@Nonnull Component component) {
    return optionalSInstance(component.getDefaultModel());
}

From source file:org.opensingular.form.wicket.util.WicketFormUtils.java

License:Apache License

public static Optional<SInstance> resolveInstance(Component component) {
    return (component != null) ? resolveInstance(component.getDefaultModel()) : Optional.empty();
}

From source file:org.opensingular.form.wicket.util.WicketFormUtils.java

License:Apache License

public static String generateTitlePath(Component parentContainer, SInstance parentContext,
        Component childComponent, SInstance childInstance) {

    List<Component> components = Lists.newArrayList(childComponent);
    WicketUtils.appendListOfParents(components, childComponent, parentContainer);

    Deque<String> titles = new LinkedList<>();
    SInstance lastInstance = null;//from   w w  w  .  j a  v  a 2  s  . co  m
    String lastTitle = null;
    for (Component comp : components) {

        SInstance instance = WicketFormUtils.instanciaIfAware(comp.getDefaultModel()).orElse(null);

        String title = findTitle(comp);
        if (title != null && !Objects.equal(title, lastTitle)) {
            lastTitle = title;
            addTitle(titles, title, instance, lastInstance);
        }
        lastInstance = instance;
    }

    if (!titles.isEmpty()) {
        return titles.stream().collect(Collectors.joining(" > "));
    }
    return null;
}

From source file:org.wicketstuff.security.components.SecureComponentHelper.java

License:Apache License

/**
 * Checks if the component has a {@link ISecureModel}.
 * /*from  w  w w  .ja  v  a  2  s . c  o  m*/
 * @param component
 * @return true if the component has a securemodel, else false.
 */
public static boolean hasSecureModel(Component component) {
    return component != null && component.getDefaultModel() instanceof ISecureModel<?>;
}

From source file:org.wicketstuff.security.components.SecureComponentHelper.java

License:Apache License

/**
 * Default implementation for {@link ISecureComponent#isActionAuthorized(String)} and
 * {@link WaspAuthorizationStrategy#isActionAuthorized(Component, org.apache.wicket.authorization.Action)}
 * . First tries to use the {@link ISecurityCheck} from the component if that is not available
 * it tries the {@link ISecureModel} if neither is present the action is authorized on the
 * component./*  w w  w  . java  2s .c om*/
 * 
 * @param component
 *            the component to check
 * @param action
 *            the required action(s)
 * 
 * @return true, if the component is authorized, false otherwise.
 * @see ISecureComponent#isActionAuthorized(String)
 * @see ISecurityCheck
 * @see ISecureModel
 */
public static boolean isActionAuthorized(Component component, String action) {
    if (action == null)
        return true;
    ISecurityCheck check = saveGetSecurityCheck(component);
    if (check != null)
        return check.isActionAuthorized(getActionFactory().getAction(action));
    if (hasSecureModel(component))
        return ((ISecureModel<?>) component.getDefaultModel()).isAuthorized(component,
                getActionFactory().getAction(action));
    return true;
}