Reputation: 10988
I am writing a class to handle with file reading and writing. I used a boolean variable named autoSave. If autoSave is true, when addRow(someData) method called, it writes given data to file immediately. If autoSave is false, it puts data to an ArrayList and wait for Save() method call to write them to file. Everything is okay with that.
What i want is; if autoSave is false, when a row added (addRow called), let user to listen for that event. So person who will use this class can refresh his gui easily.
Upvotes: 0
Views: 89
Reputation: 19667
It seems you want to create a graphical user interface?
If I understood you correctly...
Changes happening to the underlying data model (I.e. click on "Add Row" button) should be directly reflected in the view (the GUI that actually can be seen), even if 'Auto Save' is turned off.
Likely a better approach to this, instead of getting the user to know he should refresh, possibly via the Observer pattern, is to automatically refresh/redraw the GUI and show the changes. This redraw would be triggered by an observer, too. It seems you know how to refresh the graphical view?
Or is a redraw actually a complete reload of the saved file?
It could help if you told the language/framework you are developing in.
Upvotes: 0
Reputation: 44240
Make use of the Observer Pattern. A concrete implementation of this pattern includes property change listeners.
Upvotes: 2