Search in sources :

Example 1 with DatabindingsProvider

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;
}
Also used : IObserveInfo(org.eclipse.wb.internal.core.databinding.model.IObserveInfo) ComponentsObserveTypeContainer(org.eclipse.wb.internal.swing.databinding.model.components.ComponentsObserveTypeContainer) BeansObserveTypeContainer(org.eclipse.wb.internal.swing.databinding.model.beans.BeansObserveTypeContainer) NonVisualBeanContainerInfo(org.eclipse.wb.internal.core.model.nonvisual.NonVisualBeanContainerInfo) IObserveInfo(org.eclipse.wb.internal.core.databinding.model.IObserveInfo) ObserveInfo(org.eclipse.wb.internal.swing.databinding.model.ObserveInfo) DatabindingsProvider(org.eclipse.wb.internal.swing.databinding.DatabindingsProvider) Property(org.eclipse.wb.internal.core.model.property.Property) AbstractBindingsProperty(org.eclipse.wb.internal.core.databinding.ui.property.AbstractBindingsProperty)

Example 2 with DatabindingsProvider

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;
}
Also used : DatabindingsProvider(org.eclipse.wb.internal.swing.databinding.DatabindingsProvider) ParseState(org.eclipse.wb.internal.core.databinding.parser.ParseState)

Example 3 with 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());
    }
}
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)

Example 4 with DatabindingsProvider

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);
}
Also used : IObserveInfo(org.eclipse.wb.internal.core.databinding.model.IObserveInfo) JPanelInfo(org.eclipse.wb.internal.swing.model.component.JPanelInfo) IGenericType(org.eclipse.wb.internal.swing.databinding.model.generic.IGenericType) DatabindingsProvider(org.eclipse.wb.internal.swing.databinding.DatabindingsProvider) GenericTypeContainer(org.eclipse.wb.internal.swing.databinding.model.generic.GenericTypeContainer) FieldBeanObserveInfo(org.eclipse.wb.internal.swing.databinding.model.beans.FieldBeanObserveInfo)

Aggregations

DatabindingsProvider (org.eclipse.wb.internal.swing.databinding.DatabindingsProvider)4 IObserveInfo (org.eclipse.wb.internal.core.databinding.model.IObserveInfo)2 JPanelInfo (org.eclipse.wb.internal.swing.model.component.JPanelInfo)2 IBindingInfo (org.eclipse.wb.internal.core.databinding.model.IBindingInfo)1 ParseState (org.eclipse.wb.internal.core.databinding.parser.ParseState)1 AbstractBindingsProperty (org.eclipse.wb.internal.core.databinding.ui.property.AbstractBindingsProperty)1 NonVisualBeanContainerInfo (org.eclipse.wb.internal.core.model.nonvisual.NonVisualBeanContainerInfo)1 Property (org.eclipse.wb.internal.core.model.property.Property)1 ObserveInfo (org.eclipse.wb.internal.swing.databinding.model.ObserveInfo)1 BeansObserveTypeContainer (org.eclipse.wb.internal.swing.databinding.model.beans.BeansObserveTypeContainer)1 FieldBeanObserveInfo (org.eclipse.wb.internal.swing.databinding.model.beans.FieldBeanObserveInfo)1 AutoBindingInfo (org.eclipse.wb.internal.swing.databinding.model.bindings.AutoBindingInfo)1 UpdateStrategyInfo (org.eclipse.wb.internal.swing.databinding.model.bindings.UpdateStrategyInfo)1 ComponentsObserveTypeContainer (org.eclipse.wb.internal.swing.databinding.model.components.ComponentsObserveTypeContainer)1 GenericTypeContainer (org.eclipse.wb.internal.swing.databinding.model.generic.GenericTypeContainer)1 IGenericType (org.eclipse.wb.internal.swing.databinding.model.generic.IGenericType)1