Search in sources :

Example 56 with IFormField

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

the class AbstractListBox method initConfig.

@Override
protected void initConfig() {
    m_fields = CollectionUtility.emptyArrayList();
    m_movedFormFieldsByClass = new HashMap<Class<? extends IFormField>, IFormField>();
    super.initConfig();
    setFilterActiveRows(getConfiguredFilterActiveRows());
    setFilterActiveRowsValue(TriState.TRUE);
    setFilterCheckedRows(getConfiguredFilterCheckedRows());
    setFilterCheckedRowsValue(getConfiguredFilterCheckedRows());
    List<ITable> contributedTables = m_contributionHolder.getContributionsByClass(ITable.class);
    m_table = CollectionUtility.firstElement(contributedTables);
    if (m_table == null) {
        Class<? extends ITable> configuredTable = getConfiguredTable();
        if (configuredTable != null) {
            m_table = ConfigurationUtility.newInnerInstance(this, configuredTable);
        }
    }
    if (m_table != null) {
        if (m_table instanceof AbstractTable) {
            ((AbstractTable) m_table).setContainerInternal(this);
        }
        updateActiveRowsFilter();
        updateCheckedRowsFilter();
        m_table.addTableListener(new TableAdapter() {

            @Override
            public void tableChanged(TableEvent e) {
                switch(e.getType()) {
                    case TableEvent.TYPE_ROWS_SELECTED:
                        {
                            if (!getTable().isCheckable()) {
                                syncTableToValue();
                            }
                            break;
                        }
                    case TableEvent.TYPE_ROWS_CHECKED:
                        {
                            if (getTable().isCheckable()) {
                                syncTableToValue();
                            }
                            break;
                        }
                }
            }
        });
        // default icon
        if (m_table.getDefaultIconId() == null && this.getConfiguredIconId() != null) {
            m_table.setDefaultIconId(this.getConfiguredIconId());
        }
        m_table.setEnabled(isEnabled());
    } else {
        LOG.warn("there is no inner class of type ITable in {}", getClass().getName());
    }
    // lookup call
    Class<? extends ILookupCall<KEY>> lookupCallClass = getConfiguredLookupCall();
    if (lookupCallClass != null) {
        ILookupCall<KEY> call = BEANS.get(lookupCallClass);
        setLookupCall(call);
    }
    // code type
    if (getConfiguredCodeType() != null) {
        setCodeTypeClass(getConfiguredCodeType());
    }
    // local property listener
    addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent e) {
            if (m_table == null) {
                return;
            }
            String name = e.getPropertyName();
            if (PROP_ENABLED_COMPUTED.equals(name)) {
                boolean newEnabled = ((Boolean) e.getNewValue()).booleanValue();
                m_table.setEnabled(newEnabled);
            } else if (PROP_FILTER_CHECKED_ROWS_VALUE.equals(name)) {
                updateCheckedRowsFilter();
            } else if (PROP_FILTER_ACTIVE_ROWS_VALUE.equals(name)) {
                updateActiveRowsFilter();
            }
        }
    });
    // add fields
    List<Class<? extends IFormField>> fieldClasses = getConfiguredFields();
    List<IFormField> contributedFields = m_contributionHolder.getContributionsByClass(IFormField.class);
    List<IFormField> fieldList = new ArrayList<IFormField>(fieldClasses.size() + contributedFields.size());
    for (Class<? extends IFormField> fieldClazz : fieldClasses) {
        IFormField f = ConfigurationUtility.newInnerInstance(this, fieldClazz);
        fieldList.add(f);
    }
    fieldList.addAll(contributedFields);
    Collections.sort(fieldList, new OrderedComparator());
    for (IFormField f : fieldList) {
        f.setParentFieldInternal(this);
    }
    m_fields = fieldList;
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) ArrayList(java.util.ArrayList) TableAdapter(org.eclipse.scout.rt.client.ui.basic.table.TableAdapter) IFormField(org.eclipse.scout.rt.client.ui.form.fields.IFormField) AbstractTable(org.eclipse.scout.rt.client.ui.basic.table.AbstractTable) TableEvent(org.eclipse.scout.rt.client.ui.basic.table.TableEvent) OrderedComparator(org.eclipse.scout.rt.platform.OrderedComparator) ITable(org.eclipse.scout.rt.client.ui.basic.table.ITable)

Example 57 with IFormField

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

the class AbstractWrappedFormField method acceptVisitor.

@Override
public boolean acceptVisitor(IFormFieldVisitor visitor, int level, int fieldIndex, boolean includeThis) {
    Collection<IFormField> innerFormRootGroupBox = null;
    FORM innerForm = getInnerForm();
    if (innerForm != null) {
        IGroupBox rootGroupBox = innerForm.getRootGroupBox();
        if (rootGroupBox != null) {
            innerFormRootGroupBox = Collections.<IFormField>singletonList(rootGroupBox);
        }
    }
    IFormField thisField = null;
    if (includeThis) {
        thisField = this;
    }
    return CompositeFieldUtility.applyFormFieldVisitor(visitor, thisField, innerFormRootGroupBox, level, fieldIndex);
}
Also used : IFormField(org.eclipse.scout.rt.client.ui.form.fields.IFormField) IGroupBox(org.eclipse.scout.rt.client.ui.form.fields.groupbox.IGroupBox)

Example 58 with IFormField

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

the class ColumnEditableTest method testDynamicEditableColumn.

/**
 * Tests if cell can set to be dynamically not editable with execIsEditable
 */
@Test
public void testDynamicEditableColumn() {
    DynamicEditableTestTable testTable = new DynamicEditableTestTable();
    testTable.setEnabled(true);
    testTable.addRowByArray(getTestRow());
    testTable.addRowByArray(getTestRow());
    IColumn editableCol = testTable.getDynamicEditableTestColumn();
    assertTrue(editableCol.isEditable());
    IFormField field = editableCol.prepareEdit(testTable.getRow(0));
    assertNotNull(field);
    assertTrue(field.isEnabled());
    field = editableCol.prepareEdit(testTable.getRow(1));
    assertNull(field);
    assertTrue(testTable.getCell(0, 0).isEditable());
    assertFalse(testTable.getCell(1, 0).isEditable());
}
Also used : IFormField(org.eclipse.scout.rt.client.ui.form.fields.IFormField) Test(org.junit.Test)

Example 59 with IFormField

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

the class ColumnMandatoryTest method testValidationOnMandatoryColumn.

/**
 * Tests, if a field is mandatory in a mandatory column
 */
@Test
public void testValidationOnMandatoryColumn() {
    MandatoryTestTable testTable = new MandatoryTestTable();
    testTable.addRowByArray(getEmptyTestRow());
    IColumn mandatoryCol = testTable.getMandatoryTestColumn();
    IFormField field = mandatoryCol.prepareEdit(testTable.getRow(0));
    assertFalse(field.isContentValid());
}
Also used : IFormField(org.eclipse.scout.rt.client.ui.form.fields.IFormField) IColumn(org.eclipse.scout.rt.client.ui.basic.table.columns.IColumn) Test(org.junit.Test)

Example 60 with IFormField

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

the class JsonGroupBoxTest method testDontSendNonDisplayableFields.

/**
 * Tests whether non displayable fields are sent.
 * <p>
 * This reduces response size and also leverages security because the fields are never visible to the user, not even
 * with the dev tools of the browser
 */
@Test
public void testDontSendNonDisplayableFields() throws Exception {
    IGroupBox groupBox = new GroupBoxWithNonDisplayableField();
    JsonTestUtility.initField(groupBox);
    JsonGroupBox<IGroupBox> jsonGroupBox = UiSessionTestUtility.newJsonAdapter(m_uiSession, groupBox, null);
    JsonFormField<IFormField> jsonDisplayableField = m_uiSession.getJsonAdapter(groupBox.getFieldByClass(GroupBoxWithNonDisplayableField.DisplayableField.class), jsonGroupBox);
    JsonFormField<IFormField> jsonNonDisplayableField = m_uiSession.getJsonAdapter(groupBox.getFieldByClass(GroupBoxWithNonDisplayableField.NonDisplayableField.class), jsonGroupBox);
    // Adapter for NonDisplayableField must not exist
    assertNull(jsonNonDisplayableField);
    // Json response must not contain NonDisplayableField
    JSONObject json = jsonGroupBox.toJson();
    JSONArray jsonFormFields = json.getJSONArray("fields");
    assertEquals(1, jsonFormFields.length());
    assertEquals(jsonDisplayableField.getId(), jsonFormFields.get(0));
}
Also used : IFormField(org.eclipse.scout.rt.client.ui.form.fields.IFormField) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) IGroupBox(org.eclipse.scout.rt.client.ui.form.fields.groupbox.IGroupBox) Test(org.junit.Test) BaseFormFieldTest(org.eclipse.scout.rt.ui.html.json.form.fields.BaseFormFieldTest)

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