Announcement Announcement Module
Collapse
No announcement yet.
Problem with nested objects Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with nested objects

    Hello,

    I have a problem with nested properties bound to a form model. The first time the dialog is created the text in the text fields are synchronized with the form object, but if I change the form model only the root properties change, the nested ones remain the same. Is there a way to get around this and obtain the same functionality?

    Below I attached a quick & dirty example of the problem.

    Tks,
    Catalin

    Code:
    class Bean1
    {
    	public Bean2 getBean()
    	{
    		return bean;
    	}
    
    	public void setBean( Bean2 bean )
    	{
    		this.bean = bean;
    	}
    
    	public String getProp()
    	{
    		return prop;
    	}
    
    	public void setProp( String prop )
    	{
    		this.prop = prop;
    	}
    
    	Bean2 bean;
    	String prop;
    }
    
    class Bean2
    {
    	public String getProp()
    	{
    		return prop;
    	}
    
    	public void setProp( String prop )
    	{
    		this.prop = prop;
    	}
    
    	String prop;
    }
    
    public class NestedPropertyTest extends AbstractDialogPage
    {
    	SwingFormModel formModel = null;
    
    	protected JComponent createControl()
    	{
    		return new JButton( "GIGIG" )
    		{
    			{
    				addActionListener( new ActionListener()
    				{
    					public void actionPerformed( ActionEvent e )
    					{
    						TitledPageApplicationDialog dialog = new TitledPageApplicationDialog( new AbstractDialogPage( "test" )
    						{
    							protected JComponent createControl()
    							{
    								Bean1 bean = new Bean1();
    								bean.setProp( "mumuProp" );
    								bean.setBean( new Bean2() );
    								bean.getBean().setProp( "mumuPropNested" );
    								NestedPropertyTest.this.formModel = SwingFormModel.createFormModel( bean );
    
    								JGoodiesBeanFormBuilder fb = new JGoodiesBeanFormBuilder( NestedPropertyTest.this.formModel, new FormLayout( "pref, pref", "pref, pref" ) );
    
    								fb.add( "bean.prop" );
    								fb.add( "prop" );
    
    								JComponent form = fb.getForm();
    
    								CellConstraints cc = new CellConstraints();
    
    								form.add( new JButton( "Test" )
    								{
    									{
    										addActionListener( new ActionListener()
    										{
    											public void actionPerformed( ActionEvent e )
    											{
    												Bean1 bean = new Bean1();
    												bean.setProp( "cucuProp" );
    												bean.setBean( new Bean2() );
    												bean.getBean().setProp( "cucuPropNested" );
    
    												System.err.println( "gigi" );
    
    												NestedPropertyTest.this.formModel.setFormObject( bean );
    												NestedPropertyTest.this.formModel.revert();
    											}
    										} );
    									}
    								}, cc.xy( 2, 1 ) );
    
    								return form;
    							}
    						} )
    						{
    							protected boolean onFinish()
    							{
    								return false;  //To change body of implemented methods use File | Settings | File Templates.
    							}
    						};
    						dialog.showDialog();
    					}
    				} );
    			}
    		};
    	}

  • #2
    This is a known problem. A new bug report was created, nevertheless this is the same RCP-57 problem. (just another use case)

    The most simple way to come arround is to add "custom" listeners to sync properties. I suppose when method 'setFormObject(bean) is called, only top level properties (value models) are notified. So you need to add listeners on such top level properties:
    Code:
    NestedPropertyTest.this.formModel.createFormValueModel("bean");           
    ValueChangeListener listener = new ValueChangeListener() {
        public void valueChanged() {
            // update "bean.prop" property
            // when "bean" changes
        }
    };
    NestedPropertyTest.this.formModel.getValueModel("bean").addValueChangeListener(lister);
    ...or try patch 'DefaultFormModel.java.patch' to RCP-57 and report about results.

    Comment

    Working...
    X