Search in sources :

Example 16 with InternalComponentState

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

the class WindowComponentState method setActiveTab.

@Override
public void setActiveTab(final String tabName) {
    InternalComponentState tabComponentState = getChild(tabName);
    if (tabComponentState == null) {
        String errorMsg = String.format("Can't activate WindowTab with name '%s' - it doesn't exist.", tabName);
        throw new IllegalArgumentException(errorMsg);
    }
    tabComponentState.setVisible(true);
    tabsSelectionState.switchTab(tabName);
}
Also used : InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState)

Example 17 with InternalComponentState

use of com.qcadoo.view.internal.api.InternalComponentState 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 18 with InternalComponentState

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

the class SmallTabLayoutState method renderContent.

@Override
protected JSONObject renderContent() throws JSONException {
    JSONObject state = new JSONObject();
    List<String> errorTabs = new LinkedList<String>();
    for (Map.Entry<String, InternalComponentState> child : getChildren().entrySet()) {
        if (child.getValue().isHasError()) {
            for (SmallTabLayoutPatternTab tab : tabs) {
                boolean found = false;
                for (ComponentPattern tabComponents : tab.getComponents()) {
                    if (tabComponents.getName().equals(child.getValue().getName())) {
                        errorTabs.add(tab.getName());
                        found = true;
                        break;
                    }
                }
                if (found) {
                    break;
                }
            }
        }
    }
    JSONArray errors = new JSONArray();
    for (String tabName : errorTabs) {
        errors.put(tabName);
    }
    state.put("errors", errors);
    return state;
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) ComponentPattern(com.qcadoo.view.internal.api.ComponentPattern) Map(java.util.Map) LinkedList(java.util.LinkedList) InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState)

Example 19 with InternalComponentState

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

the class ViewDefinitionStateImpl method renderContent.

@Override
protected JSONObject renderContent() throws JSONException {
    JSONObject json = new JSONObject();
    boolean isOk = true;
    List<InternalComponentState> states = getStatesAsList(getChildren().values());
    for (ComponentState state : states) {
        if (state.isHasError()) {
            isOk = false;
            break;
        }
    }
    json.put("status", isOk ? "ok" : "error");
    return json;
}
Also used : JSONObject(org.json.JSONObject) InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState) ComponentState(com.qcadoo.view.api.ComponentState) InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState)

Example 20 with InternalComponentState

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

the class WindowComponentState method renderContent.

@Override
protected JSONObject renderContent() throws JSONException {
    JSONObject json = new JSONObject();
    List<String> errorTabs = new LinkedList<String>();
    for (Map.Entry<String, InternalComponentState> child : getChildren().entrySet()) {
        if (child.getValue().isHasError()) {
            errorTabs.add(child.getKey());
        }
    }
    JSONArray errors = new JSONArray();
    for (String tabName : errorTabs) {
        errors.put(tabName);
    }
    json.put("errors", errors);
    json.put(JSON_TABS_SELECTION_STATE, tabsSelectionState.toJson());
    if (pattern.getContextualHelpUrl() != null) {
        json.put("contextualHelpUrl", pattern.getContextualHelpUrl());
    }
    if (ribbon != null) {
        InternalRibbon diffrenceRibbon = ribbon.getUpdate();
        if (diffrenceRibbon != null) {
            json.put("ribbon", RibbonUtils.translateRibbon(diffrenceRibbon, getLocale(), pattern));
        }
    }
    if (activeMenu != null) {
        json.put(JSON_ACTIVE_MENU, activeMenu);
    }
    return json;
}
Also used : JSONObject(org.json.JSONObject) InternalRibbon(com.qcadoo.view.internal.ribbon.model.InternalRibbon) JSONArray(org.json.JSONArray) Map(java.util.Map) LinkedList(java.util.LinkedList) InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState)

Aggregations

InternalComponentState (com.qcadoo.view.internal.api.InternalComponentState)29 Test (org.junit.Test)20 JSONObject (org.json.JSONObject)17 SimpleComponentState (com.qcadoo.view.internal.components.SimpleComponentState)8 FormComponentPattern (com.qcadoo.view.internal.components.form.FormComponentPattern)8 FormComponentState (com.qcadoo.view.internal.components.form.FormComponentState)7 ContainerState (com.qcadoo.view.internal.api.ContainerState)4 AbstractStateTest (com.qcadoo.view.internal.states.AbstractStateTest)4 Map (java.util.Map)4 ComponentState (com.qcadoo.view.api.ComponentState)3 InternalViewDefinition (com.qcadoo.view.internal.api.InternalViewDefinition)3 JSONArray (org.json.JSONArray)3 ComponentPattern (com.qcadoo.view.internal.api.ComponentPattern)2 InternalViewDefinitionState (com.qcadoo.view.internal.api.InternalViewDefinitionState)2 ViewDefinitionStateImpl (com.qcadoo.view.internal.internal.ViewDefinitionStateImpl)2 AbstractContainerState (com.qcadoo.view.internal.states.AbstractContainerState)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 DataDefinition (com.qcadoo.model.api.DataDefinition)1 CrudService (com.qcadoo.view.api.crud.CrudService)1