Search in sources :

Example 11 with Holder

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

the class AbstractForm method interceptInitConfig.

protected final void interceptInitConfig() {
    final Holder<RuntimeException> exceptionHolder = new Holder<>(RuntimeException.class, null);
    final Holder<PlatformError> errorHolder = new Holder<>(PlatformError.class, null);
    m_objectExtensions.initConfig(createLocalExtension(), new Runnable() {

        @Override
        public void run() {
            try {
                initConfig();
            } catch (RuntimeException e) {
                exceptionHolder.setValue(e);
            } catch (PlatformError e) {
                errorHolder.setValue(e);
            }
        }
    });
    if (exceptionHolder.getValue() != null) {
        throw exceptionHolder.getValue();
    } else if (errorHolder.getValue() != null) {
        throw errorHolder.getValue();
    }
}
Also used : PlatformError(org.eclipse.scout.rt.platform.exception.PlatformError) 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) IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable)

Example 12 with Holder

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

the class AbstractForm method exportFormData.

@Override
public void exportFormData(final AbstractFormData target) {
    // locally declared form properties
    Map<String, Object> properties = BeanUtility.getProperties(this, AbstractForm.class, new FormDataPropertyFilter());
    BeanUtility.setProperties(target, properties, false, null);
    // properties in extensions of form
    exportExtensionProperties(this, target);
    final Set<IFormField> exportedFields = new HashSet<IFormField>();
    // all fields
    Map<Integer, Map<String, AbstractFormFieldData>> /* qualified field id */
    breadthFirstMap = target.getAllFieldsRec();
    for (Map<String, AbstractFormFieldData> /* qualified field id */
    targetMap : breadthFirstMap.values()) {
        for (Map.Entry<String, AbstractFormFieldData> e : targetMap.entrySet()) {
            String fieldQId = e.getKey();
            AbstractFormFieldData data = e.getValue();
            FindFieldByFormDataIdVisitor v = new FindFieldByFormDataIdVisitor(fieldQId, this);
            visitFields(v);
            IFormField f = v.getField();
            if (f != null) {
                // field properties
                properties = BeanUtility.getProperties(f, AbstractFormField.class, new FormDataPropertyFilter());
                BeanUtility.setProperties(data, properties, false, null);
                exportExtensionProperties(f, data);
                // field state
                f.exportFormFieldData(data);
                // remember exported fields
                exportedFields.add(f);
            } else {
                LOG.warn("Cannot find field with id '{}' in form '{}' for DTO '{}'.", fieldQId, getClass().getName(), data.getClass().getName());
            }
        }
    }
    // visit remaining fields (there could be an extension with properties e.g. on a groupbox)
    final Holder<RuntimeException> exHolder = new Holder<>(RuntimeException.class);
    final Holder<PlatformError> errorHolder = new Holder<>(PlatformError.class);
    visitFields(new IFormFieldVisitor() {

        @Override
        public boolean visitField(IFormField field, int level, int fieldIndex) {
            if (exportedFields.contains(field)) {
                // already exported -> skip
                return true;
            }
            final IForm formOfField = field.getForm();
            if (formOfField == null) {
                // either form has not been initialized or the field is part of a composite field, that does not override setForminternal -> skip
                LOG.info("Extension properties are not exported for fields on which getForm() returns null. " + "Ensure that the form is initialized and that the field's parent invokes field.setFormInternal(IForm) [exportingForm={}, field={}]", AbstractForm.this.getClass().getName(), field.getClass().getName());
                return true;
            }
            if (formOfField != AbstractForm.this) {
                // field belongs to another form -> skip
                return true;
            }
            try {
                exportExtensionProperties(field, target);
            } catch (RuntimeException e) {
                exHolder.setValue(e);
            } catch (PlatformError e) {
                errorHolder.setValue(e);
            }
            return exHolder.getValue() == null && errorHolder.getValue() == null;
        }
    });
    if (exHolder.getValue() != null) {
        throw exHolder.getValue();
    } else if (errorHolder.getValue() != null) {
        throw errorHolder.getValue();
    }
}
Also used : AbstractFormField(org.eclipse.scout.rt.client.ui.form.fields.AbstractFormField) AbstractFormFieldData(org.eclipse.scout.rt.shared.data.form.fields.AbstractFormFieldData) 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) FormDataPropertyFilter(org.eclipse.scout.rt.client.ui.form.internal.FormDataPropertyFilter) IFormField(org.eclipse.scout.rt.client.ui.form.fields.IFormField) PlatformError(org.eclipse.scout.rt.platform.exception.PlatformError) FindFieldByFormDataIdVisitor(org.eclipse.scout.rt.client.ui.form.internal.FindFieldByFormDataIdVisitor) IExtensibleObject(org.eclipse.scout.rt.shared.extension.IExtensibleObject) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 13 with Holder

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

the class AbstractForm method getClientPartOfExtensionOrContributionRec.

private Object getClientPartOfExtensionOrContributionRec(final Object extToSearch, Object owner) {
    Object ext = getClientPartOfExtensionOrContribution(extToSearch, owner);
    if (ext != null) {
        return ext;
    }
    // search for the extension in the children
    final IHolder<Object> result = new Holder<Object>(Object.class);
    IFormFieldVisitor visitor = new IFormFieldVisitor() {

        @Override
        public boolean visitField(IFormField field, int level, int fieldIndex) {
            result.setValue(getClientPartOfExtensionOrContribution(extToSearch, field));
            return result.getValue() == null;
        }
    };
    if (owner instanceof IForm) {
        ((IForm) owner).visitFields(visitor);
    } else if (owner instanceof IFormField) {
        ((IFormField) owner).acceptVisitor(visitor, 0, 0, true);
    }
    return result.getValue();
}
Also used : IFormField(org.eclipse.scout.rt.client.ui.form.fields.IFormField) 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) IExtensibleObject(org.eclipse.scout.rt.shared.extension.IExtensibleObject)

Example 14 with Holder

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

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

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