Search in sources :

Example 6 with UpdateStrategyInfo

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

the class DataBindingsRootInfo method createBindingForListToJComponent.

/**
 * SwingBindings.createJListBinding(UpdateStrategy, List<E>, JList, [String])<br>
 * SwingBindings.createJTableBinding(UpdateStrategy, List<E>, JTable, [String])<br>
 * SwingBindings.createJComboBoxBinding(UpdateStrategy, List<E>, JComboBox, [String])
 */
private BindingInfo createBindingForListToJComponent(AstEditor editor, String signature, MethodInvocation invocation, Expression[] arguments, IModelResolver resolver, Constructor<? extends BindingInfo> constructor) throws Exception {
    // strategy
    UpdateStrategyInfo strategyInfo = createStrategy(arguments[0]);
    // model object
    ObserveInfo model = getBeanObserveInfo(arguments[1]);
    if (model == null) {
        AbstractParser.addError(editor, MessageFormat.format(Messages.DataBindingsRootInfo_errModelArgumentNotFound, arguments[1]), new Throwable());
        return null;
    }
    // model properties
    PropertyInfo modelAstProperty = new ObjectPropertyInfo(model.getObjectType());
    ObserveInfo modelProperty = modelAstProperty.getObserveProperty(model);
    Assert.isNotNull(modelProperty);
    assertEquals(modelProperty, modelAstProperty);
    // target object
    ObserveInfo target = getComponentObserveInfo(arguments[2]);
    if (target == null) {
        AbstractParser.addError(editor, MessageFormat.format(Messages.DataBindingsRootInfo_errTargetArgumentNotFound, arguments[2]), new Throwable());
        return null;
    }
    // target properties
    PropertyInfo targetAstProperty = new ObjectPropertyInfo(target.getObjectType());
    ObserveInfo targetProperty = targetAstProperty.getObserveProperty(target);
    Assert.isNotNull(targetProperty);
    assertEquals(targetProperty, targetAstProperty);
    // binding
    return addBinding(editor, signature, arguments, constructor.newInstance(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) ObjectPropertyInfo(org.eclipse.wb.internal.swing.databinding.model.properties.ObjectPropertyInfo) 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 7 with UpdateStrategyInfo

use of org.eclipse.wb.internal.swing.databinding.model.bindings.UpdateStrategyInfo 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

UpdateStrategyInfo (org.eclipse.wb.internal.swing.databinding.model.bindings.UpdateStrategyInfo)7 PropertyInfo (org.eclipse.wb.internal.swing.databinding.model.properties.PropertyInfo)6 ElPropertyObserveInfo (org.eclipse.wb.internal.swing.databinding.model.beans.ElPropertyObserveInfo)4 AutoBindingInfo (org.eclipse.wb.internal.swing.databinding.model.bindings.AutoBindingInfo)4 BeanPropertyInfo (org.eclipse.wb.internal.swing.databinding.model.properties.BeanPropertyInfo)4 ElPropertyInfo (org.eclipse.wb.internal.swing.databinding.model.properties.ElPropertyInfo)4 ObjectPropertyInfo (org.eclipse.wb.internal.swing.databinding.model.properties.ObjectPropertyInfo)4 IGenericType (org.eclipse.wb.internal.swing.databinding.model.generic.IGenericType)3 IBindingInfo (org.eclipse.wb.internal.core.databinding.model.IBindingInfo)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 JComboBoxBindingInfo (org.eclipse.wb.internal.swing.databinding.model.bindings.JComboBoxBindingInfo)1 JListBindingInfo (org.eclipse.wb.internal.swing.databinding.model.bindings.JListBindingInfo)1 JTableBindingInfo (org.eclipse.wb.internal.swing.databinding.model.bindings.JTableBindingInfo)1 VirtualBindingInfo (org.eclipse.wb.internal.swing.databinding.model.bindings.VirtualBindingInfo)1 JPanelInfo (org.eclipse.wb.internal.swing.model.component.JPanelInfo)1