use of com.qcadoo.view.internal.api.ComponentPattern in project qcadoo by qcadoo.
the class ViewDefinitionImpl method prepareView.
@Override
public Map<String, Object> prepareView(final JSONObject jsonObject, final Locale locale) {
viewHooksHolder.callConstructionHooks(this, jsonObject, locale);
Map<String, Object> model = Maps.newHashMap();
Map<String, Object> childrenModels = Maps.newHashMap();
toggleAdditionalNavigationGroup(getBooleanFromJson(jsonObject, "window.showBack"));
permanentlyDisabled = getBooleanFromJson(jsonObject, "window." + AbstractComponentState.JSON_PERMANENTLY_DISABLED);
toggleRibbonPermanentlyDisabled();
for (ComponentPattern componentPattern : patterns.values()) {
childrenModels.put(componentPattern.getName(), componentPattern.prepareView(locale));
}
model.put(JSON_COMPONENTS, childrenModels);
model.put(JSON_JS_FILE_PATHS, getJsFilePaths());
model.put("hasDataDefinition", getDataDefinition() != null);
try {
JSONObject json = new JSONObject();
JSONObject translations = new JSONObject();
translations.put("backWithChangesConfirmation", translationService.translate("qcadooView.backWithChangesConfirmation", locale));
json.put("translations", translations);
if (windowWidth != null) {
json.put("windowWidth", windowWidth);
}
if (windowHeight != null) {
json.put("windowHeight", windowHeight);
}
model.put("jsOptions", json);
} catch (JSONException e) {
throw new IllegalStateException(e.getMessage(), e);
}
return model;
}
use of com.qcadoo.view.internal.api.ComponentPattern in project qcadoo by qcadoo.
the class ViewDefinitionImpl method getPatternsAsList.
private List<ComponentPattern> getPatternsAsList(final Collection<ComponentPattern> patterns) {
List<ComponentPattern> list = new ArrayList<ComponentPattern>();
list.addAll(patterns);
for (ComponentPattern pattern : patterns) {
if (pattern instanceof ContainerPattern) {
list.addAll(getPatternsAsList(((ContainerPattern) pattern).getChildren().values()));
}
}
return list;
}
use of com.qcadoo.view.internal.api.ComponentPattern in project qcadoo by qcadoo.
the class ViewDefinitionImpl method performEvent.
@Override
public ViewDefinitionState performEvent(final JSONObject jsonObject, final Locale locale) throws JSONException {
viewHooksHolder.callConstructionHooks(this, jsonObject, locale);
ViewDefinitionStateImpl viewDefinitionState = new ViewDefinitionStateImpl();
viewDefinitionState.setTranslationService(translationService);
viewDefinitionState.setJsonContext(getJsonContext());
JSONObject eventJson = jsonObject.getJSONObject(JSON_EVENT);
String eventName = eventJson.getString(JSON_EVENT_NAME);
viewDefinitionState.setViewAfterReload(!(eventName.startsWith("initialize") || "reset".equals(eventName)));
viewDefinitionState.setViewAfterRedirect(eventName.startsWith("redirect") || eventName.startsWith("initialize"));
for (ComponentPattern cp : patterns.values()) {
viewDefinitionState.addChild(cp.createComponentState(viewDefinitionState));
}
viewHooksHolder.callLifecycleHooks(HookType.BEFORE_INITIALIZE, viewDefinitionState);
if (permanentlyDisabled) {
jsonObject.put(AbstractComponentState.JSON_PERMANENTLY_DISABLED, true);
}
viewDefinitionState.initialize(jsonObject, locale);
for (ComponentPattern cp : patterns.values()) {
((AbstractComponentPattern) cp).updateComponentStateListeners(viewDefinitionState);
}
viewHooksHolder.callLifecycleHooks(HookType.AFTER_INITIALIZE, viewDefinitionState);
String eventComponent = eventJson.has(JSON_EVENT_COMPONENT) ? eventJson.getString(JSON_EVENT_COMPONENT) : null;
JSONArray eventArgsArray = eventJson.has(JSON_EVENT_ARGS) ? eventJson.getJSONArray(JSON_EVENT_ARGS) : new JSONArray();
String[] eventArgs = new String[eventArgsArray.length()];
for (int i = 0; i < eventArgsArray.length(); i++) {
eventArgs[i] = eventArgsArray.getString(i);
}
viewDefinitionState.performEvent(eventComponent, eventName, eventArgs);
viewHooksHolder.callLifecycleHooks(HookType.BEFORE_RENDER, viewDefinitionState);
return viewDefinitionState;
}
use of com.qcadoo.view.internal.api.ComponentPattern in project qcadoo by qcadoo.
the class ViewListenerModule method getComponent.
private ComponentPattern getComponent() {
InternalViewDefinition extendsView = viewDefinitionService.getWithoutSession(extendsViewPlugin, extendsViewName);
Preconditions.checkNotNull(extendsView, String.format("extension in %s: referes to view which not exists (%s - %s)", pluginIdentifier, extendsViewPlugin, extendsViewName));
ComponentPattern component = extendsView.getComponentByReference(extendsComponentName);
Preconditions.checkNotNull(component, String.format("extension in %s: component '%s' not exists in view (%s - %s)", pluginIdentifier, extendsComponentName, extendsViewPlugin, extendsViewName));
return component;
}
use of com.qcadoo.view.internal.api.ComponentPattern in project qcadoo by qcadoo.
the class FlowGridLayoutPattern method createFlowGridLayoutCell.
private FlowGridLayoutCell createFlowGridLayoutCell(final Node child, final ViewDefinitionParser parser) throws ViewDefinitionParserNodeException {
Integer colspan = getIntAttribute(child, "width", parser);
Integer rowspan = getIntAttribute(child, "height", parser);
Integer minHeight = null;
if (rowspan == null) {
rowspan = minHeight = getIntAttribute(child, "minHeight", parser);
if (minHeight == null) {
rowspan = 1;
}
}
ComponentPattern elementComponent = null;
NodeList elementComponentNodes = child.getChildNodes();
FlowGridLayoutCell cell = new FlowGridLayoutCell();
for (int elementComponentNodesIter = 0; elementComponentNodesIter < elementComponentNodes.getLength(); elementComponentNodesIter++) {
Node elementComponentNode = elementComponentNodes.item(elementComponentNodesIter);
if (elementComponentNode.getNodeType() != Node.ELEMENT_NODE) {
continue;
}
parser.checkState("component".equals(elementComponentNode.getNodeName()), elementComponentNode, "layoutElement can contains only components");
elementComponent = parser.parseComponent(elementComponentNode, this);
this.addChild(elementComponent);
cell.addComponent(elementComponent);
}
if (colspan != null) {
cell.setColspan(colspan);
}
if (rowspan != null) {
cell.setRowspan(rowspan);
}
cell.setMinHeight(minHeight);
return cell;
}
Aggregations