Search in sources :

Example 31 with IFormField

use of org.eclipse.scout.rt.client.ui.form.fields.IFormField in project scout.rt by eclipse.

the class FindFieldByFormDataIdVisitorTest method testGetSecondFieldOnInnerInnerForm.

@Test
public void testGetSecondFieldOnInnerInnerForm() throws Exception {
    InnerInnerForm innerInnerForm = m_mainForm.getWrappedFormField().getInnerForm().getWrappedFormField().getInnerForm();
    FindFieldByFormDataIdVisitor visitor = new FindFieldByFormDataIdVisitor(SECOND_FIELD_DATA_ID, innerInnerForm);
    innerInnerForm.visitFields(visitor);
    IFormField field = visitor.getField();
    assertNotNull(field);
    assertSame(innerInnerForm.getSecondField(), field);
}
Also used : IFormField(org.eclipse.scout.rt.client.ui.form.fields.IFormField) Test(org.junit.Test)

Example 32 with IFormField

use of org.eclipse.scout.rt.client.ui.form.fields.IFormField in project scout.rt by eclipse.

the class MoveFormFieldsHandler method findContainer.

protected ICompositeField findContainer(ICompositeField container, ClassIdentifier newModelContainerClassIdentifier, ICompositeField ignoredChildContainer) {
    // 1. no new container defined. Hence do not move field into different container.
    if (newModelContainerClassIdentifier == null) {
        return container;
    }
    Class<?> newModelContainerClass = newModelContainerClassIdentifier.getLastSegment();
    // 2. field is moved to root, i.e. into the main box
    if (newModelContainerClass == IMoveModelObjectToRootMarker.class) {
        return container.getForm().getRootGroupBox();
    }
    // 3. current container matches
    if (newModelContainerClass.isInstance(container) && matchesClassIdentifier(container, newModelContainerClassIdentifier)) {
        return container;
    }
    // 4. check current container's child composite fields
    for (IFormField c : container.getFields()) {
        if (newModelContainerClass.isInstance(c) && c instanceof ICompositeField && matchesClassIdentifier((ICompositeField) c, newModelContainerClassIdentifier)) {
            return (ICompositeField) c;
        }
    }
    // 5. visit child containers
    for (IFormField c : container.getFields()) {
        if (c == ignoredChildContainer || !(c instanceof ICompositeField)) {
            continue;
        }
        ICompositeField recursiveContainer = findContainer((ICompositeField) c, newModelContainerClassIdentifier, container);
        if (recursiveContainer != null) {
            return recursiveContainer;
        }
    }
    // 6. current container is a template field. Do not exit template scope
    if (container instanceof AbstractCompositeField && ((AbstractCompositeField) container).isTemplateField()) {
        return null;
    }
    // 7. continue search on parent container (without revisiting the current container)
    ICompositeField parent = container.getParentField();
    if (parent != null && parent != ignoredChildContainer) {
        return findContainer(parent, newModelContainerClassIdentifier, container);
    }
    return null;
}
Also used : IFormField(org.eclipse.scout.rt.client.ui.form.fields.IFormField) ICompositeField(org.eclipse.scout.rt.client.ui.form.fields.ICompositeField) AbstractCompositeField(org.eclipse.scout.rt.client.ui.form.fields.AbstractCompositeField)

Example 33 with IFormField

use of org.eclipse.scout.rt.client.ui.form.fields.IFormField in project scout.rt by eclipse.

the class AbstractForm method closeFormInternal.

private void closeFormInternal(boolean kill) {
    if (isBlockingInternal()) {
        try {
            // check if there is an active close, cancel or finish button
            final Set<Integer> enabledSystemTypes = new HashSet<Integer>();
            final Set<IButton> enabledSystemButtons = new HashSet<IButton>();
            IFormFieldVisitor v = new IFormFieldVisitor() {

                @Override
                public boolean visitField(IFormField field, int level, int fieldIndex) {
                    if (field instanceof IButton) {
                        IButton b = (IButton) field;
                        if (b.isEnabled() && b.isVisible()) {
                            enabledSystemTypes.add(b.getSystemType());
                            enabledSystemButtons.add(b);
                        }
                    }
                    return true;
                }
            };
            visitFields(v);
            interceptOnCloseRequest(kill, enabledSystemTypes);
        } catch (RuntimeException | PlatformError e) {
            throw BEANS.get(PlatformExceptionTranslator.class).translate(e).withContextInfo("form", getClass().getName());
        }
    }
}
Also used : IFormField(org.eclipse.scout.rt.client.ui.form.fields.IFormField) PlatformError(org.eclipse.scout.rt.platform.exception.PlatformError) IButton(org.eclipse.scout.rt.client.ui.form.fields.button.IButton) PlatformExceptionTranslator(org.eclipse.scout.rt.platform.exception.PlatformExceptionTranslator) HashSet(java.util.HashSet)

Example 34 with IFormField

use of org.eclipse.scout.rt.client.ui.form.fields.IFormField in project scout.rt by eclipse.

the class AbstractForm method doReset.

@Override
public void doReset() {
    setFormLoading(true);
    // reset values
    P_AbstractCollectingFieldVisitor v = new P_AbstractCollectingFieldVisitor() {

        @Override
        public boolean visitField(IFormField field, int level, int fieldIndex) {
            if (field instanceof IValueField) {
                IValueField f = (IValueField) field;
                f.resetValue();
            } else if (field instanceof IComposerField) {
                IComposerField f = (IComposerField) field;
                f.resetValue();
            }
            return true;
        }
    };
    try {
        visitFields(v);
        // init again
        initForm();
        // load again
        loadStateInternal();
    } catch (RuntimeException | PlatformError e) {
        throw BEANS.get(PlatformExceptionTranslator.class).translate(e).withContextInfo("form", getClass().getName());
    }
}
Also used : IFormField(org.eclipse.scout.rt.client.ui.form.fields.IFormField) PlatformError(org.eclipse.scout.rt.platform.exception.PlatformError) PlatformExceptionTranslator(org.eclipse.scout.rt.platform.exception.PlatformExceptionTranslator) IValueField(org.eclipse.scout.rt.client.ui.form.fields.IValueField) IComposerField(org.eclipse.scout.rt.client.ui.form.fields.composer.IComposerField)

Example 35 with IFormField

use of org.eclipse.scout.rt.client.ui.form.fields.IFormField 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

IFormField (org.eclipse.scout.rt.client.ui.form.fields.IFormField)60 Test (org.junit.Test)19 ArrayList (java.util.ArrayList)13 GridData (org.eclipse.scout.rt.client.ui.form.fields.GridData)12 IButton (org.eclipse.scout.rt.client.ui.form.fields.button.IButton)5 PlatformError (org.eclipse.scout.rt.platform.exception.PlatformError)5 PropertyChangeEvent (java.beans.PropertyChangeEvent)4 PropertyChangeListener (java.beans.PropertyChangeListener)4 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 IColumn (org.eclipse.scout.rt.client.ui.basic.table.columns.IColumn)4 IGroupBox (org.eclipse.scout.rt.client.ui.form.fields.groupbox.IGroupBox)4 IExtensibleObject (org.eclipse.scout.rt.shared.extension.IExtensibleObject)4 Map (java.util.Map)3 PlatformExceptionTranslator (org.eclipse.scout.rt.platform.exception.PlatformExceptionTranslator)3 LinkedList (java.util.LinkedList)2 ITable (org.eclipse.scout.rt.client.ui.basic.table.ITable)2 ICompositeField (org.eclipse.scout.rt.client.ui.form.fields.ICompositeField)2 IValueField (org.eclipse.scout.rt.client.ui.form.fields.IValueField)2 FindFieldByFormDataIdVisitor (org.eclipse.scout.rt.client.ui.form.internal.FindFieldByFormDataIdVisitor)2