Search in sources :

Example 6 with FormDataValue

use of edu.stanford.bmir.protege.web.shared.form.data.FormDataValue in project webprotege by protegeproject.

the class CompositeFieldEditor method getValue.

@Override
public Optional<FormDataValue> getValue() {
    GWT.log("[CompositeFieldEditor] Getting values");
    Map<String, FormDataValue> childData = new HashMap<>();
    for (FormElementId childId : childEditors.keySet()) {
        GWT.log("[CompositeFieldEditor] " + childId);
        ValueEditor<FormDataValue> childEditor = childEditors.get(childId);
        if (childEditor != null) {
            Optional<FormDataValue> childValue = childEditor.getValue();
            GWT.log("[CompositeFieldEditor] Value: " + childValue);
            if (childValue.isPresent()) {
                childData.put(childId.getId(), childValue.get());
            }
        }
    }
    GWT.log("[CompositeFieldEditor] All values: " + childData);
    if (childData.isEmpty()) {
        return Optional.empty();
    }
    FormDataObject theValue = new FormDataObject(childData);
    GWT.log("[CompositeFieldEditor] The value: " + theValue);
    return Optional.of(theValue);
}
Also used : FormElementId(edu.stanford.bmir.protege.web.shared.form.field.FormElementId) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FormDataObject(edu.stanford.bmir.protege.web.shared.form.data.FormDataObject) FormDataValue(edu.stanford.bmir.protege.web.shared.form.data.FormDataValue)

Example 7 with FormDataValue

use of edu.stanford.bmir.protege.web.shared.form.data.FormDataValue in project webprotege by protegeproject.

the class FormPresenter method setFormData.

private void setFormData(@Nonnull FormData formData) {
    formView.getElementViews().forEach(view -> {
        Optional<FormElementId> theId = view.getId();
        if (theId.isPresent()) {
            FormElementId id = theId.get();
            Optional<FormDataValue> formElementData = formData.getFormElementData(id);
            if (formElementData.isPresent()) {
                view.getEditor().setValue(formElementData.get());
            } else {
                view.getEditor().clearValue();
            }
            updateRequiredValuePresent(view);
        } else {
            view.getEditor().clearValue();
        }
    });
}
Also used : FormElementId(edu.stanford.bmir.protege.web.shared.form.field.FormElementId) FormDataValue(edu.stanford.bmir.protege.web.shared.form.data.FormDataValue)

Example 8 with FormDataValue

use of edu.stanford.bmir.protege.web.shared.form.data.FormDataValue in project webprotege by protegeproject.

the class FormPresenter method createFormAndSetFormData.

/**
 * Creates the form from scratch and fills in the specified form data.
 *
 * @param formDescriptor The descriptor that describes the form.
 * @param formData       The form data to be filled into the form.
 */
private void createFormAndSetFormData(@Nonnull FormDescriptor formDescriptor, @Nonnull FormData formData) {
    formView.clear();
    for (FormElementDescriptor elementDescriptor : formDescriptor.getElements()) {
        Optional<FormDataValue> dataValue = formData.getFormElementData(elementDescriptor.getId());
        createFormEditor(elementDescriptor, dataValue);
    }
}
Also used : FormDataValue(edu.stanford.bmir.protege.web.shared.form.data.FormDataValue) FormElementDescriptor(edu.stanford.bmir.protege.web.shared.form.field.FormElementDescriptor)

Example 9 with FormDataValue

use of edu.stanford.bmir.protege.web.shared.form.data.FormDataValue in project webprotege by protegeproject.

the class FormDataValueConverter method encodeObject.

@Override
public Object encodeObject(FormDataValue value, MappedField optionalExtraInfo) {
    if (value instanceof FormDataObject) {
        Document document = new Document();
        FormDataObject object = (FormDataObject) value;
        object.getMap().forEach((key, val) -> document.put(key, encodeObject(val, optionalExtraInfo)));
        return document;
    } else if (value instanceof FormDataList) {
        List<Object> result = new ArrayList<>();
        FormDataList list = (FormDataList) value;
        list.getList().forEach(e -> result.add(encodeObject(e, optionalExtraInfo)));
        return result;
    } else if (value instanceof FormDataPrimitive) {
        FormDataPrimitive primitive = (FormDataPrimitive) value;
        if (primitive.isNumber()) {
            return primitive.getValueAsDouble();
        } else if (primitive.isString()) {
            return primitive.getValueAsString();
        } else if (primitive.isBoolean()) {
            return primitive.getValueAsBoolean();
        } else if (primitive instanceof FormDataPrimitive.LiteralPrimitive) {
            OWLLiteral literal = primitive.asLiteral().get();
            Document document = new Document();
            document.put("literal", literal.getLiteral());
            if (literal.isRDFPlainLiteral()) {
                document.put("lang", literal.getLang());
            } else {
                document.put("datatype", literal.getDatatype());
            }
            return document;
        } else if (primitive instanceof FormDataPrimitive.IRIPrimitive) {
            return new Document("iri", primitive.asIRI().get().toString());
        } else if (primitive instanceof FormDataPrimitive.OWLEntityPrimitive) {
            OWLEntity entity = (OWLEntity) primitive.getValue();
            return entityConverter.encodeObject(entity, optionalExtraInfo);
        }
    } else {
        throw new RuntimeException("Unknown type of object " + value);
    }
    return null;
}
Also used : TypeSafeConverter(edu.stanford.bmir.protege.web.server.persistence.TypeSafeConverter) Document(org.bson.Document) OWLLiteral(org.semanticweb.owlapi.model.OWLLiteral) OWLDataFactory(org.semanticweb.owlapi.model.OWLDataFactory) OWLEntityConverter(edu.stanford.bmir.protege.web.server.persistence.OWLEntityConverter) HashMap(java.util.HashMap) FormDataPrimitive(edu.stanford.bmir.protege.web.shared.form.data.FormDataPrimitive) FormDataList(edu.stanford.bmir.protege.web.shared.form.data.FormDataList) MappedField(org.mongodb.morphia.mapping.MappedField) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) List(java.util.List) FormDataObject(edu.stanford.bmir.protege.web.shared.form.data.FormDataObject) DBObject(com.mongodb.DBObject) IRI(org.semanticweb.owlapi.model.IRI) Map(java.util.Map) OWLEntity(org.semanticweb.owlapi.model.OWLEntity) FormDataValue(edu.stanford.bmir.protege.web.shared.form.data.FormDataValue) SimpleValueConverter(org.mongodb.morphia.converters.SimpleValueConverter) FormDataList(edu.stanford.bmir.protege.web.shared.form.data.FormDataList) FormDataPrimitive(edu.stanford.bmir.protege.web.shared.form.data.FormDataPrimitive) FormDataObject(edu.stanford.bmir.protege.web.shared.form.data.FormDataObject) OWLEntity(org.semanticweb.owlapi.model.OWLEntity) Document(org.bson.Document) OWLLiteral(org.semanticweb.owlapi.model.OWLLiteral) FormDataList(edu.stanford.bmir.protege.web.shared.form.data.FormDataList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 10 with FormDataValue

use of edu.stanford.bmir.protege.web.shared.form.data.FormDataValue in project webprotege by protegeproject.

the class ChoiceFieldCheckBoxEditor method setValue.

@Override
public void setValue(FormDataValue value) {
    clearValue();
    for (FormDataValue data : value.asList()) {
        for (CheckBox checkBox : checkBoxes.keySet()) {
            if (checkBoxes.get(checkBox).getValue().equals(data)) {
                checkBox.setValue(true);
            }
        }
    }
    selectDefaultChoices();
}
Also used : CheckBox(com.google.gwt.user.client.ui.CheckBox) FormDataValue(edu.stanford.bmir.protege.web.shared.form.data.FormDataValue)

Aggregations

FormDataValue (edu.stanford.bmir.protege.web.shared.form.data.FormDataValue)16 FormElementId (edu.stanford.bmir.protege.web.shared.form.field.FormElementId)9 HashMap (java.util.HashMap)8 FormData (edu.stanford.bmir.protege.web.shared.form.FormData)7 CollectionItemData (edu.stanford.bmir.protege.web.shared.collection.CollectionItemData)3 FormDataList (edu.stanford.bmir.protege.web.shared.form.data.FormDataList)3 FormDataObject (edu.stanford.bmir.protege.web.shared.form.data.FormDataObject)3 Test (org.junit.Test)3 FormId (edu.stanford.bmir.protege.web.shared.form.FormId)2 CheckBox (com.google.gwt.user.client.ui.CheckBox)1 DBObject (com.mongodb.DBObject)1 OWLEntityConverter (edu.stanford.bmir.protege.web.server.persistence.OWLEntityConverter)1 TypeSafeConverter (edu.stanford.bmir.protege.web.server.persistence.TypeSafeConverter)1 FormDataPrimitive (edu.stanford.bmir.protege.web.shared.form.data.FormDataPrimitive)1 ChoiceDescriptor (edu.stanford.bmir.protege.web.shared.form.field.ChoiceDescriptor)1 FormElementDescriptor (edu.stanford.bmir.protege.web.shared.form.field.FormElementDescriptor)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1