Search in sources :

Example 21 with Holder

use of org.eclipse.scout.rt.platform.holders.Holder in project scout.rt by eclipse.

the class AbstractForm method storeToXml.

@Override
public void storeToXml(Element root) {
    root.setAttribute("formId", getFormId());
    root.setAttribute("formQname", getClass().getName());
    // add custom properties
    Element xProps = root.getOwnerDocument().createElement("properties");
    root.appendChild(xProps);
    IPropertyFilter filter = new IPropertyFilter() {

        @Override
        public boolean accept(FastPropertyDescriptor descriptor) {
            if (descriptor.getPropertyType().isInstance(IFormField.class)) {
                return false;
            }
            if (!descriptor.getPropertyType().isPrimitive() && !Serializable.class.isAssignableFrom(descriptor.getPropertyType())) {
                return false;
            }
            if (descriptor.getReadMethod() == null || descriptor.getWriteMethod() == null) {
                return false;
            }
            return true;
        }
    };
    Map<String, Object> props = BeanUtility.getProperties(this, AbstractForm.class, filter);
    storePropertiesToXml(xProps, props);
    // add extension properties
    for (IExtension<?> ex : getAllExtensions()) {
        Map<String, Object> extensionProps = BeanUtility.getProperties(ex, AbstractFormExtension.class, filter);
        if (extensionProps.isEmpty()) {
            continue;
        }
        Element xExtension = root.getOwnerDocument().createElement("extension");
        xProps.appendChild(xExtension);
        xExtension.setAttribute("extensionId", ex.getClass().getSimpleName());
        xExtension.setAttribute("extensionQname", ex.getClass().getName());
        storePropertiesToXml(xExtension, extensionProps);
    }
    // add fields
    final Element xFields = root.getOwnerDocument().createElement("fields");
    root.appendChild(xFields);
    final Holder<RuntimeException> exceptionHolder = new Holder<>(RuntimeException.class);
    final Holder<PlatformError> errorHolder = new Holder<>(PlatformError.class);
    P_AbstractCollectingFieldVisitor v = new P_AbstractCollectingFieldVisitor() {

        @Override
        public boolean visitField(IFormField field, int level, int fieldIndex) {
            if (field.getForm() != AbstractForm.this) {
                // field is part of a wrapped form and is handled by the AbstractWrappedFormField
                return true;
            }
            Element xField = xFields.getOwnerDocument().createElement("field");
            try {
                field.storeToXml(xField);
                xFields.appendChild(xField);
            } catch (RuntimeException e) {
                exceptionHolder.setValue(e);
                return false;
            } catch (PlatformError e) {
                errorHolder.setValue(e);
                return false;
            }
            return true;
        }
    };
    visitFields(v);
    if (exceptionHolder.getValue() != null) {
        throw exceptionHolder.getValue();
    } else if (errorHolder.getValue() != null) {
        throw errorHolder.getValue();
    }
}
Also used : IHtmlListElement(org.eclipse.scout.rt.platform.html.IHtmlListElement) Element(org.w3c.dom.Element) IHolder(org.eclipse.scout.rt.platform.holders.IHolder) IPropertyHolder(org.eclipse.scout.rt.shared.data.form.IPropertyHolder) Holder(org.eclipse.scout.rt.platform.holders.Holder) FastPropertyDescriptor(org.eclipse.scout.rt.platform.reflect.FastPropertyDescriptor) IFormField(org.eclipse.scout.rt.client.ui.form.fields.IFormField) PlatformError(org.eclipse.scout.rt.platform.exception.PlatformError) IExtensibleObject(org.eclipse.scout.rt.shared.extension.IExtensibleObject) IPropertyFilter(org.eclipse.scout.rt.platform.reflect.IPropertyFilter)

Example 22 with Holder

use of org.eclipse.scout.rt.platform.holders.Holder in project scout.rt by eclipse.

the class SelectInputBindTest method testBatchUpdateFromListInHolder.

/**
 * Batch update from a list in an holder.
 */
@Test
public void testBatchUpdateFromListInHolder() throws Exception {
    SqlServiceMock sql = createSqlServiceMock();
    Long person = 9L;
    List<Long> roles = Arrays.asList(5L, 6L);
    Holder<List> holder = new Holder<List>(List.class, roles);
    sql.update("UDPATE this_table SET v = :value where r = :{roles} and p = :personNr", new NVPair("personNr", person), new NVPair("roles", holder), new NVPair("value", "lorem"));
    assertExpectedProtocol2(sql);
}
Also used : SqlServiceMock(org.eclipse.scout.rt.server.jdbc.fixture.SqlServiceMock) ITableBeanHolder(org.eclipse.scout.rt.platform.holders.ITableBeanHolder) ITableBeanRowHolder(org.eclipse.scout.rt.platform.holders.ITableBeanRowHolder) Holder(org.eclipse.scout.rt.platform.holders.Holder) NVPair(org.eclipse.scout.rt.platform.holders.NVPair) List(java.util.List) Test(org.junit.Test)

Example 23 with Holder

use of org.eclipse.scout.rt.platform.holders.Holder 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)

Example 24 with Holder

use of org.eclipse.scout.rt.platform.holders.Holder in project scout.rt by eclipse.

the class AbstractDesktopTest method testDataChangedChanging.

@Test
public void testDataChangedChanging() {
    TestEnvironmentDesktop desktop = (TestEnvironmentDesktop) IDesktop.CURRENT.get();
    final Holder<Object[]> resultHolder = new Holder<Object[]>(Object[].class);
    desktop.addDataChangeListener(new DataChangeListener() {

        @Override
        public void dataChanged(Object... dataTypes) {
            resultHolder.setValue(dataTypes);
        }
    }, TEST_DATA_TYPE_1, TEST_DATA_TYPE_2);
    desktop.setDataChanging(true);
    desktop.dataChanged(TEST_DATA_TYPE_1);
    desktop.dataChanged(TEST_DATA_TYPE_1, TEST_DATA_TYPE_1, TEST_DATA_TYPE_1);
    desktop.dataChanged(TEST_DATA_TYPE_2, TEST_DATA_TYPE_2);
    desktop.dataChanged(TEST_DATA_TYPE_1, TEST_DATA_TYPE_2);
    desktop.dataChanged(TEST_DATA_TYPE_1);
    desktop.dataChanged(TEST_DATA_TYPE_2);
    desktop.setDataChanging(false);
    verifyDataChanged(resultHolder);
}
Also used : Holder(org.eclipse.scout.rt.platform.holders.Holder) DataChangeListener(org.eclipse.scout.rt.client.ui.DataChangeListener) TestEnvironmentDesktop(org.eclipse.scout.rt.client.testenvironment.ui.desktop.TestEnvironmentDesktop) Test(org.junit.Test)

Example 25 with Holder

use of org.eclipse.scout.rt.platform.holders.Holder in project scout.rt by eclipse.

the class WhenDoneTest method testSuccess.

@Test
public void testSuccess() throws InterruptedException {
    // synchronized because modified/read by different threads.
    final List<String> protocol = Collections.synchronizedList(new ArrayList<String>());
    final Holder<DoneEvent<String>> eventHolder = new Holder<>();
    final IFuture<String> future = Jobs.schedule(new Callable<String>() {

        @Override
        public String call() throws Exception {
            protocol.add("1");
            return "result";
        }
    }, Jobs.newInput().withRunContext(RunContexts.copyCurrent()).withExecutionTrigger(Jobs.newExecutionTrigger().withStartIn(1, TimeUnit.SECONDS)));
    final BlockingCountDownLatch verifyLatch = new BlockingCountDownLatch(1);
    future.whenDone(new IDoneHandler<String>() {

        @Override
        public void onDone(DoneEvent<String> event) {
            protocol.add("2");
            if (future.isDone()) {
                protocol.add("done");
            }
            if (future.isCancelled()) {
                protocol.add("cancelled");
            }
            eventHolder.setValue(event);
            verifyLatch.countDown();
        }
    }, RunContexts.copyCurrent());
    assertTrue(verifyLatch.await());
    assertEquals(CollectionUtility.arrayList("1", "2", "done"), protocol);
    assertNull(eventHolder.getValue().getException());
    assertEquals("result", eventHolder.getValue().getResult());
    assertFalse(eventHolder.getValue().isCancelled());
    assertFalse(eventHolder.getValue().isFailed());
}
Also used : BlockingCountDownLatch(org.eclipse.scout.rt.testing.platform.util.BlockingCountDownLatch) Holder(org.eclipse.scout.rt.platform.holders.Holder) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) Test(org.junit.Test)

Aggregations

Holder (org.eclipse.scout.rt.platform.holders.Holder)28 Test (org.junit.Test)20 ProcessingException (org.eclipse.scout.rt.platform.exception.ProcessingException)6 IRunnable (org.eclipse.scout.rt.platform.util.concurrent.IRunnable)6 BlockingCountDownLatch (org.eclipse.scout.rt.testing.platform.util.BlockingCountDownLatch)6 IHolder (org.eclipse.scout.rt.platform.holders.IHolder)4 IPropertyHolder (org.eclipse.scout.rt.shared.data.form.IPropertyHolder)4 SocketTimeoutException (java.net.SocketTimeoutException)3 List (java.util.List)3 WebServiceException (javax.xml.ws.WebServiceException)3 JaxWsConsumerTestServicePortType (org.eclipse.scout.jaxws.consumer.jaxwsconsumertestservice.JaxWsConsumerTestServicePortType)3 IFormFieldVisitor (org.eclipse.scout.rt.client.ui.form.IFormFieldVisitor)3 IFormField (org.eclipse.scout.rt.client.ui.form.fields.IFormField)3 CallableChain (org.eclipse.scout.rt.platform.chain.callable.CallableChain)3 PlatformError (org.eclipse.scout.rt.platform.exception.PlatformError)3 AssertionException (org.eclipse.scout.rt.platform.util.Assertions.AssertionException)3 IExtensibleObject (org.eclipse.scout.rt.shared.extension.IExtensibleObject)3 InOrder (org.mockito.InOrder)3 InvocationHandler (java.lang.reflect.InvocationHandler)2 Method (java.lang.reflect.Method)2