Search in sources :

Example 11 with ComponentPattern

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;
}
Also used : JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) AbstractComponentPattern(com.qcadoo.view.internal.patterns.AbstractComponentPattern) ComponentPattern(com.qcadoo.view.internal.api.ComponentPattern) WindowComponentPattern(com.qcadoo.view.internal.components.window.WindowComponentPattern)

Example 12 with ComponentPattern

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;
}
Also used : ContainerPattern(com.qcadoo.view.internal.api.ContainerPattern) AbstractComponentPattern(com.qcadoo.view.internal.patterns.AbstractComponentPattern) ComponentPattern(com.qcadoo.view.internal.api.ComponentPattern) WindowComponentPattern(com.qcadoo.view.internal.components.window.WindowComponentPattern)

Example 13 with ComponentPattern

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;
}
Also used : JSONObject(org.json.JSONObject) AbstractComponentPattern(com.qcadoo.view.internal.patterns.AbstractComponentPattern) JSONArray(org.json.JSONArray) AbstractComponentPattern(com.qcadoo.view.internal.patterns.AbstractComponentPattern) ComponentPattern(com.qcadoo.view.internal.api.ComponentPattern) WindowComponentPattern(com.qcadoo.view.internal.components.window.WindowComponentPattern)

Example 14 with ComponentPattern

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;
}
Also used : InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) ComponentPattern(com.qcadoo.view.internal.api.ComponentPattern)

Example 15 with ComponentPattern

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;
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ComponentPattern(com.qcadoo.view.internal.api.ComponentPattern)

Aggregations

ComponentPattern (com.qcadoo.view.internal.api.ComponentPattern)30 Test (org.junit.Test)15 WindowComponentPattern (com.qcadoo.view.internal.components.window.WindowComponentPattern)14 InternalViewDefinition (com.qcadoo.view.internal.api.InternalViewDefinition)13 FormComponentPattern (com.qcadoo.view.internal.components.form.FormComponentPattern)13 TextInputComponentPattern (com.qcadoo.view.internal.components.TextInputComponentPattern)10 AbstractComponentPattern (com.qcadoo.view.internal.patterns.AbstractComponentPattern)6 DataDefinition (com.qcadoo.model.api.DataDefinition)5 ViewDefinitionImpl (com.qcadoo.view.internal.internal.ViewDefinitionImpl)5 AbstractPatternTest (com.qcadoo.view.internal.patterns.AbstractPatternTest)5 JSONObject (org.json.JSONObject)5 Node (org.w3c.dom.Node)5 JSONException (org.json.JSONException)3 NodeList (org.w3c.dom.NodeList)3 ModuleException (com.qcadoo.plugin.api.ModuleException)2 ComponentState (com.qcadoo.view.api.ComponentState)2 ComponentDefinition (com.qcadoo.view.internal.ComponentDefinition)2 ContainerPattern (com.qcadoo.view.internal.api.ContainerPattern)2 InternalComponentState (com.qcadoo.view.internal.api.InternalComponentState)2 AbstractContainerPattern (com.qcadoo.view.internal.patterns.AbstractContainerPattern)2