Search in sources :

Example 1 with AutoBindingInfo

use of org.eclipse.wb.internal.swing.databinding.model.bindings.AutoBindingInfo in project windowbuilder by eclipse.

the class DatabindingsProvider method createBinding.

public IBindingInfo createBinding(IObserveInfo target, IObserveInfo targetProperty, IObserveInfo model, IObserveInfo modelProperty) throws Exception {
    // prepare ObserveInfo's
    ObserveInfo targetObserve = (ObserveInfo) target;
    ObserveInfo targetPropertyObserve = (ObserveInfo) targetProperty;
    ObserveInfo modelObserve = (ObserveInfo) model;
    ObserveInfo modelPropertyObserve = (ObserveInfo) modelProperty;
    // check virtual bindings
    if (targetObserve.getCreationType() == ObserveCreationType.VirtualBinding || modelObserve.getCreationType() == ObserveCreationType.VirtualBinding) {
        return new VirtualBindingInfo(targetObserve, targetPropertyObserve, createProperty(targetObserve, targetPropertyObserve), modelObserve, modelPropertyObserve, createProperty(modelObserve, modelPropertyObserve));
    }
    // check swing bindings
    if (targetObserve.getCreationType() != ObserveCreationType.AutoBinding) {
        IBindingInfo binding = createSwingBinding(targetObserve, targetPropertyObserve, modelObserve, modelPropertyObserve);
        if (binding != null) {
            return binding;
        }
    }
    if (modelObserve.getCreationType() != ObserveCreationType.AutoBinding) {
        IBindingInfo binding = createSwingBinding(modelObserve, modelPropertyObserve, targetObserve, targetPropertyObserve);
        if (binding != null) {
            return binding;
        }
    }
    // auto bindings
    UpdateStrategyInfo strategy = new UpdateStrategyInfo(UpdateStrategyInfo.Value.READ);
    PropertyInfo targetAstProperty = createProperty(targetObserve, targetPropertyObserve);
    PropertyInfo modelAstProperty = createProperty(modelObserve, modelPropertyObserve);
    // 
    return new AutoBindingInfo(strategy, targetObserve, targetPropertyObserve, targetAstProperty, modelObserve, modelPropertyObserve, modelAstProperty);
}
Also used : UpdateStrategyInfo(org.eclipse.wb.internal.swing.databinding.model.bindings.UpdateStrategyInfo) ObserveInfo(org.eclipse.wb.internal.swing.databinding.model.ObserveInfo) IObserveInfo(org.eclipse.wb.internal.core.databinding.model.IObserveInfo) IBindingInfo(org.eclipse.wb.internal.core.databinding.model.IBindingInfo) AutoBindingInfo(org.eclipse.wb.internal.swing.databinding.model.bindings.AutoBindingInfo) PropertyInfo(org.eclipse.wb.internal.swing.databinding.model.properties.PropertyInfo) VirtualBindingInfo(org.eclipse.wb.internal.swing.databinding.model.bindings.VirtualBindingInfo)

Example 2 with AutoBindingInfo

use of org.eclipse.wb.internal.swing.databinding.model.bindings.AutoBindingInfo in project windowbuilder by eclipse.

the class DataBindingsRootInfo method createAutoBindingForObjectToProperty.

/**
 * Bindings.createAutoBinding(UpdateStrategy, SS, TS, Property<TS, TV>, [String])
 */
private BindingInfo createAutoBindingForObjectToProperty(AstEditor editor, String signature, MethodInvocation invocation, Expression[] arguments, IModelResolver resolver) throws Exception {
    // strategy
    UpdateStrategyInfo strategyInfo = createStrategy(arguments[0]);
    // model object
    ObserveInfo model = getObserveInfo(arguments[1]);
    if (model == null) {
        AbstractParser.addError(editor, MessageFormat.format(Messages.DataBindingsRootInfo_errModelArgumentNotFound, arguments[1]), new Throwable());
        return null;
    }
    // model properties
    IGenericType[] types = GenericUtils.getReturnTypeArguments(editor, invocation, 3);
    PropertyInfo modelAstProperty = new ObjectPropertyInfo(types[0]);
    ObserveInfo modelProperty = modelAstProperty.getObserveProperty(model);
    Assert.isNotNull(modelProperty);
    assertEquals(modelProperty, modelAstProperty);
    // target object
    ObserveInfo target = getObserveInfo(arguments[2]);
    if (target == null) {
        AbstractParser.addError(editor, MessageFormat.format(Messages.DataBindingsRootInfo_errTargetArgumentNotFound, arguments[2]), new Throwable());
        return null;
    }
    // target AST property
    PropertyInfo targetAstProperty = (PropertyInfo) resolver.getModel(arguments[3]);
    if (targetAstProperty == null) {
        AbstractParser.addError(editor, MessageFormat.format(Messages.DataBindingsRootInfo_errTargetPropertyArgumentNotFound, arguments[3]), new Throwable());
        return null;
    }
    // target property
    ObserveInfo targetProperty = targetAstProperty.getObserveProperty(target);
    if (targetProperty == null) {
        AbstractParser.addError(editor, MessageFormat.format(Messages.DataBindingsRootInfo_errTargetProperty2NotFound, arguments[2], arguments[3]), new Throwable());
        targetProperty = createDefaultProperty(targetAstProperty);
    } else {
        assertObserves(types, 1, target, targetAstProperty, targetProperty);
    }
    // binding
    return addBinding(editor, signature, arguments, new AutoBindingInfo(strategyInfo, target, targetProperty, targetAstProperty, model, modelProperty, modelAstProperty));
}
Also used : UpdateStrategyInfo(org.eclipse.wb.internal.swing.databinding.model.bindings.UpdateStrategyInfo) ElPropertyObserveInfo(org.eclipse.wb.internal.swing.databinding.model.beans.ElPropertyObserveInfo) IGenericType(org.eclipse.wb.internal.swing.databinding.model.generic.IGenericType) ObjectPropertyInfo(org.eclipse.wb.internal.swing.databinding.model.properties.ObjectPropertyInfo) AutoBindingInfo(org.eclipse.wb.internal.swing.databinding.model.bindings.AutoBindingInfo) PropertyInfo(org.eclipse.wb.internal.swing.databinding.model.properties.PropertyInfo) ElPropertyInfo(org.eclipse.wb.internal.swing.databinding.model.properties.ElPropertyInfo) ObjectPropertyInfo(org.eclipse.wb.internal.swing.databinding.model.properties.ObjectPropertyInfo) BeanPropertyInfo(org.eclipse.wb.internal.swing.databinding.model.properties.BeanPropertyInfo)

Example 3 with AutoBindingInfo

use of org.eclipse.wb.internal.swing.databinding.model.bindings.AutoBindingInfo in project windowbuilder by eclipse.

the class DataBindingsRootInfo method createAutoBindingForProperties.

/**
 * Bindings.createAutoBinding(UpdateStrategy, SS, Property<SS, SV>, TS, Property<TS, TV>,
 * [String])
 */
private BindingInfo createAutoBindingForProperties(AstEditor editor, String signature, MethodInvocation invocation, Expression[] arguments, IModelResolver resolver) throws Exception {
    // strategy
    UpdateStrategyInfo strategyInfo = createStrategy(arguments[0]);
    // model object
    ObserveInfo model = getObserveInfo(arguments[1]);
    if (model == null) {
        AbstractParser.addError(editor, MessageFormat.format(Messages.DataBindingsRootInfo_errModelArgumentNotFound, arguments[1]), new Throwable());
        return null;
    }
    // model AST property
    PropertyInfo modelAstProperty = (PropertyInfo) resolver.getModel(arguments[2]);
    if (modelAstProperty == null) {
        AbstractParser.addError(editor, MessageFormat.format(Messages.DataBindingsRootInfo_errModelPropertyArgumentNotFound, arguments[2]), new Throwable());
        return null;
    }
    // model property
    ObserveInfo modelProperty = modelAstProperty.getObserveProperty(model);
    IGenericType[] types = GenericUtils.getReturnTypeArguments(editor, invocation, 4);
    if (modelProperty == null) {
        AbstractParser.addError(editor, MessageFormat.format(Messages.DataBindingsRootInfo_errModelProperty2NotFound, arguments[1], arguments[2]), new Throwable());
        modelProperty = createDefaultProperty(modelAstProperty);
    } else {
        assertObserves(types, 0, model, modelAstProperty, modelProperty);
    }
    // target object
    ObserveInfo target = getObserveInfo(arguments[3]);
    if (target == null) {
        AbstractParser.addError(editor, MessageFormat.format(Messages.DataBindingsRootInfo_errTargetArgumentNotFound, arguments[3]), new Throwable());
        return null;
    }
    // target AST property
    PropertyInfo targetAstProperty = (PropertyInfo) resolver.getModel(arguments[4]);
    if (targetAstProperty == null) {
        AbstractParser.addError(editor, MessageFormat.format(Messages.DataBindingsRootInfo_errArgumentNotFound, arguments[4]), new Throwable());
        return null;
    }
    // target property
    ObserveInfo targetProperty = targetAstProperty.getObserveProperty(target);
    if (targetProperty == null) {
        AbstractParser.addError(editor, MessageFormat.format(Messages.DataBindingsRootInfo_errTargetProperty2NotFound, arguments[3], arguments[4]), new Throwable());
        targetProperty = createDefaultProperty(targetAstProperty);
    } else {
        assertObserves(types, 2, target, targetAstProperty, targetProperty);
    }
    // binding
    return addBinding(editor, signature, arguments, new AutoBindingInfo(strategyInfo, target, targetProperty, targetAstProperty, model, modelProperty, modelAstProperty));
}
Also used : UpdateStrategyInfo(org.eclipse.wb.internal.swing.databinding.model.bindings.UpdateStrategyInfo) ElPropertyObserveInfo(org.eclipse.wb.internal.swing.databinding.model.beans.ElPropertyObserveInfo) IGenericType(org.eclipse.wb.internal.swing.databinding.model.generic.IGenericType) AutoBindingInfo(org.eclipse.wb.internal.swing.databinding.model.bindings.AutoBindingInfo) PropertyInfo(org.eclipse.wb.internal.swing.databinding.model.properties.PropertyInfo) ElPropertyInfo(org.eclipse.wb.internal.swing.databinding.model.properties.ElPropertyInfo) ObjectPropertyInfo(org.eclipse.wb.internal.swing.databinding.model.properties.ObjectPropertyInfo) BeanPropertyInfo(org.eclipse.wb.internal.swing.databinding.model.properties.BeanPropertyInfo)

Example 4 with AutoBindingInfo

use of org.eclipse.wb.internal.swing.databinding.model.bindings.AutoBindingInfo in project windowbuilder by eclipse.

the class BindValueTest method test_strategy_policy_variable.

// //////////////////////////////////////////////////////////////////////////
// 
// Tests
// 
// //////////////////////////////////////////////////////////////////////////
public void test_strategy_policy_variable() throws Exception {
    JPanelInfo shell = DatabindingTestUtils.parseTestSource(this, new String[] { "public class Test extends JPanel {", "  public static class MyBean {", "    protected String name;", "    public String getName() {", "      return name;", "    }", "    public void setName(String newName) {", "      this.name = newName;", "    }", "  }", "  public static void main(String[] args) {", "    JFrame frame = new JFrame();", "    frame.getContentPane().add(new Test(), BorderLayout.CENTER);", "    frame.setMinimumSize(new Dimension(500, 500));", "    frame.setVisible(true);", "    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);", "  }", "  protected MyBean myBean = new MyBean();", "  private JLabel label;", "  private JTextField textField;", "  private JButton button;", "  public Test() {", "    label = new JLabel();", "    add(label);", "    textField = new JTextField();", "    add(textField);", "    button = new JButton();", "    add(button);", "    initDataBindings();", "  }", "  AutoBinding.UpdateStrategy m_strategy = AutoBinding.UpdateStrategy.READ_ONCE;", "  protected void initDataBindings() {", "    {", "      BeanProperty<MyBean, String> modelBeanProperty = BeanProperty.create(\"name\");", "      BeanProperty<JLabel, String> labelBeanProperty = BeanProperty.create(\"text\");", "      AutoBinding.UpdateStrategy strategy = AutoBinding.UpdateStrategy.READ;", "      AutoBinding<MyBean, String, JLabel, String> autoBinding = Bindings.createAutoBinding(", "        strategy, myBean, modelBeanProperty, label, labelBeanProperty);", "      autoBinding.bind();", "    }", "    {", "      BeanProperty<MyBean, String> modelBeanProperty = BeanProperty.create(\"name\");", "      BeanProperty<JTextField, String> textFieldBeanProperty = BeanProperty.create(\"text\");", "      AutoBinding<MyBean, String, JTextField, String> autoBinding = Bindings.createAutoBinding(", "        AutoBinding.UpdateStrategy.READ_WRITE, myBean, modelBeanProperty, textField, textFieldBeanProperty);", "      autoBinding.bind();", "    }", "    {", "      BeanProperty<MyBean, String> modelBeanProperty = BeanProperty.create(\"name\");", "      BeanProperty<JButton, String> buttonBeanProperty = BeanProperty.create(\"text\");", "      AutoBinding<MyBean, String, JButton, String> autoBinding = Bindings.createAutoBinding(", "        m_strategy, myBean, modelBeanProperty, button, buttonBeanProperty);", "      autoBinding.bind();", "    }", "  }", "}" });
    assertNotNull(shell);
    // 
    DatabindingsProvider provider = getDatabindingsProvider();
    List<IBindingInfo> bindings = provider.getBindings();
    // 
    assertNotNull(bindings);
    assertEquals(3, bindings.size());
    // label bindings
    {
        assertInstanceOf(AutoBindingInfo.class, bindings.get(0));
        AutoBindingInfo binding = (AutoBindingInfo) bindings.get(0);
        // 
        UpdateStrategyInfo strategyInfo = binding.getStrategyInfo();
        assertEquals("READ", strategyInfo.getStrategyValue());
    }
    // text bindings
    {
        assertInstanceOf(AutoBindingInfo.class, bindings.get(1));
        AutoBindingInfo binding = (AutoBindingInfo) bindings.get(1);
        // 
        UpdateStrategyInfo strategyInfo = binding.getStrategyInfo();
        assertEquals("READ_WRITE", strategyInfo.getStrategyValue());
    }
    // button bindings
    {
        assertInstanceOf(AutoBindingInfo.class, bindings.get(2));
        AutoBindingInfo binding = (AutoBindingInfo) bindings.get(2);
        // 
        UpdateStrategyInfo strategyInfo = binding.getStrategyInfo();
        assertEquals("READ_ONCE", strategyInfo.getStrategyValue());
    }
}
Also used : UpdateStrategyInfo(org.eclipse.wb.internal.swing.databinding.model.bindings.UpdateStrategyInfo) JPanelInfo(org.eclipse.wb.internal.swing.model.component.JPanelInfo) IBindingInfo(org.eclipse.wb.internal.core.databinding.model.IBindingInfo) DatabindingsProvider(org.eclipse.wb.internal.swing.databinding.DatabindingsProvider) AutoBindingInfo(org.eclipse.wb.internal.swing.databinding.model.bindings.AutoBindingInfo)

Aggregations

AutoBindingInfo (org.eclipse.wb.internal.swing.databinding.model.bindings.AutoBindingInfo)4 UpdateStrategyInfo (org.eclipse.wb.internal.swing.databinding.model.bindings.UpdateStrategyInfo)4 PropertyInfo (org.eclipse.wb.internal.swing.databinding.model.properties.PropertyInfo)3 IBindingInfo (org.eclipse.wb.internal.core.databinding.model.IBindingInfo)2 ElPropertyObserveInfo (org.eclipse.wb.internal.swing.databinding.model.beans.ElPropertyObserveInfo)2 IGenericType (org.eclipse.wb.internal.swing.databinding.model.generic.IGenericType)2 BeanPropertyInfo (org.eclipse.wb.internal.swing.databinding.model.properties.BeanPropertyInfo)2 ElPropertyInfo (org.eclipse.wb.internal.swing.databinding.model.properties.ElPropertyInfo)2 ObjectPropertyInfo (org.eclipse.wb.internal.swing.databinding.model.properties.ObjectPropertyInfo)2 IObserveInfo (org.eclipse.wb.internal.core.databinding.model.IObserveInfo)1 DatabindingsProvider (org.eclipse.wb.internal.swing.databinding.DatabindingsProvider)1 ObserveInfo (org.eclipse.wb.internal.swing.databinding.model.ObserveInfo)1 VirtualBindingInfo (org.eclipse.wb.internal.swing.databinding.model.bindings.VirtualBindingInfo)1 JPanelInfo (org.eclipse.wb.internal.swing.model.component.JPanelInfo)1