Пример #1
0
  private static BindingInfo createBindingInfo(
      Object targetSource, String propertyName, XamlElement bindingNode) {
    BindingInfo bindingInfo = bindingCache.get(bindingNode);
    if (bindingInfo != null) {
      // TODO: To check if binding changed.
      return bindingInfo;
    }

    Observable target = ObservableUtil.getObservable(targetSource);
    Property targetProperty = target.getProperty(propertyName);

    String elementName = null;
    String modelPropertyName = null;
    String bindingMode = null;
    String updateTtrigger = null;
    String converter = null;
    XamlAttribute attribute = bindingNode.getAttribute(ELEMENT_NAME);
    if (attribute != null) {
      elementName = attribute.getValue();
    }
    attribute = bindingNode.getAttribute(PATH);
    if (attribute != null) {
      modelPropertyName = attribute.getValue();
    }
    attribute = bindingNode.getAttribute(MODE);
    if (attribute != null) {
      bindingMode = attribute.getValue();
    }
    attribute = bindingNode.getAttribute(CONVERTER);
    if (attribute != null) {
      converter = attribute.getValue();
    }
    attribute = bindingNode.getAttribute(UPDATE_SOURCE_TRIGGER);
    if (attribute != null) {
      updateTtrigger = attribute.getValue();
    }
    Object modelSource;
    if (elementName != null) {
      modelSource = XWT.findElementByName(targetSource, elementName);
    } else {
      modelSource = getDataContext(targetSource);
    }
    IObservable model = ObservableUtil.getObservable(modelSource);
    if (model == null) {
      return null;
    }
    Property modelProperty = model.getProperty(modelPropertyName);

    bindingInfo = new BindingInfo(new BindingContext(target, targetProperty, model, modelProperty));
    bindingInfo.setElementName(elementName);
    if (bindingMode != null) {
      bindingInfo.setBindingMode(BindingMode.valueOf(bindingMode));
    }
    if (updateTtrigger != null) {
      bindingInfo.setTriggerMode(UpdateSourceTrigger.valueOf(updateTtrigger));
    }
    bindingInfo.setConverter(converter);
    bindingInfo.setBindingNode(bindingNode);
    bindingCache.put(bindingNode, bindingInfo);
    return bindingInfo;
  }