Search in sources :

Example 6 with WindowComponentPattern

use of com.qcadoo.view.internal.components.window.WindowComponentPattern in project qcadoo by qcadoo.

the class LookupComponentPattern method initializeComponent.

@Override
protected void initializeComponent() throws JSONException {
    super.initializeComponent();
    for (ComponentOption option : getOptions()) {
        if ("expression".equals(option.getType())) {
            expression = option.getValue();
        } else if ("fieldCode".equals(option.getType())) {
            fieldCode = option.getValue();
        } else if ("header".equals(option.getType())) {
            header = Boolean.parseBoolean(option.getValue());
        } else if ("prioritizable".equals(option.getType())) {
            prioritizable = Boolean.parseBoolean(option.getValue());
        } else if ("onlyActive".equals(option.getType())) {
            onlyActive = Boolean.parseBoolean(option.getValue());
        } else if ("textRepresentationOnDisabled".equals(option.getType())) {
            textRepresentationOnDisabled = Boolean.parseBoolean(option.getValue());
        } else if ("boldTextRepresentationOnDisabled".equals(option.getType())) {
            Boolean optionValue = Boolean.parseBoolean(option.getValue());
            textRepresentationOnDisabled = optionValue;
            boldTextRepresentationOnDisabled = optionValue;
        }
    }
    modalDimensions = ModalDimensions.parseFromOptions(getOptions());
    checkState(hasText(fieldCode), "Missing fieldCode for lookup");
    checkState(hasText(expression), "Missing expression for lookup");
    String viewName = getViewName();
    DataDefinition dataDefinition = getDataDefinition();
    if (getScopeFieldDefinition() != null) {
        dataDefinition = getScopeFieldDefinition().getDataDefinition();
    }
    lookupViewDefinition = new ViewDefinitionImpl(viewName, getViewDefinition().getPluginIdentifier(), dataDefinition, false, getTranslationService());
    WindowComponentPattern window = createWindowComponentPattern(lookupViewDefinition);
    GridComponentPattern grid = createGridComponentPattern(lookupViewDefinition, window);
    for (ComponentOption option : getOptions()) {
        if ("orderable".equals(option.getType())) {
            Map<String, String> newAttributes = new HashMap<>();
            newAttributes.put(L_VALUE, option.getValue() + ",lookupCode");
            option = new ComponentOption("orderable", newAttributes);
            grid.addOption(option);
        } else if ("searchable".equals(option.getType())) {
            Map<String, String> newAttributes = new HashMap<>();
            newAttributes.put(L_VALUE, option.getValue() + ",lookupCode");
            option = new ComponentOption("searchable", newAttributes);
            grid.addOption(option);
        } else if (!"expression".equals(option.getType()) && !"fieldCode".equals(option.getType()) && !"textRepresentationOnDisabled".equals(option.getType()) && !"labelWidth".equals(option.getType())) {
            grid.addOption(option);
        }
    }
    grid.addOption(new ComponentOption("lookup", Collections.singletonMap(L_VALUE, L_TRUE)));
    window.addChild(grid);
    lookupViewDefinition.addComponentPattern(window);
    lookupViewDefinition.initialize();
}
Also used : ViewDefinitionImpl(com.qcadoo.view.internal.internal.ViewDefinitionImpl) GridComponentPattern(com.qcadoo.view.internal.components.grid.GridComponentPattern) WindowComponentPattern(com.qcadoo.view.internal.components.window.WindowComponentPattern) HashMap(java.util.HashMap) DataDefinition(com.qcadoo.model.api.DataDefinition) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 7 with WindowComponentPattern

use of com.qcadoo.view.internal.components.window.WindowComponentPattern in project qcadoo by qcadoo.

the class ViewRibbonModule method enable.

@Override
public void enable() {
    addedGroups = new HashMap<WindowComponentPattern, RibbonGroupsPack>();
    InternalViewDefinition viewDefinition = viewDefinitionService.getWithoutSession(viewExtension.getPluginName(), viewExtension.getViewName());
    if (viewDefinition == null) {
        throw new ModuleException(pluginIdentifier, "view", "reference to view which not exists");
    }
    try {
        for (Node groupNode : viewDefinitionParser.geElementChildren(viewExtension.getExtesionNode())) {
            try {
                InternalRibbonGroup group = viewDefinitionParser.parseRibbonGroup(groupNode, viewDefinition);
                group.setExtensionPluginIdentifier(pluginIdentifier);
                RibbonGroupsPack groupsPack = new SingleRibbonGroupPack(group);
                WindowComponentPattern window = viewDefinition.getRootWindow();
                window.getRibbon().addGroupsPack(groupsPack);
                addedGroups.put(window, groupsPack);
            } catch (ViewDefinitionParserNodeException e) {
                throw ViewDefinitionParserException.forFileAndNode(fileName, e);
            }
        }
    } catch (Exception e) {
        throw new ModuleException(pluginIdentifier, "view-ribbon-group", e);
    }
}
Also used : WindowComponentPattern(com.qcadoo.view.internal.components.window.WindowComponentPattern) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) Node(org.w3c.dom.Node) SingleRibbonGroupPack(com.qcadoo.view.internal.ribbon.model.SingleRibbonGroupPack) ViewDefinitionParserNodeException(com.qcadoo.view.internal.xml.ViewDefinitionParserNodeException) RibbonGroupsPack(com.qcadoo.view.internal.ribbon.model.RibbonGroupsPack) ModuleException(com.qcadoo.plugin.api.ModuleException) InternalRibbonGroup(com.qcadoo.view.internal.ribbon.model.InternalRibbonGroup) ViewDefinitionParserNodeException(com.qcadoo.view.internal.xml.ViewDefinitionParserNodeException) IOException(java.io.IOException) ModuleException(com.qcadoo.plugin.api.ModuleException) ViewDefinitionParserException(com.qcadoo.view.internal.xml.ViewDefinitionParserException)

Example 8 with WindowComponentPattern

use of com.qcadoo.view.internal.components.window.WindowComponentPattern in project qcadoo by qcadoo.

the class ViewTabModule method enable.

@Override
public void enable() {
    addedTabs = ArrayListMultimap.create();
    InternalViewDefinition viewDefinition = viewDefinitionService.getWithoutSession(viewExtension.getPluginName(), viewExtension.getViewName());
    if (viewDefinition == null) {
        throw new ModuleException(pluginIdentifier, "view", String.format("Reference to view which not exists: %s[%s]", viewExtension.getPluginName(), viewExtension.getViewName()));
    }
    try {
        for (Node tabNode : viewDefinitionParser.geElementChildren(viewExtension.getExtesionNode())) {
            WindowComponentPattern window = viewDefinition.getRootWindow();
            ComponentDefinition tabDefinition = viewDefinitionParser.getComponentDefinition(tabNode, window, viewDefinition);
            tabDefinition.setExtensionPluginIdentifier(pluginIdentifier);
            ComponentPattern tabPattern = new WindowTabComponentPattern(tabDefinition);
            try {
                tabPattern.parse(tabNode, viewDefinitionParser);
            } catch (ViewDefinitionParserNodeException e) {
                throw ViewDefinitionParserException.forFileAndNode(fileName, e);
            }
            window.addChild(tabPattern);
            addedTabs.put(window, tabPattern);
            tabPattern.initializeAll();
            tabPattern.registerViews(viewDefinitionService);
        }
    } catch (Exception e) {
        throw new ModuleException(pluginIdentifier, "view-tab", e);
    }
}
Also used : WindowComponentPattern(com.qcadoo.view.internal.components.window.WindowComponentPattern) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) Node(org.w3c.dom.Node) ViewDefinitionParserNodeException(com.qcadoo.view.internal.xml.ViewDefinitionParserNodeException) WindowTabComponentPattern(com.qcadoo.view.internal.components.window.WindowTabComponentPattern) ComponentPattern(com.qcadoo.view.internal.api.ComponentPattern) WindowComponentPattern(com.qcadoo.view.internal.components.window.WindowComponentPattern) ModuleException(com.qcadoo.plugin.api.ModuleException) WindowTabComponentPattern(com.qcadoo.view.internal.components.window.WindowTabComponentPattern) ViewDefinitionParserNodeException(com.qcadoo.view.internal.xml.ViewDefinitionParserNodeException) IOException(java.io.IOException) ModuleException(com.qcadoo.plugin.api.ModuleException) ViewDefinitionParserException(com.qcadoo.view.internal.xml.ViewDefinitionParserException) ComponentDefinition(com.qcadoo.view.internal.ComponentDefinition)

Example 9 with WindowComponentPattern

use of com.qcadoo.view.internal.components.window.WindowComponentPattern in project qcadoo by qcadoo.

the class LookupComponentPattern method createWindowComponentPattern.

private WindowComponentPattern createWindowComponentPattern(final ViewDefinition lookupViewDefinition) {
    ComponentDefinition windowComponentDefinition = new ComponentDefinition();
    windowComponentDefinition.setName(QcadooViewConstants.L_WINDOW);
    windowComponentDefinition.setTranslationService(getTranslationService());
    windowComponentDefinition.setApplicationContext(getApplicationContext());
    windowComponentDefinition.setViewDefinition(lookupViewDefinition);
    windowComponentDefinition.setContextualHelpService(getContextualHelpService());
    WindowComponentPattern window = new WindowComponentPattern(windowComponentDefinition);
    window.setFixedHeight(true);
    window.setHeader(header);
    window.setRibbon(createRibbon());
    return window;
}
Also used : WindowComponentPattern(com.qcadoo.view.internal.components.window.WindowComponentPattern)

Example 10 with WindowComponentPattern

use of com.qcadoo.view.internal.components.window.WindowComponentPattern in project qcadoo by qcadoo.

the class ComponentPatternTest method shouldHaveOptionsWhenAdded.

@Test
public void shouldHaveOptionsWhenAdded() throws Exception {
    // given
    AbstractComponentPattern pattern = new WindowComponentPattern(getComponentDefinition("testName", null));
    // when
    Map<String, Object> model = pattern.prepareView(Locale.ENGLISH);
    // then
    JSONObject options = (JSONObject) model.get("jsOptions");
    assertTrue(options.getBoolean("hasRibbon"));
}
Also used : WindowComponentPattern(com.qcadoo.view.internal.components.window.WindowComponentPattern) JSONObject(org.json.JSONObject) JSONObject(org.json.JSONObject) Test(org.junit.Test)

Aggregations

WindowComponentPattern (com.qcadoo.view.internal.components.window.WindowComponentPattern)16 Test (org.junit.Test)12 InternalViewDefinition (com.qcadoo.view.internal.api.InternalViewDefinition)11 DataDefinition (com.qcadoo.model.api.DataDefinition)9 TextInputComponentPattern (com.qcadoo.view.internal.components.TextInputComponentPattern)9 FieldDefinition (com.qcadoo.model.api.FieldDefinition)6 ComponentPattern (com.qcadoo.view.internal.api.ComponentPattern)4 FormComponentPattern (com.qcadoo.view.internal.components.form.FormComponentPattern)3 BelongsToType (com.qcadoo.model.api.types.BelongsToType)2 HasManyType (com.qcadoo.model.api.types.HasManyType)2 ModuleException (com.qcadoo.plugin.api.ModuleException)2 ViewDefinitionImpl (com.qcadoo.view.internal.internal.ViewDefinitionImpl)2 ViewDefinitionParserException (com.qcadoo.view.internal.xml.ViewDefinitionParserException)2 ViewDefinitionParserNodeException (com.qcadoo.view.internal.xml.ViewDefinitionParserNodeException)2 IOException (java.io.IOException)2 JSONObject (org.json.JSONObject)2 Node (org.w3c.dom.Node)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ComponentDefinition (com.qcadoo.view.internal.ComponentDefinition)1 ContainerPattern (com.qcadoo.view.internal.api.ContainerPattern)1