Search in sources :

Example 21 with InternalViewDefinition

use of com.qcadoo.view.internal.api.InternalViewDefinition 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;
}
Also used : AbstractComponentPattern(com.qcadoo.view.internal.patterns.AbstractComponentPattern) ComponentPattern(com.qcadoo.view.internal.api.ComponentPattern) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) AbstractComponentPattern(com.qcadoo.view.internal.patterns.AbstractComponentPattern) ComponentPattern(com.qcadoo.view.internal.api.ComponentPattern)

Example 22 with InternalViewDefinition

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

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

the class ViewModule method disable.

@Override
public void disable() {
    InternalViewDefinition viewDefinition = viewDefinitionParser.parseViewXml(xmlFile, pluginIdentifier);
    viewDefinitionService.delete(viewDefinition);
}
Also used : InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition)

Example 24 with InternalViewDefinition

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

the class ViewModule method enable.

@Override
public void enable() {
    try {
        InternalViewDefinition viewDefinition = viewDefinitionParser.parseViewXml(xmlFile, pluginIdentifier);
        viewDefinitionService.save(viewDefinition);
    } catch (Exception e) {
        throw new ModuleException(pluginIdentifier, "view", e);
    }
}
Also used : InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) ModuleException(com.qcadoo.plugin.api.ModuleException) ModuleException(com.qcadoo.plugin.api.ModuleException)

Example 25 with InternalViewDefinition

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

the class CrudServiceImpl method prepareView.

@Override
public ModelAndView prepareView(final String pluginIdentifier, final String viewName, final Map<String, String> arguments, final Locale locale) {
    InternalViewDefinition viewDefinition = (InternalViewDefinition) viewDefinitionService.get(pluginIdentifier, viewName);
    Preconditions.checkState(viewDefinition != null, String.format("Can't find view '%s/%s'", pluginIdentifier, viewName));
    ModelAndView modelAndView = new ModelAndView("crud/crudView");
    String context = viewDefinition.translateContextReferences(arguments.get("context"));
    JSONObject jsonContext = new JSONObject();
    if (StringUtils.hasText(context)) {
        try {
            jsonContext = new JSONObject(context);
            viewDefinition.setJsonContext(jsonContext);
        } catch (JSONException e) {
            throw new IllegalStateException(e.getMessage(), e);
        }
    }
    modelAndView.addObject("model", viewDefinition.prepareView(jsonContext, locale));
    modelAndView.addObject("viewName", viewName);
    modelAndView.addObject("pluginIdentifier", pluginIdentifier);
    modelAndView.addObject("context", context);
    boolean popup = false;
    if (arguments.containsKey("popup")) {
        popup = Boolean.parseBoolean(arguments.get("popup"));
    }
    modelAndView.addObject("popup", popup);
    modelAndView.addObject("locale", locale.getLanguage());
    return modelAndView;
}
Also used : JSONObject(org.json.JSONObject) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) ModelAndView(org.springframework.web.servlet.ModelAndView) JSONException(org.json.JSONException)

Aggregations

InternalViewDefinition (com.qcadoo.view.internal.api.InternalViewDefinition)49 Test (org.junit.Test)40 DataDefinition (com.qcadoo.model.api.DataDefinition)25 TextInputComponentPattern (com.qcadoo.view.internal.components.TextInputComponentPattern)21 WindowComponentPattern (com.qcadoo.view.internal.components.window.WindowComponentPattern)15 FieldDefinition (com.qcadoo.model.api.FieldDefinition)14 AbstractPatternTest (com.qcadoo.view.internal.patterns.AbstractPatternTest)14 ComponentPattern (com.qcadoo.view.internal.api.ComponentPattern)13 ComponentDefinition (com.qcadoo.view.internal.ComponentDefinition)11 JSONObject (org.json.JSONObject)10 FormComponentPattern (com.qcadoo.view.internal.components.form.FormComponentPattern)9 GridComponentPattern (com.qcadoo.view.internal.components.grid.GridComponentPattern)9 ComponentOption (com.qcadoo.view.internal.ComponentOption)8 ComponentState (com.qcadoo.view.api.ComponentState)7 ViewDefinitionImpl (com.qcadoo.view.internal.internal.ViewDefinitionImpl)7 InternalViewDefinitionState (com.qcadoo.view.internal.api.InternalViewDefinitionState)6 BelongsToType (com.qcadoo.model.api.types.BelongsToType)5 HasManyType (com.qcadoo.model.api.types.HasManyType)5 ModuleException (com.qcadoo.plugin.api.ModuleException)4 EnumType (com.qcadoo.model.internal.types.EnumType)3