Say I have a component C that is being used in 2 places in my application. For example, I have a list of folders that are being displayed in 2 tabs. When user renames a folder in one part, this change should be reflected in the other as well.
I'm thinking to use EventBus for this and make the folders component to fire an EventBus event, say FolderChangedEvent. This event will be intercepted by the second folder component which will automatically update it's folder list.
The question is that if I want at some point to use this Folder component in a 3-rd place, this place will also have the folder list updated. This might not be a desired behavior of the application.
Normally, I'd make the Folder component have an own addFolderChangedHandler(...) method but since this component is quite complex and has sub-components, this might create spaghetti-type of code. However, I don't feel like this component should contain any application-specific logic and throw events directly in the application's EventBus which is a big too high-level for it.
What is the best practice for this case and how do you efficiently use EventBus?
The purpose of the event bus is make event handling easier and yes to make code more readable and manageable. I'll answer this question assuming your dilemma is on how to classify events.
The GWTEvent class has a source() method. This tells you who fired the event. If that isn't acceptable , then you can always have an "id" field in your event which is populated by the sender. So if TreeView1 is firing the event , the id of the event will be set to "treeView1". When the event handler receives this event , it'll check for id and decide wether or not to handle the event. This way you can use a single "God" event handler for your entire application.