setData

Hi,

Is a simple question…
Example : In a button clicklistener
Which is better or what is the diference? Execute a stored function stored with setData or calling de function directly?


			        b = new NativeButton("Manteniment de Autors",change);
			        b.setData(buildComponentsAutors());
			        menu.addComponent(b);

		     ComponentContainer buildComponentsAutors() {
			    	
		    		
			        TabSheet ts = new TabSheet();
			        ts.setSizeFull();
			        ....

			        return ts;
			    }
//What is better or diference

[b]
			        final Button.ClickListener change = new Button.ClickListener() {
						
					@Override
				public void buttonClick(ClickEvent event) {
    		                        split.setSecondComponent((Component) event.getButton().getData());		
						}
					};

//   or
			        final Button.ClickListener change = new Button.ClickListener() {
						
				@Override
				public void buttonClick(ClickEvent event) {
    		                          split.setSecondComponent(buildComponentsAutors());
							
						}
					};

[/b]

Hi,

Your setData() version ( A ) is not storing a function (that’s not actually possible in Java like that), but instead will create the new TabSheet (and all that’s inside of it) before it is actually needed, storing the whole structure with setData().

The other version ( B ) creates the TabSheet at the time it is actually needed.

A would be better if it takes a (too) long time to create the TabSheet and memory consumption is not an issue.
B is better if creating the TabSheet does not take a (too) long time.

I’m willing to bet B is the better alternative for you.

HTH

Best Regards,
Marc

In first time thanks for your answer.

I was confused because I saw the version ( A ) in the addon ReindeerMods example.

Thanks again!