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));
}
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());
}
}
Aggregations