Search in sources :

Example 16 with IFormField

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

the class AbstractForm method initConfig.

protected void initConfig() {
    m_uiFacade = BEANS.get(ModelContextProxy.class).newProxy(new P_UIFacade(), ModelContext.copyCurrent().withForm(this));
    m_timerFutureMap = new HashMap<>();
    setShowOnStart(getConfiguredShowOnStart());
    m_contributionHolder = new ContributionComposite(this);
    // prepare injected fields
    List<Class<IFormField>> fieldArray = getConfiguredInjectedFields();
    DefaultFormFieldInjection injectedFields = null;
    IGroupBox rootBox = getRootGroupBox();
    try {
        if (fieldArray.size() > 0) {
            injectedFields = new DefaultFormFieldInjection(this);
            injectedFields.addFields(fieldArray);
            FormFieldInjectionThreadLocal.push(injectedFields);
        }
        // add mainbox if getter returns null
        if (rootBox == null) {
            List<IGroupBox> contributedFields = m_contributionHolder.getContributionsByClass(IGroupBox.class);
            rootBox = CollectionUtility.firstElement(contributedFields);
            if (rootBox == null) {
                Class<? extends IGroupBox> mainBoxClass = getConfiguredMainBox();
                if (mainBoxClass != null) {
                    rootBox = ConfigurationUtility.newInnerInstance(this, mainBoxClass);
                }
            }
            m_mainBox = rootBox;
        }
    } finally {
        if (injectedFields != null) {
            m_fieldReplacements = injectedFields.getReplacementMapping();
            FormFieldInjectionThreadLocal.pop(injectedFields);
        }
    }
    if (rootBox != null) {
        rootBox.setFormInternal(this);
        rootBox.setMainBox(true);
        rootBox.updateKeyStrokes();
        if (rootBox.isScrollable().isUndefined()) {
            rootBox.setScrollable(true);
        }
    }
    // move form fields
    new MoveFormFieldsHandler(this).moveFields();
    // 
    if (getConfiguredCloseTimer() > 0) {
        setCloseTimer(getConfiguredCloseTimer());
    }
    if (getConfiguredCustomTimer() > 0) {
        setTimer("custom", getConfiguredCustomTimer());
    }
    if (getConfiguredCancelVerificationText() != null) {
        setCancelVerificationText(getConfiguredCancelVerificationText());
    }
    if (getConfiguredTitle() != null) {
        setTitle(getConfiguredTitle());
    }
    if (getConfiguredSubTitle() != null) {
        setSubTitle(getConfiguredSubTitle());
    }
    setMinimizeEnabled(getConfiguredMinimizeEnabled());
    setMaximizeEnabled(getConfiguredMaximizeEnabled());
    setMinimized(getConfiguredMinimized());
    setMaximized(getConfiguredMaximized());
    setCacheBounds(getConfiguredCacheBounds());
    setAskIfNeedSave(getConfiguredAskIfNeedSave());
    setIconId(getConfiguredIconId());
    setCssClass((getConfiguredCssClass()));
    // Set 'modality' as preferred value if not 'auto'.
    int modalityHint = getConfiguredModalityHint();
    if (modalityHint != MODALITY_HINT_AUTO) {
        m_modal.set(modalityHint == MODALITY_HINT_MODAL, true);
    }
    // Set 'displayParent' as preferred value if not null; must precede setting of the 'displayHint'.
    IDisplayParent displayParent = getConfiguredDisplayParent();
    if (displayParent != null) {
        m_displayParent.set(displayParent, true);
    } else {
        m_displayParent.set(getDesktop(), false);
    }
    setDisplayHint(getConfiguredDisplayHint());
    setDisplayViewId(getConfiguredDisplayViewId());
    setClosable(getConfiguredClosable());
    setSaveNeededVisible(getConfiguredSaveNeededVisible());
    // visit all system buttons and attach observer
    // is auto-detaching
    m_systemButtonListener = new P_SystemButtonListener();
    IFormFieldVisitor v2 = new IFormFieldVisitor() {

        @Override
        public boolean visitField(IFormField field, int level, int fieldIndex) {
            if (field instanceof IButton) {
                final IButton button = (IButton) field;
                if (button.getSystemType() != IButton.SYSTEM_TYPE_NONE) {
                    button.addButtonListener(m_systemButtonListener);
                }
            }
            return true;
        }
    };
    visitFields(v2);
    getRootGroupBox().addPropertyChangeListener(new P_MainBoxPropertyChangeProxy());
    setButtonsArmed(true);
}
Also used : ContributionComposite(org.eclipse.scout.rt.shared.extension.ContributionComposite) IFormField(org.eclipse.scout.rt.client.ui.form.fields.IFormField) MoveFormFieldsHandler(org.eclipse.scout.rt.client.extension.ui.form.MoveFormFieldsHandler) IButton(org.eclipse.scout.rt.client.ui.form.fields.button.IButton) IGroupBox(org.eclipse.scout.rt.client.ui.form.fields.groupbox.IGroupBox) IDisplayParent(org.eclipse.scout.rt.client.ui.IDisplayParent)

Example 17 with IFormField

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

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

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

the class AbstractForm method importFormData.

@Override
public void importFormData(AbstractFormData source, boolean valueChangeTriggersEnabled, IPropertyFilter filter, IFormFieldFilter formFieldFilter) {
    Assertions.assertNotNull(source, "source form data must not be null");
    if (filter == null) {
        filter = new FormDataPropertyFilter();
    }
    // form properties
    importProperties(source, this, AbstractFormData.class, filter);
    // sort fields, first non-slave fields, then slave fields in transitive order
    LinkedList<IFormField> masterList = new LinkedList<IFormField>();
    LinkedList<IFormField> slaveList = new LinkedList<IFormField>();
    HashMap<IFormField, AbstractFormFieldData> dataMap = new HashMap<IFormField, AbstractFormFieldData>();
    // collect fields and split them into masters/slaves
    Map<Integer, Map<String, AbstractFormFieldData>> /* qualified field id */
    breadthFirstMap = source.getAllFieldsRec();
    for (Map<String, AbstractFormFieldData> /* qualified field id */
    sourceMap : breadthFirstMap.values()) {
        for (Map.Entry<String, AbstractFormFieldData> e : sourceMap.entrySet()) {
            String fieldQId = e.getKey();
            AbstractFormFieldData data = e.getValue();
            FindFieldByFormDataIdVisitor v = new FindFieldByFormDataIdVisitor(fieldQId, this);
            visitFields(v);
            IFormField f = v.getField();
            if (f != null) {
                if (formFieldFilter == null || formFieldFilter.accept(f)) {
                    dataMap.put(f, data);
                    if (f.getMasterField() != null) {
                        int index = slaveList.indexOf(f.getMasterField());
                        if (index >= 0) {
                            slaveList.add(index + 1, f);
                        } else {
                            slaveList.addFirst(f);
                        }
                    } else {
                        masterList.add(f);
                    }
                }
            } else {
                LOG.warn("cannot find field data for '{}' in form '{}'.", fieldQId, getClass().getName());
            }
        }
    }
    for (IFormField f : masterList) {
        importFormField(f, dataMap, valueChangeTriggersEnabled, filter);
    }
    for (IFormField f : slaveList) {
        importFormField(f, dataMap, valueChangeTriggersEnabled, filter);
    }
}
Also used : AbstractFormFieldData(org.eclipse.scout.rt.shared.data.form.fields.AbstractFormFieldData) HashMap(java.util.HashMap) FormDataPropertyFilter(org.eclipse.scout.rt.client.ui.form.internal.FormDataPropertyFilter) LinkedList(java.util.LinkedList) IFormField(org.eclipse.scout.rt.client.ui.form.fields.IFormField) FindFieldByFormDataIdVisitor(org.eclipse.scout.rt.client.ui.form.internal.FindFieldByFormDataIdVisitor) Map(java.util.Map) HashMap(java.util.HashMap)

Example 20 with IFormField

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

the class DefaultFormFieldInjection method createAndInsertField.

/**
 * Adds the field f to the end of the list. If the field is already part of the given list, this method does nothing.
 */
private void createAndInsertField(IFormField container, OrderedCollection<IFormField> fields, Class<? extends IFormField> fieldClass) {
    // check if list already contains the field
    for (IFormField f : fields) {
        if (f.getClass() == fieldClass) {
            return;
        }
    }
    IFormField f = newInnerInstance(container, fieldClass);
    fields.addOrdered(f);
}
Also used : IFormField(org.eclipse.scout.rt.client.ui.form.fields.IFormField)

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