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;
}
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);
}
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");
}
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;
}
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;
}
Aggregations