Search in sources :

Example 91 with MetaClass

use of com.haulmont.chile.core.model.MetaClass in project cuba by cuba-platform.

the class AttributePermissionsFrame method applyPermissions.

protected void applyPermissions(boolean editable) {
    allHideCheck.setEditable(editable);
    allModifyCheck.setEditable(editable);
    allReadOnlyCheck.setEditable(editable);
    MetaClass metaClass = attributeTargetsDs.getItem().getEntityMetaClass();
    for (AttributePermissionControl attributePermissionControl : permissionControls) {
        attributePermissionControl.getHideCheckBox().setEditable(editable);
        attributePermissionControl.getHideCheckBox().setEnabled(editable);
        attributePermissionControl.getReadOnlyCheckBox().setEditable(editable);
        attributePermissionControl.getReadOnlyCheckBox().setEnabled(editable);
        String attributeName = attributePermissionControl.getAttributeName();
        if (userSession.isEntityAttrPermitted(metaClass, attributeName, EntityAttrAccess.MODIFY)) {
            boolean canUpdateEntity = userSession.isEntityOpPermitted(metaClass, EntityOp.UPDATE);
            attributePermissionControl.getModifyCheckBox().setEditable(canUpdateEntity && editable);
            attributePermissionControl.getModifyCheckBox().setEnabled(canUpdateEntity && editable);
        } else {
            attributePermissionControl.getModifyCheckBox().setEditable(false);
            attributePermissionControl.getModifyCheckBox().setEnabled(false);
        }
    }
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass)

Example 92 with MetaClass

use of com.haulmont.chile.core.model.MetaClass in project cuba by cuba-platform.

the class EntityNameFilter method test.

@Override
public boolean test(@Nullable T target) {
    if (target != null) {
        if (Boolean.TRUE.equals(assignedOnlyCheckBox.getValue()) && !target.isAssigned()) {
            return false;
        }
        if (Boolean.FALSE.equals(systemLevelCheckBox.getValue()) && (target instanceof EntityPermissionTarget) && !target.isAssigned()) {
            Class entityClass = ((EntityPermissionTarget) target).getEntityClass();
            MetaClass metaClass = metadata.getSession().getClassNN(entityClass);
            if (metadata.getTools().isSystemLevel(metaClass)) {
                return false;
            }
        }
        String filterValue = StringUtils.trimToEmpty(entityFilter.<String>getValue());
        return StringUtils.isBlank(filterValue) || StringUtils.containsIgnoreCase(target.getCaption(), filterValue);
    }
    return false;
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) MetaClass(com.haulmont.chile.core.model.MetaClass) EntityPermissionTarget(com.haulmont.cuba.gui.app.security.entity.EntityPermissionTarget)

Example 93 with MetaClass

use of com.haulmont.chile.core.model.MetaClass in project cuba by cuba-platform.

the class AttributeEditor method openConstraintWizard.

public void openConstraintWizard() {
    Class entityClass = attribute.getJavaClassForEntity();
    if (entityClass == null) {
        showNotification(getMessage("selectEntityType"));
        return;
    }
    MetaClass metaClass = metadata.getClassNN(entityClass);
    FakeFilterSupport fakeFilterSupport = new FakeFilterSupport(this, metaClass);
    final Filter fakeFilter = fakeFilterSupport.createFakeFilter();
    final FilterEntity filterEntity = fakeFilterSupport.createFakeFilterEntity(attribute.getFilterXml());
    final ConditionsTree conditionsTree = fakeFilterSupport.createFakeConditionsTree(fakeFilter, filterEntity);
    Map<String, Object> params = new HashMap<>();
    params.put("filter", fakeFilter);
    params.put("filterEntity", filterEntity);
    params.put("conditions", conditionsTree);
    params.put("useShortConditionForm", true);
    FilterEditor filterEditor = (FilterEditor) openWindow("filterEditor", WindowManager.OpenType.DIALOG, params);
    filterEditor.addCloseListener(actionId -> {
        if (!COMMIT_ACTION_ID.equals(actionId))
            return;
        FilterParser filterParser1 = AppBeans.get(FilterParser.class);
        filterEntity.setXml(filterParser1.getXml(filterEditor.getConditions(), Param.ValueProperty.DEFAULT_VALUE));
        if (filterEntity.getXml() != null) {
            Element element = Dom4j.readDocument(filterEntity.getXml()).getRootElement();
            com.haulmont.cuba.core.global.filter.FilterParser filterParser = new com.haulmont.cuba.core.global.filter.FilterParser(element);
            String jpql = new SecurityJpqlGenerator().generateJpql(filterParser.getRoot());
            attribute.setWhereClause(jpql);
            Set<String> joins = filterParser.getRoot().getJoins();
            if (!joins.isEmpty()) {
                String joinsStr = new StrBuilder().appendWithSeparators(joins, " ").toString();
                attribute.setJoinClause(joinsStr);
            }
            attribute.setFilterXml(filterEntity.getXml());
        }
    });
}
Also used : FilterEntity(com.haulmont.cuba.security.entity.FilterEntity) Element(org.dom4j.Element) FilterEditor(com.haulmont.cuba.gui.components.filter.edit.FilterEditor) com.haulmont.cuba.core.global(com.haulmont.cuba.core.global) FakeFilterSupport(com.haulmont.cuba.gui.components.filter.FakeFilterSupport) MetaClass(com.haulmont.chile.core.model.MetaClass) MetaClass(com.haulmont.chile.core.model.MetaClass) FilterParser(com.haulmont.cuba.gui.components.filter.FilterParser) SecurityJpqlGenerator(com.haulmont.cuba.core.global.filter.SecurityJpqlGenerator) ConditionsTree(com.haulmont.cuba.gui.components.filter.ConditionsTree) StrBuilder(org.apache.commons.lang.text.StrBuilder)

Example 94 with MetaClass

use of com.haulmont.chile.core.model.MetaClass in project cuba by cuba-platform.

the class AttributeEditor method setupVisibility.

private void setupVisibility() {
    for (FieldGroup.FieldConfig fieldConfig : attributeFieldGroup.getFields()) {
        if (!ALWAYS_VISIBLE_FIELDS.contains(fieldConfig.getId())) {
            attributeFieldGroup.setVisible(fieldConfig.getId(), false);
        }
    }
    Collection<String> componentIds = FIELDS_VISIBLE_FOR_DATATYPES.get(attribute.getDataType());
    if (componentIds != null) {
        for (String componentId : componentIds) {
            attributeFieldGroup.setVisible(componentId, true);
        }
    }
    if (attribute.getDataType() == PropertyType.ENTITY) {
        if (StringUtils.isNotBlank(attribute.getEntityClass())) {
            defaultEntityField.setEditable(true);
            whereField.setEnabled(true);
            joinField.setEnabled(true);
            Class entityClass = attribute.getJavaClassForEntity();
            MetaClass metaClass = metadata.getClass(entityClass);
            defaultEntityField.setMetaClass(metaClass);
            fillDefaultEntities(entityClass);
            fillSelectEntityScreens(entityClass);
            dynamicAttributesGuiTools.initEntityPickerField(defaultEntityField, attribute);
        } else {
            defaultEntityField.setEditable(false);
            whereField.setEnabled(false);
            joinField.setEnabled(false);
        }
        if (Boolean.TRUE.equals(attribute.getLookup())) {
            attributeFieldGroup.setVisible("screen", false);
        } else {
            attributeFieldGroup.setVisible("screen", true);
        }
        getDialogOptions().center();
    }
    if (attribute.getDataType() == PropertyType.DATE) {
        if (Boolean.TRUE.equals(attribute.getDefaultDateIsCurrent())) {
            attributeFieldGroup.setVisible("defaultDate", false);
            attributeFieldGroup.setFieldValue("defaultDate", null);
        } else {
            attributeFieldGroup.setVisible("defaultDate", true);
        }
    }
    if (attribute.getDataType() == PropertyType.BOOLEAN || attribute.getDataType() == PropertyType.ENUMERATION) {
        attributeFieldGroup.setFieldValue("isCollection", null);
    }
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) MetaClass(com.haulmont.chile.core.model.MetaClass)

Example 95 with MetaClass

use of com.haulmont.chile.core.model.MetaClass in project cuba by cuba-platform.

the class AttributeEditor method initFieldGroup.

protected void initFieldGroup() {
    attributeFieldGroup.addCustomField("defaultBoolean", new FieldGroup.CustomFieldGenerator() {

        @Override
        public Component generateField(Datasource datasource, String propertyId) {
            LookupField lookupField = factory.createComponent(LookupField.class);
            Map<String, Object> options = new TreeMap<>();
            options.put(datatypeFormatter.formatBoolean(true), true);
            options.put(datatypeFormatter.formatBoolean(false), false);
            lookupField.setOptionsMap(options);
            lookupField.setDatasource(attributeDs, "defaultBoolean");
            return lookupField;
        }
    });
    attributeFieldGroup.addCustomField("dataType", new FieldGroup.CustomFieldGenerator() {

        @Override
        public Component generateField(Datasource datasource, String propertyId) {
            dataTypeField = factory.createComponent(LookupField.class);
            Map<String, Object> options = new TreeMap<>();
            PropertyType[] types = PropertyType.values();
            for (PropertyType propertyType : types) {
                options.put(getMessage(propertyType.toString()), propertyType);
            }
            dataTypeField.setWidth(fieldWidth);
            dataTypeField.setNewOptionAllowed(false);
            dataTypeField.setRequired(true);
            dataTypeField.setRequiredMessage(getMessage("dataTypeRequired"));
            dataTypeField.setOptionsMap(options);
            dataTypeField.setCaption(getMessage("dataType"));
            dataTypeField.setFrame(frame);
            dataTypeField.setDatasource(datasource, propertyId);
            return dataTypeField;
        }
    });
    attributeFieldGroup.addCustomField("screen", new FieldGroup.CustomFieldGenerator() {

        @Override
        public Component generateField(Datasource datasource, String propertyId) {
            screenField = factory.createComponent(LookupField.class);
            screenField.setId("screenField");
            screenField.setCaption(getMessage("screen"));
            screenField.setWidth(fieldWidth);
            screenField.setRequired(true);
            screenField.setRequiredMessage(getMessage("entityScreenRequired"));
            screenField.setFrame(frame);
            screenField.setDatasource(datasource, propertyId);
            return screenField;
        }
    });
    attributeFieldGroup.addCustomField("entityClass", new FieldGroup.CustomFieldGenerator() {

        @Override
        public Component generateField(Datasource datasource, String propertyId) {
            entityTypeField = factory.createComponent(LookupField.class);
            entityTypeField.setId("entityClass");
            entityTypeField.setCaption(getMessage("entityType"));
            entityTypeField.setRequired(true);
            entityTypeField.setRequiredMessage(getMessage("entityTypeRequired"));
            entityTypeField.setWidth(fieldWidth);
            entityTypeField.setFrame(frame);
            Map<String, Object> options = new TreeMap<>();
            MetaClass entityType = null;
            for (MetaClass metaClass : metadataTools.getAllPersistentMetaClasses()) {
                if (!metadataTools.isSystemLevel(metaClass)) {
                    if (metadata.getTools().hasCompositePrimaryKey(metaClass) && !HasUuid.class.isAssignableFrom(metaClass.getJavaClass())) {
                        continue;
                    }
                    options.put(messageTools.getDetailedEntityCaption(metaClass), metaClass.getJavaClass().getName());
                    if (attribute != null && metaClass.getJavaClass().getName().equals(attribute.getEntityClass())) {
                        entityType = metaClass;
                    }
                }
            }
            entityTypeField.setOptionsMap(options);
            entityTypeField.setValue(entityType);
            entityTypeField.setDatasource(datasource, propertyId);
            return entityTypeField;
        }
    });
    attributeFieldGroup.addCustomField("defaultEntityId", (datasource, propertyId) -> {
        defaultEntityField = factory.createComponent(PickerField.class);
        defaultEntityField.setCaption(messages.getMessage(CategoryAttribute.class, "CategoryAttribute.defaultEntityId"));
        defaultEntityField.addValueChangeListener(e -> {
            Entity entity = (Entity) e.getValue();
            if (entity != null) {
                attribute.setObjectDefaultEntityId(referenceToEntitySupport.getReferenceId(entity));
            } else {
                attribute.setObjectDefaultEntityId(null);
            }
            ((AbstractDatasource) attributeDs).modified(attribute);
        });
        entityLookupAction = defaultEntityField.addLookupAction();
        defaultEntityField.addClearAction();
        return defaultEntityField;
    });
    attributeFieldGroup.addCustomField("enumeration", (datasource, propertyId) -> {
        enumerationListEditor = factory.createComponent(ListEditor.class);
        enumerationListEditor.setWidth("100%");
        enumerationListEditor.setItemType(ListEditor.ItemType.STRING);
        enumerationListEditor.setRequired(true);
        enumerationListEditor.setRequiredMessage(getMessage("enumRequired"));
        enumerationListEditor.addValueChangeListener(e -> {
            List<String> value = (List<String>) e.getValue();
            attribute.setEnumeration(Joiner.on(",").join(value));
        });
        if (localizedFrame != null) {
            enumerationListEditor.setEditorWindowId("localizedEnumerationWindow");
            enumerationListEditor.setEditorParamsSupplier(() -> ParamsMap.of("enumerationLocales", attribute.getEnumerationLocales()));
            enumerationListEditor.addEditorCloseListener(closeEvent -> {
                if (closeEvent.getActionId().equals(COMMIT_ACTION_ID)) {
                    LocalizedEnumerationWindow enumerationWindow = (LocalizedEnumerationWindow) closeEvent.getWindow();
                    attribute.setEnumerationLocales(enumerationWindow.getLocalizedValues());
                }
            });
        }
        return enumerationListEditor;
    });
    attributeFieldGroup.addCustomField("whereClause", (datasource, propertyId) -> {
        whereField = factory.createComponent(SourceCodeEditor.class);
        whereField.setDatasource(attributeDs, "whereClause");
        whereField.setWidth("100%");
        whereField.setHeight(themeConstants.get("cuba.gui.customConditionFrame.whereField.height"));
        whereField.setSuggester((source, text, cursorPosition) -> requestHint(whereField, text, cursorPosition));
        whereField.setHighlightActiveLine(false);
        whereField.setShowGutter(false);
        return whereField;
    });
    attributeFieldGroup.addCustomField("joinClause", (datasource, propertyId) -> {
        joinField = factory.createComponent(SourceCodeEditor.class);
        joinField.setDatasource(attributeDs, "joinClause");
        joinField.setWidth("100%");
        joinField.setHeight(themeConstants.get("cuba.gui.customConditionFrame.joinField.height"));
        joinField.setSuggester((source, text, cursorPosition) -> requestHint(joinField, text, cursorPosition));
        joinField.setHighlightActiveLine(false);
        joinField.setShowGutter(false);
        return joinField;
    });
    attributeFieldGroup.addCustomField("constraintWizard", (datasource, propertyId) -> {
        HBoxLayout hbox = factory.createComponent(HBoxLayout.class);
        hbox.setWidth("100%");
        LinkButton linkButton = factory.createComponent(LinkButton.class);
        linkButton.setAction(new BaseAction("constraintWizard").withHandler(event -> openConstraintWizard()));
        linkButton.setCaption(getMessage("constraintWizard"));
        linkButton.setAlignment(Alignment.MIDDLE_LEFT);
        hbox.add(linkButton);
        return hbox;
    });
    attributeDs.addItemPropertyChangeListener(e -> {
        String property = e.getProperty();
        CategoryAttribute attribute = getItem();
        if ("dataType".equalsIgnoreCase(property) || "lookup".equalsIgnoreCase(property) || "defaultDateIsCurrent".equalsIgnoreCase(property) || "entityClass".equalsIgnoreCase(property)) {
            setupVisibility();
        }
        if ("name".equalsIgnoreCase(property)) {
            fillAttributeCode();
        }
        if ("screen".equalsIgnoreCase(property) || "joinClause".equals(property) || "whereClause".equals(property)) {
            dynamicAttributesGuiTools.initEntityPickerField(defaultEntityField, attribute);
        }
    });
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) StrBuilder(org.apache.commons.lang.text.StrBuilder) StringUtils(org.apache.commons.lang.StringUtils) java.util(java.util) WindowManager(com.haulmont.cuba.gui.WindowManager) Datasource(com.haulmont.cuba.gui.data.Datasource) DynamicAttributesGuiTools(com.haulmont.cuba.gui.dynamicattributes.DynamicAttributesGuiTools) Dom4j(com.haulmont.bali.util.Dom4j) ParamsMap(com.haulmont.bali.util.ParamsMap) Multimap(com.google.common.collect.Multimap) MetaClass(com.haulmont.chile.core.model.MetaClass) FakeFilterSupport(com.haulmont.cuba.gui.components.filter.FakeFilterSupport) com.haulmont.cuba.core.global(com.haulmont.cuba.core.global) AbstractDatasource(com.haulmont.cuba.gui.data.impl.AbstractDatasource) DatasourceImplementation(com.haulmont.cuba.gui.data.impl.DatasourceImplementation) Inject(javax.inject.Inject) Strings(com.google.common.base.Strings) FilterEditor(com.haulmont.cuba.gui.components.filter.edit.FilterEditor) Lists(com.google.common.collect.Lists) FilterParser(com.haulmont.cuba.gui.components.filter.FilterParser) HasUuid(com.haulmont.cuba.core.entity.HasUuid) JpqlSuggestionFactory(com.haulmont.cuba.gui.components.autocomplete.JpqlSuggestionFactory) ComponentsFactory(com.haulmont.cuba.gui.xml.layout.ComponentsFactory) CategoryAttribute(com.haulmont.cuba.core.entity.CategoryAttribute) BaseAction(com.haulmont.cuba.gui.components.actions.BaseAction) Splitter(com.google.common.base.Splitter) com.haulmont.cuba.gui.components(com.haulmont.cuba.gui.components) ScreensHelper(com.haulmont.cuba.gui.ScreensHelper) FilterEntity(com.haulmont.cuba.security.entity.FilterEntity) Sets(com.google.common.collect.Sets) RemoveAction(com.haulmont.cuba.gui.components.actions.RemoveAction) String.format(java.lang.String.format) ConditionsTree(com.haulmont.cuba.gui.components.filter.ConditionsTree) Suggestion(com.haulmont.cuba.gui.components.autocomplete.Suggestion) ThemeConstants(com.haulmont.cuba.gui.theme.ThemeConstants) Param(com.haulmont.cuba.gui.components.filter.Param) SecurityJpqlGenerator(com.haulmont.cuba.core.global.filter.SecurityJpqlGenerator) Element(org.dom4j.Element) PropertyType(com.haulmont.cuba.core.app.dynamicattributes.PropertyType) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) Joiner(com.google.common.base.Joiner) Entity(com.haulmont.cuba.core.entity.Entity) FilterEntity(com.haulmont.cuba.security.entity.FilterEntity) Entity(com.haulmont.cuba.core.entity.Entity) PropertyType(com.haulmont.cuba.core.app.dynamicattributes.PropertyType) HasUuid(com.haulmont.cuba.core.entity.HasUuid) Datasource(com.haulmont.cuba.gui.data.Datasource) AbstractDatasource(com.haulmont.cuba.gui.data.impl.AbstractDatasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) AbstractDatasource(com.haulmont.cuba.gui.data.impl.AbstractDatasource) BaseAction(com.haulmont.cuba.gui.components.actions.BaseAction) CategoryAttribute(com.haulmont.cuba.core.entity.CategoryAttribute) MetaClass(com.haulmont.chile.core.model.MetaClass) ParamsMap(com.haulmont.bali.util.ParamsMap)

Aggregations

MetaClass (com.haulmont.chile.core.model.MetaClass)302 MetaProperty (com.haulmont.chile.core.model.MetaProperty)103 Entity (com.haulmont.cuba.core.entity.Entity)54 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)36 Nullable (javax.annotation.Nullable)25 BaseGenericIdEntity (com.haulmont.cuba.core.entity.BaseGenericIdEntity)24 Element (org.dom4j.Element)21 java.util (java.util)18 Inject (javax.inject.Inject)17 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)16 Test (org.junit.Test)15 EntityManager (com.haulmont.cuba.core.EntityManager)14 CategoryAttribute (com.haulmont.cuba.core.entity.CategoryAttribute)14 com.haulmont.cuba.core.global (com.haulmont.cuba.core.global)13 Metadata (com.haulmont.cuba.core.global.Metadata)13 Logger (org.slf4j.Logger)13 LoggerFactory (org.slf4j.LoggerFactory)13 MetadataTools (com.haulmont.cuba.core.global.MetadataTools)12 Collectors (java.util.stream.Collectors)11 Range (com.haulmont.chile.core.model.Range)10