Search in sources :

Example 1 with IFormFieldVisitor

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

the class ScoutClientAssert method assertView.

private static void assertView(final ViewKind viewKind, final boolean strict, IForm form, IFormField... fields) {
    Assert.assertNotNull(form);
    Assert.assertNotNull(fields);
    final HashSet<IFormField> expectedFields = new HashSet<IFormField>(Arrays.asList(fields));
    final ArrayList<IFormField> unexpectedFields = new ArrayList<IFormField>();
    form.visitFields(new IFormFieldVisitor() {

        @Override
        public boolean visitField(IFormField field, int level, int fieldIndex) {
            if (viewKind.testField(field)) {
                boolean expected = expectedFields.remove(field);
                if (strict && !expected) {
                    unexpectedFields.add(field);
                }
            }
            return true;
        }
    });
    if (!expectedFields.isEmpty() || !unexpectedFields.isEmpty()) {
        StringBuilder builder = new StringBuilder();
        builder.append(viewKind.getName());
        builder.append(" fields:");
        if (!expectedFields.isEmpty()) {
            builder.append("\n\texpected ").append(viewKind.getPositive()).append(" but ").append(viewKind.getNegative()).append(": ");
            builder.append(formatFieldNames(expectedFields));
        }
        if (!unexpectedFields.isEmpty()) {
            builder.append("\n\texpected ").append(viewKind.getNegative()).append(" but ").append(viewKind.getPositive()).append(": ");
            builder.append(formatFieldNames(unexpectedFields));
        }
        Assert.fail(builder.toString());
    }
}
Also used : IFormField(org.eclipse.scout.rt.client.ui.form.fields.IFormField) ArrayList(java.util.ArrayList) IFormFieldVisitor(org.eclipse.scout.rt.client.ui.form.IFormFieldVisitor) HashSet(java.util.HashSet)

Example 2 with IFormFieldVisitor

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

the class CompositeFieldUtility method getFieldById.

public static <T extends IFormField> T getFieldById(ICompositeField compositeField, final String id, final Class<T> type) {
    // check local moved fields
    T movedField = getMovedFieldById(compositeField, id, type);
    if (movedField != null) {
        return movedField;
    }
    // visit child fields
    final Holder<T> found = new Holder<T>(type);
    IFormFieldVisitor v = new IFormFieldVisitor() {

        @Override
        public boolean visitField(IFormField field, int level, int fieldIndex) {
            if (type.isAssignableFrom(field.getClass()) && field.getFieldId().equals(id)) {
                found.setValue(type.cast(field));
            } else if (field instanceof ICompositeField) {
                T movedFieldById = getMovedFieldById((ICompositeField) field, id, type);
                if (movedFieldById != null) {
                    found.setValue(movedFieldById);
                }
            }
            return found.getValue() == null;
        }
    };
    compositeField.visitFields(v);
    return found.getValue();
}
Also used : Holder(org.eclipse.scout.rt.platform.holders.Holder) IFormFieldVisitor(org.eclipse.scout.rt.client.ui.form.IFormFieldVisitor)

Example 3 with IFormFieldVisitor

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

the class CompositeFieldUtility method getFieldByClass.

public static <T extends IFormField> T getFieldByClass(ICompositeField compositeField, final Class<T> formFieldClass) {
    // check local moved fields
    IFormField movedField = getMovedFieldByClass(compositeField, formFieldClass);
    if (movedField != null) {
        return formFieldClass.cast(movedField);
    }
    // visit child fields
    final Holder<T> found = new Holder<T>(formFieldClass);
    IFormFieldVisitor v = new IFormFieldVisitor() {

        @Override
        public boolean visitField(IFormField field, int level, int fieldIndex) {
            if (field.getClass() == formFieldClass) {
                found.setValue(formFieldClass.cast(field));
            } else if (field instanceof ICompositeField) {
                T movedFieldByClass = getMovedFieldByClass((ICompositeField) field, formFieldClass);
                if (movedFieldByClass != null) {
                    found.setValue(movedFieldByClass);
                }
            }
            return found.getValue() == null;
        }
    };
    compositeField.visitFields(v);
    return found.getValue();
}
Also used : Holder(org.eclipse.scout.rt.platform.holders.Holder) IFormFieldVisitor(org.eclipse.scout.rt.client.ui.form.IFormFieldVisitor)

Example 4 with IFormFieldVisitor

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

the class AbstractFormField method setVisible.

@Override
public void setVisible(final boolean visible, final boolean updateParents, final boolean updateChildren, final String dimension) {
    m_visible = VISIBLE_BIT_HELPER.changeBit(dimension, visible, m_visible);
    calculateVisibleInternal();
    if (visible && updateParents) {
        // also enable all parents
        visitParents(new IFormFieldVisitor() {

            @Override
            public boolean visitField(IFormField field, int level, int fieldIndex) {
                field.setVisible(true, dimension);
                return true;
            }
        });
    }
    if (updateChildren) {
        // propagate change to children
        acceptVisitor(new IFormFieldVisitor() {

            @Override
            public boolean visitField(IFormField field, int level, int fieldIndex) {
                field.setVisible(visible, dimension);
                return true;
            }
        }, 0, 0, false);
    }
}
Also used : IFormFieldVisitor(org.eclipse.scout.rt.client.ui.form.IFormFieldVisitor)

Example 5 with IFormFieldVisitor

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

the class AbstractFormField method setEnabled.

@Override
public void setEnabled(final boolean enabled, final boolean updateParents, final boolean updateChildren, final String dimension) {
    m_enabled = ENABLED_BIT_HELPER.changeBit(dimension, enabled, m_enabled);
    calculateEnabledInternal();
    if (enabled && updateParents) {
        // also enable all parents
        visitParents(new IFormFieldVisitor() {

            @Override
            public boolean visitField(IFormField field, int level, int fieldIndex) {
                field.setEnabled(true, dimension);
                return true;
            }
        });
    }
    if (updateChildren) {
        // propagate change to children
        acceptVisitor(new IFormFieldVisitor() {

            @Override
            public boolean visitField(IFormField field, int level, int fieldIndex) {
                field.setEnabled(enabled, dimension);
                return true;
            }
        }, 0, 0, false);
    }
}
Also used : IFormFieldVisitor(org.eclipse.scout.rt.client.ui.form.IFormFieldVisitor)

Aggregations

IFormFieldVisitor (org.eclipse.scout.rt.client.ui.form.IFormFieldVisitor)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 Holder (org.eclipse.scout.rt.platform.holders.Holder)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 P_String (org.eclipse.scout.rt.client.ui.form.fields.FormFieldEnabledTest.P_GroupBox.P_TabBox.Tab1.P_TreeBox.P_Seq.P_String)1 MainBox (org.eclipse.scout.rt.client.ui.form.fields.FormFieldEnabledTest.P_InnerForm.MainBox)1 P_Button2 (org.eclipse.scout.rt.client.ui.form.fields.FormFieldVisibilityTest.P_GroupBox.P_RadioButtonGroup.P_Button2)1 Tab1 (org.eclipse.scout.rt.client.ui.form.fields.FormFieldVisibilityTest.P_GroupBox.P_TabBox.Tab1)1 P_Seq (org.eclipse.scout.rt.client.ui.form.fields.FormFieldVisibilityTest.P_GroupBox.P_TabBox.Tab1.P_TreeBox.P_Seq)1 IFormField (org.eclipse.scout.rt.client.ui.form.fields.IFormField)1