use of org.eclipse.scout.rt.client.ui.form.fields.IFormField in project scout.rt by eclipse.
the class AbstractForm method initConfig.
protected void initConfig() {
m_uiFacade = BEANS.get(ModelContextProxy.class).newProxy(new P_UIFacade(), ModelContext.copyCurrent().withForm(this));
m_timerFutureMap = new HashMap<>();
setShowOnStart(getConfiguredShowOnStart());
m_contributionHolder = new ContributionComposite(this);
// prepare injected fields
List<Class<IFormField>> fieldArray = getConfiguredInjectedFields();
DefaultFormFieldInjection injectedFields = null;
IGroupBox rootBox = getRootGroupBox();
try {
if (fieldArray.size() > 0) {
injectedFields = new DefaultFormFieldInjection(this);
injectedFields.addFields(fieldArray);
FormFieldInjectionThreadLocal.push(injectedFields);
}
// add mainbox if getter returns null
if (rootBox == null) {
List<IGroupBox> contributedFields = m_contributionHolder.getContributionsByClass(IGroupBox.class);
rootBox = CollectionUtility.firstElement(contributedFields);
if (rootBox == null) {
Class<? extends IGroupBox> mainBoxClass = getConfiguredMainBox();
if (mainBoxClass != null) {
rootBox = ConfigurationUtility.newInnerInstance(this, mainBoxClass);
}
}
m_mainBox = rootBox;
}
} finally {
if (injectedFields != null) {
m_fieldReplacements = injectedFields.getReplacementMapping();
FormFieldInjectionThreadLocal.pop(injectedFields);
}
}
if (rootBox != null) {
rootBox.setFormInternal(this);
rootBox.setMainBox(true);
rootBox.updateKeyStrokes();
if (rootBox.isScrollable().isUndefined()) {
rootBox.setScrollable(true);
}
}
// move form fields
new MoveFormFieldsHandler(this).moveFields();
//
if (getConfiguredCloseTimer() > 0) {
setCloseTimer(getConfiguredCloseTimer());
}
if (getConfiguredCustomTimer() > 0) {
setTimer("custom", getConfiguredCustomTimer());
}
if (getConfiguredCancelVerificationText() != null) {
setCancelVerificationText(getConfiguredCancelVerificationText());
}
if (getConfiguredTitle() != null) {
setTitle(getConfiguredTitle());
}
if (getConfiguredSubTitle() != null) {
setSubTitle(getConfiguredSubTitle());
}
setMinimizeEnabled(getConfiguredMinimizeEnabled());
setMaximizeEnabled(getConfiguredMaximizeEnabled());
setMinimized(getConfiguredMinimized());
setMaximized(getConfiguredMaximized());
setCacheBounds(getConfiguredCacheBounds());
setAskIfNeedSave(getConfiguredAskIfNeedSave());
setIconId(getConfiguredIconId());
setCssClass((getConfiguredCssClass()));
// Set 'modality' as preferred value if not 'auto'.
int modalityHint = getConfiguredModalityHint();
if (modalityHint != MODALITY_HINT_AUTO) {
m_modal.set(modalityHint == MODALITY_HINT_MODAL, true);
}
// Set 'displayParent' as preferred value if not null; must precede setting of the 'displayHint'.
IDisplayParent displayParent = getConfiguredDisplayParent();
if (displayParent != null) {
m_displayParent.set(displayParent, true);
} else {
m_displayParent.set(getDesktop(), false);
}
setDisplayHint(getConfiguredDisplayHint());
setDisplayViewId(getConfiguredDisplayViewId());
setClosable(getConfiguredClosable());
setSaveNeededVisible(getConfiguredSaveNeededVisible());
// visit all system buttons and attach observer
// is auto-detaching
m_systemButtonListener = new P_SystemButtonListener();
IFormFieldVisitor v2 = new IFormFieldVisitor() {
@Override
public boolean visitField(IFormField field, int level, int fieldIndex) {
if (field instanceof IButton) {
final IButton button = (IButton) field;
if (button.getSystemType() != IButton.SYSTEM_TYPE_NONE) {
button.addButtonListener(m_systemButtonListener);
}
}
return true;
}
};
visitFields(v2);
getRootGroupBox().addPropertyChangeListener(new P_MainBoxPropertyChangeProxy());
setButtonsArmed(true);
}
use of org.eclipse.scout.rt.client.ui.form.fields.IFormField in project scout.rt by eclipse.
the class AbstractForm method exportFormData.
@Override
public void exportFormData(final AbstractFormData target) {
// locally declared form properties
Map<String, Object> properties = BeanUtility.getProperties(this, AbstractForm.class, new FormDataPropertyFilter());
BeanUtility.setProperties(target, properties, false, null);
// properties in extensions of form
exportExtensionProperties(this, target);
final Set<IFormField> exportedFields = new HashSet<IFormField>();
// all fields
Map<Integer, Map<String, AbstractFormFieldData>> /* qualified field id */
breadthFirstMap = target.getAllFieldsRec();
for (Map<String, AbstractFormFieldData> /* qualified field id */
targetMap : breadthFirstMap.values()) {
for (Map.Entry<String, AbstractFormFieldData> e : targetMap.entrySet()) {
String fieldQId = e.getKey();
AbstractFormFieldData data = e.getValue();
FindFieldByFormDataIdVisitor v = new FindFieldByFormDataIdVisitor(fieldQId, this);
visitFields(v);
IFormField f = v.getField();
if (f != null) {
// field properties
properties = BeanUtility.getProperties(f, AbstractFormField.class, new FormDataPropertyFilter());
BeanUtility.setProperties(data, properties, false, null);
exportExtensionProperties(f, data);
// field state
f.exportFormFieldData(data);
// remember exported fields
exportedFields.add(f);
} else {
LOG.warn("Cannot find field with id '{}' in form '{}' for DTO '{}'.", fieldQId, getClass().getName(), data.getClass().getName());
}
}
}
// visit remaining fields (there could be an extension with properties e.g. on a groupbox)
final Holder<RuntimeException> exHolder = new Holder<>(RuntimeException.class);
final Holder<PlatformError> errorHolder = new Holder<>(PlatformError.class);
visitFields(new IFormFieldVisitor() {
@Override
public boolean visitField(IFormField field, int level, int fieldIndex) {
if (exportedFields.contains(field)) {
// already exported -> skip
return true;
}
final IForm formOfField = field.getForm();
if (formOfField == null) {
// either form has not been initialized or the field is part of a composite field, that does not override setForminternal -> skip
LOG.info("Extension properties are not exported for fields on which getForm() returns null. " + "Ensure that the form is initialized and that the field's parent invokes field.setFormInternal(IForm) [exportingForm={}, field={}]", AbstractForm.this.getClass().getName(), field.getClass().getName());
return true;
}
if (formOfField != AbstractForm.this) {
// field belongs to another form -> skip
return true;
}
try {
exportExtensionProperties(field, target);
} catch (RuntimeException e) {
exHolder.setValue(e);
} catch (PlatformError e) {
errorHolder.setValue(e);
}
return exHolder.getValue() == null && errorHolder.getValue() == null;
}
});
if (exHolder.getValue() != null) {
throw exHolder.getValue();
} else if (errorHolder.getValue() != null) {
throw errorHolder.getValue();
}
}
use of org.eclipse.scout.rt.client.ui.form.fields.IFormField in project scout.rt by eclipse.
the class AbstractForm method getClientPartOfExtensionOrContributionRec.
private Object getClientPartOfExtensionOrContributionRec(final Object extToSearch, Object owner) {
Object ext = getClientPartOfExtensionOrContribution(extToSearch, owner);
if (ext != null) {
return ext;
}
// search for the extension in the children
final IHolder<Object> result = new Holder<Object>(Object.class);
IFormFieldVisitor visitor = new IFormFieldVisitor() {
@Override
public boolean visitField(IFormField field, int level, int fieldIndex) {
result.setValue(getClientPartOfExtensionOrContribution(extToSearch, field));
return result.getValue() == null;
}
};
if (owner instanceof IForm) {
((IForm) owner).visitFields(visitor);
} else if (owner instanceof IFormField) {
((IFormField) owner).acceptVisitor(visitor, 0, 0, true);
}
return result.getValue();
}
use of org.eclipse.scout.rt.client.ui.form.fields.IFormField in project scout.rt by eclipse.
the class AbstractForm method importFormData.
@Override
public void importFormData(AbstractFormData source, boolean valueChangeTriggersEnabled, IPropertyFilter filter, IFormFieldFilter formFieldFilter) {
Assertions.assertNotNull(source, "source form data must not be null");
if (filter == null) {
filter = new FormDataPropertyFilter();
}
// form properties
importProperties(source, this, AbstractFormData.class, filter);
// sort fields, first non-slave fields, then slave fields in transitive order
LinkedList<IFormField> masterList = new LinkedList<IFormField>();
LinkedList<IFormField> slaveList = new LinkedList<IFormField>();
HashMap<IFormField, AbstractFormFieldData> dataMap = new HashMap<IFormField, AbstractFormFieldData>();
// collect fields and split them into masters/slaves
Map<Integer, Map<String, AbstractFormFieldData>> /* qualified field id */
breadthFirstMap = source.getAllFieldsRec();
for (Map<String, AbstractFormFieldData> /* qualified field id */
sourceMap : breadthFirstMap.values()) {
for (Map.Entry<String, AbstractFormFieldData> e : sourceMap.entrySet()) {
String fieldQId = e.getKey();
AbstractFormFieldData data = e.getValue();
FindFieldByFormDataIdVisitor v = new FindFieldByFormDataIdVisitor(fieldQId, this);
visitFields(v);
IFormField f = v.getField();
if (f != null) {
if (formFieldFilter == null || formFieldFilter.accept(f)) {
dataMap.put(f, data);
if (f.getMasterField() != null) {
int index = slaveList.indexOf(f.getMasterField());
if (index >= 0) {
slaveList.add(index + 1, f);
} else {
slaveList.addFirst(f);
}
} else {
masterList.add(f);
}
}
} else {
LOG.warn("cannot find field data for '{}' in form '{}'.", fieldQId, getClass().getName());
}
}
}
for (IFormField f : masterList) {
importFormField(f, dataMap, valueChangeTriggersEnabled, filter);
}
for (IFormField f : slaveList) {
importFormField(f, dataMap, valueChangeTriggersEnabled, filter);
}
}
use of org.eclipse.scout.rt.client.ui.form.fields.IFormField in project scout.rt by eclipse.
the class DefaultFormFieldInjection method createAndInsertField.
/**
* Adds the field f to the end of the list. If the field is already part of the given list, this method does nothing.
*/
private void createAndInsertField(IFormField container, OrderedCollection<IFormField> fields, Class<? extends IFormField> fieldClass) {
// check if list already contains the field
for (IFormField f : fields) {
if (f.getClass() == fieldClass) {
return;
}
}
IFormField f = newInnerInstance(container, fieldClass);
fields.addOrdered(f);
}
Aggregations