Search in sources :

Example 1 with AttributeDefinitionFormObject

use of org.openforis.collect.designer.form.AttributeDefinitionFormObject in project collect by openforis.

the class AttributeVM method generateEntityAlias.

@Command
public void generateEntityAlias() {
    AttributeDefinitionFormObject<?> fo = (AttributeDefinitionFormObject<?>) formObject;
    String referencedAttributePath = fo.getReferencedAttributePath();
    EntityDefinition sourceDef = editedItem.getParentEntityDefinition();
    String aliasName = sourceDef + "_alias";
    NodeDefinition referencedAttributeDef = editedItem.getDefinitionByPath(referencedAttributePath);
    EntityDefinition parentDef = referencedAttributeDef.getNearestAncestorMultipleEntity();
    if (parentDef.containsChildDefinition(aliasName)) {
        MessageUtil.showError("survey.schema.attribute.generate_entity_alias.error.alias_already_existing", aliasName, parentDef.getName());
    } else {
        EntityDefinition aliasDef = schemaUpdater.generateAlias(sourceDef, editedItem.getName(), parentDef, referencedAttributeDef.getName());
        ((CollectSurvey) aliasDef.getSurvey()).getUIOptions().setLayout(aliasDef, Layout.TABLE);
        aliasDef.rename(aliasName);
        dispatchSchemaChangedCommand();
        MessageUtil.showInfo("survey.schema.attribute.generate_entity_alias.generation_successfull", aliasName, parentDef.getName());
    }
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) AttributeDefinitionFormObject(org.openforis.collect.designer.form.AttributeDefinitionFormObject) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) GlobalCommand(org.zkoss.bind.annotation.GlobalCommand) Command(org.zkoss.bind.annotation.Command)

Example 2 with AttributeDefinitionFormObject

use of org.openforis.collect.designer.form.AttributeDefinitionFormObject 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)

Aggregations

AttributeDefinitionFormObject (org.openforis.collect.designer.form.AttributeDefinitionFormObject)2 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)2 Command (org.zkoss.bind.annotation.Command)2 GlobalCommand (org.zkoss.bind.annotation.GlobalCommand)2 Predicate (org.openforis.collect.designer.util.Predicate)1 NodeSelectedEvent (org.openforis.collect.designer.viewmodel.SchemaTreePopUpVM.NodeSelectedEvent)1 ReferenceableKeyAttributeHelper (org.openforis.collect.manager.validation.SurveyValidator.ReferenceableKeyAttributeHelper)1 UITab (org.openforis.collect.metamodel.ui.UITab)1 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)1 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)1 SurveyObject (org.openforis.idm.metamodel.SurveyObject)1 Window (org.zkoss.zul.Window)1