All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.fluentlenium.core.domain.ComponentList Maven / Gradle / Ivy

package org.fluentlenium.core.domain;

import org.fluentlenium.core.FluentControl;
import org.fluentlenium.core.components.ComponentInstantiator;
import org.fluentlenium.core.components.LazyComponents;
import org.fluentlenium.core.components.LazyComponentsListener;
import org.openqa.selenium.WebElement;

import java.util.List;

/**
 * List of Component.
 *
 * @param  type of component
 * @see Component
 */
public class ComponentList extends DelegatingList implements WrapsElements, LazyComponents {
    protected final Class componentClass;

    protected final ComponentInstantiator instantiator;
    protected final FluentControl control;
    protected List proxy;

    private LazyComponents lazyComponents = new NotLazyComponents(); // NOPMD UnusedPrivateField

    private LazyComponents getLazyComponents() {
        return lazyComponents;
    }

    /**
     * Creates a new list of components
     *
     * @param componentClass component class
     * @param list           underlying list of components
     * @param control        control interface
     * @param instantiator   component instantiator
     */
    public ComponentList(Class componentClass, List list, FluentControl control,
            ComponentInstantiator instantiator) {
        super(list);
        if (list instanceof LazyComponents) {
            lazyComponents = (LazyComponents) list;
        }
        this.componentClass = componentClass;
        this.control = control;
        this.instantiator = instantiator;

        if (this.list instanceof WrapsElements) {
            proxy = ((WrapsElements) this.list).getWrappedElements(); // NOPMD ConstructorCallsOverridableMethod
        }
    }

    @Override
    public List getWrappedElements() {
        return proxy;
    }

    public boolean isLazy() {
        return getLazyComponents().isLazy();
    }

    public boolean addLazyComponentsListener(LazyComponentsListener listener) {
        return getLazyComponents().addLazyComponentsListener(listener);
    }

    public boolean isLazyInitialized() {
        return getLazyComponents().isLazyInitialized();
    }

    public boolean removeLazyComponentsListener(LazyComponentsListener listener) {
        return getLazyComponents().removeLazyComponentsListener(listener);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy