use of org.eclipse.scout.rt.client.ui.form.fields.IFormField in project scout.rt by eclipse.
the class AbstractForm method storeToXml.
@Override
public void storeToXml(Element root) {
root.setAttribute("formId", getFormId());
root.setAttribute("formQname", getClass().getName());
// add custom properties
Element xProps = root.getOwnerDocument().createElement("properties");
root.appendChild(xProps);
IPropertyFilter filter = new IPropertyFilter() {
@Override
public boolean accept(FastPropertyDescriptor descriptor) {
if (descriptor.getPropertyType().isInstance(IFormField.class)) {
return false;
}
if (!descriptor.getPropertyType().isPrimitive() && !Serializable.class.isAssignableFrom(descriptor.getPropertyType())) {
return false;
}
if (descriptor.getReadMethod() == null || descriptor.getWriteMethod() == null) {
return false;
}
return true;
}
};
Map<String, Object> props = BeanUtility.getProperties(this, AbstractForm.class, filter);
storePropertiesToXml(xProps, props);
// add extension properties
for (IExtension<?> ex : getAllExtensions()) {
Map<String, Object> extensionProps = BeanUtility.getProperties(ex, AbstractFormExtension.class, filter);
if (extensionProps.isEmpty()) {
continue;
}
Element xExtension = root.getOwnerDocument().createElement("extension");
xProps.appendChild(xExtension);
xExtension.setAttribute("extensionId", ex.getClass().getSimpleName());
xExtension.setAttribute("extensionQname", ex.getClass().getName());
storePropertiesToXml(xExtension, extensionProps);
}
// add fields
final Element xFields = root.getOwnerDocument().createElement("fields");
root.appendChild(xFields);
final Holder<RuntimeException> exceptionHolder = new Holder<>(RuntimeException.class);
final Holder<PlatformError> errorHolder = new Holder<>(PlatformError.class);
P_AbstractCollectingFieldVisitor v = new P_AbstractCollectingFieldVisitor() {
@Override
public boolean visitField(IFormField field, int level, int fieldIndex) {
if (field.getForm() != AbstractForm.this) {
// field is part of a wrapped form and is handled by the AbstractWrappedFormField
return true;
}
Element xField = xFields.getOwnerDocument().createElement("field");
try {
field.storeToXml(xField);
xFields.appendChild(xField);
} catch (RuntimeException e) {
exceptionHolder.setValue(e);
return false;
} catch (PlatformError e) {
errorHolder.setValue(e);
return false;
}
return true;
}
};
visitFields(v);
if (exceptionHolder.getValue() != null) {
throw exceptionHolder.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 validateForm.
@Override
public void validateForm() {
if (!interceptCheckFields()) {
VetoException veto = new VetoException("Validate " + getClass().getSimpleName());
veto.consume();
throw veto;
}
if (!getHandler().onCheckFields()) {
VetoException veto = new VetoException("Validate " + getClass().getSimpleName());
veto.consume();
throw veto;
}
// check all fields that might be invalid
final ArrayList<String> invalidTexts = new ArrayList<String>();
final ArrayList<String> mandatoryTexts = new ArrayList<String>();
P_AbstractCollectingFieldVisitor<IValidateContentDescriptor> v = new P_AbstractCollectingFieldVisitor<IValidateContentDescriptor>() {
@Override
public boolean visitField(IFormField f, int level, int fieldIndex) {
IValidateContentDescriptor desc = f.validateContent();
if (desc != null) {
if (desc.getErrorStatus() != null) {
invalidTexts.add(desc.getDisplayText() + ": " + desc.getErrorStatus().getMessage());
} else {
mandatoryTexts.add(desc.getDisplayText());
}
if (getCollectionCount() == 0) {
collect(desc);
}
}
return true;
}
};
visitFields(v);
if (v.getCollectionCount() > 0) {
IValidateContentDescriptor firstProblem = v.getCollection().get(0);
if (LOG.isInfoEnabled()) {
LOG.info("there are fields with errors");
}
if (firstProblem != null) {
firstProblem.activateProblemLocation();
}
throw new VetoException().withHtmlMessage(createValidationMessageBoxHtml(invalidTexts, mandatoryTexts));
}
if (!interceptValidate()) {
VetoException veto = new VetoException("Validate " + getClass().getSimpleName());
veto.consume();
throw veto;
}
if (!getHandler().onValidate()) {
VetoException veto = new VetoException("Validate " + getClass().getSimpleName());
veto.consume();
throw veto;
}
}
use of org.eclipse.scout.rt.client.ui.form.fields.IFormField in project scout.rt by eclipse.
the class AbstractTable method interceptRowClickSingleObserver.
protected void interceptRowClickSingleObserver(ITableRow row, MouseButton mouseButton) {
// Only toggle checked state if the table and row are enabled.
if (!row.isEnabled() || !isEnabled()) {
return;
}
// Only toggle checked state if being fired by the left mousebutton (https://bugs.eclipse.org/bugs/show_bug.cgi?id=453543).
if (mouseButton != MouseButton.Left) {
return;
}
IColumn<?> ctxCol = getContextColumn();
if (isCellEditable(row, ctxCol)) {
// cell-level checkbox
if (ctxCol instanceof IBooleanColumn) {
// editable boolean columns consume this click
IFormField field = ctxCol.prepareEdit(row);
if (field instanceof IBooleanField) {
IBooleanField bfield = (IBooleanField) field;
bfield.toggleValue();
ctxCol.completeEdit(row, field);
}
} else {
// other editable columns have no effect HERE, the ui will open an editor
}
}
}
use of org.eclipse.scout.rt.client.ui.form.fields.IFormField in project scout.rt by eclipse.
the class AbstractColumn method prepareEdit.
@Override
public final IFormField prepareEdit(ITableRow row) {
ITable table = getTable();
if (table == null || !this.isCellEditable(row)) {
return null;
}
IFormField f = interceptPrepareEdit(row);
if (f != null) {
f.setLabelVisible(false);
GridData gd = f.getGridDataHints();
gd.weightY = 1;
f.setGridDataHints(gd);
}
return f;
}
use of org.eclipse.scout.rt.client.ui.form.fields.IFormField in project scout.rt by eclipse.
the class AbstractComposerValueBox method initConfig.
@Override
protected void initConfig() {
super.initConfig();
HashMap<Integer, Map<Integer, IComposerValueField>> operatorTypeToFieldMap = new HashMap<Integer, Map<Integer, IComposerValueField>>();
interceptInitOperatorToFieldMap(operatorTypeToFieldMap);
m_operatorTypeToFieldMap = operatorTypeToFieldMap;
m_valueChangedListener = new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent e) {
if (IValueField.PROP_VALUE.equals(e.getPropertyName())) {
try {
interceptChangedValue();
} catch (Exception ex) {
LOG.error("fire value change on {}", e.getSource(), ex);
}
}
}
};
for (IFormField f : getFields()) {
f.setLabelVisible(false);
f.setLabel(TEXTS.get("Value"));
f.setVisible(false);
if (f instanceof ISequenceBox) {
List<IFormField> sequenceBoxChildFields = ((ISequenceBox) f).getFields();
if (CollectionUtility.hasElements(sequenceBoxChildFields)) {
IFormField firstField = CollectionUtility.firstElement(sequenceBoxChildFields);
firstField.setLabelVisible(false);
if (sequenceBoxChildFields.size() > 1) {
IFormField secondField = CollectionUtility.getElement(sequenceBoxChildFields, 1);
secondField.setLabel(TEXTS.get("and"));
}
}
}
}
}
Aggregations