How to set Content In layout through Custom Component?

Hello everyone,

I know, Theme isn’t good enough to begin with a problem. So, here’s some preface:

I have Completed a multiple layout screen. ATM, I’m writting a CustomComponent which has some controls (Buttons).
everything goes fine ,when i attach custom component using this:

VerticalLayout menuBar = new VerticalLayout();
menuBar.addComponent(MyFirstCustomComponent);

Here’s the thing … clicking on MyFirstCustomComonent’s buttons it should change contents in annother layout like:

annotherLayout.setContent(new PageB());

But i can’t reach it through CustomComponent.

Question is: How could i get annother Layout?

Cheers

P.S Sorry, for my bad English.

Simplest solution would be just to pass the instance of the other layout to the customcomponent e.g. in the Constructor.
If that is not possible you could also create a variable in the UI - Singleton that you can staticly reach from pretty much any point of your application. So this way you can set the instance something like MyVaadinUI.get().anotherlayout = …
and reach it with MyVaadinUI.get().anotherlayout.setContent… though the first option is preferred for such a simple case.
As this is more of a general Java Problem you will probably get a lot of information scattered around the web when googling for something like “access variable in other class” or somthing along those lines.

Just as an addition to Marius’ answer (which are both correct), in more complex cases you might want to take a look at event buses for this type of communication. There is a lot of info about them online too. With Vaadin, you can use e.g. the blackboard addon, or if you are using CDI, you can use CDI Events.