use of org.eclipse.scout.rt.client.ui.form.fields.ICompositeField in project scout.rt by eclipse.
the class FindFieldByFormDataIdVisitor method getEnclosingFieldPathRank.
/**
* @return Returns the rank of the given field's enclosing field path and the one that is requested by this visitor. A
* perfect match yields 0. Every mismatch increases the rank by 1. Hence the greatest number has the worst
* match.
*/
private int getEnclosingFieldPathRank(IFormField f) {
int rank = 0;
// the last segment is the field id, i.e. not part of the enclosing field path
int i = m_fieldIdParts.length - 2;
List<ICompositeField> enclosingFieldList = f.getEnclosingFieldList();
Collections.reverse(enclosingFieldList);
for (ICompositeField p : enclosingFieldList) {
if (i >= 0 && m_fieldIdParts[i].equals(FormDataUtility.getFieldDataId(p.getFieldId()))) {
i--;
} else {
rank++;
}
}
return rank;
}
use of org.eclipse.scout.rt.client.ui.form.fields.ICompositeField in project scout.rt by eclipse.
the class FindFieldByFormDataIdVisitor method visitField.
@Override
public boolean visitField(IFormField field, int level, int fieldIndex) {
if (m_searchContextRootForm == null) {
// auto-initialize search context
// we assume the form field tree is traversed pre-order (i.e. first node itself, then its children)
m_searchContextRootForm = field.getForm();
}
if (matchesAllParts(field)) {
int fieldTypeRank = 0;
if (m_searchContextRootForm != null) {
IForm form = field.getForm();
while (form != null && form != m_searchContextRootForm) {
fieldTypeRank += 10;
form = form.getOuterForm();
}
}
if (field instanceof IValueField) {
// fieldTypeRank is fine
} else if (field instanceof ITableField) {
fieldTypeRank += 1;
} else if (!(field instanceof ICompositeField)) {
fieldTypeRank += 2;
} else {
fieldTypeRank += 3;
}
// Compute the enclosing field path rank that is used as additional hint for determining the
// best matching form field for the requested formId. Note: for compatibility reasons, the enclosing
// field path is not enforced.
int enclosingFieldPathRank = getEnclosingFieldPathRank(field);
m_prioMap.put(new CompositeObject(fieldTypeRank, enclosingFieldPathRank), field);
}
return !m_prioMap.containsKey(PERFECT_VALUE_FIELD_MATCH_KEY);
}
use of org.eclipse.scout.rt.client.ui.form.fields.ICompositeField in project scout.rt by eclipse.
the class MoveFormFieldsHandler method moveFields.
public void moveFields() {
P_FormFieldVisitor visitor = new P_FormFieldVisitor();
m_form.visitFields(visitor);
if (m_moveDescriptors.isEmpty()) {
return;
}
StringBuilder sb = new StringBuilder();
for (MoveDescriptor<IFormField> moveItem : m_moveDescriptors) {
IFormField field = moveItem.getModel();
ICompositeField oldContainer = field.getParentField();
ICompositeField newContainer = findContainer(oldContainer, moveItem.getNewContainerIdentifer(), null);
if (newContainer != null) {
Double newOrder = moveItem.getNewOrder();
if (newOrder != null) {
field.setOrder(newOrder);
}
try {
field.setFieldChanging(true);
oldContainer.moveFieldTo(field, newContainer);
// field grid is not rebuilt for performance reasons and because this handler is intended to be used during initConfig of a form.
} finally {
field.setFieldChanging(false);
}
} else {
if (sb.length() == 0) {
sb.append("Invalid field move commands:");
}
sb.append(" \nField '").append(field).append("' cannot be moved into container '").append(newContainer).append("'");
}
}
if (sb.length() > 0) {
throw new IllegalArgumentException(sb.toString());
}
}
use of org.eclipse.scout.rt.client.ui.form.fields.ICompositeField in project scout.rt by eclipse.
the class MoveFormFieldsHandler method findContainer.
protected ICompositeField findContainer(ICompositeField container, ClassIdentifier newModelContainerClassIdentifier, ICompositeField ignoredChildContainer) {
// 1. no new container defined. Hence do not move field into different container.
if (newModelContainerClassIdentifier == null) {
return container;
}
Class<?> newModelContainerClass = newModelContainerClassIdentifier.getLastSegment();
// 2. field is moved to root, i.e. into the main box
if (newModelContainerClass == IMoveModelObjectToRootMarker.class) {
return container.getForm().getRootGroupBox();
}
// 3. current container matches
if (newModelContainerClass.isInstance(container) && matchesClassIdentifier(container, newModelContainerClassIdentifier)) {
return container;
}
// 4. check current container's child composite fields
for (IFormField c : container.getFields()) {
if (newModelContainerClass.isInstance(c) && c instanceof ICompositeField && matchesClassIdentifier((ICompositeField) c, newModelContainerClassIdentifier)) {
return (ICompositeField) c;
}
}
// 5. visit child containers
for (IFormField c : container.getFields()) {
if (c == ignoredChildContainer || !(c instanceof ICompositeField)) {
continue;
}
ICompositeField recursiveContainer = findContainer((ICompositeField) c, newModelContainerClassIdentifier, container);
if (recursiveContainer != null) {
return recursiveContainer;
}
}
// 6. current container is a template field. Do not exit template scope
if (container instanceof AbstractCompositeField && ((AbstractCompositeField) container).isTemplateField()) {
return null;
}
// 7. continue search on parent container (without revisiting the current container)
ICompositeField parent = container.getParentField();
if (parent != null && parent != ignoredChildContainer) {
return findContainer(parent, newModelContainerClassIdentifier, container);
}
return null;
}
use of org.eclipse.scout.rt.client.ui.form.fields.ICompositeField in project scout.rt by eclipse.
the class MoveFormFieldTest method testMoveToEmptyBox.
@Test
public void testMoveToEmptyBox() {
P_GroupBoxWithOneField source = new P_GroupBoxWithOneField();
P_InnerField fieldToMove = source.getFieldByClass(P_InnerField.class);
ICompositeField target = new AbstractGroupBox() {
};
// hidden because it is empty
assertFalse(target.isVisible());
source.moveFieldTo(fieldToMove, target);
// visible now because the execCalculateVisible() is true now
assertTrue(target.isVisible());
}
Aggregations