Search in sources :

Example 36 with Command

use of org.zkoss.bind.annotation.Command in project collect by openforis.

the class SchemaAttributesImportVM method openParentEntitySelectionButton.

@Command
public void openParentEntitySelectionButton() {
    Predicate<SurveyObject> includedNodePredicate = new Predicate<SurveyObject>() {

        public boolean evaluate(SurveyObject item) {
            return item instanceof UITab || item instanceof EntityDefinition;
        }
    };
    Predicate<SurveyObject> selectableNodePredicate = new Predicate<SurveyObject>() {

        public boolean evaluate(SurveyObject item) {
            return item instanceof EntityDefinition;
        }
    };
    String title = Labels.getLabel("survey.schema.attributes_import.select_entity.popup.title");
    // calculate parent item (tab or entity)
    final Window popup = SchemaTreePopUpVM.openPopup(title, parentEntityDefinition.getRootEntity(), null, includedNodePredicate, true, true, null, selectableNodePredicate, parentEntityDefinition, false);
    popup.addEventListener(SchemaTreePopUpVM.NODE_SELECTED_EVENT_NAME, new EventListener<NodeSelectedEvent>() {

        public void onEvent(NodeSelectedEvent event) throws Exception {
            SurveyObject selectedParent = event.getSelectedItem();
            parentEntityDefinition = (EntityDefinition) selectedParent;
            notifyChange("parentEntityDefinitionPath");
            closePopUp(popup);
        }
    });
}
Also used : Window(org.zkoss.zul.Window) UITab(org.openforis.collect.metamodel.ui.UITab) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) SurveyObject(org.openforis.idm.metamodel.SurveyObject) NodeSelectedEvent(org.openforis.collect.designer.viewmodel.SchemaTreePopUpVM.NodeSelectedEvent) ParseException(java.text.ParseException) Predicate(org.openforis.collect.designer.util.Predicate) Command(org.zkoss.bind.annotation.Command)

Example 37 with Command

use of org.zkoss.bind.annotation.Command in project collect by openforis.

the class AttributeVM method deleteCheck.

@Command
public void deleteCheck() {
    ConfirmParams params = new MessageUtil.ConfirmParams(new MessageUtil.ConfirmHandler() {

        @Override
        public void onOk() {
            editedItem.removeCheck(selectedCheck);
            selectedCheck = null;
            initChecks();
            notifyChange("selectedCheck", "checks");
        }
    }, "survey.schema.node.check.confirm_delete");
    params.setOkLabelKey("global.delete_item");
    MessageUtil.showConfirm(params);
}
Also used : ConfirmParams(org.openforis.collect.designer.util.MessageUtil.ConfirmParams) MessageUtil(org.openforis.collect.designer.util.MessageUtil) GlobalCommand(org.zkoss.bind.annotation.GlobalCommand) Command(org.zkoss.bind.annotation.Command)

Example 38 with Command

use of org.zkoss.bind.annotation.Command in project collect by openforis.

the class AttributeVM method addAttributeDefault.

@Command
@NotifyChange("attributeDefaults")
public void addAttributeDefault() {
    if (checkCanInsertAttributeDefault()) {
        editingNewAttributeDefault = true;
        editedAttributeDefault = new AttributeDefault();
        openAttributeDefaultEditPopUp();
    }
}
Also used : AttributeDefault(org.openforis.idm.metamodel.AttributeDefault) NotifyChange(org.zkoss.bind.annotation.NotifyChange) GlobalCommand(org.zkoss.bind.annotation.GlobalCommand) Command(org.zkoss.bind.annotation.Command)

Example 39 with Command

use of org.zkoss.bind.annotation.Command in project collect by openforis.

the class AttributeVM method addCheck.

@Command
public void addCheck(@BindingParam("checkType") String checkType) {
    if (checkCanAddCheck()) {
        CheckType type = CheckType.valueOf(checkType.toUpperCase());
        editingNewCheck = true;
        editedCheck = CheckType.createCheck(type);
        openCheckEditPopUp();
    }
}
Also used : CheckType(org.openforis.collect.designer.model.CheckType) GlobalCommand(org.zkoss.bind.annotation.GlobalCommand) Command(org.zkoss.bind.annotation.Command)

Example 40 with Command

use of org.zkoss.bind.annotation.Command 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

Command (org.zkoss.bind.annotation.Command)62 GlobalCommand (org.zkoss.bind.annotation.GlobalCommand)44 NotifyChange (org.zkoss.bind.annotation.NotifyChange)26 File (java.io.File)12 CollectSurvey (org.openforis.collect.model.CollectSurvey)10 MessageUtil (org.openforis.collect.designer.util.MessageUtil)9 UITab (org.openforis.collect.metamodel.ui.UITab)6 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)6 FileInputStream (java.io.FileInputStream)5 ConfirmParams (org.openforis.collect.designer.util.MessageUtil.ConfirmParams)5 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)5 SurveyObject (org.openforis.idm.metamodel.SurveyObject)5 Media (org.zkoss.util.media.Media)5 Window (org.zkoss.zul.Window)5 UserCredential (es.bsc.compss.ui.auth.UserCredential)4 IOException (java.io.IOException)4 Date (java.util.Date)4 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)4 SessionStatus (org.openforis.collect.designer.session.SessionStatus)3 ConfirmHandler (org.openforis.collect.designer.util.MessageUtil.ConfirmHandler)3