use of org.eclipse.wb.internal.swing.databinding.DatabindingsProvider in project windowbuilder by eclipse.
the class BindingsProperty method createProperties.
// //////////////////////////////////////////////////////////////////////////
//
// AbstractBindingsProperty
//
// //////////////////////////////////////////////////////////////////////////
@Override
protected Property[] createProperties() throws Exception {
DatabindingsProvider provider = (DatabindingsProvider) m_context.provider;
if (m_context.objectInfo.getParent() instanceof NonVisualBeanContainerInfo) {
BeansObserveTypeContainer container = (BeansObserveTypeContainer) provider.getContainer(ObserveType.BEANS);
m_context.observeObject = container.resolve(m_context.javaInfo());
} else {
ComponentsObserveTypeContainer container = (ComponentsObserveTypeContainer) provider.getContainer(ObserveType.WIDGETS);
m_context.observeObject = container.resolve(m_context.javaInfo());
}
if (m_context.observeObject == null) {
return new Property[0];
}
//
List<IObserveInfo> observes = Lists.newArrayList(m_context.observeObject.getChildren(ChildrenContext.ChildrenForPropertiesTable));
for (Iterator<IObserveInfo> I = observes.iterator(); I.hasNext(); ) {
if (!includeProperty(I.next())) {
I.remove();
}
}
//
Property[] properties = new Property[observes.size()];
for (int i = 0; i < properties.length; i++) {
ObserveInfo observeProperty = (ObserveInfo) observes.get(i);
if (observeProperty.getCreationType() == ObserveCreationType.SelfProperty) {
switch(ComponentsObserveTypeContainer.getCreationType(m_context.javaInfo().getDescription().getComponentClass())) {
case JListBinding:
properties[i] = new JListSelfObserveProperty(m_context, observeProperty);
continue;
case JTableBinding:
properties[i] = new JTableSelfObserveProperty(m_context, observeProperty);
continue;
case JComboBoxBinding:
properties[i] = new JComboBoxSelfObserveProperty(m_context, observeProperty);
continue;
}
}
properties[i] = new ObserveProperty(m_context, observeProperty);
}
return properties;
}
use of org.eclipse.wb.internal.swing.databinding.DatabindingsProvider in project windowbuilder by eclipse.
the class AbstractBindingTest method getDatabindingsProvider.
// //////////////////////////////////////////////////////////////////////////
//
// Utils
//
// //////////////////////////////////////////////////////////////////////////
protected final DatabindingsProvider getDatabindingsProvider() throws Exception {
ParseState parseState = DatabindingRootProcessor.STATES.get(m_lastEditor.getModelUnit());
assertNotNull(parseState);
assertNotNull(parseState.databindingsProvider);
assertInstanceOf(DatabindingsProvider.class, parseState.databindingsProvider);
return (DatabindingsProvider) parseState.databindingsProvider;
}
use of org.eclipse.wb.internal.swing.databinding.DatabindingsProvider 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());
}
}
use of org.eclipse.wb.internal.swing.databinding.DatabindingsProvider in project windowbuilder by eclipse.
the class GenericUtilsTest method test_getObjectType.
// //////////////////////////////////////////////////////////////////////////
//
// Tests
//
// //////////////////////////////////////////////////////////////////////////
public void test_getObjectType() throws Exception {
JPanelInfo shell = DatabindingTestUtils.parseTestSource(this, new String[] { "import java.util.List;", "import java.util.Map;", "public class Test extends JPanel {", " private List<Map<String,Number>> datas;", " public Test() {", " }", "}" });
assertNotNull(shell);
//
DatabindingsProvider provider = getDatabindingsProvider();
List<IObserveInfo> beanObserves = provider.getObserves(ObserveType.BEANS);
List<FieldBeanObserveInfo> fieldObserves = GenericsUtils.select(beanObserves, FieldBeanObserveInfo.class);
FieldBeanObserveInfo datas = fieldObserves.get(0);
IGenericType datasObjectType = datas.getObjectType();
//
assertThat(datasObjectType).isInstanceOf(GenericTypeContainer.class);
GenericTypeContainer datasType = (GenericTypeContainer) datasObjectType;
assertThat(datasType.getFullTypeName()).isEqualTo("java.util.List<java.util.Map<java.lang.String, java.lang.Number>>");
//
IGenericType datasItemObjectType = datasType.getSubType(0);
//
assertThat(datasItemObjectType).isInstanceOf(GenericTypeContainer.class);
GenericTypeContainer datasItemType = (GenericTypeContainer) datasItemObjectType;
assertThat(datasItemType.getFullTypeName()).isEqualTo("java.util.Map<java.lang.String, java.lang.Number>");
//
List<IGenericType> subTypes = datasItemType.getSubTypes();
assertThat(subTypes.size()).isEqualTo(2);
}
Aggregations