use of org.eclipse.scout.rt.client.ui.form.fields.IFormField in project scout.rt by eclipse.
the class FindFieldByFormDataIdVisitorTest method testGetSecondFieldOnInnerInnerForm.
@Test
public void testGetSecondFieldOnInnerInnerForm() throws Exception {
InnerInnerForm innerInnerForm = m_mainForm.getWrappedFormField().getInnerForm().getWrappedFormField().getInnerForm();
FindFieldByFormDataIdVisitor visitor = new FindFieldByFormDataIdVisitor(SECOND_FIELD_DATA_ID, innerInnerForm);
innerInnerForm.visitFields(visitor);
IFormField field = visitor.getField();
assertNotNull(field);
assertSame(innerInnerForm.getSecondField(), field);
}
use of org.eclipse.scout.rt.client.ui.form.fields.IFormField 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.IFormField in project scout.rt by eclipse.
the class AbstractForm method closeFormInternal.
private void closeFormInternal(boolean kill) {
if (isBlockingInternal()) {
try {
// check if there is an active close, cancel or finish button
final Set<Integer> enabledSystemTypes = new HashSet<Integer>();
final Set<IButton> enabledSystemButtons = new HashSet<IButton>();
IFormFieldVisitor v = new IFormFieldVisitor() {
@Override
public boolean visitField(IFormField field, int level, int fieldIndex) {
if (field instanceof IButton) {
IButton b = (IButton) field;
if (b.isEnabled() && b.isVisible()) {
enabledSystemTypes.add(b.getSystemType());
enabledSystemButtons.add(b);
}
}
return true;
}
};
visitFields(v);
interceptOnCloseRequest(kill, enabledSystemTypes);
} catch (RuntimeException | PlatformError e) {
throw BEANS.get(PlatformExceptionTranslator.class).translate(e).withContextInfo("form", getClass().getName());
}
}
}
use of org.eclipse.scout.rt.client.ui.form.fields.IFormField in project scout.rt by eclipse.
the class AbstractForm method doReset.
@Override
public void doReset() {
setFormLoading(true);
// reset values
P_AbstractCollectingFieldVisitor v = new P_AbstractCollectingFieldVisitor() {
@Override
public boolean visitField(IFormField field, int level, int fieldIndex) {
if (field instanceof IValueField) {
IValueField f = (IValueField) field;
f.resetValue();
} else if (field instanceof IComposerField) {
IComposerField f = (IComposerField) field;
f.resetValue();
}
return true;
}
};
try {
visitFields(v);
// init again
initForm();
// load again
loadStateInternal();
} catch (RuntimeException | PlatformError e) {
throw BEANS.get(PlatformExceptionTranslator.class).translate(e).withContextInfo("form", getClass().getName());
}
}
use of org.eclipse.scout.rt.client.ui.form.fields.IFormField in project scout.rt by eclipse.
the class AbstractForm method loadFromXml.
@Override
public void loadFromXml(Element root) {
String formId = getFormId();
String xmlId = root.getAttribute("formId");
if (!formId.equals(xmlId)) {
throw new ProcessingException("xml id='{}' does not match form id='{}'", xmlId, formId);
}
// load properties
Element xProps = XmlUtility.getFirstChildElement(root, "properties");
if (xProps != null) {
Map<String, Object> props = loadPropertiesFromXml(xProps);
BeanUtility.setProperties(this, props, true, null);
// load extension properties
for (Element xExtension : XmlUtility.getChildElements(xProps, "extension")) {
String extensionId = xExtension.getAttribute("extensionId");
String extensionQname = xExtension.getAttribute("extensionQname");
IFormExtension<? extends AbstractForm> extension = findFormExtensionById(extensionQname, extensionId);
if (extension == null) {
continue;
}
Map<String, Object> extensionProps = loadPropertiesFromXml(xExtension);
BeanUtility.setProperties(extension, extensionProps, true, null);
}
}
// load fields
Element xFields = XmlUtility.getFirstChildElement(root, "fields");
if (xFields != null) {
for (Element xField : XmlUtility.getChildElements(xFields, "field")) {
List<String> xmlFieldIds = new LinkedList<String>();
// add enclosing field path to xml field IDs
for (Element element : XmlUtility.getChildElements(xField, "enclosingField")) {
xmlFieldIds.add(element.getAttribute("fieldId"));
}
xmlFieldIds.add(xField.getAttribute("fieldId"));
FindFieldByXmlIdsVisitor v = new FindFieldByXmlIdsVisitor(xmlFieldIds.toArray(new String[xmlFieldIds.size()]));
visitFields(v);
IFormField f = v.getField();
if (f != null) {
f.loadFromXml(xField);
}
}
}
// in all tabboxes select the first tab that contains data, iff the current
// tab has no values set
getRootGroupBox().visitFields(new IFormFieldVisitor() {
@Override
public boolean visitField(IFormField field, int level, int fieldIndex) {
if (field instanceof ITabBox) {
ITabBox tabBox = (ITabBox) field;
IGroupBox selbox = tabBox.getSelectedTab();
if (selbox == null || !selbox.isSaveNeeded()) {
for (IGroupBox g : tabBox.getGroupBoxes()) {
if (g.isSaveNeeded()) {
tabBox.setSelectedTab(g);
break;
}
}
}
}
return true;
}
});
}
Aggregations