Skip to content
Snippets Groups Projects
Commit 74c67a21 authored by Cheng Zhang's avatar Cheng Zhang
Browse files

refactor code

refs 1494
parent d9860f12
No related branches found
No related tags found
No related merge requests found
......@@ -17,15 +17,11 @@ $Id$
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.ui.util;
import static org.eclipse.core.databinding.UpdateValueStrategy.POLICY_NEVER;
import org.conqat.ide.commons.ui.databinding.JFaceObservables;
import org.eclipse.core.databinding.Binding;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.UpdateListStrategy;
import org.eclipse.core.databinding.UpdateValueStrategy;
import org.eclipse.core.databinding.conversion.IConverter;
import org.eclipse.core.databinding.observable.list.IObservableList;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.databinding.validation.IValidator;
import org.eclipse.emf.ecore.EObject;
......@@ -61,9 +57,9 @@ public final class DataBindingUtils {
* @param feature
* the element's feature to be observed
*/
public static void bind(DataBindingContext dbc, Control control, EObject modelElement,
public static Binding[] bind(DataBindingContext dbc, Control control, EObject modelElement,
EStructuralFeature feature) {
performComplexTextBinding(dbc, control,
return performComplexTextBinding(dbc, control,
ObservableUtils.observeValue(modelElement, feature), null, null, null, null);
}
......@@ -165,47 +161,10 @@ public final class DataBindingUtils {
}
/**
* 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 observableList
* the model element value to be observed
* @param listToComboConverter
* the converter from the element to the control's text
* @return the array of constructed bindings
*/
public static Binding[] performTypeComboBinding(DataBindingContext dbc, Control control,
IObservableList observableList, IConverter listToComboConverter) {
Binding[] bindings = new Binding[1];
// use POLICY_UPDATE to actually perform the update
UpdateListStrategy listToComboStrategyWithUpdate =
new UpdateListStrategy(true, UpdateValueStrategy.POLICY_UPDATE)
.setConverter(listToComboConverter);
// add the "normal" binding to actually update the model
bindings[0] =
dbc.bindList(SWTObservables.observeItems(control), observableList,
new UpdateListStrategy(POLICY_NEVER), listToComboStrategyWithUpdate);
return bindings;
}
/**
* Performs a complex binding of a text control to a model element. The
* Performs a selection binding of a combo 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
* no validation support from selection to model, as the selection 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.
......@@ -217,14 +176,16 @@ public final class DataBindingUtils {
* @param modelValue
* the model element value to be observed
* @param modelToSelectionConverter
* the converter from the element to the control's text
* the converter from the model element to the control's text
* @param selectionToModelConverter
* the converter from the control's text to the element
* the converter from the control's text to the model element
* @param modelValidator
* the validate function for the model element
* @return the array of constructed bindings
*/
public static Binding[] performComboBinding(DataBindingContext dbc, Control control,
IObservableValue modelValue, IConverter modelToSelectionConverter,
IConverter selectionToModelConverter, IValidator validator) {
IConverter selectionToModelConverter, IValidator modelValidator) {
Binding[] bindings = new Binding[1];
......@@ -236,7 +197,7 @@ public final class DataBindingUtils {
// use POLICY_UPDATE to actually perform the update
UpdateValueStrategy selectionToModelStrategy =
new UpdateValueStrategy(true, UpdateValueStrategy.POLICY_UPDATE).setConverter(
selectionToModelConverter).setAfterGetValidator(validator);
selectionToModelConverter).setAfterGetValidator(modelValidator);
// add the "normal" binding to actually update the model
bindings[0] =
......@@ -247,7 +208,7 @@ public final class DataBindingUtils {
}
/**
* Performs a complex binding of a text control to a model element. The
* Performs a complex binding of a cell editor 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
......@@ -257,15 +218,18 @@ public final class DataBindingUtils {
*
* @param dbc
* the data binding context to be used
* @param control
* the SWT control
* @param cellValue
* the model element value to be observed
* the cell model element value to be observed
* @param modalToCellConverter
* the converter from the element to the control's text
* the converter from the cell model element to the control's text
* @param cellToModelConverter
* the converter from the control's text to the element
* the converter from the control's text to the cell model element
* @param validator
* the validate function for the control's text
* @return the array of constructed bindings
*/
public static Binding[] performCellTextBinding(DataBindingContext dbc, Control control,
IObservableValue cellValue, IConverter modalToCellConverter,
IConverter cellToModelConverter, IValidator validator) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment