Search in sources :

Example 1 with ContainerState

use of com.qcadoo.view.internal.api.ContainerState in project qcadoo by qcadoo.

the class AbstractContainerState method findChild.

@Override
public InternalComponentState findChild(final String name) {
    checkNotNull(name, "name should be given");
    InternalComponentState referencedComponent = getChildren().get(name);
    if (referencedComponent != null) {
        return referencedComponent;
    }
    for (InternalComponentState component : getChildren().values()) {
        if (component instanceof ContainerState) {
            ContainerState innerContainer = (ContainerState) component;
            referencedComponent = innerContainer.findChild(name);
            if (referencedComponent != null) {
                return referencedComponent;
            }
        }
    }
    return null;
}
Also used : ContainerState(com.qcadoo.view.internal.api.ContainerState) InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState)

Example 2 with ContainerState

use of com.qcadoo.view.internal.api.ContainerState in project qcadoo by qcadoo.

the class ViewDefinitionStateTest method shouldReturnStateByFunctionalPath.

@Test
public void shouldReturnStateByFunctionalPath() throws Exception {
    // given
    InternalViewDefinitionState viewDefinitionState = new ViewDefinitionStateImpl();
    ContainerState state = mock(ContainerState.class);
    viewDefinitionState.registerComponent("reference", state);
    // when
    ComponentState actualState = viewDefinitionState.getComponentByReference("reference");
    // then
    assertEquals(state, actualState);
}
Also used : InternalViewDefinitionState(com.qcadoo.view.internal.api.InternalViewDefinitionState) ViewDefinitionStateImpl(com.qcadoo.view.internal.internal.ViewDefinitionStateImpl) ContainerState(com.qcadoo.view.internal.api.ContainerState) ComponentState(com.qcadoo.view.api.ComponentState) InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState) Test(org.junit.Test) AbstractStateTest(com.qcadoo.view.internal.states.AbstractStateTest)

Example 3 with ContainerState

use of com.qcadoo.view.internal.api.ContainerState in project qcadoo by qcadoo.

the class ViewDefinitionStateTest method shouldPerformEventOnAllComponent.

@Test
public void shouldPerformEventOnAllComponent() throws Exception {
    // given
    ViewDefinitionStateImpl viewDefinitionState = new ViewDefinitionStateImpl();
    ContainerState state1 = mock(ContainerState.class);
    given(state1.getName()).willReturn("name1");
    InternalComponentState state2 = mock(InternalComponentState.class);
    viewDefinitionState.addChild(state1);
    given(state1.getChildren()).willReturn(Collections.singletonMap("name2", state2));
    // when
    viewDefinitionState.performEvent((String) null, "event", new String[] { "arg1", "arg2" });
    // then
    Mockito.verify(state1).performEvent(viewDefinitionState, "event", "arg1", "arg2");
    Mockito.verify(state2).performEvent(viewDefinitionState, "event", "arg1", "arg2");
}
Also used : ViewDefinitionStateImpl(com.qcadoo.view.internal.internal.ViewDefinitionStateImpl) ContainerState(com.qcadoo.view.internal.api.ContainerState) InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState) Test(org.junit.Test) AbstractStateTest(com.qcadoo.view.internal.states.AbstractStateTest)

Example 4 with ContainerState

use of com.qcadoo.view.internal.api.ContainerState in project qcadoo by qcadoo.

the class ViewDefinitionStateImpl method getStatesAsList.

private List<InternalComponentState> getStatesAsList(final Collection<InternalComponentState> states) {
    List<InternalComponentState> list = new ArrayList<>();
    list.addAll(states);
    for (InternalComponentState state : states) {
        if (state instanceof ContainerState) {
            list.addAll(getStatesAsList(((ContainerState) state).getChildren().values()));
        }
    }
    return list;
}
Also used : AbstractContainerState(com.qcadoo.view.internal.states.AbstractContainerState) ContainerState(com.qcadoo.view.internal.api.ContainerState) InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState)

Example 5 with ContainerState

use of com.qcadoo.view.internal.api.ContainerState in project qcadoo by qcadoo.

the class ViewDefinitionStateImpl method getComponentByPath.

private ComponentState getComponentByPath(final String path) {
    ComponentState componentState = this;
    String[] pathParts = path.split("\\.");
    for (int i = 0; i < pathParts.length; i++) {
        ContainerState container = (ContainerState) componentState;
        componentState = container.getChild(pathParts[i]);
        if (componentState == null) {
            return null;
        }
    }
    return componentState;
}
Also used : AbstractContainerState(com.qcadoo.view.internal.states.AbstractContainerState) ContainerState(com.qcadoo.view.internal.api.ContainerState) ComponentState(com.qcadoo.view.api.ComponentState) InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState)

Aggregations

ContainerState (com.qcadoo.view.internal.api.ContainerState)6 InternalComponentState (com.qcadoo.view.internal.api.InternalComponentState)6 ViewDefinitionStateImpl (com.qcadoo.view.internal.internal.ViewDefinitionStateImpl)3 AbstractStateTest (com.qcadoo.view.internal.states.AbstractStateTest)3 Test (org.junit.Test)3 ComponentState (com.qcadoo.view.api.ComponentState)2 AbstractContainerState (com.qcadoo.view.internal.states.AbstractContainerState)2 InternalViewDefinitionState (com.qcadoo.view.internal.api.InternalViewDefinitionState)1