use of com.qcadoo.view.internal.api.ComponentPattern in project qcadoo by qcadoo.
the class ViewDefinitionTest method shouldThrowCyclicDependencyOnInitialize.
@Test(expected = IllegalStateException.class)
public void shouldThrowCyclicDependencyOnInitialize() throws Exception {
// given
InternalViewDefinition viewDefinition = new ViewDefinitionImpl("name", "plugin", mock(DataDefinition.class), true, null);
ComponentPattern pattern1 = Mockito.mock(ComponentPattern.class);
given(pattern1.getName()).willReturn("test1");
given(pattern1.initialize()).willReturn(false, false, false);
ComponentPattern pattern2 = Mockito.mock(ComponentPattern.class);
given(pattern2.getName()).willReturn("test2");
given(pattern2.initialize()).willReturn(false, false, false);
ComponentPattern pattern3 = Mockito.mock(ComponentPattern.class);
given(pattern3.getName()).willReturn("test3");
given(pattern3.initialize()).willReturn(false, true);
ComponentPattern pattern4 = Mockito.mock(ComponentPattern.class);
given(pattern3.getName()).willReturn("test4");
given(pattern3.initialize()).willReturn(true);
viewDefinition.addComponentPattern(pattern1);
viewDefinition.addComponentPattern(pattern2);
viewDefinition.addComponentPattern(pattern3);
viewDefinition.addComponentPattern(pattern4);
// when
viewDefinition.initialize();
}
use of com.qcadoo.view.internal.api.ComponentPattern in project qcadoo by qcadoo.
the class ViewDefinitionTest method shouldReturnNullWhenPatternNotExists.
@Test
public void shouldReturnNullWhenPatternNotExists() throws Exception {
// given
InternalViewDefinition viewDefinition = new ViewDefinitionImpl("name", "plugin", mock(DataDefinition.class), true, null);
// when
ComponentPattern actualPattern = viewDefinition.getComponentByReference("xxx");
// then
assertNull(actualPattern);
}
use of com.qcadoo.view.internal.api.ComponentPattern in project qcadoo by qcadoo.
the class ViewGridColumnModule method getGrid.
private GridComponentPattern getGrid() {
InternalViewDefinition viewDefinition = viewDefinitionService.getWithoutSession(extendsViewPlugin, extendsViewName);
if (viewDefinition == null) {
throw new ModuleException(pluginIdentifier, "view", "reference to view which not exists");
}
ComponentPattern component = viewDefinition.getComponentByReference(extendsComponentName);
if (component == null) {
throw new ModuleException(pluginIdentifier, "view", "reference to component which not exists in " + extendsViewPlugin + "/" + extendsViewName);
}
if (!(component instanceof GridComponentPattern)) {
throw new ModuleException(pluginIdentifier, "view", "component '" + extendsComponentName + "' in " + extendsViewPlugin + "/" + extendsViewName + " is not a grid");
}
return (GridComponentPattern) component;
}
use of com.qcadoo.view.internal.api.ComponentPattern in project qcadoo by qcadoo.
the class AbstractContainerPattern method prepareView.
@Override
public Map<String, Object> prepareView(final Locale locale) {
Map<String, Object> model = super.prepareView(locale);
Map<String, Object> childrenModels = new LinkedHashMap<String, Object>();
for (ComponentPattern child : children.values()) {
if (isComponentEnabled(child)) {
childrenModels.put(child.getName(), child.prepareView(locale));
}
}
model.put("children", childrenModels);
return model;
}
use of com.qcadoo.view.internal.api.ComponentPattern in project qcadoo by qcadoo.
the class RibbonUtils method translateRibbonAction.
public static String translateRibbonAction(final String action, final ViewDefinition viewDefinition) {
if (action == null) {
return null;
}
if (viewDefinition == null) {
return action;
}
Pattern p = Pattern.compile("#\\{([^\\}]+)\\}");
Matcher m = p.matcher(action);
String translateAction = action;
while (m.find()) {
ComponentPattern actionComponentPattern = ((InternalViewDefinition) viewDefinition).getComponentByReference(m.group(1));
if (actionComponentPattern == null) {
throw new IllegalStateException("Cannot find component '" + m.group(1) + "' for action: " + action);
}
translateAction = translateAction.replace("#{" + m.group(1) + "}", "#{" + actionComponentPattern.getPath() + "}");
}
return translateAction;
}
Aggregations