Search in sources :

Example 71 with AttributeDefinition

use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.

the class SchemaVM method getIcon.

public static String getIcon(SchemaNodeData data) {
    SurveyObject surveyObject = data.getSurveyObject();
    boolean key = surveyObject instanceof KeyAttributeDefinition && ((KeyAttributeDefinition) surveyObject).isKey();
    boolean calculated = surveyObject instanceof AttributeDefinition && ((AttributeDefinition) surveyObject).isCalculated();
    return getIcon(data, key, calculated);
}
Also used : SurveyObject(org.openforis.idm.metamodel.SurveyObject) KeyAttributeDefinition(org.openforis.idm.metamodel.KeyAttributeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) KeyAttributeDefinition(org.openforis.idm.metamodel.KeyAttributeDefinition)

Example 72 with AttributeDefinition

use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.

the class SchemaVM method removeNodeDefinition.

protected void removeNodeDefinition(final NodeDefinition nodeDefn) {
    String confirmMessageKey;
    Object[] extraMessageArgs = null;
    if (nodeDefn instanceof EntityDefinition && !((EntityDefinition) nodeDefn).getChildDefinitions().isEmpty()) {
        confirmMessageKey = CONFIRM_REMOVE_NON_EMPTY_ENTITY_MESSAGE_KEY;
    } else if (nodeDefn.hasDependencies()) {
        confirmMessageKey = CONFIRM_REMOVE_NODE_WITH_DEPENDENCIES_MESSAGE_KEY;
    } else if (nodeDefn instanceof AttributeDefinition && !((AttributeDefinition) nodeDefn).getReferencingAttributes().isEmpty()) {
        confirmMessageKey = CONFIRM_REMOVE_REFERENCED_ATTRIBUTE_MESSAGE_KEY;
        List<String> referencedAttrNames = org.openforis.commons.collection.CollectionUtils.project(((AttributeDefinition) nodeDefn).getReferencingAttributes(), "name");
        extraMessageArgs = new String[] { StringUtils.join(referencedAttrNames, ", ") };
    } else {
        confirmMessageKey = CONFIRM_REMOVE_NODE_MESSAGE_KEY;
    }
    NodeType type = NodeType.valueOf(nodeDefn);
    String typeLabel = type.getLabel().toLowerCase(Locale.ENGLISH);
    boolean isRootEntity = nodeDefn.getParentDefinition() == null;
    if (isRootEntity) {
        typeLabel = Labels.getLabel("survey.schema.root_entity");
    }
    Object[] messageArgs = new String[] { typeLabel, nodeDefn.getName() };
    if (extraMessageArgs != null) {
        messageArgs = ArrayUtils.addAll(messageArgs, extraMessageArgs);
    }
    Object[] titleArgs = new String[] { typeLabel };
    MessageUtil.showConfirm(new MessageUtil.ConfirmHandler() {

        @Override
        public void onOk() {
            performRemoveNode(nodeDefn);
        }
    }, confirmMessageKey, messageArgs, CONFIRM_REMOVE_NODE_TITLE_KEY, titleArgs, "global.remove_item", "global.cancel");
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) MessageUtil(org.openforis.collect.designer.util.MessageUtil) NodeType(org.openforis.collect.designer.metamodel.NodeType) KeyAttributeDefinition(org.openforis.idm.metamodel.KeyAttributeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) SurveyObject(org.openforis.idm.metamodel.SurveyObject) FormObject(org.openforis.collect.designer.form.FormObject)

Example 73 with AttributeDefinition

use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.

the class SchemaVM method getIcon.

public static String getIcon(SchemaNodeData data, boolean key, boolean calculated) {
    SurveyObject surveyObject = data.getSurveyObject();
    String imagesRootPath = NODE_TYPES_IMAGES_PATH;
    if (surveyObject instanceof UITab) {
        return imagesRootPath + "tab-small.png";
    } else if (surveyObject instanceof EntityDefinition) {
        return getEntityIcon((EntityDefinition) surveyObject);
    } else if (key) {
        return imagesRootPath + "key-small.png";
    } else if (calculated) {
        return imagesRootPath + "calculated-small.png";
    } else {
        AttributeType attributeType = AttributeType.valueOf((AttributeDefinition) surveyObject);
        return getAttributeIcon(attributeType.name());
    }
}
Also used : UITab(org.openforis.collect.metamodel.ui.UITab) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) SurveyObject(org.openforis.idm.metamodel.SurveyObject) AttributeType(org.openforis.collect.designer.metamodel.AttributeType) KeyAttributeDefinition(org.openforis.idm.metamodel.KeyAttributeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition)

Example 74 with AttributeDefinition

use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.

the class AttributeVM method openReferencedAttributeSelector.

@Command
public void openReferencedAttributeSelector(@ContextParam(ContextType.BINDER) final Binder binder) {
    ReferenceableKeyAttributeHelper referenceableKeyAttributeHelper = new ReferenceableKeyAttributeHelper(editedItem);
    final Set<EntityDefinition> referenceableEntityDefinitions = referenceableKeyAttributeHelper.determineReferenceableEntities();
    final Set<AttributeDefinition> selectableAttributes = referenceableKeyAttributeHelper.determineReferenceableAttributes();
    if (selectableAttributes.isEmpty()) {
        MessageUtil.showWarning("survey.schema.attribute.no_referenceable_attributes_available");
    } else {
        Predicate<SurveyObject> includedNodePredicate = new Predicate<SurveyObject>() {

            public boolean evaluate(SurveyObject item) {
                EntityDefinition parentEntity;
                if (item instanceof UITab) {
                    parentEntity = survey.getUIOptions().getParentEntityForAssignedNodes((UITab) item);
                } else {
                    parentEntity = ((NodeDefinition) item).getParentEntityDefinition();
                }
                for (EntityDefinition entityDef : referenceableEntityDefinitions) {
                    if (parentEntity == entityDef || parentEntity.isAncestorOf(entityDef)) {
                        return true;
                    }
                }
                return false;
            }
        };
        Predicate<SurveyObject> disabledNodePredicate = new Predicate<SurveyObject>() {

            public boolean evaluate(SurveyObject item) {
                return !selectableAttributes.contains(item);
            }
        };
        String title = Labels.getLabel("survey.schema.attribute.select_attribute_referenced_by", new String[] { editedItem.getName() });
        final Window parentSelectorPopUp = SchemaTreePopUpVM.openPopup(title, editedItem.getRootEntity(), null, includedNodePredicate, false, false, disabledNodePredicate, null, editedItem.getReferencedAttribute(), true);
        parentSelectorPopUp.addEventListener(SchemaTreePopUpVM.NODE_SELECTED_EVENT_NAME, new EventListener<NodeSelectedEvent>() {

            public void onEvent(NodeSelectedEvent event) throws Exception {
                AttributeDefinition referencedAttribute = (AttributeDefinition) event.getSelectedItem();
                AttributeDefinitionFormObject<?> fo = (AttributeDefinitionFormObject<?>) formObject;
                fo.setReferencedAttributePath(referencedAttribute == null ? null : referencedAttribute.getPath());
                notifyChange("formObject");
                dispatchApplyChangesCommand(binder);
                closePopUp(parentSelectorPopUp);
            }
        });
    }
}
Also used : Window(org.zkoss.zul.Window) AttributeDefinitionFormObject(org.openforis.collect.designer.form.AttributeDefinitionFormObject) NodeSelectedEvent(org.openforis.collect.designer.viewmodel.SchemaTreePopUpVM.NodeSelectedEvent) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) Predicate(org.openforis.collect.designer.util.Predicate) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) UITab(org.openforis.collect.metamodel.ui.UITab) SurveyObject(org.openforis.idm.metamodel.SurveyObject) ReferenceableKeyAttributeHelper(org.openforis.collect.manager.validation.SurveyValidator.ReferenceableKeyAttributeHelper) GlobalCommand(org.zkoss.bind.annotation.GlobalCommand) Command(org.zkoss.bind.annotation.Command)

Example 75 with AttributeDefinition

use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.

the class NodeDefinitionFormValidator method validateMaxCount.

protected void validateMaxCount(ValidationContext ctx) {
    Boolean multiple = (Boolean) getValue(ctx, MULTIPLE_FIELD);
    if (multiple != null && multiple.booleanValue()) {
        NodeDefinition editedNode = getEditedNode(ctx);
        boolean result = true;
        if (editedNode instanceof AttributeDefinition) {
            result = validateRequired(ctx, MAX_COUNT_EXPRESSION_FIELD);
        }
        if (result) {
            Object maxCountVal = getValue(ctx, MAX_COUNT_EXPRESSION_FIELD);
            if (maxCountVal != null && isNumber(maxCountVal)) {
                String minCountVal = getValue(ctx, MIN_COUNT_EXPRESSION_FIELD);
                if (StringUtils.isBlank(minCountVal) || isNumber(minCountVal) && Double.parseDouble(minCountVal.toString()) < MAX_COUNT_MIN_VALUE) {
                    validateGreaterThan(ctx, MAX_COUNT_EXPRESSION_FIELD, MAX_COUNT_MIN_VALUE, false);
                } else if (isNumber(minCountVal)) {
                    String minCountLabel = Labels.getLabel(LabelKeys.NODE_MIN_COUNT);
                    validateGreaterThan(ctx, MAX_COUNT_EXPRESSION_FIELD, MIN_COUNT_EXPRESSION_FIELD, minCountLabel, false);
                }
            }
        }
    }
}
Also used : NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) NodeDefinitionFormObject(org.openforis.collect.designer.form.NodeDefinitionFormObject)

Aggregations

AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)107 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)47 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)37 ArrayList (java.util.ArrayList)33 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)27 BooleanAttributeDefinition (org.openforis.idm.metamodel.BooleanAttributeDefinition)21 NumericAttributeDefinition (org.openforis.idm.metamodel.NumericAttributeDefinition)20 DateAttributeDefinition (org.openforis.idm.metamodel.DateAttributeDefinition)18 NumberAttributeDefinition (org.openforis.idm.metamodel.NumberAttributeDefinition)18 CollectSurvey (org.openforis.collect.model.CollectSurvey)17 CoordinateAttributeDefinition (org.openforis.idm.metamodel.CoordinateAttributeDefinition)16 KeyAttributeDefinition (org.openforis.idm.metamodel.KeyAttributeDefinition)16 TextAttributeDefinition (org.openforis.idm.metamodel.TextAttributeDefinition)12 TimeAttributeDefinition (org.openforis.idm.metamodel.TimeAttributeDefinition)12 CollectAnnotations (org.openforis.collect.metamodel.CollectAnnotations)11 Schema (org.openforis.idm.metamodel.Schema)10 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)9 Entity (org.openforis.idm.model.Entity)9 Value (org.openforis.idm.model.Value)9 RangeAttributeDefinition (org.openforis.idm.metamodel.RangeAttributeDefinition)8