Illustration of Responding to Domain Object Additions and Removals
Let us take a good look at just how to react to domain object modifications. Why don’t we include a book that is new one of many going containers. We shall include this book in reaction to a button push. You will need to comprehend, but, that this domain modification could originate from “anywhere” – a database trigger, a background thread or several other system. We utilize a button press to help keep it easy.
Whenever you click the “Add New Book” key in the view’s toolbar, a book would be included with the chosen going field. What goes on as soon as the button is pressed? As soon as the SWT switch is presed the OS yields a meeting this is certainly forwarded towards the switch’s selection listener. The choice listener method adds a new guide to the chosen going box. Whenever a new guide is added, the going package will alert its audience that a domain modification has taken place. Since we included this content provider as a domain listener, it is notified of this modification. This content provider then updates the tree audience.
If there’s nothing chosen, the guide may be included with the topmost box that is moving.
Let us have a look at the code.
The addNewBook technique is named as soon as the “Add a brand new Book” toolbar switch is pressed. Realize that if numerous products are chosen, we ignore them all with the exception of the first one. Also observe that in the event that chosen item just isn’t a moving field, we ask the chosen product for the parent, which is a box that is moving. After we have actually the going package domain item, we tell it to include a book that is new.
The box that is moving add technique is not too interesting. It just adds the written guide and notifies its audience that a book happens to be added. […]