use of org.eclipse.scout.rt.client.ui.form.IFormFieldVisitor 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());
}
}
use of org.eclipse.scout.rt.client.ui.form.IFormFieldVisitor 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();
}
use of org.eclipse.scout.rt.client.ui.form.IFormFieldVisitor 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();
}
use of org.eclipse.scout.rt.client.ui.form.IFormFieldVisitor in project scout.rt by eclipse.
the class AbstractFormField method setVisible.
@Override
public void setVisible(final boolean visible, final boolean updateParents, final boolean updateChildren, final String dimension) {
m_visible = VISIBLE_BIT_HELPER.changeBit(dimension, visible, m_visible);
calculateVisibleInternal();
if (visible && updateParents) {
// also enable all parents
visitParents(new IFormFieldVisitor() {
@Override
public boolean visitField(IFormField field, int level, int fieldIndex) {
field.setVisible(true, dimension);
return true;
}
});
}
if (updateChildren) {
// propagate change to children
acceptVisitor(new IFormFieldVisitor() {
@Override
public boolean visitField(IFormField field, int level, int fieldIndex) {
field.setVisible(visible, dimension);
return true;
}
}, 0, 0, false);
}
}
use of org.eclipse.scout.rt.client.ui.form.IFormFieldVisitor in project scout.rt by eclipse.
the class AbstractFormField method setEnabled.
@Override
public void setEnabled(final boolean enabled, final boolean updateParents, final boolean updateChildren, final String dimension) {
m_enabled = ENABLED_BIT_HELPER.changeBit(dimension, enabled, m_enabled);
calculateEnabledInternal();
if (enabled && updateParents) {
// also enable all parents
visitParents(new IFormFieldVisitor() {
@Override
public boolean visitField(IFormField field, int level, int fieldIndex) {
field.setEnabled(true, dimension);
return true;
}
});
}
if (updateChildren) {
// propagate change to children
acceptVisitor(new IFormFieldVisitor() {
@Override
public boolean visitField(IFormField field, int level, int fieldIndex) {
field.setEnabled(enabled, dimension);
return true;
}
}, 0, 0, false);
}
}
Aggregations