From 94bf4ac6f977b6788aad53e5a617ed33ada7abcb Mon Sep 17 00:00:00 2001 From: reaboi <reaboi@fortiss.org> Date: Wed, 1 Aug 2018 10:51:40 +0200 Subject: [PATCH] 1326 comments in code specification m YELLOW Signed-off-by: reaboi <reaboi@fortiss.org> --- .../fortiss/tooling/kernel/ui/util/.ratings | 2 +- .../kernel/ui/util/DataBindingUtils.java | 79 +++++++++++++++++++ 2 files changed, 80 insertions(+), 1 deletion(-) diff --git a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/util/.ratings b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/util/.ratings index c96e219b7..086372296 100644 --- a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/util/.ratings +++ b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/util/.ratings @@ -1,7 +1,7 @@ ActionUtils.java 4553e487264e3d1f86f4767da4a7400cce4b9a5d GREEN ConstraintsUIUtils.java 69d5e08bbf768baf2790380e36f1020ef826a33e GREEN CopyPasteUtils.java 66ff2c44bef3bfecc85a6d3109c6b15a8960fa38 GREEN -DataBindingUtils.java 0818014c193a22d5968435e78590368b95138d5e GREEN +DataBindingUtils.java 6451a7c71d7e4e89593653159cfec35f45a426c9 YELLOW DragAndDropUtils.java 7aab91518aa12d76533a345bf6ed0be9ac7ff0e5 GREEN EObjectSelectionUtils.java 928280b5dd3bb634debc1ac3be9f15b4e45f2683 GREEN KernelUIUtils.java b038a28a44e17e5bca4d71f5dee70ee92e5324b9 GREEN diff --git a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/util/DataBindingUtils.java b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/util/DataBindingUtils.java index 0818014c1..6451a7c71 100644 --- a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/util/DataBindingUtils.java +++ b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/util/DataBindingUtils.java @@ -157,6 +157,85 @@ public final class DataBindingUtils { return bindings; } + /** + * Performs a complex binding of a text control to a model element. The + * validation is performed on modification (i.e. always), while model + * updates are only performed on focus out (if validation works). There is + * no validation support from model to text, as the model is considered to + * be always consistent. If the control has a {@link ControlDecoration} stored under the + * {@link #DECORATION_KEY} key, this is used to visualize + * the validation result. + * + * @param dbc + * the data binding context to be used + * @param control + * the SWT control + * @param modelValue + * the model element value to be observed + * @param modelValueComment + * the model element comment value to be observed + * @param modelToTextConverter + * the converter from the element to the control's text + * @param textToModelConverter + * the converter from the control's text to the element + * @param textValidator + * the validator for the control's text + * @param textPostConvertValidator + * the validator for the text after conversion + * @return the array of constructed bindings + */ + + public static Binding[] performComplexTextAndCommentBinding(DataBindingContext dbc, + Control control, IObservableValue modelValue, IObservableValue modelValueComment, + IConverter modelToTextConverter, IConverter textToModelConverter, + IValidator textValidator, IValidator textPostConvertValidator) { + + Binding[] bindings = new Binding[4]; + + // normal model to control + UpdateValueStrategy modelToTextStrategy = + new UpdateValueStrategy(true, UpdateValueStrategy.POLICY_UPDATE) + .setConverter(modelToTextConverter); + + // use POLICY_UPDATE to actually perform the update + UpdateValueStrategy textToModelStrategyWithUpdate = + new UpdateValueStrategy(true, UpdateValueStrategy.POLICY_UPDATE) + .setConverter(textToModelConverter).setAfterGetValidator(textValidator) + .setAfterConvertValidator(textPostConvertValidator); + + // add the "normal" binding to actually update the model + bindings[0] = + dbc.bindValue(observeText(control, SWT.Modify), modelValue, + textToModelStrategyWithUpdate, modelToTextStrategy); + + // add the "normal" binding to actually update the comments + bindings[1] = + dbc.bindValue(observeText(control, SWT.Modify), modelValueComment, null, null); + + // here it is important to only use POLICY_CONVERT, to not write through + // to the model + UpdateValueStrategy textToModelStrategyNoUpdate = + new UpdateValueStrategy(true, UpdateValueStrategy.POLICY_CONVERT) + .setConverter(textToModelConverter).setAfterGetValidator(textValidator) + .setAfterConvertValidator(textPostConvertValidator); + + // perform a binding which only serves for validation purposes + bindings[2] = + dbc.bindValue(observeText(control, SWT.Modify), modelValue, + textToModelStrategyNoUpdate, new UpdateValueStrategy( + UpdateValueStrategy.POLICY_NEVER)); + + // add validation of required/supported + final Object data = control.getData(DECORATION_KEY); + if(data instanceof ControlDecoration) { + bindings[3] = + dbc.bindValue( + JFaceObservables.observeControlDecoration((ControlDecoration)data), + bindings[1].getValidationStatus(), null, null); + } + return bindings; + } + /** * Performs a complex binding of a cell editor control to a model element. The * validation is performed on modification (i.e. always), while model -- GitLab