Search in sources :

Example 6 with IFormField

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

the class AbstractSequenceBox method initConfig.

@Override
protected void initConfig() {
    m_labelCompositionLock = new OptimisticLock();
    m_grid = new SequenceBoxGrid();
    super.initConfig();
    setAutoCheckFromTo(getConfiguredAutoCheckFromTo());
    setEqualColumnWidths(getConfiguredEqualColumnWidths());
    // when range box has visible label, suppress first field's label and append
    // to own label
    propertySupport.addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent e) {
            if (e.getPropertyName().equals(IFormField.PROP_LABEL_VISIBLE) || e.getPropertyName().equals(IFormField.PROP_LABEL) || e.getPropertyName().equals(IFormField.PROP_VISIBLE)) {
                updateLabelComposition();
            }
        }
    });
    // If inner fields change their visibility dynamically, the label of the SequenceBox might change.
    for (IFormField field : getFields()) {
        field.addPropertyChangeListener(new PropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent e) {
                if (e.getPropertyName().equals(IFormField.PROP_LABEL_VISIBLE) || e.getPropertyName().equals(IFormField.PROP_LABEL) || e.getPropertyName().equals(IFormField.PROP_VISIBLE)) {
                    updateLabelComposition();
                }
            }
        });
    }
    updateLabelComposition();
    hideFieldStatusOfChildren();
    // attach change triggers
    attachCheckFromToListeners();
}
Also used : IFormField(org.eclipse.scout.rt.client.ui.form.fields.IFormField) PropertyChangeEvent(java.beans.PropertyChangeEvent) SequenceBoxGrid(org.eclipse.scout.rt.client.ui.form.fields.sequencebox.internal.SequenceBoxGrid) PropertyChangeListener(java.beans.PropertyChangeListener) OptimisticLock(org.eclipse.scout.rt.platform.util.concurrent.OptimisticLock)

Example 7 with IFormField

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

the class AbstractSequenceBox method getComparableValueFields.

/**
 * @return Comparable {@link IValueField}s with the same holder type than the first one
 */
private ArrayList<IValueField> getComparableValueFields() {
    ArrayList<IValueField> valueFieldList = new ArrayList<IValueField>();
    Class<?> sharedType = null;
    for (IFormField f : getFields()) {
        if (f instanceof IValueField) {
            IValueField v = (IValueField) f;
            Class<?> valueType = v.getHolderType();
            if (Comparable.class.isAssignableFrom(valueType) && (sharedType == null || valueType == sharedType)) {
                sharedType = valueType;
                valueFieldList.add(v);
            }
        }
    }
    return valueFieldList;
}
Also used : IFormField(org.eclipse.scout.rt.client.ui.form.fields.IFormField) ArrayList(java.util.ArrayList) IValueField(org.eclipse.scout.rt.client.ui.form.fields.IValueField)

Example 8 with IFormField

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

the class AbstractGroupBoxBodyGrid method layoutAllStatic.

/**
 * Make layout based on grid-x, grid-y, grid-w and grid-h No auto-layout
 */
private void layoutAllStatic(List<IFormField> fields) {
    int totalGridW = 1;
    int totalGridH = 0;
    for (IFormField f : fields) {
        GridData hints = GridDataBuilder.createFromHints(f, 1);
        totalGridW = Math.max(totalGridW, hints.x + hints.w);
        totalGridH = Math.max(totalGridH, hints.y + hints.h);
    }
    for (IFormField f : fields) {
        GridData hints = GridDataBuilder.createFromHints(f, totalGridW);
        f.setGridDataInternal(hints);
    }
    setGridColumns(totalGridW);
    setGridRows(totalGridH);
}
Also used : IFormField(org.eclipse.scout.rt.client.ui.form.fields.IFormField) GridData(org.eclipse.scout.rt.client.ui.form.fields.GridData)

Example 9 with IFormField

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

the class VerticalGridMatrix method reorganizeGridAbove.

private void reorganizeGridAbove(int x, int y, int w) {
    Set<IFormField> fieldsToReorganize = new HashSet<IFormField>();
    Map<MatrixIndex, Cell> occupiedCells = new HashMap<MatrixIndex, Cell>();
    Bounds reorgBounds = new Bounds(x, 0, w, y + 1);
    int minY = y;
    int usedCells = 0;
    boolean continueLoop = true;
    for (int yi = y; yi >= 0 && continueLoop; yi--) {
        for (int xi = x; xi < x + w && continueLoop; xi++) {
            MatrixIndex matrixIndex = new MatrixIndex(xi, yi);
            Cell cell = m_cells.get(matrixIndex);
            if (cell != null && !cell.isEmpty()) {
                GridData gd = cell.fieldGridData;
                if (horizontalMatchesOrOverlaps(reorgBounds, gd)) {
                    continueLoop = false;
                } else if (horizontalOverlapsOnSide(reorgBounds, gd)) {
                    // freeze the cells for reorganization
                    occupiedCells.put(matrixIndex, cell);
                    usedCells++;
                    minY = Math.min(matrixIndex.y, minY);
                } else // includes
                {
                    // add field to reorganization
                    m_cells.remove(matrixIndex);
                    fieldsToReorganize.add(cell.field);
                    usedCells++;
                    minY = Math.min(matrixIndex.y, minY);
                }
            }
        }
    }
    if (fieldsToReorganize.isEmpty()) {
        return;
    }
    // sort fields
    List<IFormField> sortedFieldsToReorganize = new ArrayList<IFormField>(fieldsToReorganize);
    Collections.sort(sortedFieldsToReorganize, new Comparator<IFormField>() {

        @Override
        public int compare(IFormField o1, IFormField o2) {
            Integer i1 = m_formFieldIndexes.get(o1);
            Integer i2 = m_formFieldIndexes.get(o2);
            return i1.compareTo(i2);
        }
    });
    reorgBounds.y = minY;
    VerticalGridMatrix reorgMatrix = new VerticalGridMatrix(reorgBounds.x, reorgBounds.y, reorgBounds.w, (usedCells + reorgBounds.w - 1) / reorgBounds.w);
    reorgMatrix.addCells(occupiedCells);
    while (!reorgMatrix.computeGridData(sortedFieldsToReorganize)) {
        reorgMatrix.resetAll(reorgMatrix.getColumnCount(), reorgMatrix.getRowCount() + 1);
    }
    m_cursor.reset();
    m_cells.putAll(reorgMatrix.getCells());
    m_fieldGridDatas.putAll(reorgMatrix.getFieldGridDatas());
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IFormField(org.eclipse.scout.rt.client.ui.form.fields.IFormField) GridData(org.eclipse.scout.rt.client.ui.form.fields.GridData) HashSet(java.util.HashSet)

Example 10 with IFormField

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

the class ScoutClientAssert method assertView.

private static void assertView(final ViewKind viewKind, final boolean strict, IForm form, IFormField... fields) {
    Assert.assertNotNull(form);
    Assert.assertNotNull(fields);
    final HashSet<IFormField> expectedFields = new HashSet<IFormField>(Arrays.asList(fields));
    final ArrayList<IFormField> unexpectedFields = new ArrayList<IFormField>();
    form.visitFields(new IFormFieldVisitor() {

        @Override
        public boolean visitField(IFormField field, int level, int fieldIndex) {
            if (viewKind.testField(field)) {
                boolean expected = expectedFields.remove(field);
                if (strict && !expected) {
                    unexpectedFields.add(field);
                }
            }
            return true;
        }
    });
    if (!expectedFields.isEmpty() || !unexpectedFields.isEmpty()) {
        StringBuilder builder = new StringBuilder();
        builder.append(viewKind.getName());
        builder.append(" fields:");
        if (!expectedFields.isEmpty()) {
            builder.append("\n\texpected ").append(viewKind.getPositive()).append(" but ").append(viewKind.getNegative()).append(": ");
            builder.append(formatFieldNames(expectedFields));
        }
        if (!unexpectedFields.isEmpty()) {
            builder.append("\n\texpected ").append(viewKind.getNegative()).append(" but ").append(viewKind.getPositive()).append(": ");
            builder.append(formatFieldNames(unexpectedFields));
        }
        Assert.fail(builder.toString());
    }
}
Also used : IFormField(org.eclipse.scout.rt.client.ui.form.fields.IFormField) ArrayList(java.util.ArrayList) IFormFieldVisitor(org.eclipse.scout.rt.client.ui.form.IFormFieldVisitor) HashSet(java.util.HashSet)

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