Reputation: 6232
I am looking to implement undo/redo file/folder functionality for edit/delete/move etc using java. Is that possible ?
Detail: I am watching a given folder using javaFileWatcher
, i get a message from watcher that if any file/folder created/edited/deleted/renamed. now i want if any user has deleted/created any file/folder i would be able to undo it using java. can any one help.
Note: I am using windows
Thanks in advance.
Upvotes: 2
Views: 533
Reputation: 12367
As a kickoff idea have a look at the Command pattern. This is usually how undo/redo things are implemented. The idea is that you kind of store everything that is "important" about an operation into a single object and you store those in an ordered collection.
In your case the fact that you want to monitor the FS and not your own data model makes things really hard. However if you can afford redundant data storage then hypothetically it can be done I think. (I suggest you reading about the way git SCM works. I mean that it stores everything in a single .git
folder and it is capable of restoring any previous state in its so called working directory from the compressed data it stores.)
Actually if you could involve git into your program then it would be much easier. I am thinking that you have a git repo initialized in the directory that you want to supervise and then every time that you are being notified about some FS change, you can ask git (git status
) to tell you which files got changed actually. Even deleted file can be restored then using simple git commands.
This is far from a complete answer to your question however I might have given some ideas. Good luck.
Upvotes: 1
Reputation: 8662
Not possible, a delete is final, there is no recycle bin like in the OS, you have to implement it by yourself.
Upvotes: 3