Search in sources :

Example 6 with IFormFieldVisitor

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

the class FormFieldEnabledTest method testWrappedFormField.

@Test
public void testWrappedFormField() {
    P_OuterForm frm = new P_OuterForm();
    final AtomicReference<P_String> ref = new AtomicReference<>();
    frm.visitFields(new IFormFieldVisitor() {

        @Override
        public boolean visitField(IFormField field, int level, int fieldIndex) {
            if (field instanceof P_String) {
                ref.set((P_String) field);
            }
            return ref.get() == null;
        }
    });
    P_String stringField = ref.get();
    Assert.assertNotNull(stringField);
    final AtomicInteger counter = new AtomicInteger(0);
    stringField.visitParents(new IFormFieldVisitor() {

        @Override
        public boolean visitField(IFormField field, int level, int fieldIndex) {
            counter.incrementAndGet();
            return true;
        }
    });
    Assert.assertEquals(7, counter.intValue());
    MainBox innerMainBox = frm.getFieldByClass(Wrapped.class).getInnerForm().getFieldByClass(MainBox.class);
    final AtomicInteger counter2 = new AtomicInteger(0);
    innerMainBox.visitParents(new IFormFieldVisitor() {

        @Override
        public boolean visitField(IFormField field, int level, int fieldIndex) {
            counter2.incrementAndGet();
            return true;
        }
    });
    Assert.assertEquals(2, counter2.intValue());
}
Also used : MainBox(org.eclipse.scout.rt.client.ui.form.fields.FormFieldEnabledTest.P_InnerForm.MainBox) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) P_String(org.eclipse.scout.rt.client.ui.form.fields.FormFieldEnabledTest.P_GroupBox.P_TabBox.Tab1.P_TreeBox.P_Seq.P_String) AtomicReference(java.util.concurrent.atomic.AtomicReference) IFormFieldVisitor(org.eclipse.scout.rt.client.ui.form.IFormFieldVisitor) Test(org.junit.Test)

Example 7 with IFormFieldVisitor

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

the class FormFieldVisibilityTest method testVisitFields.

@Test
public void testVisitFields() {
    ICompositeField field = createFixture();
    final AtomicInteger counter = new AtomicInteger(0);
    field.visitFields(new IFormFieldVisitor() {

        @Override
        public boolean visitField(IFormField f, int level, int fieldIndex) {
            if (f.getClass().getName().startsWith(FormFieldVisibilityTest.class.getName())) {
                // ignore the filter boxes of treebox and listbox
                counter.incrementAndGet();
            }
            return true;
        }
    });
    Assert.assertEquals(12, counter.intValue());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IFormFieldVisitor(org.eclipse.scout.rt.client.ui.form.IFormFieldVisitor) Test(org.junit.Test)

Example 8 with IFormFieldVisitor

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

the class FormFieldVisibilityTest method testVisitParents.

@Test
public void testVisitParents() {
    ICompositeField root = createFixture();
    final AtomicInteger counter01 = new AtomicInteger(0);
    root.getFieldByClass(P_Seq.class).visitParents(new IFormFieldVisitor() {

        @Override
        public boolean visitField(IFormField f, int level, int fieldIndex) {
            counter01.incrementAndGet();
            return true;
        }
    });
    Assert.assertEquals(4, counter01.intValue());
    final AtomicInteger counter02 = new AtomicInteger(0);
    root.getFieldByClass(P_Button2.class).visitParents(new IFormFieldVisitor() {

        @Override
        public boolean visitField(IFormField f, int level, int fieldIndex) {
            counter02.incrementAndGet();
            return true;
        }
    });
    Assert.assertEquals(2, counter02.intValue());
    final AtomicInteger counter03 = new AtomicInteger(0);
    root.visitParents(new IFormFieldVisitor() {

        @Override
        public boolean visitField(IFormField f, int level, int fieldIndex) {
            counter03.incrementAndGet();
            return true;
        }
    });
    Assert.assertEquals(0, counter03.intValue());
    final AtomicInteger counter04 = new AtomicInteger(0);
    final Holder<Object> lastVisited = new Holder<>(Object.class);
    root.getFieldByClass(P_Seq.class).visitParents(new IFormFieldVisitor() {

        @Override
        public boolean visitField(IFormField f, int level, int fieldIndex) {
            counter04.incrementAndGet();
            lastVisited.setValue(f);
            return counter04.intValue() <= 1;
        }
    });
    Assert.assertEquals(2, counter04.intValue());
    Assert.assertSame(lastVisited.getValue(), root.getFieldByClass(Tab1.class));
}
Also used : P_Seq(org.eclipse.scout.rt.client.ui.form.fields.FormFieldVisibilityTest.P_GroupBox.P_TabBox.Tab1.P_TreeBox.P_Seq) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Holder(org.eclipse.scout.rt.platform.holders.Holder) Tab1(org.eclipse.scout.rt.client.ui.form.fields.FormFieldVisibilityTest.P_GroupBox.P_TabBox.Tab1) P_Button2(org.eclipse.scout.rt.client.ui.form.fields.FormFieldVisibilityTest.P_GroupBox.P_RadioButtonGroup.P_Button2) IFormFieldVisitor(org.eclipse.scout.rt.client.ui.form.IFormFieldVisitor) Test(org.junit.Test)

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