Search in sources :

Example 1 with FindFieldByXmlIdsVisitor

use of org.eclipse.scout.rt.client.ui.form.internal.FindFieldByXmlIdsVisitor in project scout.rt by eclipse.

the class AbstractForm method loadFromXml.

@Override
public void loadFromXml(Element root) {
    String formId = getFormId();
    String xmlId = root.getAttribute("formId");
    if (!formId.equals(xmlId)) {
        throw new ProcessingException("xml id='{}' does not match form id='{}'", xmlId, formId);
    }
    // load properties
    Element xProps = XmlUtility.getFirstChildElement(root, "properties");
    if (xProps != null) {
        Map<String, Object> props = loadPropertiesFromXml(xProps);
        BeanUtility.setProperties(this, props, true, null);
        // load extension properties
        for (Element xExtension : XmlUtility.getChildElements(xProps, "extension")) {
            String extensionId = xExtension.getAttribute("extensionId");
            String extensionQname = xExtension.getAttribute("extensionQname");
            IFormExtension<? extends AbstractForm> extension = findFormExtensionById(extensionQname, extensionId);
            if (extension == null) {
                continue;
            }
            Map<String, Object> extensionProps = loadPropertiesFromXml(xExtension);
            BeanUtility.setProperties(extension, extensionProps, true, null);
        }
    }
    // load fields
    Element xFields = XmlUtility.getFirstChildElement(root, "fields");
    if (xFields != null) {
        for (Element xField : XmlUtility.getChildElements(xFields, "field")) {
            List<String> xmlFieldIds = new LinkedList<String>();
            // add enclosing field path to xml field IDs
            for (Element element : XmlUtility.getChildElements(xField, "enclosingField")) {
                xmlFieldIds.add(element.getAttribute("fieldId"));
            }
            xmlFieldIds.add(xField.getAttribute("fieldId"));
            FindFieldByXmlIdsVisitor v = new FindFieldByXmlIdsVisitor(xmlFieldIds.toArray(new String[xmlFieldIds.size()]));
            visitFields(v);
            IFormField f = v.getField();
            if (f != null) {
                f.loadFromXml(xField);
            }
        }
    }
    // in all tabboxes select the first tab that contains data, iff the current
    // tab has no values set
    getRootGroupBox().visitFields(new IFormFieldVisitor() {

        @Override
        public boolean visitField(IFormField field, int level, int fieldIndex) {
            if (field instanceof ITabBox) {
                ITabBox tabBox = (ITabBox) field;
                IGroupBox selbox = tabBox.getSelectedTab();
                if (selbox == null || !selbox.isSaveNeeded()) {
                    for (IGroupBox g : tabBox.getGroupBoxes()) {
                        if (g.isSaveNeeded()) {
                            tabBox.setSelectedTab(g);
                            break;
                        }
                    }
                }
            }
            return true;
        }
    });
}
Also used : IHtmlListElement(org.eclipse.scout.rt.platform.html.IHtmlListElement) Element(org.w3c.dom.Element) FindFieldByXmlIdsVisitor(org.eclipse.scout.rt.client.ui.form.internal.FindFieldByXmlIdsVisitor) LinkedList(java.util.LinkedList) IFormField(org.eclipse.scout.rt.client.ui.form.fields.IFormField) IGroupBox(org.eclipse.scout.rt.client.ui.form.fields.groupbox.IGroupBox) IExtensibleObject(org.eclipse.scout.rt.shared.extension.IExtensibleObject) ITabBox(org.eclipse.scout.rt.client.ui.form.fields.tabbox.ITabBox) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException)

Aggregations

LinkedList (java.util.LinkedList)1 IFormField (org.eclipse.scout.rt.client.ui.form.fields.IFormField)1 IGroupBox (org.eclipse.scout.rt.client.ui.form.fields.groupbox.IGroupBox)1 ITabBox (org.eclipse.scout.rt.client.ui.form.fields.tabbox.ITabBox)1 FindFieldByXmlIdsVisitor (org.eclipse.scout.rt.client.ui.form.internal.FindFieldByXmlIdsVisitor)1 ProcessingException (org.eclipse.scout.rt.platform.exception.ProcessingException)1 IHtmlListElement (org.eclipse.scout.rt.platform.html.IHtmlListElement)1 IExtensibleObject (org.eclipse.scout.rt.shared.extension.IExtensibleObject)1 Element (org.w3c.dom.Element)1