Search in sources :

Example 36 with IFormField

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

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

the class AbstractForm method validateForm.

@Override
public void validateForm() {
    if (!interceptCheckFields()) {
        VetoException veto = new VetoException("Validate " + getClass().getSimpleName());
        veto.consume();
        throw veto;
    }
    if (!getHandler().onCheckFields()) {
        VetoException veto = new VetoException("Validate " + getClass().getSimpleName());
        veto.consume();
        throw veto;
    }
    // check all fields that might be invalid
    final ArrayList<String> invalidTexts = new ArrayList<String>();
    final ArrayList<String> mandatoryTexts = new ArrayList<String>();
    P_AbstractCollectingFieldVisitor<IValidateContentDescriptor> v = new P_AbstractCollectingFieldVisitor<IValidateContentDescriptor>() {

        @Override
        public boolean visitField(IFormField f, int level, int fieldIndex) {
            IValidateContentDescriptor desc = f.validateContent();
            if (desc != null) {
                if (desc.getErrorStatus() != null) {
                    invalidTexts.add(desc.getDisplayText() + ": " + desc.getErrorStatus().getMessage());
                } else {
                    mandatoryTexts.add(desc.getDisplayText());
                }
                if (getCollectionCount() == 0) {
                    collect(desc);
                }
            }
            return true;
        }
    };
    visitFields(v);
    if (v.getCollectionCount() > 0) {
        IValidateContentDescriptor firstProblem = v.getCollection().get(0);
        if (LOG.isInfoEnabled()) {
            LOG.info("there are fields with errors");
        }
        if (firstProblem != null) {
            firstProblem.activateProblemLocation();
        }
        throw new VetoException().withHtmlMessage(createValidationMessageBoxHtml(invalidTexts, mandatoryTexts));
    }
    if (!interceptValidate()) {
        VetoException veto = new VetoException("Validate " + getClass().getSimpleName());
        veto.consume();
        throw veto;
    }
    if (!getHandler().onValidate()) {
        VetoException veto = new VetoException("Validate " + getClass().getSimpleName());
        veto.consume();
        throw veto;
    }
}
Also used : VetoException(org.eclipse.scout.rt.platform.exception.VetoException) IFormField(org.eclipse.scout.rt.client.ui.form.fields.IFormField) IValidateContentDescriptor(org.eclipse.scout.rt.client.ui.form.fields.IValidateContentDescriptor) ArrayList(java.util.ArrayList)

Example 38 with IFormField

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

the class AbstractTable method interceptRowClickSingleObserver.

protected void interceptRowClickSingleObserver(ITableRow row, MouseButton mouseButton) {
    // Only toggle checked state if the table and row are enabled.
    if (!row.isEnabled() || !isEnabled()) {
        return;
    }
    // Only toggle checked state if being fired by the left mousebutton (https://bugs.eclipse.org/bugs/show_bug.cgi?id=453543).
    if (mouseButton != MouseButton.Left) {
        return;
    }
    IColumn<?> ctxCol = getContextColumn();
    if (isCellEditable(row, ctxCol)) {
        // cell-level checkbox
        if (ctxCol instanceof IBooleanColumn) {
            // editable boolean columns consume this click
            IFormField field = ctxCol.prepareEdit(row);
            if (field instanceof IBooleanField) {
                IBooleanField bfield = (IBooleanField) field;
                bfield.toggleValue();
                ctxCol.completeEdit(row, field);
            }
        } else {
        // other editable columns have no effect HERE, the ui will open an editor
        }
    }
}
Also used : IBooleanColumn(org.eclipse.scout.rt.client.ui.basic.table.columns.IBooleanColumn) IFormField(org.eclipse.scout.rt.client.ui.form.fields.IFormField) IBooleanField(org.eclipse.scout.rt.client.ui.form.fields.booleanfield.IBooleanField)

Example 39 with IFormField

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

the class AbstractColumn method prepareEdit.

@Override
public final IFormField prepareEdit(ITableRow row) {
    ITable table = getTable();
    if (table == null || !this.isCellEditable(row)) {
        return null;
    }
    IFormField f = interceptPrepareEdit(row);
    if (f != null) {
        f.setLabelVisible(false);
        GridData gd = f.getGridDataHints();
        gd.weightY = 1;
        f.setGridDataHints(gd);
    }
    return f;
}
Also used : IFormField(org.eclipse.scout.rt.client.ui.form.fields.IFormField) GridData(org.eclipse.scout.rt.client.ui.form.fields.GridData) ITable(org.eclipse.scout.rt.client.ui.basic.table.ITable)

Example 40 with IFormField

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

the class AbstractComposerValueBox method initConfig.

@Override
protected void initConfig() {
    super.initConfig();
    HashMap<Integer, Map<Integer, IComposerValueField>> operatorTypeToFieldMap = new HashMap<Integer, Map<Integer, IComposerValueField>>();
    interceptInitOperatorToFieldMap(operatorTypeToFieldMap);
    m_operatorTypeToFieldMap = operatorTypeToFieldMap;
    m_valueChangedListener = new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent e) {
            if (IValueField.PROP_VALUE.equals(e.getPropertyName())) {
                try {
                    interceptChangedValue();
                } catch (Exception ex) {
                    LOG.error("fire value change on {}", e.getSource(), ex);
                }
            }
        }
    };
    for (IFormField f : getFields()) {
        f.setLabelVisible(false);
        f.setLabel(TEXTS.get("Value"));
        f.setVisible(false);
        if (f instanceof ISequenceBox) {
            List<IFormField> sequenceBoxChildFields = ((ISequenceBox) f).getFields();
            if (CollectionUtility.hasElements(sequenceBoxChildFields)) {
                IFormField firstField = CollectionUtility.firstElement(sequenceBoxChildFields);
                firstField.setLabelVisible(false);
                if (sequenceBoxChildFields.size() > 1) {
                    IFormField secondField = CollectionUtility.getElement(sequenceBoxChildFields, 1);
                    secondField.setLabel(TEXTS.get("and"));
                }
            }
        }
    }
}
Also used : IFormField(org.eclipse.scout.rt.client.ui.form.fields.IFormField) PropertyChangeEvent(java.beans.PropertyChangeEvent) ISequenceBox(org.eclipse.scout.rt.client.ui.form.fields.sequencebox.ISequenceBox) PropertyChangeListener(java.beans.PropertyChangeListener) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map)

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